Commit 82710a33 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge branch 'develop' of git.mpimet.mpg.de:libcdi into develop

parents 463c7add fdf9849f
2019-02-20 Uwe Schulzweida
* uvRelativeToGrid: changed flag from grid to variable
2019-02-15 Uwe Schulzweida
* cdfScanVarAttr: ignore attribute valid_range if min > max (bug fix)
......
......@@ -7,7 +7,7 @@
AC_PREREQ([2.69])
LT_PREREQ([2.4.6])
AC_INIT([cdi], [1.9.6], [http://mpimet.mpg.de/cdi])
AC_INIT([cdi], [1.9.7rc1], [http://mpimet.mpg.de/cdi])
AC_DEFINE_UNQUOTED(CDI, ["$PACKAGE_VERSION"], [CDI version])
......
......@@ -802,6 +802,7 @@ size_t gridInqYCvals(int gridID, char *ycvals[]);
#define CDI_KEY_GRIB2LOCALSECTIONNUMBER 818 // GRIB2 grib2LocalSectionNumber
#define CDI_KEY_SECTION2PADDINGLENGTH 819 // GRIB2 length of section2Padding
#define CDI_KEY_SECTION2PADDING 820 // GRIB2 section2Padding
#define CDI_KEY_UVRELATIVETOGRID 821 // GRIB uvRelativeToGrid
// cdiDefKeyInt: Define an integer value from a key of a CDI variable
int cdiDefKeyInt(int cdiID, int varID, int key, int value);
......@@ -1001,9 +1002,6 @@ void gridChangeType(int gridID, int gridtype);
void gridDefComplexPacking(int gridID, int lpack);
int gridInqComplexPacking(int gridID);
void gridDefUvRelativeToGrid(int gridID, int uvRelativeToGrid);
int gridInqUvRelativeToGrid(int gridID);
void gridDefScanningMode(int gridID, int mode);
int gridInqScanningMode(int gridID);
......
......@@ -4,7 +4,7 @@
!
! Author:
! -------
! Uwe Schulzweida, MPI-MET, Hamburg, January 2019
! Uwe Schulzweida, MPI-MET, Hamburg, February 2019
!
INTEGER CDI_MAX_NAME
......@@ -1568,6 +1568,8 @@
PARAMETER (CDI_KEY_SECTION2PADDINGLENGTH = 819)
INTEGER CDI_KEY_SECTION2PADDING
PARAMETER (CDI_KEY_SECTION2PADDING = 820)
INTEGER CDI_KEY_UVRELATIVETOGRID
PARAMETER (CDI_KEY_UVRELATIVETOGRID = 821)
INTEGER cdiDefKeyInt
! (INTEGER cdiID,
! INTEGER varID,
......@@ -2018,15 +2020,6 @@
! (INTEGER gridID)
EXTERNAL gridInqComplexPacking
! gridDefUvRelativeToGrid
! (INTEGER gridID,
! INTEGER uvRelativeToGrid)
EXTERNAL gridDefUvRelativeToGrid
INTEGER gridInqUvRelativeToGrid
! (INTEGER gridID)
EXTERNAL gridInqUvRelativeToGrid
! gridDefScanningMode
! (INTEGER gridID,
! INTEGER mode)
......
......@@ -620,8 +620,6 @@ FCALLSCSUB2 (gridInqRowlon, GRIDINQROWLON, gridinqrowlon, INT, INTV)
FCALLSCSUB2 (gridChangeType, GRIDCHANGETYPE, gridchangetype, INT, INT)
FCALLSCSUB2 (gridDefComplexPacking, GRIDDEFCOMPLEXPACKING, griddefcomplexpacking, INT, INT)
FCALLSCFUN1 (INT, gridInqComplexPacking, GRIDINQCOMPLEXPACKING, gridinqcomplexpacking, INT)
FCALLSCSUB2 (gridDefUvRelativeToGrid, GRIDDEFUVRELATIVETOGRID, griddefuvrelativetogrid, INT, INT)
FCALLSCFUN1 (INT, gridInqUvRelativeToGrid, GRIDINQUVRELATIVETOGRID, gridinquvrelativetogrid, INT)
FCALLSCSUB2 (gridDefScanningMode, GRIDDEFSCANNINGMODE, griddefscanningmode, INT, INT)
FCALLSCFUN1 (INT, gridInqScanningMode, GRIDINQSCANNINGMODE, gridinqscanningmode, INT)
......
......@@ -41,7 +41,7 @@ char *strdup(const char *s);
char *strToLower(char *str);
bool strStartsWith(const char *vstr, const char *cstr);
inline bool
static inline bool
strIsEqual(const char *x, const char *y)
{
return (*x == *y) && strcmp(x, y) == 0;
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#ifdef HAVE_LIBGRIB_API
......@@ -764,8 +764,9 @@ void gribapiGetGridGeneric(grib_handle *gh, grid_t *grid, size_t numberOfPoints)
}
//TODO: Simplify by use of the convenience functions (gribGetLong(), gribGetLongDefault(), etc.).
void gribapiGetGrid(grib_handle *gh, grid_t *grid)
bool gribapiGetGrid(grib_handle *gh, grid_t *grid)
{
bool uvRelativeToGrid = false;
const long editionNumber = gribEditionNumber(gh);
int gridtype = gribapiGetGridType(gh);
int projtype = (gridtype == GRID_PROJECTION && gribapiGetIsRotated(gh)) ? CDI_PROJ_RLL : CDI_UNDEFID;
......@@ -833,7 +834,7 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
long temp;
GRIB_CHECK(grib_get_long(gh, "uvRelativeToGrid", &temp), 0);
assert(temp == 0 || temp == 1);
grid->uvRelativeToGrid = (bool)temp;
uvRelativeToGrid = (bool)temp;
}
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_LONLAT || gridtype == GRID_PROJECTION )
......@@ -863,14 +864,16 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
Message("(param,ltype,level) = (%3d,%3d,%4d); Scanning mode = %02d -> bits:(%1d.%1d.%1d)*32; uvRelativeToGrid = %02d",\
(int)paramId, (int)levelTypeId, (int)levelId,
grid->scanningMode,grid->jPointsAreConsecutive,
grid->jScansPositively,grid->iScansNegatively,
grid->uvRelativeToGrid);
grid->jScansPositively, grid->iScansNegatively,
uvRelativeToGrid);
}
#endif //HIRLAM_EXTENSIONS
}
grid->type = gridtype;
grid->projtype = projtype;
return uvRelativeToGrid;
}
#endif
/*
......
......@@ -31,7 +31,7 @@ int gribapiGetTsteptype(grib_handle *gh);
int gribGetDatatype(grib_handle* gribHandle);
int gribapiGetParam(grib_handle *gh);
int gribapiGetGridType(grib_handle *gh);
void gribapiGetGrid(grib_handle *gh, grid_t *grid);
bool gribapiGetGrid(grib_handle *gh, grid_t *grid);
size_t gribapiGetGridsize(grib_handle *gh);
......
......@@ -180,7 +180,6 @@ void grid_init(grid_t *gridptr)
gridptr->vtable = &cdiGridVtable;
gridptr->atts.nalloc = MAX_ATTRIBUTES;
gridptr->atts.nelems = 0;
gridptr->uvRelativeToGrid = 0; // Some models deliver wind U,V relative to the grid-cell
gridptr->iScansNegatively = 0;
gridptr->jScansPositively = 1;
gridptr->jPointsAreConsecutive = 0;
......@@ -2429,14 +2428,14 @@ bool gridCompare(int gridID, const grid_t *grid, bool coord_compare)
}
}
if ( (grid->scanningMode != gridInqScanningMode(gridID)) || (grid->uvRelativeToGrid != gridInqUvRelativeToGrid(gridID)) )
if ( (grid->scanningMode != gridInqScanningMode(gridID)) )
{
// often grid definition may differ in UV-relativeToGrid
differ = 1;
#ifdef HIRLAM_EXTENSIONS
if ( cdiDebugExt>=200 )
printf("gridCompare(gridID=%d): Differs: grid.scanningMode [%d] != gridInqScanningMode(gridID) [%d] or grid.uvRelativeToGrid [%d] != gridInqUvRelativeToGrid(gridID) [%d]\n",
gridID, grid->scanningMode, gridInqScanningMode(gridID), grid->uvRelativeToGrid, gridInqUvRelativeToGrid(gridID) );
printf("gridCompare(gridID=%d): Differs: grid.scanningMode [%d] != gridInqScanningMode(gridID) [%d]\n",
gridID, grid->scanningMode, gridInqScanningMode(gridID));
#endif // HIRLAM_EXTENSIONS
}
......@@ -2490,7 +2489,6 @@ int gridCompareP(void *gridptr1, void *gridptr2)
if ( IS_NOT_EQUAL(g1->y.last , g2->y.last) ) return differ;
if ( IS_NOT_EQUAL(g1->x.inc , g2->x.inc) ) return differ;
if ( IS_NOT_EQUAL(g1->y.inc , g2->y.inc) ) return differ;
if ( IS_NOT_EQUAL(g1->uvRelativeToGrid , g2->uvRelativeToGrid) ) return differ;
if ( IS_NOT_EQUAL(g1->scanningMode , g2->scanningMode) ) return differ;
const double *restrict g1_xvals = g1->vtable->inqXValsPtr(g1),
......@@ -2808,7 +2806,6 @@ int gridGenerate(const grid_t *grid)
gridDefArea(gridID, grid->area);
gridptr->number = grid->number;
gridptr->position = grid->position;
gridptr->uvRelativeToGrid = grid->uvRelativeToGrid;
gridptr->scanningMode = grid->scanningMode;
gridptr->iScansNegatively = grid->iScansNegatively;
gridptr->jScansPositively = grid->jScansPositively;
......@@ -4382,25 +4379,6 @@ void gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE])
}
void gridDefUvRelativeToGrid(int gridID, int uvRelativeToGrid)
{
grid_t *gridptr = grid_to_pointer(gridID);
if ( gridptr->uvRelativeToGrid != uvRelativeToGrid )
{
gridMark4Update(gridID);
gridptr->uvRelativeToGrid = (bool)uvRelativeToGrid;
}
}
int gridInqUvRelativeToGrid(int gridID)
{
grid_t *gridptr = grid_to_pointer(gridID);
return gridptr->uvRelativeToGrid;
}
void gridDefScanningMode(int gridID, int mode)
{
grid_t *gridptr = grid_to_pointer(gridID);
......@@ -4461,7 +4439,6 @@ enum {
GRID_PACK_INT_IDX_MEMBERMASK,
GRID_PACK_INT_IDX_XTSTDNNAME,
GRID_PACK_INT_IDX_YTSTDNNAME,
GRID_PACK_INT_IDX_UVRELATIVETOGRID,
GRID_PACK_INT_IDX_ISCANSNEGATIVELY,
GRID_PACK_INT_IDX_JSCANSPOSITIVELY,
GRID_PACK_INT_IDX_JPOINTSARECONSECUTIVE,
......@@ -4669,7 +4646,6 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
xystdname_tab[intBuffer[GRID_PACK_INT_IDX_XTSTDNNAME]][0];
gridP->y.stdname =
xystdname_tab[intBuffer[GRID_PACK_INT_IDX_YTSTDNNAME]][1];
gridP->uvRelativeToGrid = intBuffer[GRID_PACK_INT_IDX_UVRELATIVETOGRID];
gridP->iScansNegatively = (bool)intBuffer[GRID_PACK_INT_IDX_ISCANSNEGATIVELY];
gridP->jScansPositively = (bool)intBuffer[GRID_PACK_INT_IDX_JSCANSPOSITIVELY];
gridP->jPointsAreConsecutive = (bool)intBuffer[GRID_PACK_INT_IDX_JPOINTSARECONSECUTIVE];
......@@ -4858,7 +4834,6 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
(int)((const char (*)[2][24])gridP->y.stdname
- (const char (*)[2][24])xystdname_tab[0][1]);
intBuffer[GRID_PACK_INT_IDX_UVRELATIVETOGRID] = gridP->uvRelativeToGrid;
intBuffer[GRID_PACK_INT_IDX_ISCANSNEGATIVELY] = gridP->iScansNegatively;
intBuffer[GRID_PACK_INT_IDX_JSCANSPOSITIVELY] = gridP->jScansPositively;
intBuffer[GRID_PACK_INT_IDX_JPOINTSARECONSECUTIVE] = gridP->jPointsAreConsecutive;
......
......@@ -108,7 +108,6 @@ struct grid_t {
*/
bool lcomplex;
bool hasdims;
bool uvRelativeToGrid; /* Some models deliver wind U,V relative to the grid-cell */
struct gridaxis_t x;
struct gridaxis_t y;
const struct gridVirtTable *vtable;
......
......@@ -240,8 +240,9 @@ int cgribexGetTsteptype(int timerange)
}
static
void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, int iret)
bool cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, int iret)
{
bool uvRelativeToGrid = false;
bool compyinc = true;
int gridtype = cgribexGetGridType(isec2);
int projtype = (gridtype == GRID_PROJECTION && cgribexGetIsRotated(isec2)) ? CDI_PROJ_RLL : CDI_UNDEFID;
......@@ -268,8 +269,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, i
if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN || projtype == CDI_PROJ_RLL )
{
const bool ijDirectionIncrementGiven = gribbyte_get_bit(ISEC2_ResFlag, 1);
const bool uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
if ( uvRelativeToGrid ) grid->uvRelativeToGrid = 1;
uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
const size_t nvalues = (size_t) ISEC4_NumValues;
const size_t nlon = (size_t) ISEC2_NumLon;
......@@ -352,8 +352,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, i
else if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
const bool ijDirectionIncrementGiven = gribbyte_get_bit(ISEC2_ResFlag, 1);
const bool uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
if ( uvRelativeToGrid ) grid->uvRelativeToGrid = 1;
uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
grid->np = ISEC2_NumPar;
grid->size = (size_t)ISEC4_NumValues;
grid->rowlon = ISEC2_RowLonPtr;
......@@ -394,8 +393,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, i
}
else if ( projtype == CDI_PROJ_LCC )
{
const bool uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
if ( uvRelativeToGrid ) grid->uvRelativeToGrid = 1;
uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
const size_t nvalues = (size_t) ISEC4_NumValues;
const size_t nlon = (size_t) ISEC2_NumLon;
......@@ -443,6 +441,8 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid, i
grid->type = gridtype;
grid->projtype = projtype;
return uvRelativeToGrid;
}
static
......@@ -466,6 +466,8 @@ void cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, si
double *fsec3 = cgribexp->fsec3;
int datatype = (ISEC4_NumBits > 0 && ISEC4_NumBits <= 32) ? ISEC4_NumBits : CDI_DATATYPE_PACK;
if ( datatype > 32 ) datatype = CDI_DATATYPE_PACK32;
if ( datatype < 0 ) datatype = CDI_DATATYPE_PACK;
int varID;
int levelID = 0;
......@@ -492,7 +494,7 @@ void cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, si
record->tsteptype = (short)tsteptype;
grid_t *gridptr = (grid_t*) Malloc(sizeof(*gridptr));
cgribexGetGrid(streamptr, isec2, isec4, gridptr, iret);
const bool uvRelativeToGrid = cgribexGetGrid(streamptr, isec2, isec4, gridptr, iret);
struct addIfNewRes gridAdded = cdiVlistAddGridIfNew(vlistID, gridptr, 0);
int gridID = gridAdded.Id;
......@@ -514,9 +516,9 @@ void cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, si
}
else if ( gridptr->projtype == CDI_PROJ_LCC )
{
double a = 6367470., rf = 0;
bool earthIsOblate = gribbyte_get_bit(ISEC2_ResFlag, 2);
if ( earthIsOblate ) { a = 6378160.; rf = 297.0; }
const bool earthIsOblate = gribbyte_get_bit(ISEC2_ResFlag, 2);
const double a = earthIsOblate ? 6378160. : 6367470.;
const double rf = earthIsOblate ? 297.0 : 0;
const double xval_0 = ISEC2_FirstLon * 0.001;
const double yval_0 = ISEC2_FirstLat * 0.001;
const double lon_0 = ISEC2_Lambert_Lov * 0.001;
......@@ -552,18 +554,17 @@ void cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, si
const bool lbounds = cgribexGetZaxisHasBounds(leveltype);
if ( datatype > 32 ) datatype = CDI_DATATYPE_PACK32;
if ( datatype < 0 ) datatype = CDI_DATATYPE_PACK;
varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, 0, 0,
datatype, &varID, &levelID, tsteptype, numavg, leveltype, -1,
NULL, NULL, NULL, NULL, NULL, NULL, 0);
record->varID = (short)varID;
record->varID = (short)varID;
record->levelID = (short)levelID;
varDefCompType(varID, comptype);
if ( uvRelativeToGrid ) varDefKeyInt(varID, CDI_KEY_UVRELATIVETOGRID, 1);
if ( ISEC1_LocalFLag )
{
if ( ISEC1_CenterID == 78 && isec1[36] == 253 ) // DWD local extension
......@@ -584,9 +585,9 @@ void cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, si
if ( varInqInst(varID) == CDI_UNDEFID )
{
const int center = ISEC1_CenterID;
const int center = ISEC1_CenterID;
const int subcenter = ISEC1_SubCenterID;
int instID = institutInq(center, subcenter, NULL, NULL);
int instID = institutInq(center, subcenter, NULL, NULL);
if ( instID == CDI_UNDEFID )
instID = institutDef(center, subcenter, NULL, NULL);
varDefInst(varID, instID);
......@@ -1587,7 +1588,7 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg,
}
static
void cgribexDefGridRegular(int *isec2, double *fsec2, int gridID, int gridtype, bool gridIsRotated, bool gridIsCurvilinear)
void cgribexDefGridRegular(int *isec2, double *fsec2, int gridID, int gridtype, bool gridIsRotated, bool gridIsCurvilinear, int uvRelativeToGrid)
{
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_GridType = GRIB1_GTYPE_GAUSSIAN;
......@@ -1662,8 +1663,8 @@ void cgribexDefGridRegular(int *isec2, double *fsec2, int gridID, int gridtype,
if ( ISEC2_LonIncr == 0 && ISEC2_LatIncr != 0 ) ISEC2_LonIncr = ISEC2_LatIncr;
ISEC2_ResFlag = 0;
if ( ISEC2_LatIncr && ISEC2_LonIncr ) gribbyte_set_bit(&ISEC2_ResFlag, 1);
if ( gridInqUvRelativeToGrid(gridID) ) gribbyte_set_bit(&ISEC2_ResFlag, 5);
if ( ISEC2_LatIncr && ISEC2_LonIncr ) gribbyte_set_bit(&ISEC2_ResFlag, 1);
if ( uvRelativeToGrid > 0 ) gribbyte_set_bit(&ISEC2_ResFlag, 5);
if ( gridIsRotated )
{
......@@ -1682,7 +1683,7 @@ void cgribexDefGridRegular(int *isec2, double *fsec2, int gridID, int gridtype,
}
static
void cgribexDefGridLambert(int *isec2, int gridID)
void cgribexDefGridLambert(int *isec2, int gridID, int uvRelativeToGrid)
{
const int xsize = (int)gridInqXsize(gridID);
const int ysize = (int)gridInqYsize(gridID);
......@@ -1714,8 +1715,8 @@ void cgribexDefGridLambert(int *isec2, int gridID)
const bool earthIsOblate = (IS_EQUAL(a, 6378160.) && IS_EQUAL(rf, 297.));
ISEC2_ResFlag = 0;
if ( ISEC2_Lambert_dx && ISEC2_Lambert_dy ) gribbyte_set_bit(&ISEC2_ResFlag, 1);
if ( earthIsOblate ) gribbyte_set_bit(&ISEC2_ResFlag, 2);
if ( gridInqUvRelativeToGrid(gridID) ) gribbyte_set_bit(&ISEC2_ResFlag, 5);
if ( earthIsOblate ) gribbyte_set_bit(&ISEC2_ResFlag, 2);
if ( uvRelativeToGrid > 0 ) gribbyte_set_bit(&ISEC2_ResFlag, 5);
ISEC2_ScanFlag = 0;
gribbyte_set_bit(&ISEC2_ScanFlag, 2); // South -> North
......@@ -1764,7 +1765,7 @@ void cgribexDefGridGME(int *isec2, int gridID)
}
static
void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridID)
void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridID, int uvRelativeToGrid)
{
memset(isec2, 0, 16*sizeof(int));
ISEC1_Sec2Or3Flag = 128;
......@@ -1784,12 +1785,12 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
case GRID_GAUSSIAN_REDUCED:
case GRID_TRAJECTORY:
{
cgribexDefGridRegular(isec2, fsec2, gridID, gridtype, gridIsRotated, gridIsCurvilinear);
cgribexDefGridRegular(isec2, fsec2, gridID, gridtype, gridIsRotated, gridIsCurvilinear, uvRelativeToGrid);
break;
}
case CDI_PROJ_LCC:
{
cgribexDefGridLambert(isec2, gridID);
cgribexDefGridLambert(isec2, gridID, uvRelativeToGrid);
break;
}
case GRID_SPECTRAL:
......@@ -1817,17 +1818,6 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
break;
}
}
if ( cdiGribChangeModeUvRelativeToGrid.active )
{
// this will overrule/change the UvRelativeToGrid flag;
// typically when the wind is rotated with respect to north pole
const bool uvRelativeToGrid = gribbyte_get_bit(ISEC2_ResFlag, 5);
if ( uvRelativeToGrid && !cdiGribChangeModeUvRelativeToGrid.mode )
gribbyte_clear_bit(&ISEC2_ResFlag, 5);
else if ( !uvRelativeToGrid && cdiGribChangeModeUvRelativeToGrid.mode )
gribbyte_set_bit(&ISEC2_ResFlag, 5);
}
}
static
......@@ -2074,9 +2064,12 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
const int datatype = vlistInqVarDatatype(vlistID, varID);
int uvRelativeToGrid = -1;
cdiInqKeyInt(vlistID, varID, CDI_KEY_UVRELATIVETOGRID, &uvRelativeToGrid);
cgribexDefParam(isec1, param);
cgribexDefTime(isec1, vdate, vtime, tsteptype, numavg, vlistInqTaxis(vlistID));
cgribexDefGrid(isec1, isec2, fsec2, isec4, gridID);
cgribexDefGrid(isec1, isec2, fsec2, isec4, gridID, uvRelativeToGrid);
cgribexDefLevel(isec1, isec2, fsec2, zaxisID, levelID);
cgribexDefEnsembleVar(isec1, vlistID, varID);
......
......@@ -64,15 +64,6 @@ void streamGrbChangeParameterIdentification(int code, int ltype, int lev)
cdiGribChangeParameterID.lev = lev;
}
struct cdiGribModeChange cdiGribChangeModeUvRelativeToGrid;
// Used only for CDO module WindTrans
void streamGrbChangeModeUvRelativeToGrid(int mode)
{
cdiGribChangeModeUvRelativeToGrid.active = true;
cdiGribChangeModeUvRelativeToGrid.mode = (mode > 0);
}
struct cdiGribScanModeChange cdiGribDataScanningMode;
void streamGrbDefDataScanningMode(int scanmode)
......
......@@ -39,12 +39,6 @@ struct cdiGribParamChange
bool active;
};
struct cdiGribModeChange
{
bool mode;
bool active;
};
struct cdiGribScanModeChange
{
int value;
......@@ -52,12 +46,10 @@ struct cdiGribScanModeChange
};
extern struct cdiGribParamChange cdiGribChangeParameterID;
extern struct cdiGribModeChange cdiGribChangeModeUvRelativeToGrid;
extern struct cdiGribScanModeChange cdiGribDataScanningMode;
// Used in CDO
void streamGrbChangeParameterIdentification(int code, int ltype, int lev);
void streamGrbChangeModeUvRelativeToGrid(int mode);
void streamGrbDefDataScanningMode(int scanmode);
int streamGrbInqDataScanningMode(void);
......
......@@ -595,12 +595,12 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
{
char stdname[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME];
int vlistID = streamptr->vlistID;
int tsID = streamptr->curTsID;
int recID = recordNewEntry(streamptr, tsID);
const int vlistID = streamptr->vlistID;
const int tsID = streamptr->curTsID;
const int recID = recordNewEntry(streamptr, tsID);
record_t *record = &streamptr->tsteps[tsID].records[recID];
int tsteptype = gribapiGetTsteptype(gh);
const int tsteptype = gribapiGetTsteptype(gh);
// numavg = ISEC1_AvgNum;
int numavg = 0;
......@@ -622,16 +622,16 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
record->varname[sizeof(record->varname) - 1] = 0;
grid_t *grid = (grid_t *)Malloc(sizeof(*grid));
gribapiGetGrid(gh, grid);
const bool uvRelativeToGrid = gribapiGetGrid(gh, grid);
struct addIfNewRes gridAdded = cdiVlistAddGridIfNew(vlistID, grid, 0);
int gridID = gridAdded.Id;
const int gridID = gridAdded.Id;
if ( !gridAdded.isNew ) Free(grid);
else if ( grid->projtype == CDI_PROJ_RLL ) gribapiDefProjRLL(gh, gridID);
else if ( grid->projtype == CDI_PROJ_LCC ) gribapiDefProjLCC(gh, gridID);
else if ( grid->projtype == CDI_PROJ_STERE ) gribapiDefProjSTERE(gh, gridID);
int zaxistype = gribapiGetZaxisType(gribEditionNumber(gh), leveltype1);
const int zaxistype = gribapiGetZaxisType(gribEditionNumber(gh), leveltype1);
switch (zaxistype)
{
......@@ -641,7 +641,7 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
long lpar;
GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0);
/* FIXME: assert(lpar >= 0) */
size_t vctsize = (size_t)lpar;
const size_t vctsize = (size_t)lpar;
if ( vctsize > 0 )
{
double *vctptr = (double *) Malloc(vctsize*sizeof(double));
......@@ -697,11 +697,13 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
datatype, &varID, &levelID, tsteptype, numavg, leveltype1, leveltype2,
varname, stdname, longname, units, tiles, &tile_index, perturbationNumber);
record->varID = (short)varID;
record->varID = (short)varID;
record->levelID = (short)levelID;
varDefCompType(varID, comptype);
if ( uvRelativeToGrid ) varDefKeyInt(varID, CDI_KEY_UVRELATIVETOGRID, 1);
gribapiGetKeys(gh, varID);
if (lread_additional_keys)
......@@ -1883,7 +1885,7 @@ void gribapiDefTime(int editionNumber, int productDefinitionTemplate, int typeOf
}
static
void gribapiDefGridRegular(grib_handle *gh, int gridID, int gridtype, bool gridIsRotated, bool gridIsCurvilinear)
void gribapiDefGridRegular(grib_handle *gh, int gridID, int gridtype, bool gridIsRotated, bool gridIsCurvilinear, int uvRelativeToGrid)
{
const char *mesg;
size_t len;
......@@ -1999,12 +2001,11 @@ void gribapiDefGridRegular(grib_handle *gh, int gridID, int gridtype, bool gridI
GRIB_CHECK(my_grib_set_double(gh, "angleOfRotation", angle), 0);
}
long uvRelativeToGrid = gridInqUvRelativeToGrid(gridID);
if ( uvRelativeToGrid ) GRIB_CHECK(my_grib_set_long(gh, "uvRelativeToGrid", uvRelativeToGrid), 0);
if ( uvRelativeToGrid >= 0 ) GRIB_CHECK(my_grib_set_long(gh, "uvRelativeToGrid", uvRelativeToGrid), 0);
}
static
void gribapiDefGridLCC(grib_handle *gh, int editionNumber, int gridID)
void gribapiDefGridLCC(grib_handle *gh, int editionNumber, int gridID, int uvRelativeToGrid)
{
long xsize = (long) gridInqXsize(gridID);
long ysize = (long) gridInqYsize(gridID);
......@@ -2036,8 +2037,7 @@ void gribapiDefGridLCC(grib_handle *gh, int editionNumber, int gridID)
GRIB_CHECK(my_grib_set_double(gh, "Latin2InDegrees", lat_2), 0);
GRIB_CHECK(my_grib_set_long(gh, "projectionCentreFlag", projflag), 0);
long uvRelativeToGrid = gridInqUvRelativeToGrid(gridID);
if ( uvRelativeToGrid ) GRIB_CHECK(my_grib_set_long(gh, "uvRelativeToGrid", uvRelativeToGrid), 0);
if ( uvRelativeToGrid >= 0 ) GRIB_CHECK(my_grib_set_long(gh, "uvRelativeToGrid", uvRelativeToGrid), 0);
long earthIsOblate = (IS_EQUAL(a, 6378160.) && IS_EQUAL(rf, 297.));
if ( earthIsOblate ) GRIB_CHECK(my_grib_set_long(gh, "earthIsOblate", earthIsOblate), 0);
......@@ -2200,7 +2200,7 @@ void gribapiDefPackingType(grib_handle *gh, bool lieee, bool lspectral, bool lco
}
static
void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, int datatype)
void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, int datatype, int uvRelativeToGrid)
{
// bitsPerValue have to be defined first (complex packing)
GRIB_CHECK(my_grib_set_long(gh, "bitsPerValue", (long)grbBitsPerValue(datatype)), 0);
......@@ -2237,12 +2237,12 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
case GRID_GAUSSIAN_REDUCED:
case GRID_TRAJECTORY:
{
gribapiDefGridRegular(gh, gridID, gridtype, gridIsRotated, gridIsCurvilinear);
gribapiDefGridRegular(gh, gridID, gridtype, gridIsRotated, gridIsCurvilinear, uvRelativeToGrid);
break;
}
case CDI_PROJ_LCC:
{
gribapiDefGridLCC(gh, editionNumber, gridID);
gribapiDefGridLCC(gh, editionNumber, gridID, uvRelativeToGrid);
break;
}
case CDI_PROJ_STERE:
......@@ -2607,7 +2607,7 @@ int gribapiGetScanningMode(grib_handle *gh)
void gribapiSetScanningMode(grib_handle *gh, int scanningMode)
{
// 127: reserved for testing; generated test data will be in 64 scanning mode