Skip to content

Commit

Permalink
More ISTP metadata handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker committed Mar 8, 2024
1 parent 458eb81 commit de2cebe
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 39 deletions.
20 changes: 11 additions & 9 deletions buildfiles/Linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ $(BD)/das2_psd:$(BD)/das2_psd.o $(BD)/send.o $(BD)/$(TARG).a
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@

cdf:$(BD)/das3_cdf
$(BD)/das3_cdf:$(BD)/das3_cdf.o $(BD)/$(TARG).a

$(BD)/das3_cdf:utilities/das3_cdf.c $(BD)/$(TARG).a
@echo "An example CDF_INC value would be: /usr/local/include"
@echo "An example CDF_LIB value would be: /usr/local/lib/libcdf.a"
@if [ "$(CDF_INC)" = "" ] ; then echo "CDF_INC not set"; exit 3; fi
@if [ "$(CDF_LIB)" = "" ] ; then echo "CDF_LIB not set"; exit 3; fi
$(CC) $(CFLAGS) -I$(CDF_INC) -o $@ $< $(BD)/$(TARG).a $(CDF_LIB) $(LFLAGS)
$(CC) $(CFLAGS) -Wno-unused -I$(CDF_INC) -o $@ $< $(BD)/$(TARG).a $(CDF_LIB) $(LFLAGS)

# Run tests
test: $(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
Expand Down Expand Up @@ -217,11 +217,13 @@ test: $(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
$(BD)/TestV3Read
@echo "INFO: All test programs completed without errors"

# Can't test CDF creation this way due to stupide embedded time stamps
# cmp $(BD)/ex12_sounder_xyz.cdf test/ex12_sounder_xyz.cdf

test_cdf:$(BD) $(BD)/das3_cdf $(BD)/$(TARG).a
@echo "INFO: Testing CDF creation"
$(BD)/das3_cdf -l warning -i test/ex12_sounder_xyz.d3t -o $(BD) -r
cmp $(BD)/ex12_sounder_xyz.cdf test/ex12_sounder_xyz.cdf
@echo "INFO: Good, CDF matches expected output."
@echo "INFO: CDF was created"

test_spice:$(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
@echo "INFO: Running unit test for spice error redirect, $(BD)/TestSpice..."
Expand All @@ -247,15 +249,15 @@ $(BD)/html:$(BD) $(BD)/$(TARG).a
@cd $(BD)
(cat Doxyfile; echo "HTML_OUTPUT = $@ ") | doxygen -

install_doc:$(INST_DOC)/libdas2
install_doc:$(INST_DOC)/das2C

clean_doc:
-rm -r $(BD)/html

$(INST_DOC)/libdas2:$(BD)/html
$(INST_DOC)/das2C:$(BD)/html
-mkdir -p $(INST_DOC)
@if [ -e "$(INST_DOC)/libdas2" ]; then rm -r $(INST_DOC)/libdas2; fi
cp -r $(BD)/html $(INST_DOC)/libdas2
@if [ -e "$(INST_DOC)/das2C" ]; then rm -r $(INST_DOC)/libdas2; fi
cp -r $(BD)/html $(INST_DOC)/das2C


# Cleanup ####################################################################
Expand Down
23 changes: 5 additions & 18 deletions das2/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,24 +445,11 @@ int DasProp_items(const DasProp* pProp)
*/
int DasProp_convertInt(const DasProp* pProp, int64_t* pBuf, size_t uBufLen)
{
/* Walk the string, every time you hit a seperator convert back to
the last one */
/* int64_t nItem;
char sItem[32] = {'\0'};
size_t uLeft = uBufLen;
const char* sValue = DasProp_value(pProp);
const char* sItem = sValue;
char cSep = DasProp_sep(pProp);
while((*sValue != '\0')&&(uLeft > 0)){
if(*sValue == cSep){
}
}
/ * Tail convert * /
sscanf */
return -1 * das_error(DASERR_NOTIMP, "Integer property conversion not yet implemented");
if(sscanf(DasProp_value(pProp), "%ld", pBuf) != 1)
return -1 * das_error(DASERR_PROP, "Error converting '%s' to a double",
DasProp_value(pProp)
);
return 1;
}

/** Convert real-value properties to double
Expand Down
54 changes: 42 additions & 12 deletions utilities/das3_cdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ void prnHelp()
" generated file name will be used. This is useful when reading\n"
" das servers since they provide default filenames.\n"
"\n"
" -N,--no-istp\n"
" Don't automatically add certian ITSP meta-data attributes such as\n"
" 'Data_version' if they are missing.\n"
"\n"
" -r,--remove Tired of libcdf refusing to overwrite a file? Use this option\n"
" with '-o'\n"
"\n"
Expand Down Expand Up @@ -300,6 +304,7 @@ static bool _getArgVal(
typedef struct program_optitons{
bool bRmFirst; /* remove output before writing */
bool bUncompressed; /* don't compress data */
bool bNoIstp; /* Don't automatical add some ISTP metadata */
size_t uMemThreshold;
char aTpltFile[256]; /* Template CDF */
char aSource[1024]; /* Input source, http://, file:// etc. */
Expand Down Expand Up @@ -346,6 +351,10 @@ int parseArgs(int argc, char** argv, popts_t* pOpts)
pOpts->bRmFirst = true;
continue;
}
if(_isArg(argv[i], "-N", "--no-istp", NULL)){
pOpts->bNoIstp = true;
continue;
}
if(_isArg(argv[i], "-u", "--uncompressed", NULL)){
pOpts->bUncompressed = true;
continue;
Expand Down Expand Up @@ -402,7 +411,8 @@ int parseArgs(int argc, char** argv, popts_t* pOpts)
/* ************************************************************************* */

struct context {
bool bCompress;
bool bCompress;
bool bIstp; /* output some ITSP metadata (or don't) */
size_t uFlushSz; /* How big to let internal memory grow before a CDF flush */
CDFid nCdfId;
char* sTpltFile; /* An empty template CDF to put data in */
Expand Down Expand Up @@ -565,28 +575,28 @@ void* DasProp_cdfValues(const DasProp* pProp){
/* Properties don't have fill, so an unsigned byte works */
case DASPROP_BOOL:
uBufLen = PROP_XFORM_SZ;
if(DasProp_convertBool(pProp, g_propBuf, uBufLen) != DAS_OKAY)
if(DasProp_convertBool(pProp, g_propBuf, uBufLen) < 1)
return NULL;
else
return g_propBuf;

case DASPROP_INT:
uBufLen = PROP_XFORM_SZ / sizeof(int64_t);
if(DasProp_convertInt(pProp, (int64_t*)g_propBuf, uBufLen) != DAS_OKAY)
if(DasProp_convertInt(pProp, (int64_t*)g_propBuf, uBufLen) < 1)
return NULL;
else
return g_propBuf;

case DASPROP_REAL:
uBufLen = PROP_XFORM_SZ / sizeof(double);
if(DasProp_convertReal(pProp, (double*)g_propBuf, uBufLen) != DAS_OKAY)
if(DasProp_convertReal(pProp, (double*)g_propBuf, uBufLen) < 1)
return NULL;
else
return g_propBuf;

case DASPROP_DATETIME:
uBufLen = PROP_XFORM_SZ / sizeof(int64_t);
if(DasProp_convertTt2k(pProp, (int64_t*)g_propBuf, uBufLen) != DAS_OKAY)
if(DasProp_convertTt2k(pProp, (int64_t*)g_propBuf, uBufLen) < 1)
return NULL;
else
return g_propBuf;
Expand Down Expand Up @@ -659,7 +669,7 @@ DasErrCode writeGlobalProp(struct context* pCtx, const DasProp* pProp)
if((strncmp(sName, "inst", 4) == 0)&&(sName[4] != '\0'))
sName += 4;

if(sName[0] != toupper(sName[0])){
if( (sName[0] != toupper(sName[0])) && (strncmp(sName, "spase", 5)!=0) ){
daslog_debug_v("Ignoring lower-case property '%s' in global area.", sName);
return DAS_OKAY;
}
Expand Down Expand Up @@ -833,15 +843,26 @@ DasErrCode onStream(StreamDesc* pSd, void* pUser){

if(pDot != NULL) *pDot = '.'; /* But our damn dot back */

if(pCtx->bIstp){
if(!DasDesc_has((DasDesc*)pSd, "Data_version"))
DasDesc_setInt((DasDesc*)pSd, "Data_version", 1);
if(!DasDesc_has((DasDesc*)pSd, "Generation_date")){
das_time dt;
dt_now(&dt);
char sTime[32] = {'\0'};
snprintf(sTime, 31, "%04d%02d%02d", dt.year, dt.month, dt.mday);
}
}

/* We have the file, run in our properties */
size_t uProps = DasDesc_length((DasDesc*)pSd);
for(size_t u = 0; u < uProps; ++u){
const DasProp* pProp = DasDesc_getPropByIdx((DasDesc*)pSd, u);
if(pProp == NULL) continue;

/* Some properties are meta-data controllers */
if(strcmp(DasProp_name(pProp), "CDF_NAME") == 0)
continue;
if(strcmp(DasProp_name(pProp), "cdfName") == 0)
continue;

if(writeGlobalProp(pCtx, pProp) != DAS_OKAY)
return PERR;
Expand Down Expand Up @@ -1209,10 +1230,18 @@ const char* DasVar_cdfName(
/* If I'm the point var, don't adorn the name with the role */
const DasVar* pPtVar = DasDim_getPointVar(pDim);
if(pPtVar == pVar){
if((pDim->dtype == DASDIM_COORD)&&(strcmp(DasDim_dim(pDim), "time") == 0))
if( (pDim->dtype == DASDIM_COORD)&&(strcmp(DasDim_dim(pDim), "time") == 0)) {
strncpy(sBuf, "Epoch", uBufLen - 1);
else
snprintf(sBuf, uBufLen - 1, "%s", DasDim_id(pDim));
}
else{
/* Check to see if this variable has a given CDF name. Use if for the
* center variable only */
const DasProp* pOverride = DasDesc_getLocal((DasDesc*)pDim, "cdfName");
if(pOverride)
snprintf(sBuf, uBufLen - 1, "%s", DasProp_value(pOverride));
else
snprintf(sBuf, uBufLen - 1, "%s", DasDim_id(pDim));
}
}
else
snprintf(sBuf, uBufLen - 1, "%s_%s", DasDim_id(pDim), sRole);
Expand Down Expand Up @@ -2072,6 +2101,7 @@ int main(int argc, char** argv)
ctx.sTpltFile = opts.aTpltFile;
ctx.bCompress = !opts.bUncompressed;
ctx.uFlushSz = opts.uMemThreshold;
ctx.bIstp = !opts.bNoIstp;

/* Figure out where we're gonna write before potentially contacting servers */
bool bReStream = false;
Expand Down Expand Up @@ -2216,4 +2246,4 @@ int main(int argc, char** argv)
}

return nRet;
};
};

0 comments on commit de2cebe

Please sign in to comment.