20 #include <lal/LALStdlib.h>
23 #include <lal/Units.h>
25 #define UNITDEFSC_TEMPSIZE 20
137 "m",
"kg",
"s",
"A",
"K",
"strain",
"count"
156 const LALUnit lalDimensionlessUnit = { 0, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
160 const LALUnit lalMeterUnit = { 0, { 1, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
161 const LALUnit lalKiloGramUnit = { 0, { 0, 1, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
162 const LALUnit lalSecondUnit = { 0, { 0, 0, 1, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
163 const LALUnit lalAmpereUnit = { 0, { 0, 0, 0, 1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
164 const LALUnit lalKelvinUnit = { 0, { 0, 0, 0, 0, 1, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
165 const LALUnit lalStrainUnit = { 0, { 0, 0, 0, 0, 0, 1, 0}, { 0, 0, 0, 0, 0, 0, 0} };
166 const LALUnit lalADCCountUnit = { 0, { 0, 0, 0, 0, 0, 0, 1}, { 0, 0, 0, 0, 0, 0, 0} };
171 const LALUnit lalHertzUnit = { 0, { 0, 0,-1, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
172 const LALUnit lalNewtonUnit = { 0, { 1, 1,-2, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
173 const LALUnit lalPascalUnit = { 0, {-1, 1,-2, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
174 const LALUnit lalJouleUnit = { 0, { 2, 1,-2, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
175 const LALUnit lalWattUnit = { 0, { 2, 1,-3, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
180 const LALUnit lalCoulombUnit = { 0, { 0, 0, 1, 1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
181 const LALUnit lalVoltUnit = { 0, { 2, 1,-3,-1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
182 const LALUnit lalOhmUnit = { 0, { 2, 1,-3,-2, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
183 const LALUnit lalFaradUnit = { 0, {-2,-1, 4, 2, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
184 const LALUnit lalWeberUnit = { 0, { 2, 1,-2,-1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
185 const LALUnit lalHenryUnit = { 0, { 2, 1,-2,-2, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
186 const LALUnit lalTeslaUnit = { 0, { 0, 1,-2,-1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
191 const LALUnit lalYottaUnit = { 24, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
192 const LALUnit lalZettaUnit = { 21, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
193 const LALUnit lalExaUnit = { 18, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
194 const LALUnit lalPetaUnit = { 15, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
195 const LALUnit lalTeraUnit = { 12, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
196 const LALUnit lalGigaUnit = { 9, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
197 const LALUnit lalMegaUnit = { 6, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
198 const LALUnit lalKiloUnit = { 3, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
199 const LALUnit lalHectoUnit = { 2, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
200 const LALUnit lalDekaUnit = { 1, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
201 const LALUnit lalDeciUnit = { -1, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
202 const LALUnit lalCentiUnit = { -2, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
203 const LALUnit lalMilliUnit = { -3, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
204 const LALUnit lalMicroUnit = { -6, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
205 const LALUnit lalNanoUnit = { -9, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
206 const LALUnit lalPicoUnit = {-12, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
207 const LALUnit lalFemtoUnit = {-15, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
208 const LALUnit lalAttoUnit = {-18, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
209 const LALUnit lalZeptoUnit = {-21, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
210 const LALUnit lalYoctoUnit = {-24, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
215 const LALUnit lalGramUnit = { -3, { 0, 1, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
216 const LALUnit lalAttoStrainUnit = {-18, { 0, 0, 0, 0, 0, 1, 0}, { 0, 0, 0, 0, 0, 0, 0} };
217 const LALUnit lalPicoFaradUnit = {-12, {-2,-1, 2, 2, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} };
223 static int readNumber(
char temp[],
const char **charPtrPtr )
225 CHAR *tempPtr, *tempStopPtr;
231 if ( ! isdigit(**charPtrPtr) )
return 1;
235 *tempPtr = **charPtrPtr;
236 ++tempPtr, ++*charPtrPtr;
237 if (tempPtr >= tempStopPtr)
return 1;
239 while ( isdigit(**charPtrPtr) );
249 CHAR *tempPtr, *tempStopPtr;
255 if ( ! isalpha(**charPtrPtr) )
return 1;
259 *tempPtr = **charPtrPtr;
260 ++tempPtr, ++*charPtrPtr;
261 if (tempPtr >= tempStopPtr)
return 1;
263 while ( isalpha(**charPtrPtr) );
282 if ( !
string || ! input )
291 n = snprintf(s, length,
"10^%d", input->
powerOfTen);
300 const char *delim = (s != string) ? (
const char*)
" " : (
const char*)
"";
306 n = snprintf(s, length,
"%s%s^%d/%d", delim,
lalUnitName[i], numer,
311 n = snprintf(s, length,
"%s%s", delim,
lalUnitName[i]);
315 n = snprintf(s, length,
"%s%s^%d", delim,
lalUnitName[i], numer);
359 int outputAllocated = 0;
377 string += strspn(
string,
"\t\n\v\f\r ");
386 if (*
string ==
'1' && *(
string+1) ==
'0' && *(
string+2) ==
'^')
391 if ( *
string ==
'-' )
404 if ( outputAllocated )
418 if ( outputAllocated )
434 if ( outputAllocated )
449 if ( outputAllocated )
455 if (
output->unitNumerator[i] ||
output->unitDenominatorMinusOne[i] )
457 if ( outputAllocated )
462 if ( *
string ==
' ' || *
string ==
'\0' )
464 output->unitNumerator[i] = 1;
466 else if ( *
string ==
'^' )
471 if ( *
string ==
'-' )
485 if ( outputAllocated )
491 if ( *
string ==
'/' )
498 if (
readNumber( temp, &
string ) || temp[0] ==
'0')
500 if ( outputAllocated )
504 output->unitDenominatorMinusOne[i] = atoi(temp) - 1;
509 if ( outputAllocated )
514 if ( *
string ==
' ') ++string;
517 while ( *
string !=
'\0' );
#define UNITDEFSC_TEMPSIZE
int16_t INT2
Two-byte signed integer.
uint16_t UINT2
Two-byte unsigned integer.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
@ LALNumUnits
The number of units.
#define XLALRealloc(p, n)
const LALUnit lalExaUnit
Exa [1e18].
const LALUnit lalWattUnit
Watt [W ].
const LALUnit lalKelvinUnit
Kelvin [K].
const LALUnit lalHenryUnit
Henry [H].
const LALUnit lalStrainUnit
Strain [1].
const LALUnit lalWeberUnit
Weber [Wb].
const LALUnit lalZeptoUnit
Zepto [1e-21].
static int readString(char temp[UNITDEFSC_TEMPSIZE], const char **charPtrPtr)
const LALUnit lalMicroUnit
Micro [1e-6].
const LALUnit lalTeraUnit
Tera [1e12].
const LALUnit lalDekaUnit
Deka [1e1].
const LALUnit lalCentiUnit
Centi [1e-2].
const LALUnit lalDeciUnit
Deci [1e-1].
const LALUnit lalHectoUnit
Hecto [1e2].
const LALUnit lalKiloGramUnit
kilogram [kg]
const LALUnit lalNewtonUnit
Newton [N].
const LALUnit lalAmpereUnit
Ampere [A].
const LALUnit lalAttoStrainUnit
AttoStrain [1e-18].
const LALUnit lalCoulombUnit
Coulomb [C].
const LALUnit lalZettaUnit
Zetta [1e21].
const LALUnit lalTeslaUnit
Tesla [T].
const LALUnit lalSecondUnit
second [s]
const LALUnit lalGigaUnit
Giga [1e9].
const LALUnit lalGramUnit
Gram [1e-3].
char * XLALUnitToString(const LALUnit *input)
Allocates and returns a new string, which is populated with the unit string.
const LALUnit lalJouleUnit
Joule [J].
const CHAR lalUnitName[LALNumUnits][LALUnitNameSize]
To convert a units structure to a string repesentation, we need to define the names of the basic unit...
const LALUnit lalADCCountUnit
ADC count [count].
const LALUnit lalHertzUnit
Hertz [Hz].
const LALUnit lalMeterUnit
meter [m]
const LALUnit lalPetaUnit
Peta [1e15].
LALUnit * XLALParseUnitString(LALUnit *output, const char *string)
Returns the pointer output upon return or a pointer to newly allocated memory if output was NULL; on ...
const LALUnit lalPicoFaradUnit
PicoFarad [1e-12 F].
const LALUnit lalAttoUnit
Atto [1e-18].
const LALUnit lalDimensionlessUnit
dimensionless units
const LALUnit lalOhmUnit
Ohm [ ].
const LALUnit lalKiloUnit
Kilo [1e3].
const LALUnit lalVoltUnit
Volt [V].
const LALUnit lalFemtoUnit
Femto [1e-15].
const LALUnit lalPascalUnit
Pascal [Pa].
const LALUnit lalMegaUnit
Mega [1e6].
const LALUnit lalNanoUnit
Nano [1e-9].
const LALUnit lalYoctoUnit
Yocto [1e-24].
const LALUnit lalYottaUnit
Yotta [1e24].
static int readNumber(char temp[], const char **charPtrPtr)
const LALUnit lalFaradUnit
Farad [F].
const LALUnit lalPicoUnit
Pico [1e-12].
char * XLALUnitAsString(char *string, UINT4 length, const LALUnit *input)
Returns the pointer to the input string, which is populated with the unit string if successful.
const LALUnit lalMilliUnit
Milli [1e-3].
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFAILED
Generic failure.
This structure stores units in the mksA system (plus Kelvin, Strain, and ADC Count).
INT2 powerOfTen
Overall power-of-ten scaling is 10^powerOfTen.
UINT2 unitDenominatorMinusOne[LALNumUnits]
Array of unit power denominators-minus-one.
INT2 unitNumerator[LALNumUnits]
Array of unit power numerators.
void output(int gps_sec, int output_type)