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
71DAS_API plane_type_t das_plane_type_fromStr(const char* sType);
72
78DAS_API const char* das_plane_type_toStr(plane_type_t type);
79
80/* ************************************************************************* */
129typedef struct plane_descriptor{
130 DasDesc base;
131
132 plane_type_t planeType;
133 char* sName;
134
135 /* The encoder/decoder used to read and write values for this plane. */
136 DasEncoding* pEncoding;
137
138 /* The units of measurement for values in this plane */
139 das_units units;
140
141 /* The number of values in each packet of this plane.
142 * For planes other than <yscan>'s this is always 1
143 */
144 size_t uItems;
145
146 /* Das 3.0 note:
147 * One of the fundamental assumptions in this code, way back from when
148 * it started was that all data could be converted to doubles. That
149 * remains true for this old packet structure. For das3 streams many
150 * data types are supported, see codec.h and array.h for details.
151 */
152 double* pData;
153 double value; /* Convenience for planes that only store one data point */
154 bool bAlloccedBuf; /* true if had to allocate a data buffer (<yscan> only)*/
155
156 double rFill; /* The fill value for this plane, will be wrapped in a
157 macro to make isFill look like a function */
158 bool _bFillSet; /* Flag to make sure fill value has been set */
159
160 ytag_spec_t ytag_spec;
161
162 double* pYTags; /* Explicit Y value array <yscan>'s */
163
164 double yTagInter; /* Or spec as a series <yscans>'s */
165 double yTagMin;
166 double yTagMax;
167
168 das_units yTagUnits;
169 DasEncoding* pYEncoding;
170
171 /* set to true setValues or decode is called, set to false when encode is
172 * called */
173 bool bPlaneDataValid;
174
175 /* User data pointer.
176 * The stream->packet->plane hierarchy provides a good organizational
177 * structure for application data, especially for applications whose
178 * purpose is to filter streams. This pointer can be used to hold
179 * a reference to information that is not serialized. It is initialized
180 * to NULL when a Plane Descriptor is created otherwise the library
181 * doesn't deal with it in any other way. */
182 void* pUser;
183
184} PlaneDesc;
185
190
209 plane_type_t pt, const char* sGroup, DasEncoding* pType, das_units units
210);
211
239 const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
240 DasEncoding* pYType, const double* pYTags, das_units yUnits
241);
242
270 const char* sGroup, DasEncoding* pZType, das_units zUnits, size_t uItems,
271 double yTagInter, double yTagMin, double yTagMax, das_units yUnits
272);
273
274/* Creates a new plane descriptor from attribute strings
275 *
276 * Unlike the other top-level descriptor objects in a Das2 Stream planes
277 * are not independent XML documents. This constructor is called from
278 * the new_PktDesc_xml constructor to build plane descriptor object from
279 * keyword / value style string lists. The top level XML parsing is handled
280 * by the PktDesc class.
281 *
282 * @param pParent the Properties parent for the new plane descriptor, this
283 * is always a PktDesc object pointer.
284 *
285 * @param pt The ::PlaneType, must be one of:
286 * - X
287 * - Y
288 * - YScan
289 * - Z
290 *
291 * @param attrs A null terminated array of strings. It is assumed that
292 * the strings represent keyword value pairs. i.e the first string
293 * is a setting name, such as 'units' the second string is the the
294 * value for 'units'. Strings are processed in pairs until a NULL
295 * pointer is encountered.
296 *
297 * @todo When encountering ASCII times, change the units to us2000 to better
298 * preserve precision for fine times for down stream processors.
299 *
300 * @returns A pointer to new PlaneDesc allocated on the heap or NULL on an
301 * error
302 * @memberof PlaneDesc
303 */
304DAS_API PlaneDesc* new_PlaneDesc_pairs(
305 DasDesc* pParent, plane_type_t pt, const char** attrs
306);
307
315DAS_API PlaneDesc* PlaneDesc_copy(const PlaneDesc* pThis);
316
317
326DAS_API void del_PlaneDesc(PlaneDesc* pThis);
327
349DAS_API bool PlaneDesc_equivalent(const PlaneDesc* pThis, const PlaneDesc* pOther);
350
358
366DAS_API size_t PlaneDesc_getNItems(const PlaneDesc* pThis);
367
382DAS_API void PlaneDesc_setNItems(PlaneDesc* pThis, size_t nItems);
383
384
397DAS_API double PlaneDesc_getValue(const PlaneDesc* pThis, size_t uIdx);
398
399
416DAS_API const das_datum* PlaneDesc_getDatum(
417 const PlaneDesc* pThis, size_t uIdx, das_datum* pD
418);
419
420
432DAS_API DasErrCode PlaneDesc_setValue(PlaneDesc* pThis, size_t uIdx, double value);
433
451 PlaneDesc* pThis, const char* sTime, size_t idx
452);
453
463
473
486DAS_API const double* PlaneDesc_getValues(const PlaneDesc* pThis);
487
488
498DAS_API void PlaneDesc_setValues(PlaneDesc* pThis, const double* pData);
499
500
506DAS_API double PlaneDesc_getFill(const PlaneDesc* pThis );
507
512#define PlaneDesc_isFill(P, V) \
513 ((P->rFill == 0.0 && V == 0.0) || (fabs((P->rFill - V)/P->rFill)<0.00001))
514
515/* bool PlaneDesc_isFill(const PlaneDesc* pThis, double value ); */
516
520DAS_API void PlaneDesc_setFill( PlaneDesc* pThis, double value );
521
526DAS_API const char* PlaneDesc_getName(const PlaneDesc* pThis );
527
528
535DAS_API void PlaneDesc_setName(PlaneDesc* pThis, const char* sName);
536
537
543
554DAS_API void PlaneDesc_setUnits(PlaneDesc* pThis, das_units units);
555
561
567DAS_API void PlaneDesc_setYTagUnits(PlaneDesc* pThis, das_units units);
568
569
579#define PlaneDesc_getYTagSpec(P) ((P)->ytag_spec)
580
586#define PlaneDesc_getYTagInterval(P) \
587 (((P)->ytag_spec == ytags_series) ? (P)->yTagInter : DAS_FILL_VALUE)
588
594#define PlaneDesc_getYTagMin(P) \
595 (((P)->ytag_spec == ytags_series) ? (P)->yTagMin : DAS_FILL_VALUE)
596
607DAS_API const double* PlaneDesc_getYTags(const PlaneDesc* pThis);
608
609
617DAS_API const double* PlaneDesc_getOrMakeYTags(PlaneDesc* pThis);
618
619
627DAS_API void PlaneDesc_setYTags(PlaneDesc* pThis, const double* pYTags);
628
648 const PlaneDesc* pThis, double* pInterval, double* pMin, double* pMax
649);
650
662 PlaneDesc* pThis, double rInterval, double rMin, double rMax
663);
664
665
677 PlaneDesc* pThis, DasBuf* pBuf, const char* sIndent
678);
679
697DAS_API DasErrCode PlaneDesc_encodeData(PlaneDesc* pThis, DasBuf* pBuf, bool bLast);
698
706DAS_API DasErrCode PlaneDesc_decodeData(const PlaneDesc* pThis, DasBuf* pBuf);
707
708#ifdef __cplusplus
709}
710#endif
711
712#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:189
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:141
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 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 * das_plane_type_toStr(plane_type_t type)
Get the das2 element name for a plane type.
plane_type_t
An enumeration of packet data plane types.
Definition plane.h:59
DAS_API plane_type_t das_plane_type_fromStr(const char *sType)
Get the plane type for a das2 element name.
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:96
Describes a data plane within a packet type.
Definition plane.h:129
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...