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

stream_gribapi: changed units for level type GRIB2_LTYPE_LANDDEPTH to m (internally mm)

parent e4604a74
...@@ -3,9 +3,13 @@ ...@@ -3,9 +3,13 @@
* Version 1.6.0 released * Version 1.6.0 released
* using CGRIBEX library version 1.6.0 * using CGRIBEX library version 1.6.0
2013-03-12 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* stream_gribapi: changed units for level type GRIB2_LTYPE_LANDDEPTH to m (internally mm) [Bug #3287]
2013-03-11 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> 2013-03-11 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* stream_gribapi: added support for local table shortName.def * stream_gribapi: added support for local table shortName.def (Bug #3343)
2013-03-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de> 2013-03-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......
...@@ -408,7 +408,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d ...@@ -408,7 +408,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d
if ( datatype > 32 ) datatype = DATATYPE_PACK32; if ( datatype > 32 ) datatype = DATATYPE_PACK32;
if ( datatype < 0 ) datatype = DATATYPE_PACK; if ( datatype < 0 ) datatype = DATATYPE_PACK;
varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, 0,
datatype, &varID, &levelID, tsteptype, numavg, ISEC1_LevelType, NULL, NULL, NULL); datatype, &varID, &levelID, tsteptype, numavg, ISEC1_LevelType, NULL, NULL, NULL);
(*record).varID = varID; (*record).varID = varID;
......
...@@ -275,7 +275,7 @@ void extAddRecord(stream_t *streamptr, int param, int level, int xysize, ...@@ -275,7 +275,7 @@ void extAddRecord(stream_t *streamptr, int param, int level, int xysize,
*/ */
leveltype = ZAXIS_GENERIC; leveltype = ZAXIS_GENERIC;
varAddRecord(recID, param, gridID, leveltype, 0, level, 0, varAddRecord(recID, param, gridID, leveltype, 0, level, 0, 0,
extInqDatatype(prec, number), &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); extInqDatatype(prec, number), &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID; (*record).varID = varID;
......
...@@ -689,7 +689,7 @@ void grib1GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i ...@@ -689,7 +689,7 @@ void grib1GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i
} }
static static
void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, int *level2) void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, int *level2, int *level_sf)
{ {
int status; int status;
int leveltype2 = -1; int leveltype2 = -1;
...@@ -701,6 +701,7 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i ...@@ -701,6 +701,7 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i
*lbounds = 0; *lbounds = 0;
*level1 = 0; *level1 = 0;
*level2 = 0; *level2 = 0;
*level_sf = 0;
status = grib_get_long(gh, "typeOfFirstFixedSurface", &lpar); status = grib_get_long(gh, "typeOfFirstFixedSurface", &lpar);
if ( status == 0 ) if ( status == 0 )
...@@ -718,9 +719,11 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i ...@@ -718,9 +719,11 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i
{ {
GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0); GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0);
GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0);
if ( factor == 0 ) dlevel *= 100; // m to cm if ( factor == 0 ) dlevel *= 1000; // m to mm
else if ( factor == 1 ) dlevel *= 10; // dm to cm else if ( factor == 1 ) dlevel *= 100; // dm to mm
else if ( factor == 3 ) dlevel *= 0.1; // mm to cm else if ( factor == 2 ) dlevel *= 10; // cm to mm
else if ( factor == 3 ) dlevel *= 1; // mm to mm
*level_sf = 77;
} }
else else
{ {
...@@ -739,16 +742,19 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i ...@@ -739,16 +742,19 @@ void grib2GetLevel(grib_handle *gh, int *leveltype, int *lbounds, int *level1, i
{ {
GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0); GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0);
GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0);
if ( factor == 0 ) dlevel *= 100; // m to cm if ( factor == 0 ) dlevel *= 1000; // m to mm
else if ( factor == 1 ) dlevel *= 10; // dm to cm else if ( factor == 1 ) dlevel *= 100; // dm to mm
else if ( factor == 3 ) dlevel *= 0.1; // mm to cm else if ( factor == 2 ) dlevel *= 10; // cm to mm
else if ( factor == 3 ) dlevel *= 1; // mm to mm
*level1 = (int) dlevel; *level1 = (int) dlevel;
GRIB_CHECK(grib_get_long(gh, "scaleFactorOfSecondFixedSurface", &factor), 0); GRIB_CHECK(grib_get_long(gh, "scaleFactorOfSecondFixedSurface", &factor), 0);
GRIB_CHECK(grib_get_double(gh, "scaledValueOfSecondFixedSurface", &dlevel), 0); GRIB_CHECK(grib_get_double(gh, "scaledValueOfSecondFixedSurface", &dlevel), 0);
if ( factor == 0 ) dlevel *= 100; // m to cm if ( factor == 0 ) dlevel *= 1000; // m to mm
else if ( factor == 1 ) dlevel *= 10; // dm to cm else if ( factor == 1 ) dlevel *= 100; // dm to mm
else if ( factor == 3 ) dlevel *= 0.1; // mm to cm else if ( factor == 2 ) dlevel *= 10; // cm to mm
else if ( factor == 3 ) dlevel *= 1; // mm to mm
*level2 = (int) dlevel; *level2 = (int) dlevel;
*level_sf = 77;
} }
else else
{ {
...@@ -773,21 +779,19 @@ void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t len ...@@ -773,21 +779,19 @@ void gribapiGetString(grib_handle *gh, const char *key, char *string, size_t len
static static
void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
long recsize, off_t position, int datatype, int comptype, size_t len, const char *varname) long recsize, off_t position, int datatype, int comptype, size_t len, const char *varname,
int leveltype, int lbounds, int level1, int level2, int level_sf)
{ {
long editionNumber; long editionNumber;
int zaxistype; int zaxistype;
int gridID = CDI_UNDEFID, varID; int gridID = CDI_UNDEFID, varID;
int levelID = 0; int levelID = 0;
int tsID, recID; int tsID, recID;
int level1 = 0, level2 = 0;
int numavg; int numavg;
int tsteptype; int tsteptype;
int lbounds = 0;
record_t *record; record_t *record;
grid_t grid; grid_t grid;
int vlistID; int vlistID;
int leveltype;
long lpar; long lpar;
int status; int status;
char longname[256], units[256]; char longname[256], units[256];
...@@ -805,11 +809,6 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -805,11 +809,6 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0); GRIB_CHECK(grib_get_long(gh, "editionNumber", &editionNumber), 0);
if ( editionNumber <= 1 )
grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2);
else
grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2);
// fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, leveltype); // fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, leveltype);
(*record).size = recsize; (*record).size = recsize;
...@@ -886,7 +885,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -886,7 +885,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
} }
// fprintf(stderr, "param %d name %s %s %s\n", param, name, longname, units); // fprintf(stderr, "param %d name %s %s %s\n", param, name, longname, units);
varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, varAddRecord(recID, param, gridID, zaxistype, lbounds, level1, level2, level_sf,
datatype, &varID, &levelID, tsteptype, numavg, leveltype, datatype, &varID, &levelID, tsteptype, numavg, leveltype,
varname, longname, units); varname, longname, units);
...@@ -1062,6 +1061,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1062,6 +1061,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
int bitsPerValue; int bitsPerValue;
int lieee = FALSE; int lieee = FALSE;
int lbounds; int lbounds;
int level_sf;
char paramstr[32]; char paramstr[32];
char varname[256]; char varname[256];
...@@ -1129,6 +1129,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1129,6 +1129,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
param = cdiEncodeParam(rcode, rtabnum, 255); param = cdiEncodeParam(rcode, rtabnum, 255);
grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2);
level_sf = 0;
} }
else else
{ {
...@@ -1145,7 +1146,7 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1145,7 +1146,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
param = gribapiGetParam(gh); param = gribapiGetParam(gh);
grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf);
} }
cdiParamToString(param, paramstr, sizeof(paramstr)); cdiParamToString(param, paramstr, sizeof(paramstr));
...@@ -1240,7 +1241,8 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -1240,7 +1241,8 @@ int gribapiScanTimestep1(stream_t * streamptr)
if ( CDI_Debug ) if ( CDI_Debug )
Message("%4d %8d %4d %8d %8d %6d", nrecs, (int)recpos, param, level1, vdate, vtime); Message("%4d %8d %4d %8d %8d %6d", nrecs, (int)recpos, param, level1, vdate, vtime);
gribapiAddRecord(streamptr, param, gh, recsize, recpos, datatype, comptype, len, varname); gribapiAddRecord(streamptr, param, gh, recsize, recpos, datatype, comptype, len, varname,
leveltype, lbounds, level1, level2, level_sf);
grib_handle_delete(gh); grib_handle_delete(gh);
gh = NULL; gh = NULL;
...@@ -1349,6 +1351,8 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1349,6 +1351,8 @@ int gribapiScanTimestep2(stream_t * streamptr)
long editionNumber; long editionNumber;
long lpar; long lpar;
int lbounds; int lbounds;
int level_sf;
char paramstr[32];
char varname[256]; char varname[256];
streamptr->curTsID = 1; streamptr->curTsID = 1;
...@@ -1430,14 +1434,17 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1430,14 +1434,17 @@ int gribapiScanTimestep2(stream_t * streamptr)
param = cdiEncodeParam(rcode, rtabnum, 255); param = cdiEncodeParam(rcode, rtabnum, 255);
grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2);
level_sf = 0;
} }
else else
{ {
param = gribapiGetParam(gh); param = gribapiGetParam(gh);
grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf);
} }
cdiParamToString(param, paramstr, sizeof(paramstr));
varname[0] = 0; varname[0] = 0;
gribapiGetString(gh, "shortName", varname, sizeof(varname)); gribapiGetString(gh, "shortName", varname, sizeof(varname));
...@@ -1490,42 +1497,24 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1490,42 +1497,24 @@ int gribapiScanTimestep2(stream_t * streamptr)
if ( recID == nrecords ) if ( recID == nrecords )
{ {
char paramstr[32]; Warning("Param=%s (%s) l1=%d l2=%d not defined at timestep 1!", paramstr, varname, level1, level2);
cdiParamToString(param, paramstr, sizeof(paramstr));
Warning("Param=%s level=%d not defined at timestep 1!", paramstr, level1);
return (CDI_EUFSTRUCT); return (CDI_EUFSTRUCT);
} }
if ( cdiInventoryMode == 1 )
{
if ( streamptr->tsteps[tsID].records[recID].used ) if ( streamptr->tsteps[tsID].records[recID].used )
{ {
break; if ( cdiInventoryMode == 1 ) break;
}
else else
{ {
streamptr->tsteps[tsID].records[recID].used = TRUE;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
else
{
if ( streamptr->tsteps[tsID].records[recID].used )
{
char paramstr[32];
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break; if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
Warning("Param=%s level=%d already exist, skipped!", paramstr, level1); Warning("Param=%s level=%d already exist, skipped!", paramstr, level1);
continue; continue;
} }
else }
{
streamptr->tsteps[tsID].records[recID].used = TRUE; streamptr->tsteps[tsID].records[recID].used = TRUE;
streamptr->tsteps[tsID].recIDs[rindex] = recID; streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
if ( CDI_Debug ) if ( CDI_Debug )
Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime); Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime);
...@@ -1626,6 +1615,8 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1626,6 +1615,8 @@ int gribapiScanTimestep(stream_t * streamptr)
long editionNumber; long editionNumber;
long lpar; long lpar;
int lbounds; int lbounds;
int level_sf;
char paramstr[32];
char varname[256]; char varname[256];
vlistID = streamptr->vlistID; vlistID = streamptr->vlistID;
...@@ -1714,14 +1705,17 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1714,14 +1705,17 @@ int gribapiScanTimestep(stream_t * streamptr)
param = cdiEncodeParam(rcode, rtabnum, 255); param = cdiEncodeParam(rcode, rtabnum, 255);
grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib1GetLevel(gh, &leveltype, &lbounds, &level1, &level2);
level_sf = 0;
} }
else else
{ {
param = gribapiGetParam(gh); param = gribapiGetParam(gh);
grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2); grib2GetLevel(gh, &leveltype, &lbounds, &level1, &level2, &level_sf);
} }
cdiParamToString(param, paramstr, sizeof(paramstr));
varname[0] = 0; varname[0] = 0;
gribapiGetString(gh, "shortName", varname, sizeof(varname)); gribapiGetString(gh, "shortName", varname, sizeof(varname));
...@@ -1778,8 +1772,6 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1778,8 +1772,6 @@ int gribapiScanTimestep(stream_t * streamptr)
if ( vrecID == nrecs ) if ( vrecID == nrecs )
{ {
char paramstr[32];
cdiParamToString(param, paramstr, sizeof(paramstr));
Warning("Param=%s level=%d not available at timestep %d!", paramstr, level1, tsID+1); Warning("Param=%s level=%d not available at timestep %d!", paramstr, level1, tsID+1);
if ( cdiInventoryMode == 1 ) if ( cdiInventoryMode == 1 )
...@@ -1788,18 +1780,10 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1788,18 +1780,10 @@ int gribapiScanTimestep(stream_t * streamptr)
continue; continue;
} }
if ( cdiInventoryMode == 1 ) if ( cdiInventoryMode != 1 )
{
streamptr->tsteps[tsID].records[recID].used = TRUE;
streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
else
{ {
if ( streamptr->tsteps[tsID].records[recID].used ) if ( streamptr->tsteps[tsID].records[recID].used )
{ {
char paramstr[32];
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break; if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( CDI_Debug ) if ( CDI_Debug )
...@@ -1807,12 +1791,10 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1807,12 +1791,10 @@ int gribapiScanTimestep(stream_t * streamptr)
continue; continue;
} }
else }
{
streamptr->tsteps[tsID].records[recID].used = TRUE; streamptr->tsteps[tsID].records[recID].used = TRUE;
streamptr->tsteps[tsID].recIDs[rindex] = recID; streamptr->tsteps[tsID].recIDs[rindex] = recID;
}
}
if ( CDI_Debug ) if ( CDI_Debug )
Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime); Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime);
...@@ -1848,7 +1830,6 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1848,7 +1830,6 @@ int gribapiScanTimestep(stream_t * streamptr)
if ( vrecID < nrecs ) if ( vrecID < nrecs )
{ {
char paramstr[32];
cdiParamToString(streamptr->tsteps[tsID].records[recID].param, paramstr, sizeof(paramstr)); cdiParamToString(streamptr->tsteps[tsID].records[recID].param, paramstr, sizeof(paramstr));
Warning("Param %d level %d not found at timestep %d!", Warning("Param %d level %d not found at timestep %d!",
paramstr, streamptr->tsteps[tsID].records[recID].ilevel, tsID+1); paramstr, streamptr->tsteps[tsID].records[recID].ilevel, tsID+1);
...@@ -2558,6 +2539,18 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int ljpeg, i ...@@ -2558,6 +2539,18 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int ljpeg, i
} }
} }
static
void getLevelFactor(double level, long *factor, double *scale)
{
double dum;
if ( level >= 1 && (int)(1000*modf(level, &dum)) == 0 ) { *factor = 0; *scale = 1; }
else if ( level >= 0.1 && (int)(1000*modf(level*10, &dum)) == 0 ) { *factor = 1; *scale = 10; }
else if ( level >= 0.01 && (int)(1000*modf(level*100, &dum)) == 0 ) { *factor = 2; *scale = 100; }
else if ( level >= 0.001 && (int)(1000*modf(level*1000, &dum)) == 0 ) { *factor = 3; *scale = 1000; }
else { *factor = 2; *scale = 10; }
}
static static
void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, int levelID, int gcinit) void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, int levelID, int gcinit)
{ {
...@@ -2810,29 +2803,37 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -2810,29 +2803,37 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
else else
{ {
long factor; long factor;
if ( memcmp(units, "mm", 2) == 0 ) factor = 3; double scale;
else if ( memcmp(units, "cm", 2) == 0 ) factor = 2; double scalefactor;
else if ( memcmp(units, "dm", 2) == 0 ) factor = 1;
else factor = 0; // meter if ( memcmp(units, "mm", 2) == 0 ) scalefactor = 0.001;
else if ( memcmp(units, "cm", 2) == 0 ) scalefactor = 0.01;
else if ( memcmp(units, "dm", 2) == 0 ) scalefactor = 0.1;
else scalefactor = 1; // meter
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{ {
double level1, level2; double level1, level2;
level1 = zaxisInqLbound(zaxisID, levelID); level1 = scalefactor*zaxisInqLbound(zaxisID, levelID);
level2 = zaxisInqUbound(zaxisID, levelID); level2 = scalefactor*zaxisInqUbound(zaxisID, levelID);
getLevelFactor(level1, &factor, &scale);
if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0);
GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level1), 0); GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level1*scale), 0);
getLevelFactor(level, &factor, &scale);
if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_long(gh, "scaleFactorOfSecondFixedSurface", factor), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfSecondFixedSurface", factor), 0);
GRIB_CHECK(grib_set_double(gh, "scaledValueOfSecondFixedSurface", level2), 0); GRIB_CHECK(grib_set_double(gh, "scaledValueOfSecondFixedSurface", level2*scale), 0);
} }
else else
{ {
level *= scalefactor;
getLevelFactor(level, &factor, &scale);
if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0); if ( !gcinit ) GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0); GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0);
GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level), 0); GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level*scale), 0);
} }
} }
......
...@@ -769,7 +769,7 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc ...@@ -769,7 +769,7 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
datatype = iegInqDatatype(prec); datatype = iegInqDatatype(prec);
varAddRecord(recID, param, gridID, leveltype, lbounds, level1, level2, varAddRecord(recID, param, gridID, leveltype, lbounds, level1, level2, 0,
datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID; (*record).varID = varID;
......
...@@ -276,7 +276,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys ...@@ -276,7 +276,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys
datatype = srvInqDatatype(prec); datatype = srvInqDatatype(prec);
varAddRecord(recID, param, gridID, leveltype, 0, level, 0, varAddRecord(recID, param, gridID, leveltype, 0, level, 0, 0,
datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL); datatype, &varID, &levelID, UNDEFID, 0, 0, NULL, NULL, NULL);
(*record).varID = varID; (*record).varID = varID;
......
...@@ -47,6 +47,7 @@ typedef struct ...@@ -47,6 +47,7 @@ typedef struct
int zaxistype; int zaxistype;
int ltype; /* GRIB level type */ int ltype; /* GRIB level type */
int lbounds; int lbounds;
int level_sf;
int zaxisID; int zaxisID;
int nlevels; int nlevels;
int levelTableSize; int levelTableSize;
...@@ -83,6 +84,8 @@ void paramInitEntry(int varID, int param) ...@@ -83,6 +84,8 @@ void paramInitEntry(int varID, int param)
vartable[varID].gridID = UNDEFID; vartable[varID].gridID = UNDEFID;
vartable[varID].zaxistype = 0; vartable[varID].zaxistype = 0;
vartable[varID].ltype = 0; vartable[varID].ltype = 0;
vartable[varID].lbounds = 0;
vartable[varID].level_sf = 0;
vartable[varID].levelTable = NULL; vartable[varID].levelTable = NULL;
vartable[varID].levelTableSize = 0;