Skip to content

Commit

Permalink
Adds variable rename maps when exporting to CDF
Browse files Browse the repository at this point in the history
A new command line argument, '-m' can be used to map a
dataset,dimension,role triplet to a CDF variable name without
requiring a skeleton file.
  • Loading branch information
cpiker committed Jul 29, 2024
1 parent c7405f7 commit 3291c61
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 68 deletions.
18 changes: 16 additions & 2 deletions das2/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ DasErrCode DasStream_freeSubDesc(DasStream* pThis, int nPktId)

PktDesc* DasStream_getPktDesc(const DasStream* pThis, int nPacketId)
{
if(nPacketId < 1 || nPacketId > 99){
if(nPacketId < 1 || nPacketId > (MAX_PKTIDS-1)){
das_error(DASERR_STREAM,
"Illegal Packet ID %d in getPacketDescriptor", nPacketId
);
Expand All @@ -245,14 +245,28 @@ PktDesc* DasStream_getPktDesc(const DasStream* pThis, int nPacketId)
return (pDesc == NULL)||(pDesc->type != PACKET) ? NULL : (PktDesc*)pDesc;
}

int DasStream_getPktId(DasStream* pThis, const DasDesc* pDesc)
{
/* Linear search for now, but small vector assumption may no always hold
in the future */

/* 0 is never a container ID */
for(int i = 1; i < MAX_PKTIDS; ++i){
if((pThis->descriptors[i] != NULL)&&(pThis->descriptors[i] == pDesc))
return i;
}
return -1;
}


DasDesc* DasStream_nextPktDesc(const DasStream* pThis, int* pPrevPktId)
{
int nBeg = *pPrevPktId + 1;
if(nBeg < 1){
das_error(DASERR_STREAM, "Illegal descriptor value %d", nBeg);
return NULL;
}
for(int i = nBeg; i < 100; ++i){
for(int i = nBeg; i < MAX_PKTIDS; ++i){
if(pThis->descriptors[i] != NULL){
*pPrevPktId = i;
return pThis->descriptors[i];
Expand Down
20 changes: 17 additions & 3 deletions das2/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ extern "C" {
* Desciptor IDs:
* The lookup ID is the same value used as the header & data IDs in the
* stream. The legal packet ID range depends on the stream serilazation
* method. For the das2 format, the valid range is 0 to 99.
* method. For the das2 format, the valid range is 1 to 99.
*
* For the das3 format, packet ID's must be positive and fit in an integer
* so the maximum is about 2.1 billion.
* For the das3 format, packet ID's must be positive and fit into a
* short unsigned integer, so the valid range is 1 to 65,535.
*
* Note that das v2 Streams can re-use packet ID's. So the PacketDescriptor
* at, for example, ID 2 may be completely different from one invocation
Expand Down Expand Up @@ -452,6 +452,20 @@ DAS_API PktDesc* DasStream_getPktDesc(const DasStream* pThis, int id);

#define StreamDesc_getPktDesc DasStream_getPktDesc

/** If a data container is owned by this stream object, return it's packet ID
*
* @param pThis The stream that is being asked to provide the ID
*
* @param pDesc The owned object descriptor
*
* @returns A number between 1 and MAX_PKTIDS, or -1 if the object is not
* owned by this stream. The returned object may be a PktDesc or
* a DasDs.
*
* @membefof DasStream
*/
DAS_API int DasStream_getPktId(DasStream* pThis, const DasDesc* pDesc);


/** Get a frame pointer by it's index
*
Expand Down
39 changes: 39 additions & 0 deletions das2/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,45 @@ bool das_assert_valid_id(const char* sId){
return true;
}

/* Common config-file case, remove whitespace and simple line comments */
char* das_strip(char* sLine, char cComment)
{
if(sLine == NULL) return NULL;

/* Terminate at comment char if there is one */
char* pBeg = sLine;
if(cComment != '\0'){
while(*pBeg != '\0'){
if(*pBeg == cComment){
*pBeg = '\0';
break;
}
else
++pBeg;
}
}

/* Advance past whitespace, or bail out */
pBeg = sLine;
while(*pBeg != '\0'){
if(isspace(*pBeg))
++pBeg;
else
break;
}
if(*pBeg == '\0')
return NULL;

/* Null out ending whitespace. Loop will terminate because
we know there's at least one non-space char in there */
char* pEnd = pBeg + strlen(pBeg) - 1;
while(isspace(*pEnd)){
*pEnd = '\0';
--pEnd;
}
return pBeg;
}

/* ************************************************************************* */
/* Copy string as an XML token, leading and traily spaces are ignore,
* internal space characters are converted and collapsed to single spaces
Expand Down
17 changes: 17 additions & 0 deletions das2/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@ DAS_API void das_store_str(char** psDest, size_t* puLen, const char* sSrc);
*/
DAS_API char* das_string(const char* fmt, ...);

/** Strip whitespace from a string
*
* @param sLine - Pointer to a writable null terminated string, or a
* NULL pointer.
*
* @param cComment - Treat the character if it was a null character
* terminating the string. Replace it with an actual null if
* found. Use '\0' to avoid stripping "comments".
*
* @returns NULL if the string consisted only of whitespace, or was empty
* or was a NULL pointer.
* Otherwise a pointer to the first non-whitespace portion is
* returned. A null character will be written to the string
* at the start of trailing whitespace.
*/
DAS_API char* das_strip(char* sLine, char cComment);

/** Copy string as an XML token
*
* Copy a string ignoring leading and traily spaces. Internal whitespace
Expand Down
34 changes: 34 additions & 0 deletions test/ex18_waves_survey_varmap.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file provides a mapping between Juno/Waves survey data as
# pulled from a das2 server into desired CDF variable names. To
# use it run:
#
# BEGIN=2020-01-01
# END=2020-01-02
#
# SERVER="https://jupiter.physics.uiowa.edu/das/server?server=dataset"
# DATASET="&dataset=Juno/WAV/Survey"
# START="&start_time=${BEGIN}"
# STOP="&stop_time=${END}"
#
# INPUT="${SERVER}${DATASET}${START}${STOP}"
# OUTPUT="./jno_wav_survey_${BEGIN}_v0.1.cdf"
#
# das3_cdf -r -i "${INPUT}" -m waves_survey_cdf_map.conf -o ${OUTPUT}
#

LFR_LO = 10 spec_dens
LFR_LO_Epoch = 10 Time
LFR_LO_Freq = 10 frequency

LFR_HI = 20 spec_dens
LFR_HI_Epoch = 20 Time
LFR_HI_Freq = 20 frequency

HFR_LO = 30 spec_dens
HFR_LO_Epoch = 30 Time
HFR_LO_Freq = 30 frequency

HFR_HI = 40 spec_dens
HFR_HI_Epoch = 40 Time
HFR_HI_Freq = 40 frequency

Loading

0 comments on commit 3291c61

Please sign in to comment.