das2C
das core C utilities (v3)
units.h
Go to the documentation of this file.
1 /* Copyright (C) 2004-2017 Chris Piker <chris-piker@uiowa.edu>
2  * Jeremy Faden <jeremy-faden@uiowa.edu>
3  *
4  * This file is part of libdas2, the Core Das2 C Library.
5  *
6  * Libdas2 is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * Libdas2 is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
24 #ifndef _das_units_h_
25 #define _das_units_h_
26 
27 #include <stdbool.h>
28 #include <das2/time.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 bool units_init(const char* sProgName);
35 
36 #ifndef _das_units_c_
37 
38 extern const char* UNIT_US2000; /* microseconds since midnight, Jan 1, 2000 */
39 extern const char* UNIT_MJ1958; /* days since midnight, Jan 1, 1958 */
40 extern const char* UNIT_T2000; /* seconds since midnight, Jan 1, 2000 */
41 extern const char* UNIT_T1970; /* seconds since midnight, Jan 1, 1970 */
42 extern const char* UNIT_NS1970; /* nanoseconds since midnight, Jan 1, 1970 */
43 extern const char* UNIT_UTC; /* Time strings on the Gregorian Calendar */
44 
45 /* nanoseconds since 2000-01-01T11:58:55.816, the only leap-second aware time
46  unit in the library. Uses the CDF_LEAPSECONDSTABLE environment variable
47  to find new leap seconds. Not needed if library has been build since
48  last know leapsecond in the data time. */
49 extern const char* UNIT_TT2000;
50 
51 /* Other common units */
52 extern const char* UNIT_SECONDS;
53 extern const char* UNIT_HOURS;
54 extern const char* UNIT_DAYS;
55 extern const char* UNIT_MILLISECONDS;
56 extern const char* UNIT_MICROSECONDS;
57 extern const char* UNIT_NANOSECONDS;
58 
59 extern const char* UNIT_HERTZ;
60 extern const char* UNIT_KILO_HERTZ;
61 extern const char* UNIT_MEGA_HERTZ;
62 extern const char* UNIT_E_SPECDENS;
63 extern const char* UNIT_B_SPECDENS;
64 extern const char* UNIT_NT;
65 
66 extern const char* UNIT_NUMBER_DENS;
67 
68 extern const char* UNIT_DB;
69 
70 extern const char* UNIT_KM;
71 
72 extern const char* UNIT_EV;
73 
74 extern const char* UNIT_DEGREES;
75 extern const char* UNIT_DIMENSIONLESS;
76 
77 /* color: Color should be handled as as vector, we don't have
78  * support for vectors at this time. Also a datatype of
79  * byte is needed for small values
80  */
81 /* extern const char* UNIT_RGB; */
82 
83 
84 #endif
85 
139 typedef const char* das_units;
140 
153 DAS_API das_units Units_fromStr(const char* string);
154 
155 
162 DAS_API const char* Units_toStr(das_units unit);
163 
164 
186 DAS_API char* Units_toLabel(das_units unit, char* sBuf, int nLen);
187 
188 
214 
215 
231 
245 
246 
261 DAS_API das_units Units_power(das_units unit, int power);
262 
263 
276 DAS_API das_units Units_root(das_units unit, int root );
277 
278 
294 
295 
316 DAS_API das_units Units_reduce(das_units orig, double* pFactor);
317 
328 DAS_API bool Units_canConvert(das_units fromUnits , das_units toUnits);
329 
330 
343 DAS_API double Units_convertTo( das_units toUnits, double rVal, das_units fromUnits );
344 
345 
362 DAS_API bool Units_haveCalRep(das_units unit);
363 
364 
375 DAS_API void Units_convertToDt(das_time* pDt, double value, das_units epoch_units);
376 
384 DAS_API double Units_convertFromDt(das_units epoch_units, const das_time* pDt);
385 
391 DAS_API double Units_secondsSinceMidnight( double rVal, das_units epoch_units );
392 
393 
394 /* Get the Julian day for the Datum (double,unit) */
395 DAS_API int Units_getJulianDay( double timeDouble, das_units epoch_units );
396 
404 DAS_API bool Units_canMerge(das_units left, int op, das_units right);
405 
406 #ifdef __cplusplus
407 }
408 #endif
409 
410 #endif /* _das_units_h_ */
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition: time.h:43
Das Time Utilities.
DAS_API double Units_convertTo(das_units toUnits, double rVal, das_units fromUnits)
Generic unit conversion utility.
DAS_API das_units Units_invert(das_units unit)
Invert the units, most commonly used for Fourier transform results.
DAS_API das_units Units_reduce(das_units orig, double *pFactor)
Reduce arbitrary units to the most basic know representation.
DAS_API double Units_convertFromDt(das_units epoch_units, const das_time *pDt)
Convert a calendar representation of a time to value in time offset units.
DAS_API das_units Units_root(das_units unit, int root)
Reduce units to a root.
DAS_API bool Units_canConvert(das_units fromUnits, das_units toUnits)
Determine if given units are interchangeable Though not as good a solution as using UDUNITS2 works fo...
DAS_API das_units Units_divide(das_units a, das_units b)
Combine units via division.
DAS_API bool Units_haveCalRep(das_units unit)
Determine if the units in question can be converted to date-times.
DAS_API bool Units_canMerge(das_units left, int op, das_units right)
Determine if the units of values in a binary expression are compatible.
DAS_API das_units Units_power(das_units unit, int power)
Raise units to a power.
DAS_API void Units_convertToDt(das_time *pDt, double value, das_units epoch_units)
Convert a value in time offset units to a calendar representation.
DAS_API char * Units_toLabel(das_units unit, char *sBuf, int nLen)
Get label string representation das_units.
DAS_API das_units Units_interval(das_units unit)
Get the unit type for intervals between data points of a given unit type.
DAS_API das_units Units_multiply(das_units ut1, das_units ut2)
Combine units via multiplication.
DAS_API double Units_secondsSinceMidnight(double rVal, das_units epoch_units)
Get seconds since midnight for some value of an epoch time unit.