Commit 2a2ec25e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

time axis: added support for datatype integer

parent 8f2cef35
......@@ -3,6 +3,10 @@
* using CGRIBEX library version 1.9.4
* Version 1.9.8 released
2019-09-08 Uwe Schulzweida
* time axis: added support for datatype integer
2019-09-06 Uwe Schulzweida
* gribapiDefTime: adjust reference time if necessary (bug fix) [report: Helmut Haak]
......
......@@ -158,13 +158,11 @@ static
int setBaseTime(const char *timeunits, taxis_t *taxis)
{
int taxistype = TAXIS_ABSOLUTE;
int64_t rdate = -1;
int rtime = -1;
size_t len = strlen(timeunits);
while ( isspace(*timeunits) && len ) { timeunits++; len--; }
char *restrict tu = (char *)Malloc((len+1) * sizeof(char));
char *tu = (char *)Malloc((len+1) * sizeof(char));
for ( size_t i = 0; i < len; i++ ) tu[i] = (char)tolower((int)timeunits[i]);
tu[len] = 0;
......@@ -182,8 +180,7 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
{
while ( isspace(tu[pos]) ) ++pos;
if ( strStartsWith(tu+pos, "since") )
taxistype = TAXIS_RELATIVE;
if ( strStartsWith(tu+pos, "since") ) taxistype = TAXIS_RELATIVE;
while ( pos < len && !isspace(tu[pos]) ) ++pos;
if ( tu[pos] )
......@@ -211,13 +208,13 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
}
else if ( taxistype == TAXIS_RELATIVE )
{
int64_t rdate = -1;
int rtime = -1;
scanTimeString(tu+pos, &rdate, &rtime);
taxis->rdate = rdate;
taxis->rtime = rtime;
if ( CDI_Debug )
Message("rdate = %lld rtime = %d", rdate, rtime);
if ( CDI_Debug ) Message("rdate = %lld rtime = %d", rdate, rtime);
}
}
}
......@@ -227,8 +224,7 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
Free(tu);
if ( CDI_Debug )
Message("taxistype = %d unit = %d", taxistype, timeunit);
if ( CDI_Debug ) Message("taxistype = %d unit = %d", taxistype, timeunit);
return 0;
}
......@@ -4101,7 +4097,8 @@ int cdfInqContents(stream_t *streamptr)
if ( ncvars[nctimevarid].units[0] )
ptaxisDefUnits(taxis, ncvars[nctimevarid].units);
int datatype = (ncvars[nctimevarid].xtype == NC_FLOAT) ? CDI_DATATYPE_FLT32 : CDI_DATATYPE_FLT64;
int xtype = ncvars[nctimevarid].xtype;
int datatype = (xtype == NC_INT) ? CDI_DATATYPE_INT32 : ((xtype == NC_FLOAT) ? CDI_DATATYPE_FLT32 : CDI_DATATYPE_FLT64);
ptaxisDefDatatype(taxis, datatype);
}
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#ifdef HAVE_LIBNETCDF
......@@ -12,10 +12,10 @@
#include "stream_cdf.h"
#include "cdf_int.h"
static
int cdfDefTimeBounds(int fileID, int nctimevarid, int nctimedimid, const char *taxis_name, taxis_t* taxis)
{
int time_bndsid = -1;
int dims[2];
dims[0] = nctimedimid;
......@@ -48,6 +48,8 @@ int cdfDefTimeBounds(int fileID, int nctimevarid, int nctimedimid, const char *t
bndsAttValLen = tmpstrLen;
bndsAttVal = tmpstr;
}
int time_bndsid = -1;
cdf_def_var(fileID, bndsAttVal, NC_DOUBLE, 2, dims, &time_bndsid);
cdf_put_att_text(fileID, nctimevarid, bndsAttName, bndsAttValLen, bndsAttVal);
......@@ -137,9 +139,6 @@ void cdfDefCalendar(int fileID, int ncvarid, int calendar)
void cdfDefTime(stream_t* streamptr)
{
int time_varid;
int time_dimid;
int time_bndsid = -1;
static const char default_name[] = "time";
if ( streamptr->basetime.ncvarid != CDI_UNDEFID ) return;
......@@ -152,15 +151,18 @@ void cdfDefTime(stream_t* streamptr)
taxis_t *taxis = &streamptr->tsteps[0].taxis;
const char *taxis_name = (taxis->name && taxis->name[0]) ? taxis->name : default_name ;
int time_dimid;
cdf_def_dim(fileID, taxis_name, NC_UNLIMITED, &time_dimid);
streamptr->basetime.ncdimid = time_dimid;
const nc_type xtype = (taxis->datatype == CDI_DATATYPE_FLT32) ? NC_FLOAT : NC_DOUBLE;
cdf_def_var(fileID, taxis_name, xtype, 1, &time_dimid, &time_varid);
const int datatype = taxis->datatype;
const nc_type xtype = (datatype == CDI_DATATYPE_INT32) ? NC_INT : ((datatype == CDI_DATATYPE_FLT32) ? NC_FLOAT : NC_DOUBLE);
int time_varid;
cdf_def_var(fileID, taxis_name, xtype, 1, &time_dimid, &time_varid);
streamptr->basetime.ncvarid = time_varid;
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
if ( streamptr->filetype == CDI_FILETYPE_NC4 || streamptr->filetype == CDI_FILETYPE_NC4C )
{
const size_t chunk = 512;
......@@ -176,7 +178,7 @@ void cdfDefTime(stream_t* streamptr)
if ( taxis->has_bounds )
{
time_bndsid = cdfDefTimeBounds(fileID, time_varid, time_dimid, taxis_name, taxis);
int time_bndsid = cdfDefTimeBounds(fileID, time_varid, time_dimid, taxis_name, taxis);
streamptr->basetime.ncvarboundsid = time_bndsid;
}
......@@ -184,12 +186,10 @@ void cdfDefTime(stream_t* streamptr)
cdfDefTimeUnits(unitstr, taxis);
size_t len = strlen(unitstr);
if (len) cdf_put_att_text(fileID, time_varid, "units", len, unitstr);
// if ( len && taxis->has_bounds ) cdf_put_att_text(fileID, time_bndsid, "units", len, unitstr);
if ( taxis->calendar != -1 )
{
cdfDefCalendar(fileID, time_varid, taxis->calendar);
// ( taxis->has_bounds ) cdfDefCalendar(fileID, time_bndsid, taxis->calendar);
}
if ( taxis->type == TAXIS_FORECAST )
......@@ -214,7 +214,6 @@ void cdfDefTime(stream_t* streamptr)
if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
}
#endif
/*
* Local Variables:
......
......@@ -104,35 +104,6 @@ const char *tunitNamePtr(int unitID)
return (unitID > 0 && unitID < size) ? Timeunits[unitID] : Timeunits[0];
}
#if 0
static
void taxis_defaults(void)
{
char *timeunit = getenv("TIMEUNIT");
if ( timeunit )
{
if ( strcmp(timeunit, "minutes") == 0 )
DefaultTimeUnit = TUNIT_MINUTE;
else if ( strcmp(timeunit, "hours") == 0 )
DefaultTimeUnit = TUNIT_HOUR;
else if ( strcmp(timeunit, "3hours") == 0 )
DefaultTimeUnit = TUNIT_3HOURS;
else if ( strcmp(timeunit, "6hours") == 0 )
DefaultTimeUnit = TUNIT_6HOURS;
else if ( strcmp(timeunit, "12hours") == 0 )
DefaultTimeUnit = TUNIT_12HOURS;
else if ( strcmp(timeunit, "days") == 0 )
DefaultTimeUnit = TUNIT_DAY;
else if ( strcmp(timeunit, "months") == 0 )
DefaultTimeUnit = TUNIT_MONTH;
else if ( strcmp(timeunit, "years") == 0 )
DefaultTimeUnit = TUNIT_YEAR;
else
Warning("Unsupported TIMEUNIT %s!", timeunit);
}
}
#endif
static
void taxisDefaultValue(taxis_t* taxisptr)
{
......@@ -295,6 +266,7 @@ void taxisDefType(int taxisID, int taxistype)
if ( taxisptr->type != taxistype )
{
taxisptr->type = taxistype;
taxisptr->datatype = CDI_DATATYPE_FLT64;
if ( taxisptr->units )
{
delete_refcount_string(taxisptr->units);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment