Commit 276f5046 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced vlistDefVarEnsemble() by cdiDefKeyInt().

parent 4c5f31c1
......@@ -4,6 +4,7 @@
2018-01-05 Uwe Schulzweida
* Replaced vlistDefVarEnsemble() by cdiDefKeyInt().
* Consistent test for GRIB2 shortName [patch from: Florian Prill]
* Added support for GRIB2 keys shapeOfTheEarth and typeOfProcessedData
* Replaced vlistDefVarProductDefinitionTemplate() by cdiDefKeyInt().
......
......@@ -21,7 +21,6 @@ int main(void)
size_t nmiss;
int instID;
int i1,i2,i3;
size_t datasize = (size_t)nlon * (size_t)nlat;
data = (double *) malloc(datasize * sizeof (double));
......@@ -38,10 +37,17 @@ int main(void)
vlistID = vlistCreate();
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARYING);
vlistDefVarEnsemble( vlistID, varID, 1, 2, 3);
int perturbationNumber = 1;
int numberOfForecastsInEnsemble = 2;
int typeOfEnsembleForecast = 3;
vlistInqVarEnsemble( vlistID, varID, &i1,&i2,&i3);
cdiDefKeyInt(vlistID, varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, typeOfEnsembleForecast);
cdiDefKeyInt(vlistID, varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, numberOfForecastsInEnsemble);
cdiDefKeyInt(vlistID, varID, CDI_KEY_PERTURBATIONNUMBER, perturbationNumber);
cdiInqKeyInt(vlistID, varID, CDI_KEY_PERTURBATIONNUMBER, &perturbationNumber);
cdiInqKeyInt(vlistID, varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, &numberOfForecastsInEnsemble);
cdiInqKeyInt(vlistID, varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, &typeOfEnsembleForecast);
vlistDefInstitut( vlistID,instID );
......
......@@ -332,7 +332,6 @@ int cdfDefVar(stream_t *streamptr, int varID)
int dimorder[3];
size_t iax = 0;
char axis[5];
int ensID, ensCount, forecast_type;
int fileID = streamptr->fileID;
......@@ -750,15 +749,13 @@ int cdfDefVar(stream_t *streamptr, int varID)
}
}
if ( vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) )
{
/* void cdf_put_att_int( int ncid, int varid, const char *name, nc_type xtype,
size_t len, const int *ip )
*/
cdf_put_att_int(fileID, ncvarid, "realization", NC_INT, 1, &ensID);
cdf_put_att_int(fileID, ncvarid, "ensemble_members", NC_INT, 1, &ensCount);
cdf_put_att_int(fileID, ncvarid, "forecast_init_type", NC_INT, 1, &forecast_type);
}
int perturbationNumber, numberOfForecastsInEnsemble, typeOfEnsembleForecast;
if ( cdiInqKeyInt(vlistID, varID, CDI_KEY_PERTURBATIONNUMBER, &perturbationNumber) == 0 )
cdf_put_att_int(fileID, ncvarid, "realization", NC_INT, 1, &perturbationNumber);
if ( cdiInqKeyInt(vlistID, varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, &numberOfForecastsInEnsemble) == 0 )
cdf_put_att_int(fileID, ncvarid, "ensemble_members", NC_INT, 1, &numberOfForecastsInEnsemble);
if ( cdiInqKeyInt(vlistID, varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, &typeOfEnsembleForecast) == 0 )
cdf_put_att_int(fileID, ncvarid, "forecast_init_type", NC_INT, 1, &typeOfEnsembleForecast);
/* Attributes */
cdfDefineAttributes(vlistID, varID, fileID, ncvarid);
......
......@@ -676,10 +676,6 @@ int vlistFindLevel(int vlistID, int fvarID, int flevelID);
int vlistMergedVar(int vlistID, int varID);
int vlistMergedLevel(int vlistID, int varID, int levelID);
/* Ensemble info routines */
void vlistDefVarEnsemble(int vlistID, int varID, int ensID, int ensCount, int forecast_type);
int vlistInqVarEnsemble(int vlistID, int varID, int *ensID, int *ensCount, int *forecast_type);
/* cdiClearAdditionalKeys: Clear the list of additional GRIB keys. */
void cdiClearAdditionalKeys(void);
/* cdiDefAdditionalKey: Register an additional GRIB key which is read when file is opened. */
......@@ -803,7 +799,7 @@ int gridInqYIsc(int gridID);
/* gridInqYCvals: Get strings from Y-axis in case grid is of type GRID_CHARXY */
size_t gridInqYCvals(int gridID, char *ycvals[]);
// CDI var key values
// CDI var keys
#define CDI_KEY_TABLESVERSION 801 // GRIB2 tablesVersion
#define CDI_KEY_LOCALTABLESVERSION 802 // GRIB2 localTablesVersion
#define CDI_KEY_TYPEOFGENERATINGPROCESS 803 // GRIB2 typeOfGeneratingProcess
......@@ -811,6 +807,9 @@ size_t gridInqYCvals(int gridID, char *ycvals[]);
#define CDI_KEY_TYPEOFPROCESSEDDATA 805 // GRIB2 typeOfProcessedData
#define CDI_KEY_SHAPEOFTHEEARTH 806 // GRIB2 shapeOfTheEarth
#define CDI_KEY_BACKGROUNDPROCESS 807 // GRIB2 backgroundProcess
#define CDI_KEY_TYPEOFENSEMBLEFORECAST 808 // GRIB2 typeOfEnsembleForecast
#define CDI_KEY_NUMBEROFFORECASTSINENSEMBLE 809 // GRIB2 numberOfForecastsInEnsemble
#define CDI_KEY_PERTURBATIONNUMBER 810 // GRIB2 perturbationNumber
// cdiDefKeyInt: Define a CDI varianble integer value from a key
int cdiDefKeyInt(int cdiID, int varID, int key, int value);
......@@ -818,7 +817,7 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value);
// cdiInqKeyInt: Get a CDI variable integer value from a key
int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
// CDI grid key values
// CDI grid keys
#define CDI_KEY_XNAME 901 // X-axis name
#define CDI_KEY_XDIMNAME 902 // X-axis dimension name
#define CDI_KEY_XLONGNAME 903 // X-axis longname
......@@ -831,7 +830,7 @@ int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
#define CDI_KEY_MAPPING 921 // Grid mapping var name
#define CDI_KEY_MAPNAME 922 // Grid mapping name
// CDI zaxis key values
// CDI zaxis keys
#define CDI_KEY_NAME 941 // Z-axis name
#define CDI_KEY_DIMNAME 942 // Z-axis dimension name
#define CDI_KEY_LONGNAME 943 // Z-axis longname
......@@ -840,8 +839,6 @@ int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
#define CDI_KEY_P0NAME 951 // Z-axis reference pressure name
#define CDI_KEY_P0VALUE 952 // Z-axis reference pressure in Pa
// CDI var key values
// cdiGridDefKeyStr: Define a CDI grid string value from a key
int cdiGridDefKeyStr(int gridID, int key, int size, const char *mesg);
......
......@@ -1312,25 +1312,6 @@
! INTEGER levelID)
EXTERNAL vlistMergedLevel
!
! Ensemble info routines
!
! vlistDefVarEnsemble
! (INTEGER vlistID,
! INTEGER varID,
! INTEGER ensID,
! INTEGER ensCount,
! INTEGER forecast_type)
EXTERNAL vlistDefVarEnsemble
INTEGER vlistInqVarEnsemble
! (INTEGER vlistID,
! INTEGER varID,
! INTEGER ensID,
! INTEGER ensCount,
! INTEGER forecast_type)
EXTERNAL vlistInqVarEnsemble
! cdiClearAdditionalKeys
EXTERNAL cdiClearAdditionalKeys
......@@ -1595,6 +1576,12 @@
PARAMETER (CDI_KEY_SHAPEOFTHEEARTH = 806)
INTEGER CDI_KEY_BACKGROUNDPROCESS
PARAMETER (CDI_KEY_BACKGROUNDPROCESS = 807)
INTEGER CDI_KEY_TYPEOFENSEMBLEFORECAST
PARAMETER (CDI_KEY_TYPEOFENSEMBLEFORECAST = 808)
INTEGER CDI_KEY_NUMBEROFFORECASTSINENSEMBLE
PARAMETER (CDI_KEY_NUMBEROFFORECASTSINENSEMBLE = 809)
INTEGER CDI_KEY_PERTURBATIONNUMBER
PARAMETER (CDI_KEY_PERTURBATIONNUMBER = 810)
INTEGER cdiDefKeyInt
! (INTEGER cdiID,
! INTEGER varID,
......
......@@ -377,11 +377,6 @@ FCALLSCFUN2 (INT, vlistFindVar, VLISTFINDVAR, vlistfindvar, INT, INT)
FCALLSCFUN3 (INT, vlistFindLevel, VLISTFINDLEVEL, vlistfindlevel, INT, INT, INT)
FCALLSCFUN2 (INT, vlistMergedVar, VLISTMERGEDVAR, vlistmergedvar, INT, INT)
FCALLSCFUN3 (INT, vlistMergedLevel, VLISTMERGEDLEVEL, vlistmergedlevel, INT, INT, INT)
/* Ensemble info routines */
FCALLSCSUB5 (vlistDefVarEnsemble, VLISTDEFVARENSEMBLE, vlistdefvarensemble, INT, INT, INT, INT, INT)
FCALLSCFUN5 (INT, vlistInqVarEnsemble, VLISTINQVARENSEMBLE, vlistinqvarensemble, INT, INT, PINT, PINT, PINT)
FCALLSCSUB0 (cdiClearAdditionalKeys, CDICLEARADDITIONALKEYS, cdiclearadditionalkeys)
FCALLSCSUB1 (cdiDefAdditionalKey, CDIDEFADDITIONALKEY, cdidefadditionalkey, STRING)
FCALLSCSUB4 (vlistDefVarIntKey, VLISTDEFVARINTKEY, vlistdefvarintkey, INT, INT, STRING, INT)
......
......@@ -109,7 +109,9 @@ typedef struct {
char stdname[CDI_MAX_NAME];
char units[CDI_MAX_NAME];
char extra[CDI_MAX_NAME];
ensinfo_t *ensdata; /* Ensemble information */
int typeOfEnsembleForecast;
int numberOfForecastsInEnsemble;
int perturbationNumber;
}
ncvar_t;
......@@ -692,7 +694,9 @@ void init_ncvars(long nvars, ncvar_t *ncvars)
ncvars[ncvarid].lvalidrange = false;
ncvars[ncvarid].validrange[0] = VALIDMISS;
ncvars[ncvarid].validrange[1] = VALIDMISS;
ncvars[ncvarid].ensdata = NULL;
ncvars[ncvarid].typeOfEnsembleForecast = -1;
ncvars[ncvarid].numberOfForecastsInEnsemble = -1;
ncvars[ncvarid].perturbationNumber = -1;
memset(ncvars[ncvarid].name, 0, CDI_MAX_NAME);
memset(ncvars[ncvarid].longname, 0, CDI_MAX_NAME);
memset(ncvars[ncvarid].stdname, 0, CDI_MAX_NAME);
......@@ -1537,18 +1541,11 @@ void cdf_scan_var_attr(int nvars, ncvar_t *ncvars, ncdim_t *ncdims, int timedimi
strcmp(attname, "forecast_init_type") == 0) )
{
int temp;
if( ncvars[ncvarid].ensdata == NULL )
ncvars[ncvarid].ensdata = (ensinfo_t *) Malloc( sizeof( ensinfo_t ) );
cdfGetAttInt(ncid, ncvarid, attname, 1, &temp);
if( strcmp(attname, "realization") == 0 )
ncvars[ncvarid].ensdata->ens_index = temp;
else if( strcmp(attname, "ensemble_members") == 0 )
ncvars[ncvarid].ensdata->ens_count = temp;
else if( strcmp(attname, "forecast_init_type") == 0 )
ncvars[ncvarid].ensdata->forecast_init_type = temp;
if ( strcmp(attname, "realization") == 0 ) ncvars[ncvarid].perturbationNumber = temp;
else if ( strcmp(attname, "ensemble_members") == 0 ) ncvars[ncvarid].numberOfForecastsInEnsemble = temp;
else if ( strcmp(attname, "forecast_init_type") == 0 ) ncvars[ncvarid].typeOfEnsembleForecast = temp;
cdf_set_var(ncvars, ncvarid, TRUE);
}
......@@ -3180,13 +3177,11 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
printf("dimids: %d %d\n", i, dimids[i]);
printf("xdimid, ydimid %d %d\n", xdimid, ydimid);
*/
if ( ncvars[ncvarid].ensdata != NULL )
if ( ncvars[ncvarid].numberOfForecastsInEnsemble != -1 )
{
vlistDefVarEnsemble( vlistID, varID, ncvars[ncvarid].ensdata->ens_index,
ncvars[ncvarid].ensdata->ens_count,
ncvars[ncvarid].ensdata->forecast_init_type );
Free(ncvars[ncvarid].ensdata);
ncvars[ncvarid].ensdata = NULL;
cdiDefKeyInt(vlistID, varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, ncvars[ncvarid].typeOfEnsembleForecast);
cdiDefKeyInt(vlistID, varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, ncvars[ncvarid].numberOfForecastsInEnsemble);
cdiDefKeyInt(vlistID, varID, CDI_KEY_PERTURBATIONNUMBER, ncvars[ncvarid].perturbationNumber);
}
if ( ncvars[ncvarid].extra[0] != 0 )
......
......@@ -2054,8 +2054,6 @@ void cgribexDefaultSec4(int *isec4)
static
void cgribexDefEnsembleVar(int *isec1, int vlistID, int varID)
{
int ensID, ensCount, forecast_type;
/* For Ensemble info */
//Put1Byte(isec1[36]); /* MPIM local GRIB use definition identifier */
......@@ -2064,16 +2062,21 @@ void cgribexDefEnsembleVar(int *isec1, int vlistID, int varID)
//Put2Byte(isec1[38]); /* individual ensemble member */
//Put2Byte(isec1[39]); /* number of forecasts in ensemble */
if ( vlistInqVarEnsemble(vlistID, varID, &ensID, &ensCount, &forecast_type) )
int perturbationNumber, numberOfForecastsInEnsemble, typeOfEnsembleForecast;
int r1 = cdiInqKeyInt(vlistID, varID, CDI_KEY_PERTURBATIONNUMBER, &perturbationNumber);
int r2 = cdiInqKeyInt(vlistID, varID, CDI_KEY_NUMBEROFFORECASTSINENSEMBLE, &numberOfForecastsInEnsemble);
int r3 = cdiInqKeyInt(vlistID, varID, CDI_KEY_TYPEOFENSEMBLEFORECAST, &typeOfEnsembleForecast);
if ( r1 == 0 && r2 == 0 && r3 == 0 )
{
if ( ISEC1_CenterID == 252 )
{
ISEC1_LocalFLag = 1;
isec1[36] = 1;
isec1[37] = forecast_type;
isec1[38] = ensID;
isec1[39] = ensCount;
isec1[37] = typeOfEnsembleForecast;
isec1[38] = perturbationNumber;
isec1[39] = numberOfForecastsInEnsemble;
}
}
}
......
......@@ -3057,11 +3057,11 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
}
/*
if( vlistInqVarEnsemble( vlistID, varID, &ensID, &ensCount, &forecast_type ) )
if( vlistInqVarEnsemble(vlistID, varID, &perturbationNumber, &numberOfForecastsInEnsemble, &typeOfEnsembleForecast) )
{
GRIB_CHECK(my_grib_set_long(gh, "typeOfEnsembleForecast", forecast_type ), 0);
GRIB_CHECK(my_grib_set_long(gh, "numberOfForecastsInEnsemble", ensCount ), 0);
GRIB_CHECK(my_grib_set_long(gh, "perturbationNumber", ensID ), 0);
GRIB_CHECK(my_grib_set_long(gh, "typeOfEnsembleForecast", typeOfEnsembleForecast), 0);
GRIB_CHECK(my_grib_set_long(gh, "numberOfForecastsInEnsemble", numberOfForecastsInEnsemble), 0);
GRIB_CHECK(my_grib_set_long(gh, "perturbationNumber", perturbationNumber), 0);
}
*/
......
......@@ -787,10 +787,6 @@ void cdi_generate_vars(stream_t *streamptr)
if ( vartable[varid].longname ) vlistDefVarLongname(vlistID, varID, vartable[varid].longname);
if ( vartable[varid].units ) vlistDefVarUnits(vlistID, varID, vartable[varid].units);
if ( vartable[varid].ensdata ) vlistDefVarEnsemble(vlistID, varID, vartable[varid].ensdata->ens_index,
vartable[varid].ensdata->ens_count,
vartable[varid].ensdata->forecast_init_type);
vlist_t *vlistptr = vlist_to_pointer(vlistID);
for ( int i = 0; i < vartable[varid].opt_grib_nentries; i++ )
{
......
......@@ -1687,45 +1687,6 @@ int vlistInqVarXYZ(int vlistID, int varID)
return vlistptr->vars[varID].xyz;
}
/* Ensemble Info Routines */
void vlistDefVarEnsemble(int vlistID, int varID, int ensID, int ensCount, int forecast_type )
{
vlist_t *vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(__func__, vlistID, varID);
if ( vlistptr->vars[varID].ensdata == NULL )
vlistptr->vars[varID].ensdata
= (ensinfo_t *) Malloc( sizeof( ensinfo_t ) );
vlistptr->vars[varID].ensdata->ens_index = ensID;
vlistptr->vars[varID].ensdata->ens_count = ensCount;
vlistptr->vars[varID].ensdata->forecast_init_type = forecast_type;
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
}
int vlistInqVarEnsemble( int vlistID, int varID, int *ensID, int *ensCount, int *forecast_type )
{
int status = 0;
vlist_t *vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(__func__, vlistID, varID);
if ( vlistptr->vars[varID].ensdata )
{
*ensID = vlistptr->vars[varID].ensdata->ens_index;
*ensCount = vlistptr->vars[varID].ensdata->ens_count;
*forecast_type = vlistptr->vars[varID].ensdata->forecast_init_type;
status = 1;
}
return status;
}
/* vlistDefVarIntKey: Set an arbitrary keyword/integer value pair for GRIB API */
void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value)
{
......
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