Skip to content

Commit

Permalink
Schema simpliciation for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker committed Oct 7, 2024
1 parent be9936e commit ff5cfc0
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 139 deletions.
52 changes: 40 additions & 12 deletions das2/dataset_hdr3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector> 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 <vector> 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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){
Expand All @@ -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(
Expand All @@ -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' */
Expand Down
41 changes: 13 additions & 28 deletions das2/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,37 +118,22 @@ 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;

nWritten = snprintf(
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);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions das2/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions das2/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 <stream> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion das2/var_ary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit ff5cfc0

Please sign in to comment.