das2C
das core C utilities (v3)
datum.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of das2C, the Core Das2 C Library.
4  *
5  * Das2C is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
20 #ifndef _das_datum_h_
21 #define _das_datum_h_
22 
23 #include <das2/value.h>
24 #include <das2/units.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define DATUM_BUF_SZ 32 // big enough to hold a das_vector and das_time
31 
67 typedef struct datum_t {
68  ubyte bytes[DATUM_BUF_SZ]; /* 32 bytes of space */
69  das_val_type vt;
70  uint32_t vsize;
71  das_units units;
72 } das_datum;
73 
88 #define das_datum_valid(p) ((p)->vsize > 0)
89 
90 ptrdiff_t das_datum_shape0(const das_datum* pThis);
91 
103 DAS_API bool das_datum_fromStr(das_datum* pThis, const char* sStr);
104 
115 DAS_API bool das_datum_fromDbl(das_datum* pThis, double value, das_units units);
116 
137 DAS_API bool das_datum_wrapStr(das_datum* pTHis, const char* sStr, das_units units);
138 
139 
146 DAS_API bool das_datum_byteSeq(
147  das_datum* pThis, das_byteseq seq, das_units units
148 );
149 
174 DAS_API char* das_datum_toStr(
175  const das_datum* pThis, char* sStr, size_t uLen, int nFracDigits
176 );
177 
184  const das_datum* pThis, char* sStr, size_t uLen, int nFracDigits
185 );
186 
187 
197 DAS_API double das_datum_toDbl(const das_datum* pThis);
198 
199 
212 DAS_API bool das_datum_toEpoch(
213  const das_datum* pThis, das_units epoch, double* pResult
214 );
215 
220 #define das_datum_asStr(dm) *((char**)&dm)
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* _das_datum_h_ */
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
das_val_type
Enumeration of types stored in Das Array (DasAry) objects from value.h.
Definition: value.h:64
An atomic data processing unit, and it's units.
Definition: datum.h:67
DAS_API bool das_datum_byteSeq(das_datum *pThis, das_byteseq seq, das_units units)
Wrap an external unknown type pointer as a datum.
DAS_API bool das_datum_fromStr(das_datum *pThis, const char *sStr)
Initialize a numeric datum from a value and units string.
DAS_API char * das_datum_toStr(const das_datum *pThis, char *sStr, size_t uLen, int nFracDigits)
Write a UTF-8 string representation of a datum to a buffer.
DAS_API double das_datum_toDbl(const das_datum *pThis)
Get a datum value as a double.
DAS_API char * das_datum_toStrValOnly(const das_datum *pThis, char *sStr, size_t uLen, int nFracDigits)
Same as das_datum_toStr, but never print the units.
DAS_API bool das_datum_wrapStr(das_datum *pTHis, const char *sStr, das_units units)
Wrap an external string as a datum.
DAS_API bool das_datum_fromDbl(das_datum *pThis, double value, das_units units)
Create a datum from a double value and units.
DAS_API bool das_datum_toEpoch(const das_datum *pThis, das_units epoch, double *pResult)
Get a time datum value as a double at a given epoch an scale.
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...
A generic value type for use in arrays, datums and variables.