The unit manager reads the file unitfile.txt. The file loaded is the first found according the following search sequence:
gridlabd.exe GLPATH environment variable.Units are based on 6 physical/economic constants:
#c=2.997925e8 ; speed of light (m/s) #e=1.602189246e-19 ; electron charge (C) #h=6.62617636e-24 ; Plank's constant (kg.m.m/s) #k=1.38066244e-13 ; Boltzman's constant (kg.m.m/s.s.K) #m=9.10953447e-31 ; electron rest mass (kg) #s=1.233270e4 ; average price of gold in 1990 ($/kg - 383.59$/oz)
From these are derived all the fundamental SI units:
m=-1,0,1,0,-1,0,4.121487e01,0,7 kg=0,0,0,0,1,0,1.09775094e30,0,10 s=-2,0,1,0,-1,0,1.235591e10,0,7 A=2,1,-1,0,1,0,5.051397e08,0,7 K=2,0,0,-1,1,0,1.686358e00,0,7 cd=4,0,-1,0,2,0,1.447328E+00,0,7
An addition currency unit is defined because it's really useful:
1990$=0,0,0,0,1,1,1.097751e30,0,7
Based on these units, all the other units are derived using simple formulae, e.g.:
; Length cm=0.01 m mm=0.001 m km=1000 m in=2.54 cm ft=12 in yd=3 ft mile=5280 ft
where
where c, e, h, k, m, and s are the constants defined above, and the k terms are the unit terms defined for that unit.
Thus, two values can only be added (or subtracted) only if their units are the same (i.e., unit is a common factor), and when two values are multiplied (or divided), the exponential terms of the units are added (or subtracted).
For example, 1 second is defined as
Typedefs | |
| typedef struct s_unit | UNIT |
| the UNIT structure | |
Functions | |
| int | unit_convert (char *from, char *to, double *pValue) |
| Convert a value from one unit to another. | |
| int | unit_convert_complex (UNIT *pFrom, UNIT *pTo, complex *pValue) |
| Convert a complex value from one unit to another. | |
| int | unit_convert_ex (UNIT *pFrom, UNIT *pTo, double *pValue) |
| Convert a value from one unit to another. | |
| UNIT * | unit_find (char *unit) |
| Find a unit. | |
| void | unit_init (void) |
| Initialize the unit manager. | |
| int | unit_test (void) |
| Test the unit manager. | |
| int unit_convert | ( | char * | from, | |
| char * | to, | |||
| double * | pValue | |||
| ) |
Convert a value from one unit to another.
Definition at line 608 of file unit.c.
Referenced by convert_unit_double(), and unit_test().
Convert a complex value from one unit to another.
Definition at line 656 of file unit.c.
References output_error().
Convert a value from one unit to another.
Definition at line 632 of file unit.c.
References output_error().
Referenced by aggregate_mkgroup(), convert_from_complex(), and convert_from_double().
| UNIT * unit_find | ( | char * | unit | ) |
Find a unit.
| unit | the name of the unit |
Definition at line 681 of file unit.c.
References output_error(), and unit_init().
Referenced by aggregate_mkgroup(), class_define_map(), global_create(), and object_get_unit().
| int unit_test | ( | void | ) |
Test the unit manager.
Definition at line 712 of file unit.c.
References output_test(), output_verbose(), and unit_convert().
Referenced by cmdarg_load().