das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
das2_compat.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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
60#ifndef _das2_compat_h_
61#define _das2_compat_h_
62
63#include <string.h>
64
65#include <das3/core.h>
66#include <das3/generator.h>
67
68/* v2.3.0's core.h included these, today's does not */
69#include <das3/utf8.h>
70#include <das3/plane.h>
71#include <das3/packet.h>
72#include <das3/dsdf.h>
73#include <das3/builder.h>
74#include <das3/dft.h>
75#include <das3/credentials.h>
76#include <das3/http.h>
77#include <das3/node.h>
78
79/* The rest of the v2.3.0 installed headers, which core.h never included */
80#include <das3/das1.h>
81#include <das3/send.h>
82#include <das3/cli.h>
83#include <das3/json.h>
84
85/* ************************************************************************* */
86/* Basic types */
87
88/* Only ubyte is left. Both are uint8_t, so the old byte* signatures of
89 DasAry_*, getpkt() and friends take a ubyte* unchanged. */
90typedef ubyte byte;
91
92/* ************************************************************************* */
93/* Text output, 2026-10 (issue #7)
94 *
95 * Rules now: X_info() is a possibly multi-line summary that returns the
96 * length needed, as snprintf does. X_toStr() is one short line that returns
97 * sBuf, or NULL if it was cut off. Buffer sizes are size_t.
98 */
99
100/* DasDs_toStr() and DasDim_toStr() used to print the whole multi-line
101 description, which is now DasDs_info() and DasDim_info(). The new _toStr
102 functions print one line. These restore the old output and the old
103 return of sBuf; NULL is no longer returned when the buffer is short. */
104#define DasDs_toStr(P, B, N) (DasDs_info((P), (B), (size_t)(N)), (B))
105#define DasDim_toStr(P, B, N) (DasDim_info((P), (B), (size_t)(N)), (B))
106
107/* das_shape_prnRng() returned the end of the written text, for appending.
108 B is evaluated twice. */
109#define das_shape_prnRng(S, E, L, B, N) \
110 (das_shape_info((S), (E), (L), (B), (size_t)(N)), (B) + strlen(B))
111
112/* DasEnc_toStr() returned 0 on success, an error code otherwise */
113#define DasEnc_toStr(P, B, N) \
114 ((DasEnc_toStr((P), (B), (size_t)(N)) == NULL) ? DASERR_ENC : DAS_OKAY)
115
116/* das_url_toStr() returned true on success; the new non-NULL return reads
117 the same in a test, so no macro.
118
119 These kept their names and char* returns but now return NULL, instead of a
120 cut off sBuf, when the text doesn't fit:
121 DasVar_toStr, DasAry_toStr, das_datum_toStr, das_datum_toStrValOnly,
122 Units_toLabel
123
124 Their int length arguments are now size_t.
125
126 das_doubles2csv() gained a buffer length after pBuf. No macro, there is no
127 honest default; the compiler's "too few arguments" marks each call. */
128
129/* das_idx_prn() was declared in array.h but never exported, it is private */
130#define das_idx_prn(...) das_idx_prn_is_private__see_das2_compat_h
131
132/* ************************************************************************* */
133/* Time functions, 2026-10: das_time* first, as if it were "this" */
134
135#define dt_isoc(B, N, T, F) dt_isoc((T), (B), (size_t)(N), (F))
136#define dt_isod(B, N, T, F) dt_isod((T), (B), (size_t)(N), (F))
137#define dt_dual_str(B, N, T, F) dt_dual_str((T), (B), (size_t)(N), (F))
138#define dt_parsetime(S, T) dt_parsetime((T), (S))
139#define dt_emitt(TT, T) dt_emitt((T), (TT))
140#define dt_from_1958(D, MS, T) dt_from_1958((T), (D), (MS))
141
142#define dt_cmp dt_compare
143
144/* ************************************************************************* */
145/* Code to name lookups, 2026-10: _toStr / _fromStr pairs */
146
147#define PlaneType_toStr das_plane_type_toStr
148#define str2PlaneType das_plane_type_fromStr
149#define LogLvl_string das_loglvl_toStr
150
151/* ************************************************************************* */
152/* Streams */
153
154/* StreamDesc became DasStream. Packet descriptors are now one kind of
155 DasDesc a stream holds (datasets are the other), so the *PktDesc names
156 that work on either kind lost the "Pkt". */
157#define stream_descriptor das_stream /* struct tag */
158#define StreamDesc DasStream
159#define StreamDescHandler DasStreamHandler
160#define new_StreamDesc new_DasStream
161#define new_StreamDesc_str new_DasStream_str
162#define del_StreamDesc del_DasStream
163#define StreamDesc_copy DasStream_copy
164#define StreamDesc_getNPktDesc DasStream_numDesc
165#define StreamDesc_addPktDesc DasStream_addDesc
166#define StreamDesc_freePktDesc DasStream_freeDesc
167#define StreamDesc_setMonotonic DasStream_setMonotonic
168#define StreamDesc_addStdProps DasStream_addStdProps
169#define StreamDesc_addCmdLineProp DasStream_addCmdLineProp
170#define StreamDesc_createPktDesc DasStream_createPktDesc
171#define StreamDesc_clonePktDesc DasStream_clonePktDesc
172#define StreamDesc_clonePktDescById DasStream_clonePktDescById
173#define StreamDesc_isValidId DasStream_isValidId
174#define StreamDesc_getPktDesc DasStream_getPktDesc
175
176/* The un-numbered encoders wrote das2 headers, das3 ones are _encode3 */
177#define StreamDesc_encode DasStream_encode2
178#define DasDesc_encode DasDesc_encode2
179
180/* Declared since the earliest das2C but never implemented, any use was
181 already a link error */
182#define StreamDesc_getOffset(...) StreamDesc_getOffset_never_existed
183
184/* The factory now takes the stream, the packet ID and the data model it
185 should parse into */
186#define Das2Desc_decode(...) Das2Desc_decode_removed__use_DasDesc_decode
187
188/* <packet group=> is not in the das2 schema; das2 plane names become das3
189 dataset groups, see DasDs_group() */
190#define PktDesc_getGroup(...) PktDesc_getGroup_removed__see_DasDs_group
191#define PktDesc_setGroup(...) PktDesc_setGroup_removed__see_DasDs_group
192
193/* Properties are no longer a fixed size table, DasDesc_length() counts them */
194#define DAS_XML_MAXPROPS DAS_XML_MAXPROPS_removed__use_DasDesc_length
195
196/* ************************************************************************* */
197/* Datasets, dimensions and the builder */
198
199#define dasds_iterator DasDsIter
200#define dasds_iter_init DasDsIter_init
201#define dasds_iter_next DasDsIter_next
202
203/* DasDs_getDim() now looks dimensions up by name, the index lookup kept its
204 behavior under a new name */
205#define DasDs_getDim DasDs_getDimByIdx
206
207/* Dimensions gained a name within their kind, so several can share a kind
208 ("Search_Coil" and "DC_MAG" are both "magnetic_field"). NULL makes the
209 name the same as the kind, the old behavior. */
210#define new_DasDim(S, T, R) new_DasDim((S), NULL, (T), (R))
211#define DasDs_makeDim(D, T, S) DasDs_makeDim((D), (T), (S), NULL)
212
213/* DasDs_addAry() returned true on success, now DAS_OKAY (0) */
214#define DasDs_addAry(D, A) (DasDs_addAry((D), (A)) == DAS_OKAY)
215
216/* DasDim_getVar() and DasDim_getPointVar() now take and return non-const
217 pointers; passing a const DasDim* warns. No macro. */
218
219/* Property merging moved to the descriptor base, which copies all of them
220 and returns nothing; the per-axis filtering of the DasDim version is gone */
221#define DasDs_copyInProps(...) DasDs_copyInProps_removed__use_DasDesc_copyIn
222#define DasDim_copyInProps(...) DasDim_copyInProps_removed__use_DasDesc_copyIn
223
224/* Declared under these names, defined only under the new ones */
225#define DASVAR_MAXERR DASVAR_MAX_ERR
226#define DASVAR_MINERR DASVAR_MIN_ERR
227
228/* "uncertainty" named no defined quantity */
229#define DASVAR_UNCERT DASVAR_UNCERT_removed__use_DASVAR_STD_DEV_or_MIN_ERR_MAX_ERR
230#define DASVAR_SPREAD DASVAR_SPREAD_withheld__no_point_spread_formalism_yet
231
232/* All three handed back pieces of the stream the builder assembles. Take
233 the whole stream instead with DasDsBldr_getStream(); its descriptors are
234 all DasDs objects, walk them with DasStream_nextDesc(). The stream itself
235 is the old "global properties" descriptor. stream_from_stdin() replaces
236 build_from_stdin(). */
237#define DasDsBldr_getDataSets(...) \
238 DasDsBldr_getDataSets_removed__use_DasDsBldr_getStream
239#define DasDsBldr_getProps(...) \
240 DasDsBldr_getProps_removed__use_DasDsBldr_getStream
241#define build_from_stdin(...) \
242 build_from_stdin_removed__use_stream_from_stdin
243
244/* ************************************************************************* */
245/* Index vocabulary: array extents are ARYIDX_*, dataset index space is
246 VARIDX_*. Same values, EXCEPT the maximum rank: DASIDX_MAX was 16 in
247 v2.3.0 and is 8 now, and the _INIT_ lists shrank to match. Arrays sized
248 DASIDX_MAX and filled from DASIDX_INIT_* still agree with each other. */
249
250#define DASIDX_MAX ARYIDX_MAX
251#define DASIDX_RAGGED VARIDX_RAGGED
252#define DASIDX_FUNC VARIDX_BORROW /* renamed DASIDX_BORROW, then this */
253#define DASIDX_UNUSED VARIDX_UNUSED
254#define DASIDX_INIT_UNUSED VARIDX_INIT_UNUSED
255#define DASIDX_INIT_BEGIN VARIDX_INIT_BEGIN
256#define DEGEN VARIDX_UNUSED
257
258/* The globals are gone, these compound literals still work as memcpy()
259 sources and in sizeof */
260#define g_aShapeUnused ((const ptrdiff_t[ARYIDX_MAX])VARIDX_INIT_UNUSED)
261#define g_aShapeZeros ((const ptrdiff_t[ARYIDX_MAX])VARIDX_INIT_BEGIN)
262
263/* ************************************************************************* */
264/* Values and datums */
265
266#define das_byteseq_t das_const_byte_seq_t
267#define das_byteseq das_cbyte_seq
268
269/* das_datum_toDbl() returned the value, DAS_FILL_VALUE on failure */
270static inline double _das2_compat_datum_toDbl(const das_datum* pDm)
271{
272 double rVal;
273 return das_datum_toDbl(pDm, &rVal) ? rVal : DAS_FILL_VALUE;
274}
275#define das_datum_toDbl(P) _das2_compat_datum_toDbl(P)
276
277/* ************************************************************************* */
278/* Variables, 2026-08 (the generator / formalism rewrite)
279 *
280 * A variable is now three parts: a generator for the values, a form saying
281 * what they mean, and the variable that joins them:
282 *
283 * pGen = new_DasGenAry(pAry, MAP_2(0, DEGEN)) (or new_DasGenSeq, ...Const)
284 * pForm = new_DasFormLinear() (scalars, form_lin.h)
285 * pVar = new_DasVar(pGen, units, pForm)
286 * DasGen_decRef(pGen); del_DasForm(pForm);
287 *
288 * new_DasGenAry() takes the same (rank, map) pair new_DasVarArray() did, so
289 * the MAP_n helpers below still fit it. Units are passed in, they are no
290 * longer taken from the array. Use new_DasVarComp() for variables with
291 * internal indices and new_DasVarBytes() for strings.
292 */
293
294#define MAP_0 0, (NULL)
295#define MAP_1(I) 1, (int8_t[1]){I}
296#define MAP_2(I,J) 2, (int8_t[2]){I,J}
297#define MAP_3(I,J,K) 3, (int8_t[3]){I,J,K}
298#define MAP_4(I,J,K,L) 4, (int8_t[4]){I,J,K,L}
299#define MAP_5(I,J,K,L,M) 5, (int8_t[5]){I,J,K,L,M}
300#define MAP_6(I,J,K,L,M,N) 6, (int8_t[6]){I,J,K,L,M,N}
301#define MAP_7(I,J,K,L,M,N,O) 7, (int8_t[7]){I,J,K,L,M,N,O}
302
303#define das_variable das_var /* struct tag, the fields all changed */
304
305#define var_type das_gen_type_e
306#define D2V_DATUM gtConst /* values differ, D2V_DATUM was 0 */
307#define D2V_SEQUENCE gtSeq
308#define D2V_ARRAY gtArray
309#define D2V_UNARY_OP gtUnop
310#define D2V_BINARY_OP gtBinop
311
312/* A binary operation has no generator. P is evaluated twice. */
313#define DasVar_type(P) \
314 (DasVar_gen(P) ? DasGen_type(DasVar_gen(P)) : gtBinop)
315
316/* The old meaning, an operator tree. NOT a test for a DasVarComp, which is
317 what "composite" means now. */
318#define DasVar_isComposite(P) (DasVar_gen(P) == NULL)
319
320#define DasVarAry_getArray DasVar_getAry
321#define ref_DasVar(P) ((P)->nRef)
322
323/* Returned true on success. A variable that needs caller scratch
324 (DasVar_getNeedsBuf) fails here, call DasVar_get() directly for those. */
325#define DasVar_getDatum(P, L, D) \
326 (DasVar_get((P), (L), (das_byte_seq){NULL, 0}, (D)) == 0)
327
328/* DasVar_subset() took a fifth argument, pShapeFrom; old calls add NULL to
329 wear the variable's own extents. No macro, DasVar_allVals() expands to
330 the five argument form. */
331
332#define D2V_EXP_UNITS D2V_EXP_removed__DasVar_toStr_takes_no_flags
333#define D2V_EXP_RANGE D2V_EXP_removed__DasVar_toStr_takes_no_flags
334#define D2V_EXP_SUBEX D2V_EXP_removed__DasVar_toStr_takes_no_flags
335
336#define new_DasVarArray(...) \
337 new_DasVarArray_removed__use_new_DasGenAry_plus_new_DasVar
338#define new_DasVarSeq(...) \
339 new_DasVarSeq_removed__use_new_DasGenSeq_plus_new_DasVar
340#define new_DasConstant(...) \
341 new_DasConstant_removed__use_new_DasGenConst_plus_new_DasVar
342#define new_DasVarUnary(...) \
343 new_DasVarUnary_removed__no_unary_vars_in_v3
344#define new_DasVarUnary_tok(...) \
345 new_DasVarUnary_removed__no_unary_vars_in_v3
346
347/* Not mapped onto new_DasVarBin() on purpose: the old call took over the
348 caller's operand references, the new one takes its own, so old callers
349 would leak. The id argument is gone and only + - * are accepted. */
350#define new_DasVarBinary(...) \
351 new_DasVarBinary_removed__use_new_DasVarBin
352
353#define DasVar_valSize(...) \
354 DasVar_valSize_removed__use_das_vt_size_of_elemType
355#define DasVar_isFill(...) \
356 DasVar_isFill_removed__compare_with_DasGen_getFill
357
358/* Declared but never implemented, any use was already a link error */
359#define DasVar_id(...) DasVar_id_never_existed
360#define DasVar_orthoginal(...) DasVar_orthoginal_never_existed__use_DasVar_degenerate
361#define new_DasVarEval(...) new_DasVarEval_never_existed__use_DasVar_materialize
362
363/* ************************************************************************* */
364/* Credentials */
365
366/* Gained a key argument (unused, NULL) and returns the rows saved or -1 */
367#define CredMngr_save(P, F) (CredMngr_save((P), NULL, (F)) >= 0)
368
369/* ************************************************************************* */
370/* das2 encodings: the integer categories were parsed but never read or written,
371 das3 streams carry integers through DasCodec */
372
373#define DAS2DT_BE_INT DAS2DT_BE_INT_removed__use_das3_DasCodec
374#define DAS2DT_LE_INT DAS2DT_LE_INT_removed__use_das3_DasCodec
375#define DAS2DT_BE_UINT DAS2DT_BE_UINT_removed__use_das3_DasCodec
376#define DAS2DT_LE_UINT DAS2DT_LE_UINT_removed__use_das3_DasCodec
377
378/* ************************************************************************* */
379/* Das1 output */
380
381/* Public names don't start with an underscore */
382#define _das_swap_float das_swap_float
383#define _swapBufInPlace das_swapBufInPlace
384
385/* Was a second copy of das_xml_escape() with the arguments in another order */
386#define _das_escape_xml(D, L, S) ((void)das_xml_escape((D), (S), (L)))
387
388/* ************************************************************************* */
389/* JSON */
390
391/* The json.h names all carry das_ now, this one was missed */
392#define json_parse_error_info das_json_parse_error_info
393
394/* utf8.h's character class helpers were generic names, now static in utf8.c */
395#define octal_digit(...) octal_digit_is_private__use_isdigit
396#define hex_digit(...) hex_digit_is_private__use_isxdigit
397
398/* ************************************************************************* */
399/* TT2000: tt2000.h is no longer installed. Its CDF style variadic calls took
400 every field as a double; time.h has integer versions, tt2k_from_parts() and
401 tt2k_to_parts(). These adapters keep the v2.3.0 behavior, including a
402 silent ILLEGAL_TT2000_VALUE for bad fields. */
403
404#define DAS_TT2000_JD_ORIGIN 2451545.0
405
406static inline long long _das2_compat_utc_to_tt2K(
407 double yr, double mt, double dy, double hr, double mn, double sc,
408 double ms, double us, double ns
409){
410 das_time dt = {0};
411 dt.year = (int)yr; dt.month = (int)mt; dt.mday = (int)dy;
412 dt.hour = (int)hr; dt.minute = (int)mn;
413 dt.second = sc + ms*1.0e-3 + us*1.0e-6 + ns*1.0e-9;
414 return dt_to_tt2k(&dt);
415}
416#define das_utc_to_tt2K(Y, M, D, h, m, s, ms, us, ns) \
417 _das2_compat_utc_to_tt2K((Y), (M), (D), (h), (m), (s), (ms), (us), (ns))
418
419static inline void _das2_compat_tt2K_to_utc(
420 long long tt, double* yr, double* mt, double* dy, double* hr, double* mn,
421 double* sc, double* ms, double* us, double* ns
422){
423 int y, m, d, h, n, s;
424 int32_t nNano;
425 tt2k_to_parts(tt, &y, &m, &d, &h, &n, &s, &nNano);
426 *yr = y; *mt = m; *dy = d; *hr = h; *mn = n; *sc = s;
427 *ms = nNano / 1000000; *us = (nNano / 1000) % 1000; *ns = nNano % 1000;
428}
429#define das_tt2K_to_utc(T, Y, M, D, h, m, s, ms, us, ns) \
430 _das2_compat_tt2K_to_utc((T), (Y), (M), (D), (h), (m), (s), (ms), (us), (ns))
431
432#define das_tt2K_to_us2K(T) Units_convertTo(UNIT_US2000, (T), UNIT_TT2000)
433#define das_us2K_to_tt2K(U) Units_convertTo(UNIT_TT2000, (U), UNIT_US2000)
434
435#define das_tt2k_reinit(...) das_tt2k_reinit_is_private__see_das2_compat_h
436
437/* ************************************************************************* */
438/* Exceptions, 2026-04: the type is a das_except_t, not a string
439 *
440 * The old type strings are kept and mapped with das_except_fromStr(), which
441 * also knows the das3 names; other strings map to DAS_EX_UNKNOWN. The
442 * OobExcept sType and uTypeLen members are gone, read nType or
443 * OobExcept_typeStr(). Exceptions are written with each stream version's
444 * own names, das_except_toStr() has the table.
445 */
446
447#define DAS2_EXCEPT_NO_DATA_IN_INTERVAL "NoDataInInterval"
448#define DAS2_EXCEPT_ILLEGAL_ARGUMENT "IllegalArgument"
449#define DAS2_EXCEPT_SERVER_ERROR "ServerError"
450#define EXCEPTION_UNTYPED ""
451
452#define OobExcept_set(P, T, M) \
453 OobExcept_set((P), das_except_fromStr(T), (M))
454#define DasIO_throwException(IO, S, T, M) \
455 DasIO_throwException((IO), (S), das_except_fromStr(T), (M))
456
457/* das_send_spice_err() took the type string too. This header can't include
458 <das3/spice.h>, which needs the CSPICE headers, and a function-like macro
459 would mangle that file's prototype if it came second, so the adapter is
460 only defined when spice.h was included FIRST. */
461#ifdef _das2_spice_H_
462#define das_send_spice_err(V, T) das_send_spice_err((V), das_except_fromStr(T))
463#endif
464
465#endif /* _das2_compat_h_ */
Das Reader Version 2.2/2.3 command line argument handling
A roll-up header for the core Das2 C-Library.
Handle storing credentials during a Das2 session and optionally save them to a file.
Das 1 Compatibility Utilities.
Provides a wrapper around FFTW for memory management and normalization.
Utilities for parsing DSDF files into descriptor objects.
Value sources for the DasVar layer.
functions for reading and writing http messages
Sheredom's json.h parser with global symbol name changes.
Header for Plane Descriptor Objects.
Das Reader output formatting helpers
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition time.h:43
double second
Second of the minute.
Definition time.h:69
int hour
Hour of day, range is 0 to 23.
Definition time.h:60
int minute
Minute of the hour, range 0 to 59.
Definition time.h:63
int mday
Calendar Day of month, starts at 1.
Definition time.h:52
int year
Calendar year number, cannot hold years before 1 AD.
Definition time.h:46
int month
Calendar month number, 1 = January.
Definition time.h:49
DAS_API void tt2k_to_parts(int64_t nTT, int *pYear, int *pMonth, int *pMday, int *pHour, int *pMinute, int *pSecond, int32_t *pNanosec)
Break a TT2000 time into UTC fields, without floating point seconds.
#define DAS_FILL_VALUE
Canonical fill value (.
Definition value.h:37