das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
form_vec.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * Author: C. Piker, via Claude Opus 5
4 *
5 * This file is part of das2C, the Core Das2 C Library.
6 *
7 * Das2C is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License version 2.1 as published
9 * by the Free Software Foundation.
10 *
11 * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
18 */
19
52#ifndef _das_form_vec_h_
53#define _das_form_vec_h_
54
55#include <das3/form.h>
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/* --- component systems --------------------------------------------------- *
62 *
63 * The six geometric systems, one vocabulary for vectors and positions alike.
64 * The first four need no origin. Detic and graphic are lat/lon/alt ON a
65 * reference ellipsoid, so the systems that need a surface are exactly the
66 * systems that need an origin, and only a position may use them.
67 *
68 * That last rule belongs to the FORMALISM, not to the vocabulary. The
69 * das_vsys_* lookups answer for all six, and new_DasFormVector() and the
70 * vector system= parser refuse anything past DAS_VSYS_VEC_MAX themselves. The
71 * names and symbols are plain data that consumers -- das3_spice, das3_cdf, the
72 * CDF reader -- read across all six without caring which form issued a code,
73 * and splitting the lookups at the formalism line only made each of them pick
74 * a family first. form_pos.h includes this file, so position code needs only
75 * that header.
76 *
77 * The ID SPACE IS SHARED with form_cplx.h, which continues it at 7. Separate
78 * per-formalism spaces would be tidier, but a ubyte would then only be
79 * readable next to the form that issued it. The das_vsys_* lookups answer
80 * NULL or -1 for the complex codes.
81 */
82
83#define DAS_VSYS_TYPE_MASK 0x0000000F
84#define DAS_VSYS_UNKNOWN 0x00000000
85#define DAS_VSYS_MIN 0x00000001
86
87#define DAS_VSYS_CART 0x00000001 /* x, y, z */
88#define DAS_VSYS_CYL 0x00000002 /* rho, phi, z */
89#define DAS_VSYS_SPH 0x00000003 /* r, colatitude from +Z, phi */
90#define DAS_VSYS_CENTRIC 0x00000004 /* r, phi, latitude from the equator */
91#define DAS_VSYS_DETIC 0x00000005 /* eastward lon, lat, alt (Earth) */
92#define DAS_VSYS_GRAPHIC 0x00000006 /* WESTWARD lon, lat, alt */
93
94#define DAS_VSYS_VEC_MAX 0x00000004 /* the last one a free vector may use */
95#define DAS_VSYS_MAX 0x00000006 /* the last geometric system */
96
98DAS_API const char* das_vsys_toStr(ubyte uSys);
99
103DAS_API ubyte das_vsys_fromStr(const char* sSys);
104
107DAS_API const char* das_vsys_desc(ubyte uSys);
108
111DAS_API const char* das_vsys_symbol(ubyte uSys, int iDir);
112
115DAS_API int8_t das_vsys_index(ubyte uSys, const char* sSymbol);
116
120DAS_API const char* das_vsys_name(ubyte uSys, int iDir);
121
125DAS_API int8_t das_vsys_nameIndex(ubyte uSys, const char* sName);
126
128#define das_vsys_isEllipsoidal(S) \
129 (((S) == DAS_VSYS_DETIC)||((S) == DAS_VSYS_GRAPHIC))
130
139DAS_API double das_vsys_default(ubyte uSys, int iDir);
140
141/* Exported so that its address can be compared. Client code uses the
142 DAS_FORM_VEC macro below and has no reason to name this directly. */
143DAS_API extern const DasForm_VTbl das_form_vector_vtbl;
144
148#define DAS_FORM_VEC (&das_form_vector_vtbl)
149
161DAS_API DasForm* new_DasFormVector(
162 const char* sFrame, ubyte uSysType, const ubyte* pDirs
163);
164
171DAS_API const char* DasFormVector_frame(const DasForm* pThis);
172
174DAS_API ubyte DasFormVector_sysType(const DasForm* pThis);
175
179DAS_API const ubyte* DasFormVector_dirs(const DasForm* pThis);
180
181/* For a component's display symbol -- "x", "λ", "θ" -- use DasVar_compSym(),
182 which works for every kind of composite value and not just this one. */
183
184/* To read a vector datum's components use das_datum_toDoubles(). It returns
185 them in storage order and leaves any slot it does not fill untouched, so set
186 those from das_vsys_default() above when a stream sends fewer components
187 than its system defines. */
188
189
190/* --- coordinate system conversion --------------------------------------- *
191 *
192 * Free functions rather than form methods, because form_pos.c needs them
193 * for the systems it shares with this file. No kernel data is involved;
194 * the trigonometry is exact for the four systems a free vector may use.
195 * Agreement with cspice's conventions is checked by test/TestSpice.c rather
196 * than by linking cspice in, so libdas3's numbers never depend on a build
197 * setting.
198 */
199
217DAS_API bool das_vsys_toCart(ubyte uSys, const double* pIn, double* pOut);
218
241DAS_API bool das_vsys_fromCart(ubyte uSys, const double* pIn, double* pOut);
242
243#ifdef __cplusplus
244}
245#endif
246
247#endif /* _das_form_vec_h_ */
What a variable's values (i.e.
DAS_API const char * das_vsys_desc(ubyte uSys)
One line of prose about any of the six, for a "notes" property.
DAS_API int8_t das_vsys_index(ubyte uSys, const char *sSymbol)
The inverse of das_vsys_symbol(): which direction a symbol names.
DAS_API bool das_vsys_fromCart(ubyte uSys, const double *pIn, double *pOut)
Convert one cartesian vector to a component system.
DAS_API const char * das_vsys_toStr(ubyte uSys)
Wire token for any of the six system codes, NULL if unrecognized.
DAS_API int8_t das_vsys_nameIndex(ubyte uSys, const char *sName)
The inverse of das_vsys_name(), also accepting the symbols, so both "theta" and the Greek letter give...
DAS_API double das_vsys_default(ubyte uSys, int iDir)
The value an ABSENT component of this system defaults to.
DAS_API bool das_vsys_toCart(ubyte uSys, const double *pIn, double *pOut)
Convert one vector from a component system to cartesian.
DAS_API ubyte das_vsys_fromStr(const char *sSys)
Wire token to system code across all six, DAS_VSYS_UNKNOWN if unrecognized.
DAS_API const char * das_vsys_symbol(ubyte uSys, int iDir)
The canonical symbol for direction iDir of a system: "x", "r", "λ", "h" ...
DAS_API const char * das_vsys_name(ubyte uSys, int iDir)
The ASCII name for direction iDir of any of the six: "x", "rho", "theta", "lambda",...