53 #include <lal/LALStdlib.h>
54 #include <lal/Units.h>
55 #include <lal/AVFactories.h>
60 LALUnit unit1, unit2, unit3, *punit;
65 printf(
"Checking input validation of XLALUnitAsString:\n");
67 length =
sizeof(
"m^2 kg s^-3 A^-1") - 1;
73 printf(
" PASS: Null pointer to output string\n");
77 printf(
" PASS: Bad output string length\n");
81 printf(
" PASS: Null pointer to input LALUnit\n");
85 printf(
" PASS: Output string too short\n");
89 printf(
"Testing response of XLALUnitAsString to valid data:\n");
91 length =
sizeof(
"m^2 kg s^-3 A^-1");
97 printf(
" PASS: String representation of Volt is '%s'\n",
string);
101 length =
sizeof(
"10^-12 m^-2 kg^-1 s^2 A^2");
107 printf(
" PASS: String representation of PicoFarad is '%s'\n",
string);
111 printf(
" PASS: String representation of Meter is '%s'\n",
string);
115 printf(
" PASS: String representation of Coulomb is '%s'\n",
string);
119 printf(
" PASS: String representation of Mega is '%s'\n",
string);
123 printf(
" PASS: String representation of AttoStrain is '%s'\n",
string);
127 printf(
" PASS: String representation of dimensionless is '%s'\n",
string);
131 printf(
"Checking input validation of XLALParseUnitString:\n");
137 printf(
" PASS: Null pointer to output LALUnit allocates new one\n");
142 printf(
" PASS: Null pointer to string returns dimensionless\n");
149 printf(
" PASS: Expected failure to parse '%s'\n", buffer);
154 printf(
" PASS: Expected failure to parse '%s'\n", buffer);
159 printf(
" PASS: Expected failure to parse '%s'\n", buffer);
161 printf(
"Testing response of XLALParseUnitString to valid data:\n");
166 printf(
" PASS: Volt <-> string\n");
171 printf(
" PASS: PicoFarad <-> string\n");
176 printf(
" PASS: Meter <-> string\n");
181 printf(
" PASS: AttoStrain <-> string\n");
186 printf(
" PASS: Coulomb <-> string\n");
191 printf(
" PASS: Mega <-> string\n");
196 printf(
" PASS: Dimensionless <-> string\n");
200 printf(
"Checking input validation of LALUnitMultiply:\n");
204 printf(
" PASS: Null pointer to output LALUnit\n");
208 printf(
" PASS: Null pointer to input LALUnits\n");
214 printf(
" PASS: Exponent outside of (U)INT2 bounds\n");
224 printf(
" PASS: Product outside of (U)INT2 bounds\n");
226 printf(
"Checking input validation of XLALUnitRaiseRAT4:\n");
230 printf(
" PASS: Null pointer to output LALUnit\n");
234 printf(
" PASS: Null pointer to input LALUnit\n");
238 printf(
" PASS: Null pointer to input RAT4\n");
245 printf(
" PASS: Non-integer power of ten\n");
253 printf(
" PASS: Exponent outside of (U)INT2 bounds\n");
255 printf(
"Testing response of XLALUnitNormalize to valid data:\n");
265 printf(
" PASS: 2/6 reduces to 1/3\n");
267 printf(
"Checking input validation of XLALUnitCompare:\n");
273 printf(
" PASS: Null pointer to input LALUnits\n");
275 printf(
"Testing response of XLALUnitCompare to valid data:\n");
278 printf(
" PASS: m = m\n");
281 printf(
" PASS: m != kg\n");
284 printf(
" PASS: g != kg\n");
286 printf(
"Testing definitions of basic units:\n");
293 printf(
" PASS: meter\n");
300 printf(
" PASS: kilogram\n");
307 printf(
" PASS: second\n");
314 printf(
" PASS: Ampere\n");
321 printf(
" PASS: Kelvin\n");
328 printf(
" PASS: strain\n");
335 printf(
" PASS: ADC Count\n");
337 printf(
"Testing definitions of derived units:\n");
343 printf(
" PASS: Hz is s^-1\n");
351 printf(
" PASS: N is kg m s^-2\n");
358 printf(
" PASS: Pa is N m^-2\n");
362 printf(
" PASS: J is N m\n");
369 printf(
" PASS: W is J/s\n");
373 printf(
" PASS: C is A s\n");
380 printf(
" PASS: V is W/A\n");
387 printf(
" PASS: Ohm is V/A\n");
394 printf(
" PASS: F is C/V\n");
398 printf(
" PASS: Wb is V s\n");
406 printf(
" PASS: H is V s/A\n");
413 printf(
" PASS: T is Wb m^-2\n");
417 printf(
"PASS: All tests\n");
void LALCheckMemoryLeaks(void)
int main(int argc, char *argv[])
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
@ LALUnitIndexKelvin
The kelvin index.
@ LALUnitIndexMeter
The meter index.
@ LALUnitIndexKiloGram
The kilogram index.
@ LALUnitIndexSecond
The second index.
@ LALUnitIndexADCCount
The ADC counts index.
@ LALUnitIndexStrain
The strain index.
@ LALUnitIndexAmpere
The ampere index.
int XLALUnitCompare(const LALUnit *unit1, const LALUnit *unit2)
Returns 0 if the the normal form of the two unit structures are the same or > 0 if they are different...
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 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 lalTeslaUnit
Tesla [T].
const LALUnit lalSecondUnit
second [s]
const LALUnit lalGramUnit
Gram [1e-3].
const LALUnit lalJouleUnit
Joule [J].
const LALUnit lalADCCountUnit
ADC count [count].
const LALUnit lalHertzUnit
Hertz [Hz].
const LALUnit lalMeterUnit
meter [m]
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 lalDimensionlessUnit
dimensionless units
const LALUnit lalOhmUnit
Ohm [ ].
const LALUnit lalKiloUnit
Kilo [1e3].
const LALUnit lalVoltUnit
Volt [V].
const LALUnit lalPascalUnit
Pascal [Pa].
const LALUnit lalMegaUnit
Mega [1e6].
const LALUnit lalFaradUnit
Farad [F].
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.
LALUnit * XLALUnitMultiply(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
This function multiplies together the LALUnit structures *(input->unitOne) and *(input->unitTwo),...
int XLALUnitNormalize(LALUnit *unit)
Returns 0 upon success or XLAL_FAILURE if the input pointer is NULL, in which case xlalErrno is set t...
LALUnit * XLALUnitRaiseRAT4(LALUnit *output, const LALUnit *input, const RAT4 *power)
Raises a LALUnit structure to a rational power given by the RAT4 structure power.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_TRY(statement, errnum)
A macro to (i) disable the XLAL error handling and preserve the current value of xlalErrno (ii) perfo...
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_ERANGE
Output range error.
@ XLAL_EINVAL
Invalid argument.
@ 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.
A four-byte rational number, used as a parameter structure for XLALUnitRaiseRAT4().
INT2 numerator
The numerator.
UINT2 denominatorMinusOne
One less than the denominator.