Skip to content

Commit

Permalink
Initial CSV converter work
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker authored and = committed Jun 28, 2024
1 parent 0263767 commit 8553bcf
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 246 deletions.
2 changes: 1 addition & 1 deletion buildfiles/Linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif
UTIL_PROGS=das1_inctime das2_prtime das1_fxtime das2_ascii das2_bin_avg \
das2_bin_avgsec das2_bin_peakavgsec das2_from_das1 das2_from_tagged_das1 \
das1_ascii das1_bin_avg das2_bin_ratesec das2_psd das2_hapi das2_histo \
das2_cache_rdr das3_node
das2_cache_rdr das3_node das3_csv

TEST_PROGS:=TestUnits TestArray TestVariable LoadStream TestBuilder \
TestAuth TestCatalog TestTT2000 ex_das_cli ex_das_ephem TestCredMngr \
Expand Down
41 changes: 31 additions & 10 deletions das2/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,38 @@
#include <strings.h>
#endif

#include "log.h"
#include "frame.h"


const char* das_frametype2str( ubyte uFT)
{
ubyte ft = uFT & DASFRM_TYPE_MASK;

if(ft == DASFRM_CARTESIAN ) return "cartesian";
if(ft == DASFRM_POLAR ) return "polar";
if(ft == DASFRM_SPHERE_SURFACE) return "sphere_surface";
if(ft == DASFRM_CYLINDRICAL ) return "cylindrical";
if(ft == DASFRM_CYLINDRICAL ) return "spherical";

daslog_error_v("Unknown vector or coordinate frame type id: '%hhu'.", uFT);
return "";
}

ubyte das_str2frametype(const char* sFT)
{
if( strcasecmp(sFT, "cartesian") == 0) return DASFRM_CARTESIAN;
if( strcasecmp(sFT, "polar") == 0) return DASFRM_POLAR;
if( strcasecmp(sFT, "sphere_surface") == 0) return DASFRM_SPHERE_SURFACE;
if( strcasecmp(sFT, "cylindrical") == 0) return DASFRM_CYLINDRICAL;
if( strcasecmp(sFT, "spherical") == 0) return DASFRM_CYLINDRICAL;

daslog_error_v("Unknown vector or coordinate frame type: '%s'.", sFT);
return 0;
}

/* ************************************************************************ */

DasFrame* new_DasFrame(DasDesc* pParent, ubyte id, const char* sName, const char* sType)
{
DasFrame* pThis = (DasFrame*) calloc(1, sizeof(DasFrame));
Expand Down Expand Up @@ -154,16 +184,7 @@ DAS_API DasErrCode DasFrame_setType(DasFrame* pThis, const char* sType)
return das_error(DASERR_FRM, "Empty coordinate frame type");

strncpy(pThis->type, sType, DASFRM_TYPE_SZ-1);
if( strcasecmp(pThis->type, "cartesian") == 0)
pThis->flags |= DASFRM_CARTESIAN;
else if( strcasecmp(pThis->type, "polar") == 0)
pThis->flags |= DASFRM_POLAR;
else if( strcasecmp(pThis->type, "sphere_surface") == 0)
pThis->flags |= DASFRM_SPHERE_SURFACE;
else if( strcasecmp(pThis->type, "cylindrical") == 0)
pThis->flags |= DASFRM_CYLINDRICAL;
else if( strcasecmp(pThis->type, "spherical") == 0)
pThis->flags |= DASFRM_CYLINDRICAL;
pThis->flags |= das_str2frametype(pThis->type);

return DAS_OKAY;
}
Expand Down
5 changes: 5 additions & 0 deletions das2/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ extern "C" {

#define DASFRM_NULLNAME "_UNDEFINED_SOURCE_FRAME_"

/* Converting vecClass strings back and forth to frame type bytes */
const char* das_frametype2str( ubyte uFT);

ubyte das_str2frametype(const char* sFT);

/** @addtogroup DM
* @{
*/
Expand Down
4 changes: 2 additions & 2 deletions das2/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ DasErrCode DasProp_init(
uFlags |= (DASPROP_STRING | DASPROP_SINGLE);
else if(strcasecmp(sType, "stringarray") == 0)
uFlags |= (DASPROP_STRING | DASPROP_SET);
else if(strcasecmp(sType, "boolean") == 0)
else if((strcasecmp(sType, "boolean") == 0)||(strcasecmp(sType, "bool") == 0))
uFlags |= (DASPROP_BOOL | DASPROP_SINGLE);
else if((strcasecmp(sType, "int") == 0)||(strcasecmp(sType, "integer") == 0))
uFlags |= (DASPROP_INT | DASPROP_SINGLE);
Expand All @@ -227,7 +227,7 @@ DasErrCode DasProp_init(
}
else
return das_error(DASERR_PROP,
"Invalid property type '%s' for value '%s'", sName, sValue
"Invalid property type '%s' for value '%s'", sType, sName
);

/* If a range property was indicated, make sure there is a second value */
Expand Down
3 changes: 3 additions & 0 deletions das2/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ DasErrCode DasProp_init(
*/
size_t DasProp_size(const DasProp* pProp);

/** Get the units for a property */
#define DasProp_units(P) ((P)->units)

/** Get name of a property
* @memberof DasProp
*/
Expand Down
29 changes: 25 additions & 4 deletions das2/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ static void _serial_clear_var_section(context_t* pCtx)
memset(pCtx->varUse, 0, DAS_FIELD_SZ(context_t, varUse) );
memset(pCtx->valSemantic, 0, DAS_FIELD_SZ(context_t, valSemantic) );
memset(pCtx->valStorage, 0, DAS_FIELD_SZ(context_t, valStorage) );
memset(pCtx->varFrameType, 0, DAS_FIELD_SZ(context_t, varFrameType) );
memset(pCtx->varCompDirs, 0, DAS_FIELD_SZ(context_t, varCompDirs) );
memset(pCtx->varCompLbl, 0, DAS_FIELD_SZ(context_t, varCompLbl) ); /* HACK ALERT */
for(int i = 0; i < DASIDX_MAX; ++i) pCtx->aVarMap[i] = DASIDX_UNUSED;
Expand Down Expand Up @@ -445,7 +446,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], )) */
else if(strcmp(psAttr[i], "vecClass")){
strncpy(pCtx->varFrameType, psAttr[i+1], DASFRM_TYPE_SZ-1);
pCtx->varFrameType[DASFRM_TYPE_SZ-1] = '\0';
}

/* Temporarily ignore values that are running around in wild */
else
Expand Down Expand Up @@ -1212,6 +1216,9 @@ static void _serial_onCloseVar(context_t* pCtx)
DasVar* pVar = NULL;
DasErrCode nRet = DAS_OKAY;

/* May not matter if variable is a scalar */
const char* sVecClass = pCtx->varFrameType[0] == '\0' ? "cartesian" : pCtx->varFrameType;

if(pCtx->varIntRank == 1){

/* HACK ALERT: Pick up names put in the wrong place and put them in a property instead */
Expand All @@ -1238,14 +1245,27 @@ static void _serial_onCloseVar(context_t* pCtx)
const DasFrame* pFrame = DasStream_getFrameByName(pCtx->pSd, DasDim_getFrame(pCtx->pCurDim));
if(pFrame == NULL){

/* If the stream had no frame, generate one for the given frame name */
/* If the stream had no frame, generate one for the given frame name.
BIG WARNING:
You want to use explicit frames in your streams... you really do.
That is because MAGnetometer people often provide *cartesian*
vectors whose orthogonal unit vectors are set by the instantaneous
location in a *non-cartesian* coordinate frame!
In order to properly take the magnitude of a vector you have to know
it's vector class and this may be different from the vector frame.
I know... wierd, right.
*/
int iFrame = DasStream_newFrameId(pCtx->pSd);
if(iFrame < 0){
pCtx->nDasErr = -1*iFrame;
goto NO_CUR_VAR;
}

DasFrame* pMkFrame = DasStream_createFrame(
pCtx->pSd, iFrame, DasDim_getFrame(pCtx->pCurDim), "cartesian"
pCtx->pSd, iFrame, DasDim_getFrame(pCtx->pCurDim), sVecClass
);
DasDesc_setStr((DasDesc*)pMkFrame, "title", "Autogenerated Frame");

Expand Down Expand Up @@ -1286,9 +1306,10 @@ static void _serial_onCloseVar(context_t* pCtx)
goto NO_CUR_VAR;
}

// Use the given vector class here, even if frame is a different class
pVar = new_DasVarVecAry(
pCtx->pCurAry, DasDs_rank(pCtx->pDs), pCtx->aVarMap, 1, /* internal rank = 1 */
pFrame->name, iFrame, pFrame->flags, pCtx->nVarComp, aDirs
pFrame->name, iFrame, das_str2frametype(sVecClass), pCtx->nVarComp, aDirs
);
}
else{
Expand Down
3 changes: 2 additions & 1 deletion das2/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ DAS_API DasVar* new_DasVarArray(DasAry* pAry, int nExtRank, int8_t* pMap, int nI
* @param nFrameId The integer id of this frame. GeoVec datums only store
* the frame ID, not the name for faster comparisons
*
* @param frametype The lower byte of DasFrame.flags
* @param frametype One of: DASFRM_CARTESIAN, DASFRM_POLAR, DASFRM_SPHERE_SURFACE
* DASFRM_CYLINDRICAL, or DASFRM_SPHERICAL
*
* @param pDir A mapping between coordinate directions and the components
* of each vector, may be NULL.
Expand Down
Loading

0 comments on commit 8553bcf

Please sign in to comment.