diff --git a/ChangeLog b/ChangeLog index 936af641127dd7c57c08d5a5c588676093d67f5e..093a8abe46e093501102c655d40c696409a862ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * Version 2.5.1 released +2025-02-28 Uwe Schulzweida + + * taxis: added support for CDI_KEY_DATATYPE + 2025-02-12 Uwe Schulzweida * GRIB_API: Handle LLAM as LCC diff --git a/src/cdi_key.c b/src/cdi_key.c index b80d936df41b9cf64976cf9639131ab2e8cd4bc4..3f0351a1e366d8eac9054cf0e10e30d82c3c6abe 100644 --- a/src/cdi_key.c +++ b/src/cdi_key.c @@ -12,6 +12,7 @@ #include "cdi.h" #include "cdi_int.h" +#include "taxis.h" #include "zaxis.h" #include "grid.h" #include "vlist.h" @@ -43,6 +44,12 @@ zaxis_get_keysp(zaxis_t *zaxisptr, int varID) return (varID == CDI_GLOBAL) ? &zaxisptr->keys : NULL; } +static cdi_keys_t * +taxis_get_keysp(taxis_t *taxisptr, int varID) +{ + return (varID == CDI_GLOBAL) ? &taxisptr->keys : NULL; +} + static cdi_key_t * new_key(cdi_keys_t *keysp, int key) { @@ -100,6 +107,7 @@ cdi_get_keysp(int objID, int varID) if (reshID == GRID) return grid_get_keysp(grid_to_pointer(objID), varID); if (reshID == DIST_GRID) return grid_get_keysp(grid_to_pointer(objID), varID); if (reshID == ZAXIS) return zaxis_get_keysp(zaxis_to_pointer(objID), varID); + if (reshID == TAXIS) return taxis_get_keysp(taxis_to_pointer(objID), varID); if (reshID == VLIST) return vlist_get_keysp(vlist_to_pointer(objID), varID); return NULL; diff --git a/src/stream.c b/src/stream.c index 34aabfbab941d64afdf4da3f208169b46c69d62f..f3a11f7c81df0494610670f4a9aa27cea5621718 100644 --- a/src/stream.c +++ b/src/stream.c @@ -430,7 +430,7 @@ cdiInqContents(stream_t *streamptr) if (taxisID != CDI_UNDEFID) { taxis_t *taxisptr1 = &streamptr->tsteps[0].taxis; - taxis_t *taxisptr2 = taxisPtr(taxisID); + taxis_t *taxisptr2 = taxis_to_pointer(taxisID); ptaxisCopy(taxisptr2, taxisptr1); } } @@ -1462,7 +1462,7 @@ cdiStreamDefTimestep_(stream_t *streamptr, int tsID) } int taxisID = vlistInqTaxis(vlistID); - if (taxisID != CDI_UNDEFID) ptaxisCopy(&streamptr->tsteps[tsID].taxis, taxisPtr(taxisID)); + if (taxisID != CDI_UNDEFID) ptaxisCopy(&streamptr->tsteps[tsID].taxis, taxis_to_pointer(taxisID)); streamptr->curTsID = tsID; streamptr->ntsteps = tsID + 1; @@ -1564,7 +1564,7 @@ streamInqTimestep(int streamID, int tsID) streamptr->tsteps[tsID].curRecID = CDI_UNDEFID; int taxisID = vlistInqTaxis(vlistID); if (taxisID == -1) Error("Timestep undefined for fileID = %d", streamID); - ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[tsID].taxis); + ptaxisCopy(taxis_to_pointer(taxisID), &streamptr->tsteps[tsID].taxis); return nrecs; } @@ -1633,7 +1633,7 @@ streamInqTimestep(int streamID, int tsID) int taxisID = vlistInqTaxis(vlistID); if (taxisID == -1) Error("Timestep undefined for fileID = %d", streamID); - ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[tsID].taxis); + ptaxisCopy(taxis_to_pointer(taxisID), &streamptr->tsteps[tsID].taxis); return nrecs; } @@ -1832,7 +1832,7 @@ cdiStreamSetupVlist_(stream_t *streamptr, int vlistID) if (taxisInqType(taxisID) == TAXIS_RELATIVE) if (cdiBaseFiletype(streamptr->filetype) == CDI_FILETYPE_NETCDF) { - const taxis_t *taxisptr = taxisPtr(taxisID); + const taxis_t *taxisptr = taxis_to_pointer(taxisID); if (cdiDateTime_isNull(taxisptr->rDateTime)) { int vdate = taxisInqVdate(taxisID); @@ -1841,7 +1841,7 @@ cdiStreamSetupVlist_(stream_t *streamptr, int vlistID) } } #endif - ptaxisCopy(&streamptr->tsteps[0].taxis, taxisPtr(taxisID)); + ptaxisCopy(&streamptr->tsteps[0].taxis, taxis_to_pointer(taxisID)); } switch (cdiBaseFiletype(streamptr->filetype)) diff --git a/src/stream_cdf_time.c b/src/stream_cdf_time.c index dc594c44d4d14dd8080fc484636b7cdff7f8ecfb..8b5e662a99bdec5b897c928e9daa94477331bb9b 100644 --- a/src/stream_cdf_time.c +++ b/src/stream_cdf_time.c @@ -153,7 +153,7 @@ cdfDefTime(stream_t *streamptr) if (streamptr->ncmode == 0) streamptr->ncmode = 1; if (streamptr->ncmode == 2) cdf_redef(fileID); - taxis_t *taxis = taxisPtr(vlistInqTaxis(streamptr->vlistID)); + taxis_t *taxis = taxis_to_pointer(vlistInqTaxis(streamptr->vlistID)); const char *taxisName = (taxis->name && taxis->name[0]) ? taxis->name : defaultTimeAxisName; @@ -170,7 +170,8 @@ cdfDefTime(stream_t *streamptr) cdf_def_dim(fileID, taxisName, timeDimLen, &timeDimId); streamptr->basetime.ncdimid = timeDimId; - int datatype = taxis->datatype; + int datatype = CDI_UNDEFID; + cdiInqKeyInt(taxis->self, CDI_GLOBAL, CDI_KEY_DATATYPE, &datatype); nc_type xtype = (datatype == CDI_DATATYPE_INT32) ? NC_INT : ((datatype == CDI_DATATYPE_FLT32) ? NC_FLOAT : NC_DOUBLE); int timeVarId; @@ -245,7 +246,7 @@ cdfDefTimestep(stream_t *streamptr, int tsID, size_t valCount) int time_varid = streamptr->basetime.ncvarid; if (time_varid != CDI_UNDEFID && tsID == 0) { - taxis_t *taxis = taxisPtr(vlistInqTaxis(streamptr->vlistID)); + taxis_t *taxis = taxis_to_pointer(vlistInqTaxis(streamptr->vlistID)); int fileID = streamptr->fileID; const char *unitstr = cdfGetTimeUnits(taxis); size_t len = strlen(unitstr); diff --git a/src/taxis.c b/src/taxis.c index e0363e598c3a59c65b47e9dbacca9b4fc8c6ff52..a252db8b187e6d64c52b75b43383d3f70fe18b07 100644 --- a/src/taxis.c +++ b/src/taxis.c @@ -122,7 +122,6 @@ ptaxisInit(taxis_t *taxisptr) cdiInitKeys(&taxisptr->keys); cdiDefVarKeyInt(&taxisptr->keys, CDI_KEY_DATATYPE, CDI_DATATYPE_FLT64); - taxisptr->datatype = CDI_DATATYPE_FLT64; } static taxis_t * @@ -239,7 +238,6 @@ taxisDefType(int taxisID, int taxistype) { taxisptr->type = taxistype; cdiDefVarKeyInt(&taxisptr->keys, CDI_KEY_DATATYPE, CDI_DATATYPE_FLT64); - taxisptr->datatype = CDI_DATATYPE_FLT64; delete_refcount_string(taxisptr->units); taxisptr->units = NULL; reshSetStatus(taxisID, &taxisOps, RESH_DESYNC_IN_USE); @@ -844,7 +842,7 @@ taxisInqNumavg(int taxisID) } taxis_t * -taxisPtr(int taxisID) +taxis_to_pointer(int taxisID) { taxis_t *taxisptr = (taxis_t *) reshGetVal(taxisID, &taxisOps); return taxisptr; @@ -854,7 +852,6 @@ void ptaxisDefDatatype(taxis_t *taxisptr, int datatype) { cdiDefVarKeyInt(&taxisptr->keys, CDI_KEY_DATATYPE, datatype); - taxisptr->datatype = datatype; } void @@ -1378,7 +1375,6 @@ ptaxisCopy(taxis_t *dest, taxis_t *source) dest->units = dup_refcount_string(source->units); if (dest->self != CDI_UNDEFID) reshSetStatus(dest->self, &taxisOps, RESH_DESYNC_IN_USE); - dest->datatype = source->datatype; cdiInitKeys(&dest->keys); cdiCopyVarKeys(&source->keys, &dest->keys); diff --git a/src/taxis.h b/src/taxis.h index 7f98b99ad7bcd5bacd91acb909b17e420e4e1bec..5888b513d4ba6715044d2d936faae5638f780dd4 100644 --- a/src/taxis.h +++ b/src/taxis.h @@ -13,8 +13,7 @@ typedef struct { int self; - int datatype; // datatype - int type; // time type + int type; // time type int calendar; int unit; // time units int numavg; @@ -39,7 +38,7 @@ CdiDateTime taxisInqSdatetime(int taxisID); void ptaxisInit(taxis_t *taxis); void ptaxisCopy(taxis_t *dest, taxis_t *source); -taxis_t *taxisPtr(int taxisID); +taxis_t *taxis_to_pointer(int taxisID); void cdi_set_forecast_period(double timevalue, taxis_t *taxis); CdiDateTime cdi_decode_timeval(double timevalue, const taxis_t *taxis); double cdi_encode_timeval(CdiDateTime datetime, taxis_t *taxis);