libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plane.h
Go to the documentation of this file.
1 /* Copyright (C) 2004-2017 Jeremy Faden <jeremy-faden@uiowa.edu>
2  * Chris Piker <chris-piker@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 
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 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* ************************************************************************* */
58 typedef enum plane_type {Invalid=-1, X=2001, Y=2003, Z=2004, YScan=2012
59 } plane_type_t;
60 
61 
62 typedef enum ytag_spec {ytags_none=0, ytags_list=1, ytags_series=2} ytag_spec_t;
63 
65 plane_type_t str2PlaneType(const char * type);
66 
68 const char* PlaneType_toStr( plane_type_t type );
69 
70 /* ************************************************************************* */
119 typedef struct plane_descriptor{
120  DasDesc base;
121 
122  plane_type_t planeType;
123  char* sName;
124 
125  /* The encoder/decoder used to read and write values for this plane. */
126  DasEncoding* pEncoding;
127 
128  /* The units of measurement for values in this plane */
129  das_units units;
130 
131  /* The number of values in each packet of this plane.
132  * For planes other than <yscan>'s this is always 1
133  */
134  size_t uItems;
135 
136  /* Das 2.3 note
137  * One of the fundamental assumptions in this code, way back from when
138  * Jeremy started it was that all data could be converted to doubles.
139  * for high-time resolution data this just won't work. There is no way
140  * to encode time to nano-second accuracy over any appreciable time range
141  * in a 64 bit floating point value.
142  *
143  * Furthermore, some data types are just fine as they are, there is no
144  * reason to convert them. We should think about removing this restriction.
145  * for das 2.3.
146  *
147  * --cwp 2018-10-25
148  */
149  double* pData;
150  double value; /* Convenience for planes that only store one data point */
151  bool bAlloccedBuf; /* true if had to allocate a data buffer (<yscan> only)*/
152 
153  double rFill; /* The fill value for this plane, will be wrapped in a
154  macro to make isFill look like a function */
155  bool _bFillSet; /* Flag to make sure fill value has been set */
156 
157  ytag_spec_t ytag_spec;
158 
159  double* pYTags; /* Explicit Y value array <yscan>'s */
160 
161  double yTagInter; /* Or spec as a series <yscans>'s */
162  double yTagMin;
163  double yTagMax;
164 
165  das_units yTagUnits;
166  DasEncoding* pYEncoding;
167 
168  /* set to true setValues or decode is called, set to false when encode is
169  * called */
170  bool bPlaneDataValid;
171 
172  /* User data pointer.
173  * The stream->packet->plane hierarchy provides a good organizational
174  * structure for application data, especially for applications whose
175  * purpose is to filter streams. This pointer can be used to hold
176  * a reference to information that is not serialized. It is initialized
177  * to NULL when a Plane Descriptor is created otherwise the library
178  * doesn't deal with it in any other way. */
179  void* pUser;
180 
181 } PlaneDesc;
182 
187 
206  plane_type_t pt, const char* sGroup, DasEncoding* pType, das_units units
207 );
208 
236  const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
237  DasEncoding* pYType, const double* pYTags, das_units yUnits
238 );
239 
267  const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
268  double yTagInter, double yTagMin, double yTagMax, das_units yUnits
269 );
270 
271 /* Creates a new plane descriptor from attribute strings
272  *
273  * Unlike the other top-level descriptor objects in a Das2 Stream planes
274  * are not independent XML documents. This constructor is called from
275  * the new_PktDesc_xml constructor to build plane descriptor object from
276  * keyword / value stlye string lists. The top level XML parsing is handled
277  * by the PktDesc class.
278  *
279  * @param pParent the Properties parent for the new plane descriptor, this
280  * is always a PktDesc object pointer.
281  *
282  * @param pt The ::PlaneType, must be one of:
283  * - X
284  * - Y
285  * - YScan
286  * - Z
287  *
288  * @param attrs A null terminated array of strings. It is assumed that
289  * the strings represent keyword value pairs. i.e the first string
290  * is a setting name, such as 'units' the second string is the the
291  * value for 'units'. Strings are processed in pairs until a NULL
292  * pointer is encountered.
293  *
294  * @todo When encountering ASCII times, change the units to us2000 to better
295  * preserve precision for fine times for down stream processors.
296  *
297  * @returns A pointer to new PlaneDesc allocated on the heap or NULL on an
298  * error
299  * @memberof PlaneDesc
300  */
301 PlaneDesc* new_PlaneDesc_pairs(
302  DasDesc* pParent, plane_type_t pt, const char** attrs
303 );
304 
312 PlaneDesc* PlaneDesc_copy(const PlaneDesc* pThis);
313 
314 
323 void del_PlaneDesc(PlaneDesc* pThis);
324 
346 bool PlaneDesc_equivalent(const PlaneDesc* pThis, const PlaneDesc* pOther);
347 
355 
363 size_t PlaneDesc_getNItems(const PlaneDesc* pThis);
364 
379 void PlaneDesc_setNItems(PlaneDesc* pThis, size_t nItems);
380 
381 
394 double PlaneDesc_getValue(const PlaneDesc* pThis, size_t uIdx);
395 
407 DasErrCode PlaneDesc_setValue(PlaneDesc* pThis, size_t uIdx, double value);
408 
426  PlaneDesc* pThis, const char* sTime, size_t idx
427 );
428 
438 
447 void PlaneDesc_setValEncoder(PlaneDesc* pThis, DasEncoding* pEnc);
448 
461 const double* PlaneDesc_getValues(const PlaneDesc* pThis);
462 
463 
473 void PlaneDesc_setValues(PlaneDesc* pThis, const double* pData);
474 
475 
481 double PlaneDesc_getFill(const PlaneDesc* pThis );
482 
487 #define PlaneDesc_isFill(P, V) \
488  ((P->rFill == 0.0 && V == 0.0) || (fabs((P->rFill - V)/P->rFill)<0.00001))
489 
490 /* bool PlaneDesc_isFill(const PlaneDesc* pThis, double value ); */
491 
495 void PlaneDesc_setFill( PlaneDesc* pThis, double value );
496 
501 const char* PlaneDesc_getName(const PlaneDesc* pThis );
502 
503 
510 void PlaneDesc_setName(PlaneDesc* pThis, const char* sName);
511 
512 
517 das_units PlaneDesc_getUnits(const PlaneDesc* pThis );
518 
529 void PlaneDesc_setUnits(PlaneDesc* pThis, das_units units);
530 
536 
542 void PlaneDesc_setYTagUnits(PlaneDesc* pThis, das_units units);
543 
544 
553 ytag_spec_t PlaneDesc_getYTagSpec(const PlaneDesc* pThis);
554 
565 const double* PlaneDesc_getYTags(const PlaneDesc* pThis);
566 
567 
575 const double* PlaneDesc_getOrMakeYTags(PlaneDesc* pThis);
576 
577 
585 void PlaneDesc_setYTags(PlaneDesc* pThis, const double* pYTags);
586 
606  const PlaneDesc* pThis, double* pInterval, double* pMin, double* pMax
607 );
608 
620  PlaneDesc* pThis, double rInterval, double rMin, double rMax
621 );
622 
623 
635  PlaneDesc* pThis, DasBuf* pBuf, const char* sIndent
636 );
637 
655 DasErrCode PlaneDesc_encodeData(PlaneDesc* pThis, DasBuf* pBuf, bool bLast);
656 
664 DasErrCode PlaneDesc_decodeData(const PlaneDesc* pThis, DasBuf* pBuf);
665 
666 #ifdef __cplusplus
667 }
668 #endif
669 
670 #endif /* _das_plane_h_ */
Describes a data plane within a packet type.
Definition: plane.h:119
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: util.h:117
DasEncoding * PlaneDesc_getValEncoder(PlaneDesc *pThis)
Get the data value encoder/decoder object for a plane The encoder returned via this pointer can be mu...
void PlaneDesc_setValEncoder(PlaneDesc *pThis, DasEncoding *pEnc)
Set the data value encoder/decoder object for a plane The previous encoder&#39;s memory is returned the h...
das_units PlaneDesc_getYTagUnits(PlaneDesc *pThis)
Get Y axis units for a 2-D plane.
PlaneDesc * PlaneDesc_copy(const PlaneDesc *pThis)
Copy constructor for planes Deep copy one a plane except for the parent id.
double PlaneDesc_getFill(const PlaneDesc *pThis)
Returns the fill value identified for the plane.
DasErrCode PlaneDesc_setValue(PlaneDesc *pThis, size_t uIdx, double value)
Set a current value in a plane.
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...
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 ...
Little buffer class to handle accumulating string data.
Definition: buffer.h:49
plane_type_t str2PlaneType(const char *type)
Returns the enumeration for the data type string.
bool PlaneDesc_equivalent(const PlaneDesc *pThis, const PlaneDesc *pOther)
Check to see if two plane descriptors describe the same output.
const double * PlaneDesc_getYTags(const PlaneDesc *pThis)
Get Y axis coordinates for a 2-D plane of data.
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 &lt;yscan&gt; plane descriptor.
Base structure for Stream Header Items.
Definition: descriptor.h:80
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.
Reading and writing values on das2 streams.
Definition: encoding.h:108
const double * PlaneDesc_getValues(const PlaneDesc *pThis)
Get a pointer to the current set of values in a plane.
DasErrCode PlaneDesc_encode(PlaneDesc *pThis, DasBuf *pBuf, const char *sIndent)
Serialize a Plane Descriptor as XML data.
void PlaneDesc_setNItems(PlaneDesc *pThis, size_t nItems)
Set the number of items in a plane.
Defines storage and access methods for values in a Das2 Stream.
void PlaneDesc_setYTagSeries(PlaneDesc *pThis, double rInterval, double rMin, double rMax)
Set a YScan to use series definition for yTags.
double PlaneDesc_getValue(const PlaneDesc *pThis, size_t uIdx)
Get the first value from a plane.
void PlaneDesc_setYTagUnits(PlaneDesc *pThis, das_units units)
Set the YTag units for a YScan plane.
DasErrCode PlaneDesc_decodeData(const PlaneDesc *pThis, DasBuf *pBuf)
Read in a plane&#39;s current data.
ytag_spec_t PlaneDesc_getYTagSpec(const PlaneDesc *pThis)
Get the storage method for yTag values.
void del_PlaneDesc(PlaneDesc *pThis)
Free a plane object allocated on the heap.
const char * PlaneDesc_getName(const PlaneDesc *pThis)
Get the data group of a plane.
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...
DasErrCode PlaneDesc_setTimeValue(PlaneDesc *pThis, const char *sTime, size_t idx)
Set a single time value in a plane.
void PlaneDesc_setYTags(PlaneDesc *pThis, const double *pYTags)
Provide a new set of yTag values to a yScan plane.
plane_type_t
An enumeration of packet data plane types.
Definition: plane.h:58
Utility to assist with encode and decode operations.
const char * PlaneType_toStr(plane_type_t type)
Returns the string for the enumeration.
void PlaneDesc_setUnits(PlaneDesc *pThis, das_units units)
Set the unit type for the plane data.
DasErrCode PlaneDesc_encodeData(PlaneDesc *pThis, DasBuf *pBuf, bool bLast)
Serialize a plane&#39;s current data.
void PlaneDesc_setName(PlaneDesc *pThis, const char *sName)
Set the data group of a plane.
plane_type_t PlaneDesc_getType(const PlaneDesc *pThis)
Get a plane&#39;s type.
void PlaneDesc_setValues(PlaneDesc *pThis, const double *pData)
Set all the current values for a plane.
const char * das_units
Enumeration of unit types, that correspond to physical unit types.
Definition: units.h:135
PlaneDesc * new_PlaneDesc_empty(void)
Creates a Plane Descriptor with mostly empty settings.
das_units PlaneDesc_getUnits(const PlaneDesc *pThis)
Get the units of measure for a plane&#39;s packet data.
void PlaneDesc_setFill(PlaneDesc *pThis, double value)
Identify the double fill value for the plane.
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 &lt;yscan&gt; plane descriptor using a yTag series.
PlaneDesc * new_PlaneDesc(plane_type_t pt, const char *sGroup, DasEncoding *pType, das_units units)
Creates a new X,Y or Z plane descriptor.