From ff5cfc0fdab3b3e13af74a8b56ff842428651b70 Mon Sep 17 00:00:00 2001 From: Chris Piker Date: Mon, 7 Oct 2024 14:25:24 -0500 Subject: [PATCH] Schema simpliciation for vectors --- das2/dataset_hdr3.c | 52 ++++++++++++---- das2/frame.c | 41 ++++--------- das2/frame.h | 6 +- das2/stream.c | 10 +-- das2/var_ary.c | 2 +- schema/das-basic-doc-ns-v3.0.xsd | 86 ++++++++++++++++---------- schema/das-basic-stream-ns-v3.0.xsd | 92 +++++++++++++++++----------- schema/das-basic-stream-v3.0.xsd | 38 +++++++----- test/ex15_vector_frame.d3b | 8 +-- test/ex17_vector_noframe.d3b | Bin 104176 -> 104189 bytes utilities/das3_cdf.c | 5 +- 11 files changed, 201 insertions(+), 139 deletions(-) diff --git a/das2/dataset_hdr3.c b/das2/dataset_hdr3.c index b4634fc..892d513 100644 --- a/das2/dataset_hdr3.c +++ b/das2/dataset_hdr3.c @@ -426,28 +426,48 @@ static void _serial_onOpenDim( /* ***************************************************************************** */ /* Helper: number of components and thier order in the packet */ -DasErrCode _setComponents(context_t* pCtx, const char* sComps){ +DasErrCode _setComponents(context_t* pCtx, const char* sNumComp, const char* sOrder) +{ ubyte uComp = 0; ubyte dirs = 0; - const char* p = sComps; + + if(sNumComp == NULL){ + return das_error(DASERR_SERIAL, + "Number of components were not specified for in dataset %d", + pCtx->nPktId + ); + } + if((strlen(sNumComp) > 1)||(sscanf(sNumComp, "%hhu", &uComp) != 1)||(uComp == 0)||(uComp > 3)) + return das_error(DASERR_SERIAL, "Invalid number of components '%s' for in dataset %d", + sNumComp, pCtx->nPktId + ); + + const char* p = sOrder; + ubyte uSeps = 0; while(*p != '\0'){ if(*p == ';'){ - uComp += 1; - if(pCtx->nVarComps > 3) goto ERROR_COMP_NUM; + uSeps += 1; + if(uSeps > 3) goto ERROR_COMP_NUM; } else{ switch(*p){ case '0': break; - case '1': dirs |= 1<<(uComp*2); break; - case '2': dirs |= 2<<(uComp*2); break; + case '1': dirs |= 1<<(uSeps*2); break; + case '2': dirs |= 2<<(uSeps*2); break; default: goto ERROR_COMP_NUM; } } ++p; } + + if((uSeps+1) != uComp) + return das_error(DASERR_SERIAL, + "Expected %d values in 'sysorder', found %d", uComp, uSeps+1 + ); + pCtx->varCompDirs = dirs; - pCtx->nVarComps = uComp + 1; + pCtx->nVarComps = uComp; /* Set the number of internal components for the variable map too */ pCtx->aVarMap[DasDs_rank(pCtx->pDs)] = pCtx->nVarComps; @@ -480,6 +500,9 @@ static void _serial_onOpenVar( /* Assume center until proven otherwise */ strncpy(pCtx->varUse, "center", DASDIM_ROLE_SZ-1); + const char* sNumber = NULL; + const char* sOrder = NULL; + for(int i = 0; psAttr[i] != NULL; i+=2){ if(strcmp(psAttr[i], "use") == 0) strncpy(pCtx->varUse, psAttr[i+1], DASDIM_ROLE_SZ-1); @@ -495,10 +518,10 @@ static void _serial_onOpenVar( strncpy(sIndex, psAttr[i+1], 31); else if(strcmp(psAttr[i], "units") == 0) pCtx->varUnits = Units_fromStr(psAttr[i+1]); - else if(strcmp(psAttr[i], "components") == 0){ - if((pCtx->nDasErr = _setComponents(pCtx, psAttr[i+1])) != DAS_OKAY) - return; - } + else if(strcmp(psAttr[i], "components") == 0) + sNumber = psAttr[i+1]; + else if(strcmp(psAttr[i], "sysorder") == 0) + sOrder = psAttr[i+1]; else if((strcmp(psAttr[i], "vecClass") == 0)||(strcmp(psAttr[i], "system") == 0)){ if( (pCtx->varCompSys = das_compsys_id(psAttr[i+1])) == 0){ @@ -514,6 +537,11 @@ static void _serial_onOpenVar( ); } + bool bIsVector = (strcmp(sVarElType, "vector") == 0); + if(bIsVector) + if((pCtx->nDasErr = _setComponents(pCtx, sNumber, sOrder)) != DAS_OKAY) + return; + /* Get the mapping from dataset space to array space */ ptrdiff_t aVarExtShape[DASIDX_MAX]; int nRet = _serial_parseIndex( @@ -538,7 +566,7 @@ static void _serial_onOpenVar( } /* If this is a vector, mention that we have 1 internal index */ - if(strcmp(sVarElType, "vector") == 0) + if(bIsVector) pCtx->varIntRank = 1; if(pCtx->varUse[0] == '\0') /* Default to a usage of 'center' */ diff --git a/das2/frame.c b/das2/frame.c index b33a346..2b5ca67 100644 --- a/das2/frame.c +++ b/das2/frame.c @@ -118,29 +118,6 @@ char* DasFrame_info(const DasFrame* pThis, char* sBuf, int nLen) pWrite += nWritten; nLen -= nWritten; -/* - / * Type and inertial * / - if(nLen < 40) return pWrite; - switch(pThis->flags & DASFRM_TYPE_MASK){ - case DASFRM_CARTESIAN : nWritten = snprintf(pWrite, nLen - 1, " | cartesian"); break; - case DASFRM_POLAR : nWritten = snprintf(pWrite, nLen - 1, " | polar"); break; - case DASFRM_CYLINDRICAL : nWritten = snprintf(pWrite, nLen - 1, " | cylindrical"); break; - case DASFRM_SPHERICAL : nWritten = snprintf(pWrite, nLen - 1, " | spherical"); break; - case DASFRM_CENTRIC : nWritten = snprintf(pWrite, nLen - 1, " | planetocentric"); break; - case DASFRM_DETIC : nWritten = snprintf(pWrite, nLen - 1, " | planetodetic"); break; - case DASFRM_GRAPHIC : nWritten = snprintf(pWrite, nLen - 1, " | planetographic"); break; - default: nWritten = 0; - } -*/ - - pWrite += nWritten; nLen -= nWritten; - if(nLen < 40) return pWrite; - - if(pThis->flags & DASFRM_INERTIAL) - nWritten = snprintf(pWrite, nLen - 1, " (inertial)\n"); - else - nWritten = snprintf(pWrite, nLen - 1, " (non-inertial)\n"); - pWrite += nWritten; nLen -= nWritten; if(nLen < 40) return pWrite; @@ -148,7 +125,15 @@ char* DasFrame_info(const DasFrame* pThis, char* sBuf, int nLen) pWrite, nLen - 1, " %s", pThis->body[0] != '\0' ? pThis->body : "UNK_Body" ); pWrite += nWritten; nLen -= nWritten; - if(nLen < 30) return pWrite; + if(nLen < 40) return pWrite; + + if(pThis->flags & DASFRM_FIXED) + nWritten = snprintf(pWrite, nLen - 1, " (body fixed)\n"); + else + nWritten = snprintf(pWrite, nLen - 1, " (body centered)\n"); + + pWrite += nWritten; nLen -= nWritten; + if(nLen < 30) return pWrite; char* pSubWrite = DasDesc_info((DasDesc*)pThis, pWrite, nLen, " "); nLen -= (pSubWrite - pWrite); @@ -161,12 +146,12 @@ char* DasFrame_info(const DasFrame* pThis, char* sBuf, int nLen) return pWrite; } -void DasFrame_inertial(DasFrame* pThis, bool bInertial) +void DasFrame_fixed(DasFrame* pThis, bool bFixed) { - if(bInertial) - pThis->flags &= DASFRM_INERTIAL; + if(bFixed) + pThis->flags &= DASFRM_FIXED; else - pThis->flags &= ~DASFRM_INERTIAL; + pThis->flags &= ~DASFRM_FIXED; } DasErrCode DasFrame_setName(DasFrame* pThis, const char* sName) diff --git a/das2/frame.h b/das2/frame.h index a5c0433..fce6500 100644 --- a/das2/frame.h +++ b/das2/frame.h @@ -29,7 +29,7 @@ extern "C" { #define DASFRM_NAME_SZ 64 #define DASFRM_CNAME_SZ 12 #define DASFRM_BODY_SZ 64 /* Direction name size */ -#define DASFRM_INERTIAL 0x00000010 +#define DASFRM_FIXED 0x00000010 #define DASFRM_NULLNAME "" /** @addtogroup DM @@ -124,9 +124,9 @@ DAS_API DasErrCode DasFrame_setBody(DasFrame* pThis, const char* sBody); #define DasFrame_id(p) ((p)->id) -DAS_API void DasFrame_inertial(DasFrame* pThis, bool bInertial); +DAS_API void DasFrame_fixed(DasFrame* pThis, bool bFixed); -#define DasFrame_isInertial(P) (P->flags & DASFRM_INERTIAL) +#define DasFrame_isFixed(P) (P->flags & DASFRM_FIXED) /** Get the frame name * @memberof DasFrame diff --git a/das2/stream.c b/das2/stream.c index 3cf948e..62a3aed 100644 --- a/das2/stream.c +++ b/das2/stream.c @@ -680,7 +680,7 @@ void parseDasStream_start(void* data, const char* el, const char** attr) char sName[64] = {'\0'}; char sBody[DASFRM_NAME_SZ] = {'\0'}; const char* pColon = NULL; - bool bInertial = false; + bool bFixed = false; pPsd->bInProp = (strcmp(el, "p") == 0); @@ -783,9 +783,9 @@ void parseDasStream_start(void* data, const char* el, const char** attr) memset(sBody, 0, 64); strncpy(sBody, attr[i+1], DASFRM_NAME_SZ-1); continue; } - if(strcmp(attr[i], "inertial") == 0){ + if(strcmp(attr[i], "fixed") == 0){ if((attr[i+1][0] == 't')||(attr[i+1][0] == 'T')||(strcasecmp(attr[i+1], "true") == 0)) - bInertial = true; + bFixed = true; continue; } } @@ -809,8 +809,8 @@ void parseDasStream_start(void* data, const char* el, const char** attr) if(!pPsd->pFrame){ pPsd->nRet = das_error(DASERR_STREAM, "Frame definition failed in header"); } - if(bInertial) - pPsd->pFrame->flags |= DASFRM_INERTIAL; + if(bFixed) + pPsd->pFrame->flags |= DASFRM_FIXED; strncpy(pPsd->pFrame->body, sBody, DASFRM_NAME_SZ-1); return; } diff --git a/das2/var_ary.c b/das2/var_ary.c index 72d075d..d610280 100644 --- a/das2/var_ary.c +++ b/das2/var_ary.c @@ -1359,8 +1359,8 @@ int das_makeCompLabels(const DasVar* pVar, char** psBuf, size_t uLenEa) for(int i = 0; i < nComp; ++i){ const char* sSym = das_geovec_compSym(&tplt, i); snprintf(psBuf[i], uLenEa - 1, "%s_%s", DasDim_dim((DasDim*)pDim), sSym); - return nComp; } + return nComp; } /* scalar version here */ diff --git a/schema/das-basic-doc-ns-v3.0.xsd b/schema/das-basic-doc-ns-v3.0.xsd index 1b922dc..c80698c 100644 --- a/schema/das-basic-doc-ns-v3.0.xsd +++ b/schema/das-basic-doc-ns-v3.0.xsd @@ -109,6 +109,7 @@ version 3.0, release candiate 2, 2024-05-27 + @@ -132,8 +133,8 @@ version 3.0, release candiate 2, 2024-05-27 - - - - - - - - + + @@ -220,7 +216,7 @@ version 3.0, release candiate 2, 2024-05-27 --> - + @@ -229,7 +225,6 @@ version 3.0, release candiate 2, 2024-05-27 - - + @@ -413,11 +409,14 @@ version 3.0, release candiate 2, 2024-05-27 - - - - - + + + + + + + + @@ -428,23 +427,32 @@ version 3.0, release candiate 2, 2024-05-27 - - - - + + + + + - + + + + + + + + + - + @@ -456,8 +464,10 @@ version 3.0, release candiate 2, 2024-05-27 - - + + + + @@ -465,16 +475,30 @@ version 3.0, release candiate 2, 2024-05-27 - + - + - - + + + + + + + + + + + + @@ -575,7 +599,7 @@ version 3.0, release candiate 2, 2024-05-27 CDF ISTP metadata model. -cwp 2020-07-17 --> - + diff --git a/schema/das-basic-stream-ns-v3.0.xsd b/schema/das-basic-stream-ns-v3.0.xsd index e7295fa..76a22e3 100644 --- a/schema/das-basic-stream-ns-v3.0.xsd +++ b/schema/das-basic-stream-ns-v3.0.xsd @@ -121,8 +121,8 @@ - - - - - - - - + + @@ -154,8 +149,8 @@ - - + + @@ -209,7 +204,7 @@ --> - + @@ -312,7 +307,7 @@ or just some information (string) --> - + @@ -330,7 +325,7 @@ + value="byte|ubyte|BEint|BEuint|BEreal|LEint|LEuint|LEreal|utf8|png|jpeg|none" /> @@ -420,11 +415,14 @@ - - - - - + + + + + + + + @@ -435,23 +433,32 @@ - - - - + + + + + - + + + + + + + + + - + @@ -463,8 +470,10 @@ - - + + + + @@ -473,16 +482,29 @@ - - - - - + + + + - - + + + + + + + + + + + + @@ -583,7 +605,7 @@ CDF ISTP metadata model. -cwp 2020-07-17 --> - + diff --git a/schema/das-basic-stream-v3.0.xsd b/schema/das-basic-stream-v3.0.xsd index 0c9a60d..5bc0f3f 100644 --- a/schema/das-basic-stream-v3.0.xsd +++ b/schema/das-basic-stream-v3.0.xsd @@ -130,18 +130,13 @@ attributes of --> - - - - - - - + + @@ -380,7 +375,7 @@ - + @@ -420,12 +415,14 @@ - - - - - - + + + + + + + + @@ -436,11 +433,17 @@ + + + + + + - + @@ -467,8 +470,9 @@ + - + @@ -500,7 +504,7 @@ + as a vector, using systems like SPICE --> diff --git a/test/ex15_vector_frame.d3b b/test/ex15_vector_frame.d3b index b95849a..6740177 100644 --- a/test/ex15_vector_frame.d3b +++ b/test/ex15_vector_frame.d3b @@ -15,7 +15,7 @@ -|Hx|80|915| +|Hx|80|891|

Electric Field, 2D-Vectors in spin plane sampled at 128 Hz

@@ -32,11 +32,9 @@

EFI SCI @ 128 Hz

+

Ex Ey

- - -

Ex Ey

-
+
diff --git a/test/ex17_vector_noframe.d3b b/test/ex17_vector_noframe.d3b index c0a697fbb2c633ce1958aec466864f91c5645462..c35d8a4bbc605f2230332cb486821dc5e92a8a9f 100644 GIT binary patch delta 54 zcmeycmhJCawhckdOok?#LzrWk_>%K;3-a?)^Gb?sm5h}pZ(udzD6TBdFG@)*YJS7I K{S7N4%R~Stm=oXt delta 41 xcmeynmhHn@whckdOa_LVLzrWkCLdrmi%iCo3b%L;z6*56S=l diff --git a/utilities/das3_cdf.c b/utilities/das3_cdf.c index 14fc2a0..1850778 100644 --- a/utilities/das3_cdf.c +++ b/utilities/das3_cdf.c @@ -1135,7 +1135,7 @@ DasErrCode onStream(StreamDesc* pSd, void* pUser){ /* If there are any coordinate frames defined in this stream, say something about them here */ if(StreamDesc_getNumFrames(pSd) > 0){ - daslog_error("TODO: Write stream vector frame info to CDF attributes."); + daslog_error("TODO: Write stream vector frame info to CDF global attributes."); } return DAS_OKAY; @@ -1784,7 +1784,8 @@ DasErrCode makeCompLabels(struct context* pCtx, DasDim* pDim, DasVar* pVar) DasErrCode nRet = DAS_OKAY; char psBuf[3][32] = {'\0'}; - int nComp = das_makeCompLabels(pVar, (char**) psBuf, 32); + char* ptrs[3] = {&(psBuf[0][0]), &(psBuf[1][0]), &(psBuf[2][0]) }; + int nComp = das_makeCompLabels(pVar, (char**) ptrs, 31); if(nComp < 0) return -1 * nComp;