Commit e8bc2cda authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added support for timestep type

parent dc3f8fe5
......@@ -3,6 +3,10 @@
* using CGRIBEX library version 1.9.4
* Version 1.9.8 released
2019-10-14 Uwe Schulzweida
* Added support for timestep type
2019-10-11 Uwe Schulzweida
* gribapi: use forecast reference time
......
......@@ -368,7 +368,7 @@ const char *cdf_var_type(nc_type xtype)
else if ( xtype == NC_INT ) ctype = "NC_INT";
else if ( xtype == NC_FLOAT ) ctype = "NC_FLOAT";
else if ( xtype == NC_DOUBLE ) ctype = "NC_DOUBLE";
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
else if ( xtype == NC_UBYTE ) ctype = "NC_UBYTE";
else if ( xtype == NC_LONG ) ctype = "NC_LONG";
else if ( xtype == NC_USHORT ) ctype = "NC_USHORT";
......@@ -687,7 +687,7 @@ void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
int status = nc_get_att_string(ncid, varid, name, tp);
if ( CDF_Debug || status != NC_NOERR )
......@@ -711,7 +711,7 @@ void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
void cdf_get_att_long(int ncid, int varid, const char *name, long *ip)
{
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
int status = nc_get_att_long(ncid, varid, name, ip);
if ( CDF_Debug || status != NC_NOERR )
......@@ -790,7 +790,7 @@ void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
}
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
void cdf_def_var_chunking(int ncid, int varid, int storage, const size_t *chunksizesp)
{
int status = nc_def_var_chunking(ncid, varid, storage, chunksizesp);
......
......@@ -167,6 +167,33 @@ void *resizeBuf(void **buf, size_t *bufSize, size_t reqSize)
return *buf;
}
static
void cdfDefineCellMethods(stream_t *streamptr, int cdiID, int varID, int fileID, int ncvarID)
{
taxis_t *taxis = &streamptr->tsteps[0].taxis;
if (!taxis->has_bounds) return;
int time_varid = streamptr->basetime.ncvarid;
char timeVarName[CDI_MAX_NAME];
cdf_inq_varname(fileID, time_varid, timeVarName);
int stepType = vlistInqVarTsteptype(cdiID, varID);
char *cellMethod = NULL;
if (stepType == TSTEP_AVG) cellMethod = "mean";
else if (stepType == TSTEP_SUM) cellMethod = "sum";
else if (stepType == TSTEP_RANGE) cellMethod = "range";
else if (stepType == TSTEP_MIN) cellMethod = "minimum";
else if (stepType == TSTEP_MAX) cellMethod = "maximum";
if (cellMethod)
{
char *attname = "cell_methods";
char atttxt[CDI_MAX_NAME+1];
sprintf(atttxt, "%s: %s", timeVarName, cellMethod);
cdf_put_att_text(fileID, ncvarID, attname, strlen(atttxt), atttxt);
}
}
void cdfDefineAttributes(int cdiID, int varID, int fileID, int ncvarID)
{
......@@ -778,6 +805,9 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdfDefineAttrEnsemble(fileID, ncvarID, vlistID, varID);
// Attribute: cell_methods
cdfDefineCellMethods(streamptr, vlistID, varID, fileID, ncvarID);
// Attributes
cdfDefineAttributes(vlistID, varID, fileID, ncvarID);
......
......@@ -586,7 +586,7 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int gridindex, int ndims, bool
static
void cdfGridCompress(int fileID, int ncvarid, size_t gridsize, int filetype, int comptype)
{
#if defined (HAVE_NETCDF4)
#ifdef HAVE_NETCDF4
if ( gridsize > 1 && comptype == CDI_COMPRESS_ZIP && (filetype == CDI_FILETYPE_NC4 || filetype == CDI_FILETYPE_NC4C) )
{
cdf_def_var_chunking(fileID, ncvarid, NC_CHUNKED, NULL);
......
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