LAL  7.5.0.1-89842e6
UnitsTest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2014 Karl Wette (XLALification)
3 * Copyright (C) 2007 Jolien Creighton, John Whelan
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with with program; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301 USA
19 */
20 
21 /**
22  * \author J. T. Whelan <john.whelan@ligo.org>
23  * \file
24  * \ingroup Units_h
25  *
26  * \brief Test Suite for unit manipulation programs
27  *
28  * ### Description ###
29  *
30  * This program tests the various units-manipulation routines, as well as
31  * the pre-defined units defined in \ref Units.h. For each
32  * successful test, it prints "PASS" to standard output.
33  *
34  * ### Uses ###
35  *
36  * \code
37  * XLALMalloc()
38  * XLALUnitAsString()
39  * XLALParseUnitString()
40  * XLALFree()
41  * XLALUnitMultiply()
42  * XLALUnitRaiseRAT4()
43  * XLALUnitNormalize()
44  * XLALUnitCompare()
45  * \endcode
46  *
47  */
48 
49 /** \cond DONT_DOXYGEN */
50 
51 #include <config.h>
52 #include <stdlib.h>
53 #include <lal/LALStdlib.h>
54 #include <lal/Units.h>
55 #include <lal/AVFactories.h>
56 
57 int main(void) {
58 
59  int errnum;
60  LALUnit unit1, unit2, unit3, *punit;
61  RAT4 power;
62  CHAR *string, buffer[LALUnitTextSize];
63  UINT4 length;
64 
65  printf("Checking input validation of XLALUnitAsString:\n");
66 
67  length = sizeof("m^2 kg s^-3 A^-1") - 1;
68  string = XLALMalloc(length);
69  XLAL_CHECK( string != NULL, XLAL_EFAILED );
70 
71  XLAL_TRY( XLALUnitAsString( NULL, length, &unit1 ), errnum );
72  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
73  printf(" PASS: Null pointer to output string\n");
74 
75  XLAL_TRY( XLALUnitAsString( string, 0, &unit1 ), errnum );
76  XLAL_CHECK( errnum == XLAL_EBADLEN, XLAL_EFAILED );
77  printf(" PASS: Bad output string length\n");
78 
79  XLAL_TRY( XLALUnitAsString( string, length, NULL ), errnum );
80  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
81  printf(" PASS: Null pointer to input LALUnit\n");
82 
83  XLAL_TRY( XLALUnitAsString( string, length, &lalVoltUnit ), errnum );
84  XLAL_CHECK( errnum == XLAL_EBADLEN, XLAL_EFAILED );
85  printf(" PASS: Output string too short\n");
86 
87  XLALFree(string);
88 
89  printf("Testing response of XLALUnitAsString to valid data:\n");
90 
91  length = sizeof("m^2 kg s^-3 A^-1");
92  string = XLALMalloc(length);
93  XLAL_CHECK( string != NULL, XLAL_EFAILED );
94 
95  XLAL_CHECK( XLALUnitAsString( string, length, &lalVoltUnit ) != NULL, XLAL_EFAILED );
96  XLAL_CHECK( strcmp(string, "m^2 kg s^-3 A^-1") == 0, XLAL_EFAILED );
97  printf(" PASS: String representation of Volt is '%s'\n", string);
98 
99  XLALFree(string);
100 
101  length = sizeof("10^-12 m^-2 kg^-1 s^2 A^2");
102  string = XLALMalloc(length);
103  XLAL_CHECK( string != NULL, XLAL_EFAILED );
104 
105  XLAL_CHECK( XLALUnitAsString( string, length, &lalPicoFaradUnit ) != NULL, XLAL_EFAILED );
106  XLAL_CHECK( strcmp(string, "10^-12 m^-2 kg^-1 s^2 A^2") == 0, XLAL_EFAILED );
107  printf(" PASS: String representation of PicoFarad is '%s'\n", string);
108 
109  XLAL_CHECK( XLALUnitAsString( string, length, &lalMeterUnit ) != NULL, XLAL_EFAILED );
110  XLAL_CHECK( strcmp(string, "m") == 0, XLAL_EFAILED );
111  printf(" PASS: String representation of Meter is '%s'\n", string);
112 
113  XLAL_CHECK( XLALUnitAsString( string, length, &lalCoulombUnit ) != NULL, XLAL_EFAILED );
114  XLAL_CHECK( strcmp(string, "s A") == 0, XLAL_EFAILED );
115  printf(" PASS: String representation of Coulomb is '%s'\n", string);
116 
117  XLAL_CHECK( XLALUnitAsString( string, length, &lalMegaUnit ) != NULL, XLAL_EFAILED );
118  XLAL_CHECK( strcmp(string, "10^6") == 0, XLAL_EFAILED );
119  printf(" PASS: String representation of Mega is '%s'\n", string);
120 
121  XLAL_CHECK( XLALUnitAsString( string, length, &lalAttoStrainUnit ) != NULL, XLAL_EFAILED );
122  XLAL_CHECK( strcmp(string, "10^-18 strain") == 0, XLAL_EFAILED );
123  printf(" PASS: String representation of AttoStrain is '%s'\n", string);
124 
125  XLAL_CHECK( XLALUnitAsString( string, length, &lalDimensionlessUnit ) != NULL, XLAL_EFAILED );
126  XLAL_CHECK( strcmp(string, "") == 0, XLAL_EFAILED );
127  printf(" PASS: String representation of dimensionless is '%s'\n", string);
128 
129  XLALFree(string);
130 
131  printf("Checking input validation of XLALParseUnitString:\n");
132 
133  punit = XLALParseUnitString( NULL, "" );
134  XLAL_CHECK( punit != NULL, XLAL_EFAILED );
136  XLALFree(punit);
137  printf(" PASS: Null pointer to output LALUnit allocates new one\n");
138 
139  punit = XLALParseUnitString( &unit1, NULL );
140  XLAL_CHECK( punit == &unit1, XLAL_EFAILED );
142  printf(" PASS: Null pointer to string returns dimensionless\n");
143 
144  memset(buffer, 0, LALUnitTextSize);
145 
146  strncpy( buffer, "10^", LALUnitTextSize );
147  XLAL_TRY( XLALParseUnitString( &unit1, buffer ), errnum );
148  XLAL_CHECK( errnum == XLAL_EFAILED, XLAL_EFAILED );
149  printf(" PASS: Expected failure to parse '%s'\n", buffer);
150 
151  strncpy( buffer, "s^3 s^2", LALUnitTextSize );
152  XLAL_TRY( XLALParseUnitString( &unit1, buffer ), errnum );
153  XLAL_CHECK( errnum == XLAL_EFAILED, XLAL_EFAILED );
154  printf(" PASS: Expected failure to parse '%s'\n", buffer);
155 
156  strncpy( buffer, "V", LALUnitTextSize );
157  XLAL_TRY( XLALParseUnitString( &unit1, buffer ), errnum );
158  XLAL_CHECK( errnum == XLAL_EFAILED, XLAL_EFAILED );
159  printf(" PASS: Expected failure to parse '%s'\n", buffer);
160 
161  printf("Testing response of XLALParseUnitString to valid data:\n");
162 
164  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
165  XLAL_CHECK( XLALUnitCompare( &unit1, &lalVoltUnit ) == 0, XLAL_EFAILED );
166  printf(" PASS: Volt <-> string\n");
167 
169  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
171  printf(" PASS: PicoFarad <-> string\n");
172 
174  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
176  printf(" PASS: Meter <-> string\n");
177 
179  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
181  printf(" PASS: AttoStrain <-> string\n");
182 
184  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
186  printf(" PASS: Coulomb <-> string\n");
187 
189  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
190  XLAL_CHECK( XLALUnitCompare( &unit1, &lalMegaUnit ) == 0, XLAL_EFAILED );
191  printf(" PASS: Mega <-> string\n");
192 
194  XLAL_CHECK( XLALParseUnitString( &unit1, buffer ) != NULL, XLAL_EFAILED );
196  printf(" PASS: Dimensionless <-> string\n");
197 
198  unit1 = unit2 = lalDimensionlessUnit;
199 
200  printf("Checking input validation of LALUnitMultiply:\n");
201 
202  XLAL_TRY( XLALUnitMultiply( NULL, &unit1, &unit2 ), errnum );
203  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
204  printf(" PASS: Null pointer to output LALUnit\n");
205 
206  XLAL_TRY( XLALUnitMultiply( &unit3, NULL, NULL ), errnum );
207  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
208  printf(" PASS: Null pointer to input LALUnits\n");
209 
210  unit1.powerOfTen = 20000;
211  unit2.powerOfTen = 30000;
212  XLAL_TRY( XLALUnitMultiply( &unit3, &unit1, &unit2 ), errnum );
213  XLAL_CHECK( errnum == XLAL_ERANGE, XLAL_EFAILED );
214  printf(" PASS: Exponent outside of (U)INT2 bounds\n");
215 
216  unit1.powerOfTen = 0;
217  unit2.powerOfTen = 0;
218  unit1.unitNumerator[2] = 12345;
219  unit1.unitDenominatorMinusOne[2] = 23456;
220  unit2.unitNumerator[2] = 23456;
221  unit2.unitDenominatorMinusOne[2] = 12345;
222  XLAL_TRY( XLALUnitMultiply( &unit3, &unit1, &unit2 ), errnum );
223  XLAL_CHECK( errnum == XLAL_ERANGE, XLAL_EFAILED );
224  printf(" PASS: Product outside of (U)INT2 bounds\n");
225 
226  printf("Checking input validation of XLALUnitRaiseRAT4:\n");
227 
228  XLAL_TRY( XLALUnitRaiseRAT4( NULL, &unit1, &power ), errnum );
229  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
230  printf(" PASS: Null pointer to output LALUnit\n");
231 
232  XLAL_TRY( XLALUnitRaiseRAT4( &unit3, NULL, &power ), errnum );
233  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
234  printf(" PASS: Null pointer to input LALUnit\n");
235 
236  XLAL_TRY( XLALUnitRaiseRAT4( &unit3, &unit1, NULL ), errnum );
237  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
238  printf(" PASS: Null pointer to input RAT4\n");
239 
240  unit1 = lalKiloUnit;
241  power.numerator = 1;
242  power.denominatorMinusOne = 1;
243  XLAL_TRY( XLALUnitRaiseRAT4( &unit2, &unit1, &power ), errnum );
244  XLAL_CHECK( errnum == XLAL_EINVAL, XLAL_EFAILED );
245  printf(" PASS: Non-integer power of ten\n");
246 
247  unit1.unitNumerator[2] = 20000;
248  unit1.unitNumerator[2] += 20000;
249  power.numerator = 2;
250  power.denominatorMinusOne = 0;
251  XLAL_TRY( XLALUnitRaiseRAT4( &unit2, &unit1, &power ), errnum );
252  XLAL_CHECK( errnum == XLAL_ERANGE, XLAL_EFAILED );
253  printf(" PASS: Exponent outside of (U)INT2 bounds\n");
254 
255  printf("Testing response of XLALUnitNormalize to valid data:\n");
256 
257  unit1 = lalDimensionlessUnit;
258  unit1.unitNumerator[0] = 2;
259  unit1.unitDenominatorMinusOne[0] = 5;
261  unit2 = lalDimensionlessUnit;
262  unit2.unitNumerator[0] = 1;
263  unit2.unitDenominatorMinusOne[0] = 2;
264  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
265  printf(" PASS: 2/6 reduces to 1/3\n");
266 
267  printf("Checking input validation of XLALUnitCompare:\n");
268 
269  XLAL_TRY( XLALUnitCompare( &unit1, NULL ), errnum );
270  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
271  XLAL_TRY( XLALUnitCompare( NULL, &unit2 ), errnum );
272  XLAL_CHECK( errnum == XLAL_EFAULT, XLAL_EFAILED );
273  printf(" PASS: Null pointer to input LALUnits\n");
274 
275  printf("Testing response of XLALUnitCompare to valid data:\n");
276 
278  printf(" PASS: m = m\n");
279 
281  printf(" PASS: m != kg\n");
282 
284  printf(" PASS: g != kg\n");
285 
286  printf("Testing definitions of basic units:\n");
287 
288  unit1 = lalDimensionlessUnit;
289  unit1.unitNumerator[LALUnitIndexMeter] = 1;
290  unit2 = lalMeterUnit;
291  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
293  printf(" PASS: meter\n");
294 
295  unit1 = lalDimensionlessUnit;
297  unit2 = lalKiloGramUnit;
298  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
300  printf(" PASS: kilogram\n");
301 
302  unit1 = lalDimensionlessUnit;
304  unit2 = lalSecondUnit;
305  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
307  printf(" PASS: second\n");
308 
309  unit1 = lalDimensionlessUnit;
311  unit2 = lalAmpereUnit;
312  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
314  printf(" PASS: Ampere\n");
315 
316  unit1 = lalDimensionlessUnit;
318  unit2 = lalKelvinUnit;
319  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
321  printf(" PASS: Kelvin\n");
322 
323  unit1 = lalDimensionlessUnit;
325  unit2 = lalStrainUnit;
326  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
328  printf(" PASS: strain\n");
329 
330  unit1 = lalDimensionlessUnit;
332  unit2 = lalADCCountUnit;
333  XLAL_CHECK( XLALUnitCompare( &unit1, &unit2 ) == 0, XLAL_EFAILED );
335  printf(" PASS: ADC Count\n");
336 
337  printf("Testing definitions of derived units:\n");
338 
339  power.numerator = -1;
340  power.denominatorMinusOne = 0;
341  XLAL_CHECK( XLALUnitRaiseRAT4( &unit1, &lalSecondUnit, &power ) != NULL, XLAL_EFAILED );
343  printf(" PASS: Hz is s^-1\n");
344 
345  power.numerator = -2;
346  power.denominatorMinusOne = 0;
347  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalSecondUnit, &power ) != NULL, XLAL_EFAILED );
348  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalMeterUnit, &unit2 ) != NULL, XLAL_EFAILED );
349  XLAL_CHECK( XLALUnitMultiply( &unit2, &lalKiloGramUnit, &unit1 ) != NULL, XLAL_EFAILED );
351  printf(" PASS: N is kg m s^-2\n");
352 
353  power.numerator = -2;
354  power.denominatorMinusOne = 0;
355  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalMeterUnit, &power ) != NULL, XLAL_EFAILED );
356  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalNewtonUnit, &unit2 ) != NULL, XLAL_EFAILED );
358  printf(" PASS: Pa is N m^-2\n");
359 
362  printf(" PASS: J is N m\n");
363 
364  power.numerator = -1;
365  power.denominatorMinusOne = 0;
366  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalSecondUnit, &power ) != NULL, XLAL_EFAILED );
367  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalJouleUnit, &unit2 ) != NULL, XLAL_EFAILED );
368  XLAL_CHECK( XLALUnitCompare( &unit1, &lalWattUnit ) == 0, XLAL_EFAILED );
369  printf(" PASS: W is J/s\n");
370 
373  printf(" PASS: C is A s\n");
374 
375  power.numerator = -1;
376  power.denominatorMinusOne = 0;
377  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalAmpereUnit, &power ) != NULL, XLAL_EFAILED );
378  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalWattUnit, &unit2 ) != NULL, XLAL_EFAILED );
379  XLAL_CHECK( XLALUnitCompare( &unit1, &lalVoltUnit ) == 0, XLAL_EFAILED );
380  printf(" PASS: V is W/A\n");
381 
382  power.numerator = -1;
383  power.denominatorMinusOne = 0;
384  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalAmpereUnit, &power ) != NULL, XLAL_EFAILED );
385  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalVoltUnit, &unit2 ) != NULL, XLAL_EFAILED );
386  XLAL_CHECK( XLALUnitCompare( &unit1, &lalOhmUnit ) == 0, XLAL_EFAILED );
387  printf(" PASS: Ohm is V/A\n");
388 
389  power.numerator = -1;
390  power.denominatorMinusOne = 0;
391  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalVoltUnit, &power ) != NULL, XLAL_EFAILED );
392  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalCoulombUnit, &unit2 ) != NULL, XLAL_EFAILED );
394  printf(" PASS: F is C/V\n");
395 
398  printf(" PASS: Wb is V s\n");
399 
400  power.numerator = -1;
401  power.denominatorMinusOne = 0;
402  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalAmpereUnit, &power ) != NULL, XLAL_EFAILED );
403  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalSecondUnit, &unit2 ) != NULL, XLAL_EFAILED );
404  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalVoltUnit, &unit1 ) != NULL, XLAL_EFAILED );
406  printf(" PASS: H is V s/A\n");
407 
408  power.numerator = -2;
409  power.denominatorMinusOne = 0;
410  XLAL_CHECK( XLALUnitRaiseRAT4( &unit2, &lalMeterUnit, &power ) != NULL, XLAL_EFAILED );
411  XLAL_CHECK( XLALUnitMultiply( &unit1, &lalWeberUnit, &unit2 ) != NULL, XLAL_EFAILED );
413  printf(" PASS: T is Wb m^-2\n");
414 
416 
417  printf("PASS: All tests\n");
418 
419  return 0;
420 
421 }
422 
423 /** \endcond */
void LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
int main(int argc, char *argv[])
Definition: cache.c:25
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.
Definition: LALDatatypes.h:477
@ LALUnitIndexMeter
The meter index.
Definition: LALDatatypes.h:473
@ LALUnitIndexKiloGram
The kilogram index.
Definition: LALDatatypes.h:474
@ LALUnitIndexSecond
The second index.
Definition: LALDatatypes.h:475
@ LALUnitIndexADCCount
The ADC counts index.
Definition: LALDatatypes.h:479
@ LALUnitIndexStrain
The strain index.
Definition: LALDatatypes.h:478
@ LALUnitIndexAmpere
The ampere index.
Definition: LALDatatypes.h:476
#define XLALMalloc(n)
Definition: LALMalloc.h:44
#define XLALFree(p)
Definition: LALMalloc.h:47
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...
Definition: UnitCompare.c:90
@ LALUnitTextSize
Definition: Units.h:174
const LALUnit lalWattUnit
Watt [W ].
Definition: UnitDefs.c:175
const LALUnit lalKelvinUnit
Kelvin [K].
Definition: UnitDefs.c:164
const LALUnit lalHenryUnit
Henry [H].
Definition: UnitDefs.c:185
const LALUnit lalStrainUnit
Strain [1].
Definition: UnitDefs.c:165
const LALUnit lalWeberUnit
Weber [Wb].
Definition: UnitDefs.c:184
const LALUnit lalKiloGramUnit
kilogram [kg]
Definition: UnitDefs.c:161
const LALUnit lalNewtonUnit
Newton [N].
Definition: UnitDefs.c:172
const LALUnit lalAmpereUnit
Ampere [A].
Definition: UnitDefs.c:163
const LALUnit lalAttoStrainUnit
AttoStrain [1e-18].
Definition: UnitDefs.c:216
const LALUnit lalCoulombUnit
Coulomb [C].
Definition: UnitDefs.c:180
const LALUnit lalTeslaUnit
Tesla [T].
Definition: UnitDefs.c:186
const LALUnit lalSecondUnit
second [s]
Definition: UnitDefs.c:162
const LALUnit lalGramUnit
Gram [1e-3].
Definition: UnitDefs.c:215
const LALUnit lalJouleUnit
Joule [J].
Definition: UnitDefs.c:174
const LALUnit lalADCCountUnit
ADC count [count].
Definition: UnitDefs.c:166
const LALUnit lalHertzUnit
Hertz [Hz].
Definition: UnitDefs.c:171
const LALUnit lalMeterUnit
meter [m]
Definition: UnitDefs.c:160
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 ...
Definition: UnitDefs.c:354
const LALUnit lalPicoFaradUnit
PicoFarad [1e-12 F].
Definition: UnitDefs.c:217
const LALUnit lalDimensionlessUnit
dimensionless units
Definition: UnitDefs.c:156
const LALUnit lalOhmUnit
Ohm [ ].
Definition: UnitDefs.c:182
const LALUnit lalKiloUnit
Kilo [1e3].
Definition: UnitDefs.c:198
const LALUnit lalVoltUnit
Volt [V].
Definition: UnitDefs.c:181
const LALUnit lalPascalUnit
Pascal [Pa].
Definition: UnitDefs.c:173
const LALUnit lalMegaUnit
Mega [1e6].
Definition: UnitDefs.c:197
const LALUnit lalFaradUnit
Farad [F].
Definition: UnitDefs.c:183
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.
Definition: UnitDefs.c:276
LALUnit * XLALUnitMultiply(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
This function multiplies together the LALUnit structures *(input->unitOne) and *(input->unitTwo),...
Definition: UnitMultiply.c:64
int XLALUnitNormalize(LALUnit *unit)
Returns 0 upon success or XLAL_FAILURE if the input pointer is NULL, in which case xlalErrno is set t...
Definition: UnitNormalize.c:72
LALUnit * XLALUnitRaiseRAT4(LALUnit *output, const LALUnit *input, const RAT4 *power)
Raises a LALUnit structure to a rational power given by the RAT4 structure power.
Definition: UnitRaise.c:56
#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...
Definition: XLALError.h:810
#define XLAL_TRY(statement, errnum)
A macro to (i) disable the XLAL error handling and preserve the current value of xlalErrno (ii) perfo...
Definition: XLALError.h:582
@ XLAL_EBADLEN
Inconsistent or invalid length.
Definition: XLALError.h:419
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_ERANGE
Output range error.
Definition: XLALError.h:411
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409
@ XLAL_EFAILED
Generic failure.
Definition: XLALError.h:418
This structure stores units in the mksA system (plus Kelvin, Strain, and ADC Count).
Definition: LALDatatypes.h:498
INT2 powerOfTen
Overall power-of-ten scaling is 10^powerOfTen.
Definition: LALDatatypes.h:499
UINT2 unitDenominatorMinusOne[LALNumUnits]
Array of unit power denominators-minus-one.
Definition: LALDatatypes.h:501
INT2 unitNumerator[LALNumUnits]
Array of unit power numerators.
Definition: LALDatatypes.h:500
A four-byte rational number, used as a parameter structure for XLALUnitRaiseRAT4().
Definition: Units.h:144
INT2 numerator
The numerator.
Definition: Units.h:145
UINT2 denominatorMinusOne
One less than the denominator.
Definition: Units.h:146