Show
Ignore:
Timestamp:
08/07/2004 09:27:59 PM (8 years ago)
Author:
kstemen
Message:

Put in some comments

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/matml/webselector/php_parser/dbquery.php.inc

    r79 r80  
    11<?php 
     2/*2 things are needed to describe a unit. 1. It's scale, and 2. it's numerical 
     3identifier. 
     4 
     5All basic SI units (and others that cannot be further simplified) are 
     6identified by a prime number, e.g. meter is 3. Once the basic SI unit has been 
     7identified, all units that describe the same thing (but with a different 
     8scale) use the same number, e.g. inch is also 3. To differentiate between 
     9inches and meters, meter has a scale of 1, inch has a scale of 0.0254. The 
     10scale is always expressed in the SI unit with the same number. 
     11 
     12Derrived units are formed by multiplying or dividing the numerical identifier 
     13as well as the scale. This way there is only 1 identifier for each type of 
     14derrived unit. When a value is expressed in a unit, the scale is multiplied 
     15with the value, and afterwards is dropped. So the scale is only necessary for 
     16describing a unit without a value. For a value unit pair, only 2 numbers are 
     17needed. 
     18*/ 
    219class Unit 
    320{ 
     21    //Text name 
    422    var $name; 
     23    //Numerical name. Multiple existing value by scale to get num_name 
    524    var $num_name; 
    6     //Multiple existing value by scale to get num_name 
    725    var $scale; 
    826    function Unit($name,$num_name,$scale) 
     
    1230        $this->scale=$scale; 
    1331    } 
     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") 
    1434    function name_split() 
    1535    { 
     
    1939        return $ret; 
    2040    } 
     41    //Returns a new unit which is this unit divided by other. 
    2142    function div($other) 
    2243    { 
     
    4263        return $ret; 
    4364    } 
     65    //Returns a new unit which is this unit multiplied by other. 
    4466    function mul($other) 
    4567    { 
     
    6587        return $ret; 
    6688    } 
     89    //Returns whether num_name is equal (or as close as they can get for 
     90    //floats) for this unit and other. 
    6791    function equals($other) 
    6892    { 
     
    7195} 
    7296 
     97//List of predefined units 
    7398$unit_infos=array( 
    7499    "g"=>new Unit("g",2,1), 
     
    77102    "s"=>new Unit("s",7,1), 
    78103    "°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 
    79110    "lb"=>new Unit("lb",13,1), 
    80111    "°F"=>new Unit("°F",17,1), 
     
    102133    //average value out of all the matches 
    103134    var $avg_value; 
     135    //numerical unit identifier 
    104136    var $num_unit; 
    105137    //number of matches 
     
    113145} 
    114146 
     147//units_element is a Units XML object. 
    115148function parse_units($units_element) 
    116149{ 
     
    147180} 
    148181 
     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. 
    149186function get_property_data($filename,$property_names) 
    150187{ 
     
    159196   $translation_string="\"abcdefghijklmnopqrstuvwxyz'\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; 
    160197   $ret=array(); 
     198   //Get the material name 
    161199   $details=$context->xpath_eval("/MatML_Doc/Material/BulkDetails/Name/text()"); 
    162200   $Matid=$details->nodeset[0]->get_content(); 
     
    218256} 
    219257 
     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? 
    220262function fractionalize($number) 
    221263{ 
     
    231273} 
    232274 
     275/*Gets the power of factor in number. Factor need not be a prime factor. The 
     276power can be 0 or negative too. 
     277Examples: 
     278get_factor_power(12,3)=1 
     279get_factor_power(12,2)=2 
     280get_factor_power(12,6)=1 
     281get_factor_power(12,5)=0 
     282 
     283get_factor_power(5/3,3)=-1 
     284*/ 
    233285function get_factor_power($number,$factor) 
    234286{ 
     
    255307} 
    256308 
     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. 
    257312function force_unit_match($material,$unit,&$property_data) 
    258313{