das2C
das core C utilities (v3)
plane.h
Go to the documentation of this file.
1 /* Copyright (C) 2017-2024 Chris Piker <chris-piker@uiowa.edu>
2  * 2004 Jeremy Faden <jeremy-faden@uiowa.edu>
3  *
4  * This file is part of das2C, the Core Das2 C Library.
5  *
6  * das2C 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  * das2C 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 das2C; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
21 #ifndef _das_plane_h_
22 #define _das_plane_h_
23 
24 #include <math.h>
25 #include <stdbool.h>
26 
27 #include <das2/buffer.h>
28 #include <das2/descriptor.h>
29 #include <das2/units.h>
30 #include <das2/encoding.h>
31 #include <das2/datum.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /* ************************************************************************* */
59 typedef enum plane_type {Invalid=-1, X=2001, Y=2003, Z=2004, YScan=2012
60 } plane_type_t;
61 
62 
63 typedef enum ytag_spec {ytags_none=0, ytags_list=1, ytags_series=2} ytag_spec_t;
64 
66 plane_type_t str2PlaneType(const char * type);
67 
69 DAS_API const char* PlaneType_toStr( plane_type_t type );
70 
71 /* ************************************************************************* */
120 typedef struct plane_descriptor{
121  DasDesc base;
122 
123  plane_type_t planeType;
124  char* sName;
125 
126  /* The encoder/decoder used to read and write values for this plane. */
127  DasEncoding* pEncoding;
128 
129  /* The units of measurement for values in this plane */
130  das_units units;
131 
132  /* The number of values in each packet of this plane.
133  * For planes other than <yscan>'s this is always 1
134  */
135  size_t uItems;
136 
137  /* Das 2.3 note
138  * One of the fundamental assumptions in this code, way back from when
139  * Jeremy started it was that all data could be converted to doubles.
140  * for high-time resolution data this just won't work. There is no way
141  * to encode time to nano-second accuracy over any appreciable time range
142  * in a 64 bit floating point value.
143  *
144  * Furthermore, some data types are just fine as they are, there is no
145  * reason to convert them. We should think about removing this restriction.
146  * for das 2.3.
147  *
148  * --cwp 2018-10-25
149  */
150  double* pData;
151  double value; /* Convenience for planes that only store one data point */
152  bool bAlloccedBuf; /* true if had to allocate a data buffer (<yscan> only)*/
153 
154  double rFill; /* The fill value for this plane, will be wrapped in a
155  macro to make isFill look like a function */
156  bool _bFillSet; /* Flag to make sure fill value has been set */
157 
158  ytag_spec_t ytag_spec;
159 
160  double* pYTags; /* Explicit Y value array <yscan>'s */
161 
162  double yTagInter; /* Or spec as a series <yscans>'s */
163  double yTagMin;
164  double yTagMax;
165 
166  das_units yTagUnits;
167  DasEncoding* pYEncoding;
168 
169  /* set to true setValues or decode is called, set to false when encode is
170  * called */
171  bool bPlaneDataValid;
172 
173  /* User data pointer.
174  * The stream->packet->plane hierarchy provides a good organizational
175  * structure for application data, especially for applications whose
176  * purpose is to filter streams. This pointer can be used to hold
177  * a reference to information that is not serialized. It is initialized
178  * to NULL when a Plane Descriptor is created otherwise the library
179  * doesn't deal with it in any other way. */
180  void* pUser;
181 
182 } PlaneDesc;
183 
188 
207  plane_type_t pt, const char* sGroup, DasEncoding* pType, das_units units
208 );
209 
237  const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
238  DasEncoding* pYType, const double* pYTags, das_units yUnits
239 );
240 
268  const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
269  double yTagInter, double yTagMin, double yTagMax, das_units yUnits
270 );
271 
272 /* Creates a new plane descriptor from attribute strings
273  *
274  * Unlike the other top-level descriptor objects in a Das2 Stream planes
275  * are not independent XML documents. This constructor is called from
276  * the new_PktDesc_xml constructor to build plane descriptor object from
277  * keyword / value stlye string lists. The top level XML parsing is handled
278  * by the PktDesc class.
279  *
280  * @param pParent the Properties parent for the new plane descriptor, this
281  * is always a PktDesc object pointer.
282  *
283  * @param pt The ::PlaneType, must be one of:
284  * - X
285  * - Y
286  * - YScan
287  * - Z
288  *
289  * @param attrs A null terminated array of strings. It is assumed that
290  * the strings represent keyword value pairs. i.e the first string
291  * is a setting name, such as 'units' the second string is the the
292  * value for 'units'. Strings are processed in pairs until a NULL
293  * pointer is encountered.
294  *
295  * @todo When encountering ASCII times, change the units to us2000 to better
296  * preserve precision for fine times for down stream processors.
297  *
298  * @returns A pointer to new PlaneDesc allocated on the heap or NULL on an
299  * error
300  * @memberof PlaneDesc
301  */
302 DAS_API PlaneDesc* new_PlaneDesc_pairs(
303  DasDesc* pParent, plane_type_t pt, const char** attrs
304 );
305 
313 DAS_API PlaneDesc* PlaneDesc_copy(const PlaneDesc* pThis);
314 
315 
324 DAS_API void del_PlaneDesc(PlaneDesc* pThis);
325 
347 DAS_API bool PlaneDesc_equivalent(const PlaneDesc* pThis, const PlaneDesc* pOther);
348 
356 
364 DAS_API size_t PlaneDesc_getNItems(const PlaneDesc* pThis);
365 
380 DAS_API void PlaneDesc_setNItems(PlaneDesc* pThis, size_t nItems);
381 
382 
395 DAS_API double PlaneDesc_getValue(const PlaneDesc* pThis, size_t uIdx);
396 
397 
415  const PlaneDesc* pThis, size_t uIdx, das_datum* pD
416 );
417 
418 
430 DAS_API DasErrCode PlaneDesc_setValue(PlaneDesc* pThis, size_t uIdx, double value);
431 
449  PlaneDesc* pThis, const char* sTime, size_t idx
450 );
451 
461 
470 DAS_API void PlaneDesc_setValEncoder(PlaneDesc* pThis, DasEncoding* pEnc);
471 
484 DAS_API const double* PlaneDesc_getValues(const PlaneDesc* pThis);
485 
486 
496 DAS_API void PlaneDesc_setValues(PlaneDesc* pThis, const double* pData);
497 
498 
504 DAS_API double PlaneDesc_getFill(const PlaneDesc* pThis );
505 
510 #define PlaneDesc_isFill(P, V) \
511  ((P->rFill == 0.0 && V == 0.0) || (fabs((P->rFill - V)/P->rFill)<0.00001))
512 
513 /* bool PlaneDesc_isFill(const PlaneDesc* pThis, double value ); */
514 
518 DAS_API void PlaneDesc_setFill( PlaneDesc* pThis, double value );
519 
524 DAS_API const char* PlaneDesc_getName(const PlaneDesc* pThis );
525 
526 
533 DAS_API void PlaneDesc_setName(PlaneDesc* pThis, const char* sName);
534 
535 
540 DAS_API das_units PlaneDesc_getUnits(const PlaneDesc* pThis );
541 
552 DAS_API void PlaneDesc_setUnits(PlaneDesc* pThis, das_units units);
553 
559 
565 DAS_API void PlaneDesc_setYTagUnits(PlaneDesc* pThis, das_units units);
566 
567 
576 DAS_API ytag_spec_t PlaneDesc_getYTagSpec(const PlaneDesc* pThis);
577 
588 DAS_API const double* PlaneDesc_getYTags(const PlaneDesc* pThis);
589 
590 
598 DAS_API const double* PlaneDesc_getOrMakeYTags(PlaneDesc* pThis);
599 
600 
608 DAS_API void PlaneDesc_setYTags(PlaneDesc* pThis, const double* pYTags);
609 
629  const PlaneDesc* pThis, double* pInterval, double* pMin, double* pMax
630 );
631 
643  PlaneDesc* pThis, double rInterval, double rMin, double rMax
644 );
645 
646 
658  PlaneDesc* pThis, DasBuf* pBuf, const char* sIndent
659 );
660 
678 DAS_API DasErrCode PlaneDesc_encodeData(PlaneDesc* pThis, DasBuf* pBuf, bool bLast);
679 
687 DAS_API DasErrCode PlaneDesc_decodeData(const PlaneDesc* pThis, DasBuf* pBuf);
688 
689 #ifdef __cplusplus
690 }
691 #endif
692 
693 #endif /* _das_plane_h_ */
Utility to assist with encode and decode operations.
Defines storage and access methods for values in a das stream.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: defs.h:164
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
DAS_API void PlaneDesc_getYTagSeries(const PlaneDesc *pThis, double *pInterval, double *pMin, double *pMax)
Get the Y axis coordinate series for a 2-D plane of data.
DAS_API void PlaneDesc_setYTags(PlaneDesc *pThis, const double *pYTags)
Provide a new set of yTag values to a yScan plane.
DAS_API void PlaneDesc_setYTagSeries(PlaneDesc *pThis, double rInterval, double rMin, double rMax)
Set a YScan to use series definition for yTags.
DAS_API ytag_spec_t PlaneDesc_getYTagSpec(const PlaneDesc *pThis)
Get the storage method for yTag values.
DAS_API void PlaneDesc_setYTagUnits(PlaneDesc *pThis, das_units units)
Set the YTag units for a YScan plane.
DAS_API void PlaneDesc_setNItems(PlaneDesc *pThis, size_t nItems)
Set the number of items in a plane.
DAS_API const char * PlaneType_toStr(plane_type_t type)
Returns the string for the enumeration.
plane_type_t
An enumeration of packet data plane types.
Definition: plane.h:59
plane_type_t str2PlaneType(const char *type)
Returns the enumeration for the data type string.
Buffer class to handle accumulating byte streams.
Definition: buffer.h:47
Base structure for Stream Header Items.
Definition: descriptor.h:74
Reading and writing values to buffers.
Definition: encoding.h:108
Describes a data plane within a packet type.
Definition: plane.h:120
DAS_API bool PlaneDesc_equivalent(const PlaneDesc *pThis, const PlaneDesc *pOther)
Check to see if two plane descriptors describe the same output.
DAS_API das_units PlaneDesc_getYTagUnits(PlaneDesc *pThis)
Get Y axis units for a 2-D plane.
DAS_API PlaneDesc * new_PlaneDesc(plane_type_t pt, const char *sGroup, DasEncoding *pType, das_units units)
Creates a new X,Y or Z plane descriptor.
DAS_API size_t PlaneDesc_getNItems(const PlaneDesc *pThis)
Get the number of items in a plane YScan planes have a variable number of items, for all other types ...
DAS_API double PlaneDesc_getValue(const PlaneDesc *pThis, size_t uIdx)
Get the a value from a plane.
DAS_API PlaneDesc * new_PlaneDesc_yscan(const char *sGroup, DasEncoding *pZType, das_units zUnits, size_t uItems, DasEncoding *pYType, const double *pYTags, das_units yUnits)
Creates a new <yscan> plane descriptor.
DAS_API DasErrCode PlaneDesc_decodeData(const PlaneDesc *pThis, DasBuf *pBuf)
Read in a plane's current data.
DAS_API DasErrCode PlaneDesc_encode(PlaneDesc *pThis, DasBuf *pBuf, const char *sIndent)
Serialize a Plane Descriptor as XML data.
DAS_API const double * PlaneDesc_getOrMakeYTags(PlaneDesc *pThis)
Get Y tags as an array regardless of the storage type If a yTags array is constructed via this method...
DAS_API PlaneDesc * new_PlaneDesc_yscan_series(const char *sGroup, DasEncoding *pZType, das_units zUnits, size_t uItems, double yTagInter, double yTagMin, double yTagMax, das_units yUnits)
Creates a new <yscan> plane descriptor using a yTag series.
DAS_API const double * PlaneDesc_getValues(const PlaneDesc *pThis)
Get a pointer to the current set of values in a plane.
DAS_API DasEncoding * PlaneDesc_getValEncoder(PlaneDesc *pThis)
Get the data value encoder/decoder object for a plane The encoder returned via this pointer can be mu...
DAS_API DasErrCode PlaneDesc_setValue(PlaneDesc *pThis, size_t uIdx, double value)
Set a current value in a plane.
DAS_API const double * PlaneDesc_getYTags(const PlaneDesc *pThis)
Get Y axis coordinates for a 2-D plane of data.
DAS_API DasErrCode PlaneDesc_setTimeValue(PlaneDesc *pThis, const char *sTime, size_t idx)
Set a single time value in a plane.
DAS_API DasErrCode PlaneDesc_encodeData(PlaneDesc *pThis, DasBuf *pBuf, bool bLast)
Serialize a plane's current data.
DAS_API void PlaneDesc_setFill(PlaneDesc *pThis, double value)
Identify the double fill value for the plane.
DAS_API void PlaneDesc_setUnits(PlaneDesc *pThis, das_units units)
Set the unit type for the plane data.
DAS_API void del_PlaneDesc(PlaneDesc *pThis)
Free a plane object allocated on the heap.
DAS_API PlaneDesc * new_PlaneDesc_empty(void)
Creates a Plane Descriptor with mostly empty settings.
DAS_API PlaneDesc * PlaneDesc_copy(const PlaneDesc *pThis)
Copy constructor for planes Deep copy one a plane except for the parent id.
DAS_API void PlaneDesc_setName(PlaneDesc *pThis, const char *sName)
Set the data group of a plane.
DAS_API double PlaneDesc_getFill(const PlaneDesc *pThis)
Returns the fill value identified for the plane.
DAS_API void PlaneDesc_setValues(PlaneDesc *pThis, const double *pData)
Set all the current values for a plane.
DAS_API const char * PlaneDesc_getName(const PlaneDesc *pThis)
Get the data group of a plane.
DAS_API const das_datum * PlaneDesc_getDatum(const PlaneDesc *pThis, size_t uIdx, das_datum *pD)
Get a datum from a plane.
DAS_API plane_type_t PlaneDesc_getType(const PlaneDesc *pThis)
Get a plane's type.
DAS_API void PlaneDesc_setValEncoder(PlaneDesc *pThis, DasEncoding *pEnc)
Set the data value encoder/decoder object for a plane The previous encoder's memory is returned the h...
DAS_API das_units PlaneDesc_getUnits(const PlaneDesc *pThis)
Get the units of measure for a plane's packet data.
An atomic data processing unit, and it's units.
Definition: datum.h:67
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...