Changeset 80 for trunk/matml/webselector/php_parser/dbquery.php.inc
- Timestamp:
- 08/07/2004 09:27:59 PM (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/webselector/php_parser/dbquery.php.inc
r79 r80 1 1 <?php 2 /*2 things are needed to describe a unit. 1. It's scale, and 2. it's numerical 3 identifier. 4 5 All basic SI units (and others that cannot be further simplified) are 6 identified by a prime number, e.g. meter is 3. Once the basic SI unit has been 7 identified, all units that describe the same thing (but with a different 8 scale) use the same number, e.g. inch is also 3. To differentiate between 9 inches and meters, meter has a scale of 1, inch has a scale of 0.0254. The 10 scale is always expressed in the SI unit with the same number. 11 12 Derrived units are formed by multiplying or dividing the numerical identifier 13 as well as the scale. This way there is only 1 identifier for each type of 14 derrived unit. When a value is expressed in a unit, the scale is multiplied 15 with the value, and afterwards is dropped. So the scale is only necessary for 16 describing a unit without a value. For a value unit pair, only 2 numbers are 17 needed. 18 */ 2 19 class Unit 3 20 { 21 //Text name 4 22 var $name; 23 //Numerical name. Multiple existing value by scale to get num_name 5 24 var $num_name; 6 //Multiple existing value by scale to get num_name7 25 var $scale; 8 26 function Unit($name,$num_name,$scale) … … 12 30 $this->scale=$scale; 13 31 } 32 //Splits up the name by the parts on the numerator and denominator. They 33 //are returned as a list (numerator,denominator). E.g. g/cc is ("g","cc") 14 34 function name_split() 15 35 { … … 19 39 return $ret; 20 40 } 41 //Returns a new unit which is this unit divided by other. 21 42 function div($other) 22 43 { … … 42 63 return $ret; 43 64 } 65 //Returns a new unit which is this unit multiplied by other. 44 66 function mul($other) 45 67 { … … 65 87 return $ret; 66 88 } 89 //Returns whether num_name is equal (or as close as they can get for 90 //floats) for this unit and other. 67 91 function equals($other) 68 92 { … … 71 95 } 72 96 97 //List of predefined units 73 98 $unit_infos=array( 74 99 "g"=>new Unit("g",2,1), … … 77 102 "s"=>new Unit("s",7,1), 78 103 "°C"=>new Unit("°C",11,1), 104 //pounds and degrees fahrenheit are given prime numbers because they 105 //cannot be simplified purely by multiplying. 106 //Pounds can be converted to grams or newtons. 107 //Degrees fahrenheit may actually be rankin. 108 //This are converted to SI units based on what the other unit is. 109 //See force_unit_match 79 110 "lb"=>new Unit("lb",13,1), 80 111 "°F"=>new Unit("°F",17,1), … … 102 133 //average value out of all the matches 103 134 var $avg_value; 135 //numerical unit identifier 104 136 var $num_unit; 105 137 //number of matches … … 113 145 } 114 146 147 //units_element is a Units XML object. 115 148 function parse_units($units_element) 116 149 { … … 147 180 } 148 181 182 //filename is the filename of a MatML document 183 //property_names is an array of the properties that should be retrieved from 184 //the file. 185 //An associative array (property name => property data) is returned. 149 186 function get_property_data($filename,$property_names) 150 187 { … … 159 196 $translation_string="\"abcdefghijklmnopqrstuvwxyz'\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; 160 197 $ret=array(); 198 //Get the material name 161 199 $details=$context->xpath_eval("/MatML_Doc/Material/BulkDetails/Name/text()"); 162 200 $Matid=$details->nodeset[0]->get_content(); … … 218 256 } 219 257 258 //Takes a floating point number and returns (numerator, denominator), where 259 //number=numerator/denominator, numerator and denominator are both integers, 260 //and numerator/denominator is a simplified fraction. 261 //Is there a name for this algorithm? 220 262 function fractionalize($number) 221 263 { … … 231 273 } 232 274 275 /*Gets the power of factor in number. Factor need not be a prime factor. The 276 power can be 0 or negative too. 277 Examples: 278 get_factor_power(12,3)=1 279 get_factor_power(12,2)=2 280 get_factor_power(12,6)=1 281 get_factor_power(12,5)=0 282 283 get_factor_power(5/3,3)=-1 284 */ 233 285 function get_factor_power($number,$factor) 234 286 { … … 255 307 } 256 308 309 //Echos an error if the unit does not match that in property_data 310 //It sometimes fudges the units by doing some last minute conversions to get 311 //them to match up. 257 312 function force_unit_match($material,$unit,&$property_data) 258 313 {