Skip to content

Commit

Permalink
Cubic dataset helpers and bug fix
Browse files Browse the repository at this point in the history
This add new functions to make it easier to work with datasets
that have one coordinate physical dimension for each array
dimension, which is a common case.  The new functions are:

  DasDs_cubicCoords()
  DasDim_degenerate()

and a new iterator:

  struct das_cube_iter

In addition a type bug that was causing incorrect conversion
of TT2000 values to dastime for the milliseconds field has
been fixed.
  • Loading branch information
cpiker committed Jun 7, 2024
1 parent 54e08d8 commit 74eeeaa
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 217 deletions.
11 changes: 6 additions & 5 deletions buildfiles/Linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ export MD5SUM
TARG=libdas3.0

SRCS:=das1.c array.c buffer.c builder.c cli.c codec.c credentials.c dataset.c \
datum.c descriptor.c dft.c dimension.c dsdf.c encoding.c frame.c http.c io.c json.c \
log.c node.c oob.c operator.c packet.c plane.c processor.c property.c serial.c \
send.c stream.c time.c tt2000.c units.c utf8.c util.c value.c variable.c vector.c
datum.c descriptor.c dft.c dimension.c dsdf.c encoding.c frame.c http.c io.c \
iterator.c json.c log.c node.c oob.c operator.c packet.c plane.c processor.c \
property.c serial.c send.c stream.c time.c tt2000.c units.c utf8.c util.c \
value.c variable.c vector.c

HDRS:=defs.h time.h das1.h util.h log.h buffer.h utf8.h value.h units.h \
tt2000.h operator.h datum.h frame.h array.h encoding.h variable.h descriptor.h \
dimension.h dataset.h plane.h packet.h stream.h processor.h property.h oob.h \
io.h builder.h dsdf.h credentials.h http.h dft.h json.h node.h cli.h send.h \
vector.h serial.h codec.h core.h
io.h iterator.h builder.h dsdf.h credentials.h http.h dft.h json.h node.h cli.h \
send.h vector.h serial.h codec.h core.h

ifeq ($(SPICE),yes)
SRCS:=$(SRCS) spice.c
Expand Down
1 change: 1 addition & 0 deletions das2/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
#include <das2/variable.h>
#include <das2/dimension.h>
#include <das2/dataset.h>
#include <das2/iterator.h>
#include <das2/builder.h>
#include <das2/dft.h>
#include <das2/log.h>
Expand Down
133 changes: 59 additions & 74 deletions das2/dataset.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* Copyright (C) 2017-2018 Chris Piker <[email protected]>
/* Copyright (C) 2017-2024 Chris Piker <[email protected]>
*
* This file is part of libdas2, the Core Das2 C Library.
* This file is part of das2C, the Core Das C Library.
*
* Libdas2 is free software; you can redistribute it and/or modify it under
* Das2C is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* Libdas2 is distributed in the hope that it will be useful, but WITHOUT ANY
* Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
* version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
*/

#define _POSIX_C_SOURCE 200112L
Expand Down Expand Up @@ -42,11 +42,25 @@ size_t DasDs_numDims(const DasDs* pThis, enum dim_type vt){
return uDims;
}

const DasDim* DasDs_getDimByIdx(const DasDs* pThis, size_t idx, enum dim_type vt)
const DasDim* DasDs_getDim(const DasDs* pThis, const char* sId, enum dim_type dmt)
{
const char* sDimId = NULL;
for(size_t u = 0; u < pThis->uDims; ++u){
if(pThis->lDims[u]->dtype != dmt)
continue;

sDimId = DasDim_id(pThis->lDims[u]);
if(strcasecmp(sId, sDimId) == 0)
return pThis->lDims[u];
}
return NULL;
}

const DasDim* DasDs_getDimByIdx(const DasDs* pThis, size_t idx, enum dim_type dmt)
{
size_t uTypeIdx = 0;
for(size_t u = 0; u < pThis->uDims; ++u){
if(pThis->lDims[u]->dtype == vt){
if(pThis->lDims[u]->dtype == dmt){
if(uTypeIdx == idx) return pThis->lDims[u];
else ++uTypeIdx;
}
Expand Down Expand Up @@ -130,80 +144,51 @@ ptrdiff_t DasDs_lengthIn(const DasDs* pThis, int nIdx, ptrdiff_t* pLoc)
return nLengthIn;
}

/* ************************************************************************* */
/* The iteration support */
bool DasDs_cubicCoords(const DasDs* pThis, const DasDim** pCoords)
{
ptrdiff_t aDsShape[DASIDX_MAX] = DASIDX_INIT_UNUSED;
int nRank = DasDs_shape(pThis, aDsShape);

void dasds_iter_init(dasds_iterator* pIter, const DasDs* pDs){

memset(pIter, 0, sizeof(dasds_iterator));

pIter->rank = DasDs_shape(pDs, pIter->shape);
pIter->pDs = pDs;

pIter->ragged = false;
for(int i = 0; i < pIter->rank; ++i){
if((pIter->shape[i] == DASIDX_RAGGED)||(pIter->shape[i] == DASIDX_RAGGED)){
pIter->ragged = true;
break;
}
}

/* Start off index at all zeros, which memset insures above */

/* If I'm ragged I'm going to need the size of the last index at the
* lowest point of all previous indexes, get that. */
if(pIter->ragged){
pIter->nLenIn = DasDs_lengthIn(pDs, pIter->rank - 1, pIter->index);
if(pIter->nLenIn < 0) pIter->done = true;
}
}
for(int i = 0; i < nRank; ++i){ /* For each index... */

bool dasds_iter_next(dasds_iterator* pIter){

if(! pIter->ragged){
/* Quicker function for CUBIC datasets */
for(int iDim = pIter->rank - 1; iDim >= 0; --iDim){
if(pIter->index[iDim] < (pIter->shape[iDim] - 1)){
pIter->index[iDim] += 1;
return true;
bool bGotIt = false;
for(int c = 0; c < pThis->uDims; ++c){ /* for each coordinate */

const DasDim* pCoord = pThis->lDims[c];

if(pCoord->dtype != DASDIM_COORD) continue;

bool bUsed = false; /* See if already used for lower index*/
for(int j = 0; j < i; ++j){
if(pCoords[j] == pCoord)
bUsed = true;
}
else{
pIter->index[iDim] = 0;
if(bUsed) continue;

if(DasDim_degenerate(pCoord, i))
continue; /* Doesn't depend on this idx */

/* make sure it depends only on this index */
bool bOnlyMe = true;
for(int j = 0; j < nRank; ++j){
if(j == i) continue;

if(! DasDim_degenerate(pCoord, j)){
bOnlyMe = false;
break;
}
}
}

pIter->done = true;
return false;
}

/* I'm ragged so I can't use the generic shape function, but I can
* at least save off the length of the last index at this point
* and only change it when a roll occurs */
ptrdiff_t nLenInIdx = 0;
for(int iDim = pIter->rank - 1; iDim >= 0; --iDim){
if(!bOnlyMe)
continue;

if(iDim == (pIter->rank - 1))
nLenInIdx = pIter->nLenIn;
else
nLenInIdx = DasDs_lengthIn(pIter->pDs, iDim, pIter->index);

if(pIter->index[iDim] < (nLenInIdx - 1)){
pIter->index[iDim] += 1;

/* If bumping an index that's not the last, recompute the length
* of the last run */
if(iDim < (pIter->rank - 1))
pIter->nLenIn = DasDs_lengthIn(pIter->pDs, pIter->rank - 1, pIter->index);

return true;
}
else{
pIter->index[iDim] = 0;
pCoords[i] = pCoord;
bGotIt = true;
break;
}

if(!bGotIt) return false;
}

pIter->done = true;
return false;
return true;
}

/* ************************************************************************* */
Expand Down
Loading

0 comments on commit 74eeeaa

Please sign in to comment.