Skip to content

Commit

Permalink
SPICE Vector rotation passes unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker committed Sep 4, 2024
1 parent 793dc96 commit e999e03
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 54 deletions.
4 changes: 4 additions & 0 deletions buildfiles/Linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ UTIL_PROGS:=$(UTIL_PROGS) das3_spice
TEST_PROGS:=$(TEST_PROGS) TestSpice
endif

ifeq ($(CDF),yes)
UTIL_PROGS:=$(UTIL_PROGS) das3_cdf
endif

BD=$(BUILD_DIR)

##############################################################################
Expand Down
7 changes: 5 additions & 2 deletions das2/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ DasErrCode DasCodec_update(
){
/* Can't just point to existing items, memset is going to erase them! */
DasAry* _pAry = pThis->pAry; /* okay, is external */
const char* _sSemantic = pThis->sSemantic; /* Okay, is external */
char _sSemantic[DASENC_SEM_LEN] = {'\0'};
strncpy(_sSemantic, pThis->sSemantic, DASENC_SEM_LEN);

char _sEncType[DASENC_TYPE_LEN] = {'\0'};
strncpy(_sEncType, (sEncType != NULL) ? sEncType : pThis->sEncType, DASENC_TYPE_LEN - 1);
Expand Down Expand Up @@ -136,7 +137,9 @@ DasErrCode DasCodec_init(
strncpy(pThis->sEncType, sEncType, DASENC_TYPE_LEN-1);

/* Save off the semantic & the output format */
pThis->sSemantic = sSemantic;
if(sSemantic != NULL)
strncpy(pThis->sSemantic, sSemantic, DASENC_SEM_LEN - 1);

if(sOutFmt != NULL)
strncpy(pThis->sOutFmt, sOutFmt, DASENC_FMT_LEN-1);

Expand Down
4 changes: 3 additions & 1 deletion das2/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <das2/encoding.h> /* <-- only to get DASENC_FMT_LEN, DASENC_TYPE_LEN */
/* otherwise independent */

#define DASENC_SEM_LEN 32

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -69,7 +71,7 @@ typedef struct das_codec {

das_val_type vtBuf; /* The value type in the external buffer */

const char* sSemantic; /* The intended meaning for the externa item */
char sSemantic[DASENC_SEM_LEN]; /* The intended meaning for the externa item */

DasAry* pAry; /* The array for which values are encoded/decoded */

Expand Down
6 changes: 3 additions & 3 deletions das2/dataset_hdr3.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define _UNIT_BUF_SZ 127
#define _NAME_BUF_SZ 63
#define _TYPE_BUF_SZ 23
#define _VAL_SEMANTIC_SZ 16
#define DASENC_SEM_LEN 32
#define _VAL_STOREAGE_SZ 12
#define _VAL_COMP_LBL_SZ ((DASFRM_NAME_SZ + 1) * 3)
#define _VAL_UNDER_SZ 64 /* Should be enough room for most variables */
Expand Down Expand Up @@ -69,7 +69,7 @@ typedef struct serial_xml_context {
int nVarComp;
das_units varUnits;
char varUse[DASDIM_ROLE_SZ];
char valSemantic[_VAL_SEMANTIC_SZ]; /* "real", "int", "datetime", "string", etc. */
char valSemantic[DASENC_SEM_LEN]; /* "real", "int", "datetime", "string", etc. */
char valStorage[_VAL_STOREAGE_SZ];
char varFrameType[DASFRM_TYPE_SZ]; /* For in-promptu creation of frames */
char varCompDirs[DASFRM_MAX_DIRS][DASFRM_NAME_SZ];
Expand Down Expand Up @@ -450,7 +450,7 @@ static void _serial_onOpenVar(
else if(
(strcmp(psAttr[i], "semantic") == 0)||(strcmp(psAttr[i], "valType") == 0)
) /* Partial value type, need pkt */
strncpy(pCtx->valSemantic, psAttr[i+1], _VAL_SEMANTIC_SZ-1);/* encoding details to decide */
strncpy(pCtx->valSemantic, psAttr[i+1], DASENC_SEM_LEN-1);/* encoding details to decide */
else if(strcmp(psAttr[i], "storage") == 0)
strncpy(pCtx->valStorage, psAttr[i+1], _VAL_STOREAGE_SZ-1);
else if(strcmp(psAttr[i], "index") == 0)
Expand Down
4 changes: 3 additions & 1 deletion das2/datum.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ double das_datum_toDbl(const das_datum* pThis)
{
double rRet;
switch(pThis->vt){
case vtUByte: rRet = *((ubyte*)pThis); break;
case vtUByte: rRet = *((ubyte*)pThis); break;
case vtUShort: rRet = *((uint16_t*)pThis); break;
case vtShort: rRet = *((int16_t*)pThis); break;
case vtUInt: rRet = *((uint32_t*)pThis); break;
case vtInt: rRet = *((int32_t*)pThis); break;
case vtULong: rRet = *((uint64_t*)pThis); break;
case vtLong: rRet = *((int64_t*)pThis); break;
case vtFloat: rRet = *((float*)pThis); break;
case vtDouble: rRet = *((double*)pThis); break;

Expand Down
2 changes: 1 addition & 1 deletion das2/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef struct das_descriptor {
//Number of invalid properites (saved to make length cals faster)
size_t uInvalid;

const struct das_descriptor* parent;
struct das_descriptor* parent;
bool bLooseParsing;
} DasDesc;

Expand Down
2 changes: 2 additions & 0 deletions das2/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DasFrame* new_DasFrame(DasDesc* pParent, ubyte id, const char* sName, const char
das_error(DASERR_FRM, "Frame IDs must be in the range 1 to 255");
goto ERROR;
}
pThis->id = id;

if( DasFrame_setSys(pThis, sType) != DAS_OKAY)
goto ERROR;
Expand All @@ -100,6 +101,7 @@ DasFrame* new_DasFrame2(DasDesc* pParent, ubyte id, const char* sName, ubyte uTy
das_error(DASERR_FRM, "Frame IDs must be in the range 1 to 255");
goto ERROR;
}
pThis->id = id;

pThis->flags |= (uType & DASFRM_TYPE_MASK);
const char* sType = das_frametype2str(uType);
Expand Down
57 changes: 54 additions & 3 deletions das2/var_ary.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ char* _DasVar_prnIntr(
char* sBuf, int nBufLen
);

DasStream* _DasVar_getStream(const DasVar* pThis);

/* ************************************************************************* */
/* Array mapping functions */

Expand All @@ -58,7 +60,11 @@ typedef struct das_var_vecary{
DasVarAry base;

das_geovec tplt;
char fname[DASFRM_NAME_SZ]; // frame name for printing info

/* TODO: Ditch this, frame name should only exist in one place, the
stream header */
char fname[DASFRM_NAME_SZ];

} DasVarVecAry;


Expand Down Expand Up @@ -947,7 +953,10 @@ DasErrCode init_DasVarAry(
}

pThis->base.vsize = das_vt_size(pThis->base.vt);
pThis->base.semantic = das_sem_default(pThis->base.vt);
if(Units_haveCalRep(pThis->base.units))
strncpy(pThis->base.semantic, DAS_SEM_DATE, D2V_MAX_SEM_LEN-1);
else
strncpy(pThis->base.semantic, das_sem_default(pThis->base.vt), D2V_MAX_SEM_LEN-1);

inc_DasAry(pAry); /* Increment the reference count for this array */
return DAS_OKAY;
Expand Down Expand Up @@ -1001,6 +1010,48 @@ int DasVarAry_getFrame(const DasVar* pBase)
return ((const DasVarVecAry*)pBase)->tplt.frame;
}


bool DasVarAry_setFrame(DasVar* pBase, int nFrameId, const ubyte* pDir)
{
if(pBase->vartype != D2V_ARRAY)
return false;

if( ((const DasVarAry*)pBase)->varsubtype != D2V_GEOVEC)
return false;

DasVarVecAry* pThis = ((DasVarVecAry*)pBase);

pThis->tplt.frame = nFrameId;
if(pDir != NULL){
for(int i = 0; i < pThis->tplt.ncomp; ++i)
pThis->tplt.dirs[i] = pDir[i];
}
else{
for(int i = 0; i < pThis->tplt.ncomp; ++i)
pThis->tplt.dirs[i] = (ubyte)i;
}


/* TODO: Ditch holding frame names internally. Once that's done
delete the following with prejudice!
This is dumb, we're reaching ALL THE WAY ACROSS the library
to set something we shouldn't care about at this point!
*/
if(nFrameId != 0){
DasStream* pSd = _DasVar_getStream(pBase);
if(pSd != NULL){
const DasFrame* pFrame = DasStream_getFrameById(pSd, nFrameId);
if(pFrame != NULL){
strncpy(pThis->fname, DasFrame_getName(pFrame), DASFRM_NAME_SZ-1);
return true;
}
}
}

return false;
}

const char* DasVarAry_getFrameName(const DasVar* pBase)
{
if(pBase->vartype != D2V_ARRAY)
Expand Down Expand Up @@ -1200,7 +1251,7 @@ DasErrCode DasVarAry_encode(DasVar* pBase, const char* sRole, DasBuf* pBuf)
DasVarVecAry* pDerived = (DasVarVecAry*)pThis;
das_geovec gvec = pDerived->tplt;

const DasFrame* pFrame = DasStream_getFrameByName(pStream, pDerived->fname);
const DasFrame* pFrame = DasStream_getFrameById(pStream, pDerived->tplt.frame);
if(pFrame == NULL){
/* No frame, just go with the defaults for the frame type */
pFrame = new_DasFrame2(NULL, 255, "derp", gvec.ftype);
Expand Down
33 changes: 32 additions & 1 deletion das2/var_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <string.h>

#include "stream.h"

#define _das_variable_c_
#include "variable.h"

Expand Down Expand Up @@ -118,7 +120,7 @@ DasErrCode DasVar_setSemantic(DasVar* pThis, const char* sSemantic)
if((sSemantic == NULL)||(sSemantic[0] == '\0'))
return das_error(DASERR_VAR, "Semantic property data values can not be empty");

pThis->semantic = sSemantic;
strncpy(pThis->semantic, sSemantic, D2V_MAX_SEM_LEN-1);
return DAS_OKAY;
}

Expand Down Expand Up @@ -199,6 +201,19 @@ bool DasVar_isNumeric(const DasVar* pThis)
return pThis->isNumeric(pThis);
}

DasStream* _DasVar_getStream(DasVar* pThis)
{
DasDesc* pDim = NULL;
DasDesc* pDs = NULL;
DasStream* pSd = NULL;

if( (pDim = ((DasDesc*)pThis)->parent) == NULL) return NULL;
if( (pDs = pDim->parent ) == NULL) return NULL;
if( (pSd = (DasStream*) pDs->parent ) == NULL) return NULL;

return pSd;
}

char* _DasVar_prnUnits(const DasVar* pThis, char* sBuf, int nLen)
{

Expand Down Expand Up @@ -561,3 +576,19 @@ const ubyte* DasVar_getDirs(const DasVar* pVar, ubyte* pNumComp)
das_error(DASERR_VAR, "Logic error");
return NULL;
}

bool DasVarAry_setFrame(DasVar* pBase, int nFrameId, const ubyte* pDir);

bool DasVar_setFrame(DasVar* pVar, int nFrameId, const ubyte* pDir){

switch(pVar->vartype){
case D2V_CONST: return false;
case D2V_SEQUENCE: return false;
case D2V_ARRAY: return DasVarAry_setFrame(pVar, nFrameId, pDir);
case D2V_UNARY_OP: return false;
case D2V_BINARY_OP: return false;
}

das_error(DASERR_VAR, "Logic error");
return false;
}
2 changes: 1 addition & 1 deletion das2/var_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ DasVar* new_DasVarBinary_tok(
pThis->et = das_vt_merge(
DasVar_elemType(pLeft), op, DasVar_elemType(pRight)
);
pThis->base.semantic = das_sem_default(pThis->et);
strncpy(pThis->base.semantic, das_sem_default(pThis->et), D2V_MAX_SEM_LEN-1);

pThis->nOp = op;
pThis->pLeft = pLeft;
Expand Down
3 changes: 2 additions & 1 deletion das2/var_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ DasVar* new_DasConstant(const char* sId, const das_datum* pDm)
/* Vsize setting */
pThis->base.vsize = das_vt_size(pDm->vt);

pThis->base.semantic = das_sem_default(pDm->vt); /* Def. semantic based on val type */
/* Def. semantic based on val type */
strncpy(pThis->base.semantic, das_sem_default(pDm->vt), D2V_MAX_SEM_LEN-1);

strncpy(pThis->sId, sId, DAS_MAX_ID_BUFSZ - 1);

Expand Down
9 changes: 5 additions & 4 deletions das2/var_seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ DasVar* new_DasVarSeq(
pThis->pM = pThis->M;
double rScale;

pThis->base.semantic = DAS_SEM_INT; /* assume integer, till poven different */
/* assume integer, till poven different */
strncpy(pThis->base.semantic, DAS_SEM_INT, D2V_MAX_SEM_LEN -1);

switch(vt){
case vtUByte:
Expand Down Expand Up @@ -596,12 +597,12 @@ DasVar* new_DasVarSeq(
case vtFloat:
*((float*)(pThis->pB)) = *((float*)pMin);
*((float*)(pThis->pM)) = *((float*)pInterval);
pThis->base.semantic = DAS_SEM_REAL;
strncpy(pThis->base.semantic, DAS_SEM_REAL, D2V_MAX_SEM_LEN -1);
break;
case vtDouble:
*((double*)(pThis->pB)) = *((double*)pMin);
*((double*)(pThis->pM)) = *((double*)pInterval);
pThis->base.semantic = DAS_SEM_REAL;
strncpy(pThis->base.semantic, DAS_SEM_REAL, D2V_MAX_SEM_LEN -1);
break;
case vtTime:
/* Use the units to get the conversion factor for the slope to seconds */
Expand All @@ -611,7 +612,7 @@ DasVar* new_DasVarSeq(
pThis->base.units = UNIT_UTC;

*((das_time*)pThis->pB) = *((das_time*)pMin);
pThis->base.semantic = DAS_SEM_DATE;
strncpy(pThis->base.semantic, DAS_SEM_DATE, D2V_MAX_SEM_LEN -1);
break;
default:
das_error(DASERR_VAR, "Value type %d not yet supported for sequences", vt);
Expand Down
27 changes: 22 additions & 5 deletions das2/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

#include <das2/descriptor.h>
#include <das2/datum.h>

#include "units.h"
#include <das2/units.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Current max length of a vector (internal index) can be changed */
#define D2V_MAX_VEC_LEN 4
#define D2V_MAX_VEC_LEN 4
#define D2V_MAX_SEM_LEN 16

enum var_type {
D2V_CONST, D2V_SEQUENCE, D2V_ARRAY, D2V_UNARY_OP, D2V_BINARY_OP
Expand Down Expand Up @@ -265,7 +265,7 @@ typedef struct das_variable{
* This matters because a vtText variable could hold values that
* should be considered as integers, booleans, datatimes, reals, pixels, etc.
*/
const char* semantic;
char semantic[D2V_MAX_SEM_LEN];

/* Number of external indexes. Many of these may not be used and are
* thus marked as degenerate */
Expand Down Expand Up @@ -609,7 +609,6 @@ DAS_API DasVar* new_DasVarVecAry(
const ubyte* pDir
);


/** Get the ID of the vector frame (if any) associated with the variable
*
* @param pVar A variable hosting vector data
Expand All @@ -622,6 +621,24 @@ DAS_API DasVar* new_DasVarVecAry(
*/
DAS_API int DasVar_getFrame(const DasVar* pVar);

/** Set the ID of the vector frame associated with the variable and it's
* directions.
*
* @param pVar A variable hosting vector data
*
* @param id The frame ID from the stream header
*
* @param pDir the direction IDs in the frame, if NULL, standard order, will
* be assumed. pDir must point to as many bytes as there are
* components for the vector
*
* @return true if a frame was set for the variable, false if this
* variable does not use vector frames
*
* @memberof DasVar
*/
DAS_API bool DasVar_setFrame(DasVar* pVar, int iFrame, const ubyte* pDir);


/** Get the name of the vector frame (if any) associated with the variable
*
Expand Down
Loading

0 comments on commit e999e03

Please sign in to comment.