libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 /* Other common units */
46 extern const char* UNIT_SECONDS;
47 extern const char* UNIT_HOURS;
48 extern const char* UNIT_DAYS;
49 extern const char* UNIT_MILLISECONDS;
50 extern const char* UNIT_MICROSECONDS;
51 extern const char* UNIT_NANOSECONDS;
52 
53 extern const char* UNIT_HERTZ;
54 extern const char* UNIT_KILO_HERTZ;
55 extern const char* UNIT_MEGA_HERTZ;
56 extern const char* UNIT_E_SPECDENS;
57 extern const char* UNIT_B_SPECDENS;
58 extern const char* UNIT_NT;
59 
60 extern const char* UNIT_NUMBER_DENS;
61 
62 extern const char* UNIT_DB;
63 
64 extern const char* UNIT_KM;
65 
66 extern const char* UNIT_DEGREES;
67 extern const char* UNIT_DIMENSIONLESS;
68 
69 /* color: Color should be handled as as vector, we don't have
70  * support for vectors at this time. Also a datatype of
71  * byte is needed for small values
72  */
73 /* extern const char* UNIT_RGB; */
74 
75 
76 #endif
77 
135 typedef const char* das_units;
136 
137 
147 das_units Units_fromStr(const char* string);
148 
149 
155 const char* Units_toStr(das_units unit);
156 
157 
179 char* Units_toLabel(das_units unit, char* sBuf, int nLen);
180 
181 
206 das_units Units_invert(das_units unit);
207 
208 
223 das_units Units_multiply(das_units ut1, das_units ut2);
224 
237 das_units Units_divide(das_units a, das_units b);
238 
239 
254 das_units Units_power(das_units unit, int power);
255 
256 
269 das_units Units_root(das_units unit, int root );
270 
271 
286 das_units Units_interval(das_units unit);
287 
288 
309 das_units Units_reduce(das_units orig, double* pFactor);
310 
321 bool Units_canConvert(das_units fromUnits , das_units toUnits);
322 
323 
336 double Units_convertTo( das_units toUnits, double rVal, das_units fromUnits );
337 
338 
355 bool Units_haveCalRep(das_units unit);
356 
357 
368 void Units_convertToDt(das_time* pDt, double value, das_units epoch_units);
369 
377 double Units_convertFromDt(das_units epoch_units, const das_time* pDt);
378 
384 double Units_secondsSinceMidnight( double rVal, das_units epoch_units );
385 
386 
387 /* Get the Julian day for the Datum (double,unit) */
388 int Units_getJulianDay( double timeDouble, das_units epoch_units );
389 
397 bool Units_canMerge(das_units left, int op, das_units right);
398 
401 #ifdef __cplusplus
402 }
403 #endif
404 
405 #endif /* _das_units_h_ */
das_units Units_invert(das_units unit)
Invert the units, most commonly used for Fourier transform results.
Das Time Utilities.
bool Units_haveCalRep(das_units unit)
Determine if the units in question can be converted to date-times.
char * Units_toLabel(das_units unit, char *sBuf, int nLen)
Get label string representation das_units.
void Units_convertToDt(das_time *pDt, double value, das_units epoch_units)
Convert a value in time offset units to a calendar representation.
das_units Units_root(das_units unit, int root)
Reduce units to a root.
double Units_convertTo(das_units toUnits, double rVal, das_units fromUnits)
Generic unit conversion utility.
const char * Units_toStr(das_units unit)
Get the canonical string representation of a das_unit Even though das_unit is a const char*...
das_units Units_interval(das_units unit)
Get the unit type for intervals between data points of a given unit type.
das_units Units_multiply(das_units ut1, das_units ut2)
Combine units via multiplication.
das_units Units_fromStr(const char *string)
Basic constructor for das_unit&#39;s.
double Units_secondsSinceMidnight(double rVal, das_units epoch_units)
Get seconds since midnight for some value of an epoch time unit.
das_units Units_divide(das_units a, das_units b)
Combine units via division.
das_units Units_reduce(das_units orig, double *pFactor)
Reduce arbitrary units to the most basic know representation.
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...
bool Units_canMerge(das_units left, int op, das_units right)
Determine if the units of values in a binary expression are compatable.
das_units Units_power(das_units unit, int power)
Raise units to a power.
double Units_convertFromDt(das_units epoch_units, const das_time *pDt)
Convert a calendar representation of a time to value in time offset units.
Basic date-time structure used throughout the Das1 &amp; Das2 utilities.
Definition: time.h:47
const char * das_units
Enumeration of unit types, that correspond to physical unit types.
Definition: units.h:135