das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
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 <das3/buffer.h>
28#include <das3/descriptor.h>
29#include <das3/units.h>
30#include <das3/encoding.h>
31#include <das3/datum.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* ************************************************************************* */
59typedef enum plane_type {Invalid=-1, X=2001, Y=2003, Z=2004, YScan=2012
61
62
63typedef enum ytag_spec {ytags_none=0, ytags_list=1, ytags_series=2} ytag_spec_t;
64
66plane_type_t str2PlaneType(const char * type);
67
69DAS_API const char* PlaneType_toStr( plane_type_t type );
70
71/* ************************************************************************* */
120typedef 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 3.0 note:
138 * One of the fundamental assumptions in this code, way back from when
139 * it started was that all data could be converted to doubles. That
140 * remains true for this old packet structure. For das3 streams many
141 * data types are supported, see codec.h and array.h for details.
142 */
143 double* pData;
144 double value; /* Convenience for planes that only store one data point */
145 bool bAlloccedBuf; /* true if had to allocate a data buffer (<yscan> only)*/
146
147 double rFill; /* The fill value for this plane, will be wrapped in a
148 macro to make isFill look like a function */
149 bool _bFillSet; /* Flag to make sure fill value has been set */
150
151 ytag_spec_t ytag_spec;
152
153 double* pYTags; /* Explicit Y value array <yscan>'s */
154
155 double yTagInter; /* Or spec as a series <yscans>'s */
156 double yTagMin;
157 double yTagMax;
158
159 das_units yTagUnits;
160 DasEncoding* pYEncoding;
161
162 /* set to true setValues or decode is called, set to false when encode is
163 * called */
164 bool bPlaneDataValid;
165
166 /* User data pointer.
167 * The stream->packet->plane hierarchy provides a good organizational
168 * structure for application data, especially for applications whose
169 * purpose is to filter streams. This pointer can be used to hold
170 * a reference to information that is not serialized. It is initialized
171 * to NULL when a Plane Descriptor is created otherwise the library
172 * doesn't deal with it in any other way. */
173 void* pUser;
174
175} PlaneDesc;
176
181
200 plane_type_t pt, const char* sGroup, DasEncoding* pType, das_units units
201);
202
230 const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
231 DasEncoding* pYType, const double* pYTags, das_units yUnits
232);
233
261 const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
262 double yTagInter, double yTagMin, double yTagMax, das_units yUnits
263);
264
265/* Creates a new plane descriptor from attribute strings
266 *
267 * Unlike the other top-level descriptor objects in a Das2 Stream planes
268 * are not independent XML documents. This constructor is called from
269 * the new_PktDesc_xml constructor to build plane descriptor object from
270 * keyword / value style string lists. The top level XML parsing is handled
271 * by the PktDesc class.
272 *
273 * @param pParent the Properties parent for the new plane descriptor, this
274 * is always a PktDesc object pointer.
275 *
276 * @param pt The ::PlaneType, must be one of:
277 * - X
278 * - Y
279 * - YScan
280 * - Z
281 *
282 * @param attrs A null terminated array of strings. It is assumed that
283 * the strings represent keyword value pairs. i.e the first string
284 * is a setting name, such as 'units' the second string is the the
285 * value for 'units'. Strings are processed in pairs until a NULL
286 * pointer is encountered.
287 *
288 * @todo When encountering ASCII times, change the units to us2000 to better
289 * preserve precision for fine times for down stream processors.
290 *
291 * @returns A pointer to new PlaneDesc allocated on the heap or NULL on an
292 * error
293 * @memberof PlaneDesc
294 */
295DAS_API PlaneDesc* new_PlaneDesc_pairs(
296 DasDesc* pParent, plane_type_t pt, const char** attrs
297);
298
306DAS_API PlaneDesc* PlaneDesc_copy(const PlaneDesc* pThis);
307
308
317DAS_API void del_PlaneDesc(PlaneDesc* pThis);
318
340DAS_API bool PlaneDesc_equivalent(const PlaneDesc* pThis, const PlaneDesc* pOther);
341
349
357DAS_API size_t PlaneDesc_getNItems(const PlaneDesc* pThis);
358
373DAS_API void PlaneDesc_setNItems(PlaneDesc* pThis, size_t nItems);
374
375
388DAS_API double PlaneDesc_getValue(const PlaneDesc* pThis, size_t uIdx);
389
390
407DAS_API const das_datum* PlaneDesc_getDatum(
408 const PlaneDesc* pThis, size_t uIdx, das_datum* pD
409);
410
411
423DAS_API DasErrCode PlaneDesc_setValue(PlaneDesc* pThis, size_t uIdx, double value);
424
442 PlaneDesc* pThis, const char* sTime, size_t idx
443);
444
454
464
477DAS_API const double* PlaneDesc_getValues(const PlaneDesc* pThis);
478
479
489DAS_API void PlaneDesc_setValues(PlaneDesc* pThis, const double* pData);
490
491
497DAS_API double PlaneDesc_getFill(const PlaneDesc* pThis );
498
503#define PlaneDesc_isFill(P, V) \
504 ((P->rFill == 0.0 && V == 0.0) || (fabs((P->rFill - V)/P->rFill)<0.00001))
505
506/* bool PlaneDesc_isFill(const PlaneDesc* pThis, double value ); */
507
511DAS_API void PlaneDesc_setFill( PlaneDesc* pThis, double value );
512
517DAS_API const char* PlaneDesc_getName(const PlaneDesc* pThis );
518
519
526DAS_API void PlaneDesc_setName(PlaneDesc* pThis, const char* sName);
527
528
534
545DAS_API void PlaneDesc_setUnits(PlaneDesc* pThis, das_units units);
546
552
558DAS_API void PlaneDesc_setYTagUnits(PlaneDesc* pThis, das_units units);
559
560
569DAS_API ytag_spec_t PlaneDesc_getYTagSpec(const PlaneDesc* pThis);
570
581DAS_API const double* PlaneDesc_getYTags(const PlaneDesc* pThis);
582
583
591DAS_API const double* PlaneDesc_getOrMakeYTags(PlaneDesc* pThis);
592
593
601DAS_API void PlaneDesc_setYTags(PlaneDesc* pThis, const double* pYTags);
602
622 const PlaneDesc* pThis, double* pInterval, double* pMin, double* pMax
623);
624
636 PlaneDesc* pThis, double rInterval, double rMin, double rMax
637);
638
639
651 PlaneDesc* pThis, DasBuf* pBuf, const char* sIndent
652);
653
671DAS_API DasErrCode PlaneDesc_encodeData(PlaneDesc* pThis, DasBuf* pBuf, bool bLast);
672
680DAS_API DasErrCode PlaneDesc_decodeData(const PlaneDesc* pThis, DasBuf* pBuf);
681
682#ifdef __cplusplus
683}
684#endif
685
686#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:184
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:144
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 const char * PlaneType_toStr(plane_type_t type)
Returns the string for the enumeration.
DAS_API void PlaneDesc_setNItems(PlaneDesc *pThis, size_t nItems)
Set the number of items in a plane.
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.
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...