Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Units.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Kipp Cannon, John Whelan
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#ifndef _UNITS_H
21#define _UNITS_H
22
23#include <lal/LALStdlib.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/**
30 * \defgroup Units_h Header Units.h
31 * \ingroup lal_tools
32 * \author J. T. Whelan <john.whelan@ligo.org>
33 *
34 * \brief Provides prototypes for manipulation of units and declares
35 * \c extern constants for the basic and derived SI units.
36 *
37 * ### Synopsis ###
38 *
39 * \code
40 * #include <lal/Units.h>
41 * \endcode
42 *
43 * This header provides prototypes for functions to manipulate
44 * the \c LALUnit structure. It also defines \c extern
45 * constants for a set of predefined units, which are designed to make
46 * the structure easier to use. For instance, to determine whether a
47 * quantity has units of strain per root hertz, one constructs the unit
48 * &quot;strain per root hertz&quot; from the predefined \c lalStrainUnit and
49 * \c lalHertzUnit constant structures using the
50 * XLALUnitRaiseRAT4() and XLALUnitMultiply() functions, then
51 * compares that to the unit structure in question using the
52 * XLALUnitCompare() function.
53 *
54 * The LALUnit datatype itself is included in the header
55 * \ref LALDatatypes.h, and defines a unit in terms of an integer
56 * power of ten multiplier along with rational powers of the basic SI
57 * units (meters, kilograms, seconds, Amperes, and Kelvins) and two
58 * custom units (strain and ADC counts).
59 *
60 * ### XLAL interface to Units.h functions ###
61 *
62 * XLALUnitAsString() converts a \c LALUnit structure into a character
63 * string of maximum length \c length (including NUL termination)
64 * representation of the units. The inverse function, XLALParseUnitString()
65 * parses a character string to produce a \c LALUnit structure; if
66 * \c output is \c NULL, memory for the output is allocated. If the input
67 * \c string is \c NULL or is empty then the output units are
68 * dimensionless: lalDimensionlessUnit.
69 *
70 * XLALUnitNormalize() puts a \c LALUnit structure into normal form
71 * by simplifying all unit exponent fractions to their simplest form.
72 *
73 * XLALUnitCompare() compares two \c LALUnit structures: they are the
74 * same if their normal forms are identical.
75 *
76 * XLALUnitMultiply() multiplies two \c LALUnit structures. The result
77 * is put into normal form.
78 *
79 * XLALUnitRaiseRAT4() raises a \c LALUnit structure to a rational
80 * power given by the \c RAT4 structure \c power.
81 * XLALUnitRaiseINT2() raises a \c LALUnit structure to an integer
82 * power \c power.
83 * XLALUnitSquare() produces the square of a \c LALUnit structure.
84 * XLALUnitSqrt() produces the square-root of a \c LALUnit structure.
85 *
86 * ### Return Values ###
87 *
88 * XLALUnitAsString() returns the pointer to the input \c string, which
89 * is populated with the unit string if successful. If there is a failure,
90 * XLALUnitAsString() returns a \c NULL pointer and ::xlalErrno
91 * is set to one of the following values: #XLAL_EFAULT if one of the
92 * input pointers is \c NULL or #XLAL_EBADLEN if the length of the
93 * string is insufficent for the unit string.
94 *
95 * XLALParseUnitString() returns the pointer \c output upon return
96 * or a pointer to newly allocated memory if \c output was \c NULL;
97 * on failure, \c XLALParseUnitString returns \c NULL and sets
98 * ::xlalErrno to one of the following values: #XLAL_ENOMEM
99 * if the routine was unable to allocate memory for the output or
100 * #XLAL_EFAILED if the routine was unable to parse the unit string.
101 *
102 * XLALUnitNormalize() returns 0 upon success or #XLAL_FAILURE
103 * if the input pointer is \c NULL, in which case \c xlalErrno
104 * is set to #XLAL_EFAULT
105 *
106 * XLALUnitCompare() returns 0 if the the normal form of the two unit
107 * structures are the same or > 0 if they are different. It returns
108 * #XLAL_FAILURE and ::xlalErrno is set to #XLAL_EFAULT if
109 * one of the input pointers is \c NULL.
110 *
111 * XLALUnitMultiply(), XLALUnitRaiseRAT4(), XLALUnitRaiseINT2(), XLALUnitSquare() and
112 * XLALUnitSqrt() all return a pointer to the output unit structure
113 * \c output upon success or \c NULL upon failure. If there is
114 * a failure, ::xlalErrno is set to one of the following values:
115 * #XLAL_EFAULT if one of the input pointers is \c NULL,
116 * #XLAL_ERANGE if one of the unit powers exceeds the allowed range,
117 * or #XLAL_EINVAL (for the raise functions only) if the unit power
118 * would not be an integer.
119 *
120 * @{
121 * \defgroup UnitDefs_c Module UnitDefs.c
122 * \defgroup UnitNormalize_c Module UnitNormalize.c
123 * \defgroup UnitRaise_c Module UnitRaise.c
124 * \defgroup UnitMultiply_c Module UnitMultiply.c
125 * \defgroup UnitCompare_c Module UnitCompare.c
126 * @}
127 */
128/** @{ */
129
130/*********************************************************
131 * *
132 * Functions to manipulate unit structures *
133 * *
134 *********************************************************/
135
136#ifndef SWIG /* exclude from SWIG interface */
137
138/**
139 * A four-byte rational number, used as a parameter structure for
140 * XLALUnitRaiseRAT4().
141 */
142typedef struct
143tagRAT4
144{
145 INT2 numerator; /**< The numerator */
146 UINT2 denominatorMinusOne; /**< One less than the denominator */
147} RAT4;
148
149/* XLAL routines */
150char * XLALUnitAsString( char *string, UINT4 length, const LALUnit *input );
151char * XLALUnitToString( const LALUnit *input );
152LALUnit * XLALParseUnitString( LALUnit *output, const char *string );
153int XLALUnitNormalize( LALUnit *unit );
154int XLALUnitCompare( const LALUnit *unit1, const LALUnit *unit2 );
156 const LALUnit *unit2 );
158 const LALUnit *unit2 );
160 const RAT4 *power );
162 INT2 power );
163LALUnit * XLALUnitSquare( LALUnit *output, const LALUnit *input );
164LALUnit * XLALUnitSqrt( LALUnit *output, const LALUnit *input );
165LALUnit * XLALUnitInvert( LALUnit *output, const LALUnit *input );
166REAL8 XLALUnitPrefactor(const LALUnit *unit);
167int XLALUnitIsDimensionless(const LALUnit *unit);
168REAL8 XLALUnitRatio(const LALUnit *unit1, const LALUnit *unit2);
169
171 LALUnitNameSize = sizeof("strain")
174 LALUnitTextSize = sizeof("10^-32768 m^-32768/32767 kg^-32768/32767 "
175 "s^-32768/32767 A^-32768/32767 "
176 "K^-32768/32767 strain^-32768/32767 "
177 "count^-32768/32767")
179
181
182#endif /* SWIG */
183
184/*********************************************************
185 * *
186 * Predefined units *
187 * *
188 *********************************************************/
189
190/* Predefined constant units make it easier for programmers to specify
191 * and compare (using XLALUnitCompare) units more easily. Those given
192 * here are an example; more can be added.
193 */
194
195/* LALUnitsTest.c will verify the definitions of the derived units,
196 * for example using XLALUnitRaise, XLALUnitMultiply and XLALUnitCompare
197 * to show that 1 Farad = 1 Coulomb Volt^-1
198 */
199
200extern const LALUnit lalDimensionlessUnit;
201
202/* Basic Units */
203extern const LALUnit lalMeterUnit ;
204extern const LALUnit lalKiloGramUnit ;
205extern const LALUnit lalSecondUnit ;
206extern const LALUnit lalAmpereUnit ;
207extern const LALUnit lalKelvinUnit ;
208extern const LALUnit lalStrainUnit ;
209extern const LALUnit lalADCCountUnit ;
210
211/* Derived Mechanical Units */
212extern const LALUnit lalHertzUnit ;
213extern const LALUnit lalNewtonUnit ;
214extern const LALUnit lalJouleUnit ;
215extern const LALUnit lalWattUnit ;
216extern const LALUnit lalPascalUnit ;
217
218/* Derived Electromagnetic Units */
219extern const LALUnit lalCoulombUnit ;
220extern const LALUnit lalVoltUnit ;
221extern const LALUnit lalOhmUnit ;
222extern const LALUnit lalFaradUnit ;
223extern const LALUnit lalWeberUnit ;
224extern const LALUnit lalTeslaUnit ;
225extern const LALUnit lalHenryUnit ;
226
227/* Powers of Ten */
228extern const LALUnit lalYottaUnit ;
229extern const LALUnit lalZettaUnit ;
230extern const LALUnit lalExaUnit ;
231extern const LALUnit lalPetaUnit ;
232extern const LALUnit lalTeraUnit ;
233extern const LALUnit lalGigaUnit ;
234extern const LALUnit lalMegaUnit ;
235extern const LALUnit lalKiloUnit ;
236extern const LALUnit lalHectoUnit ;
237extern const LALUnit lalDekaUnit ;
238extern const LALUnit lalDeciUnit ;
239extern const LALUnit lalCentiUnit ;
240extern const LALUnit lalMilliUnit ;
241extern const LALUnit lalMicroUnit ;
242extern const LALUnit lalNanoUnit ;
243extern const LALUnit lalPicoUnit ;
244extern const LALUnit lalFemtoUnit ;
245extern const LALUnit lalAttoUnit ;
246extern const LALUnit lalZeptoUnit ;
247extern const LALUnit lalYoctoUnit ;
248
249/* Convenient Scaled Units */
250extern const LALUnit lalGramUnit ;
251extern const LALUnit lalAttoStrainUnit;
252extern const LALUnit lalPicoFaradUnit ;
253
254/** @} */
255/* end: Units_h */
256
257#ifdef __cplusplus
258}
259#endif
260
261#endif /* _UNITS_H */
double REAL8
Double precision real floating-point number (8 bytes).
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.
Definition: LALDatatypes.h:480
const LALUnit lalExaUnit
Exa [1e18].
Definition: UnitDefs.c:193
LALUnit * XLALUnitDivide(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
UNDOCUMENTED.
Definition: UnitMultiply.c:108
int XLALUnitIsDimensionless(const LALUnit *unit)
Return 1 if a unit is dimensionless, 0 otherwise.
Definition: UnitCompare.c:36
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 lalZeptoUnit
Zepto [1e-21].
Definition: UnitDefs.c:209
const LALUnit lalMicroUnit
Micro [1e-6].
Definition: UnitDefs.c:204
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
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
const LALUnit lalTeraUnit
Tera [1e12].
Definition: UnitDefs.c:195
const LALUnit lalDekaUnit
Deka [1e1].
Definition: UnitDefs.c:200
const LALUnit lalCentiUnit
Centi [1e-2].
Definition: UnitDefs.c:202
const LALUnit lalDeciUnit
Deci [1e-1].
Definition: UnitDefs.c:201
char * XLALUnitToString(const LALUnit *input)
Allocates and returns a new string, which is populated with the unit string.
Definition: UnitDefs.c:332
enumLALUnitNameSize
Definition: Units.h:170
const LALUnit lalHectoUnit
Hecto [1e2].
Definition: UnitDefs.c:199
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
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
const LALUnit lalAttoStrainUnit
AttoStrain [1e-18].
Definition: UnitDefs.c:216
const LALUnit lalCoulombUnit
Coulomb [C].
Definition: UnitDefs.c:180
const LALUnit lalZettaUnit
Zetta [1e21].
Definition: UnitDefs.c:192
REAL8 XLALUnitRatio(const LALUnit *unit1, const LALUnit *unit2)
Return the ratio unit1 / unit2.
Definition: UnitCompare.c:62
const LALUnit lalTeslaUnit
Tesla [T].
Definition: UnitDefs.c:186
const LALUnit lalSecondUnit
second [s]
Definition: UnitDefs.c:162
const LALUnit lalGigaUnit
Giga [1e9].
Definition: UnitDefs.c:196
const LALUnit lalGramUnit
Gram [1e-3].
Definition: UnitDefs.c:215
const LALUnit lalJouleUnit
Joule [J].
Definition: UnitDefs.c:174
const CHAR lalUnitName[LALNumUnits][LALUnitNameSize]
To convert a units structure to a string repesentation, we need to define the names of the basic unit...
Definition: UnitDefs.c:135
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
const LALUnit lalPetaUnit
Peta [1e15].
Definition: UnitDefs.c:194
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
const LALUnit lalPicoFaradUnit
PicoFarad [1e-12 F].
Definition: UnitDefs.c:217
const LALUnit lalAttoUnit
Atto [1e-18].
Definition: UnitDefs.c:208
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 lalFemtoUnit
Femto [1e-15].
Definition: UnitDefs.c:207
const LALUnit lalPascalUnit
Pascal [Pa].
Definition: UnitDefs.c:173
const LALUnit lalMegaUnit
Mega [1e6].
Definition: UnitDefs.c:197
const LALUnit lalNanoUnit
Nano [1e-9].
Definition: UnitDefs.c:205
const LALUnit lalYoctoUnit
Yocto [1e-24].
Definition: UnitDefs.c:210
LALUnit * XLALUnitRaiseINT2(LALUnit *output, const LALUnit *input, INT2 power)
Raises a LALUnit structure to an integer power power.
Definition: UnitRaise.c:106
LALUnit * XLALUnitSqrt(LALUnit *output, const LALUnit *input)
Produces the square-root of a LALUnit structure.
Definition: UnitRaise.c:133
const LALUnit lalYottaUnit
Yotta [1e24].
Definition: UnitDefs.c:191
LALUnit * XLALUnitInvert(LALUnit *output, const LALUnit *input)
UNDOCUMENTED.
Definition: UnitRaise.c:144
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
LALUnit * XLALUnitSquare(LALUnit *output, const LALUnit *input)
Produces the square of a LALUnit structure.
Definition: UnitRaise.c:120
enumLALUnitTextSize
Definition: Units.h:173
REAL8 XLALUnitPrefactor(const LALUnit *unit)
Return the unit's prefactor.
Definition: UnitCompare.c:51
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
const LALUnit lalFaradUnit
Farad [F].
Definition: UnitDefs.c:183
const LALUnit lalPicoUnit
Pico [1e-12].
Definition: UnitDefs.c:206
const LALUnit lalMilliUnit
Milli [1e-3].
Definition: UnitDefs.c:203
@ LALUnitNameSize
Definition: Units.h:171
@ LALUnitTextSize
Definition: Units.h:174
This structure stores units in the mksA system (plus Kelvin, Strain, and ADC Count).
Definition: LALDatatypes.h:498
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
void output(int gps_sec, int output_type)
Definition: tconvert.c:440