Commit 6b28d696 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added support for ZAXIS_DEPTH_BELOW_LAND units "cm", "dm" and "m"

parent 91894b63
......@@ -3,6 +3,10 @@
* Version 1.5.5 released
* using CGRIBEX library version 1.5.2
2012-04-26 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support for ZAXIS_DEPTH_BELOW_LAND units "cm", "dm" and "m"
2012-03-24 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added single precision support: streamWriteVarF, streamWriteVarSliceF
......
......@@ -5,7 +5,7 @@
/* GRIB2 Level Types */
#define GRIB2_LTYPE_SURFACE 1
#define GRIB2_LTYPE_TOA 8
#define GRIB2_LTYPE_TOA 8
#define GRIB2_LTYPE_SEA_BOTTOM 9
#define GRIB2_LTYPE_ATMOSPHERE 10
#define GRIB2_LTYPE_ISOBARIC 100
......
......@@ -4158,7 +4158,7 @@ int isLatAxis(const char *units, const char *stdname)
#if defined (HAVE_LIBNETCDF)
static
int isDBLAxis(const char *longname)
int isDBLAxis(const char *units, const char *longname)
{
int status = FALSE;
......@@ -4166,7 +4166,12 @@ int isDBLAxis(const char *longname)
strcmp(longname, "depth_below_land") == 0 ||
strcmp(longname, "levels below the surface") == 0 )
{
status = TRUE;
/*
if ( strcmp(ncvars[ncvarid].units, "cm") == 0 ||
strcmp(ncvars[ncvarid].units, "dm") == 0 ||
strcmp(ncvars[ncvarid].units, "m") == 0 )
*/
status = TRUE;
}
return (status);
......@@ -4999,10 +5004,9 @@ void verify_coordinate_vars_1(int ndims, ncdim_t *ncdims, ncvar_t *ncvars, int t
else if ( strcmp(ncvars[ncvarid].units, "level") == 0 )
ncvars[ncvarid].zaxistype = ZAXIS_GENERIC;
}
else if ( strcmp(ncvars[ncvarid].units, "cm") == 0 )
{
if ( isDBLAxis(ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
else if ( isDBLAxis(ncvars[ncvarid].units, ncvars[ncvarid].longname) )
{
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
}
else if ( strcmp(ncvars[ncvarid].units, "m") == 0 )
{
......@@ -5081,10 +5085,9 @@ void verify_coordinate_vars_2(int nvars, ncvar_t *ncvars)
ncvars[ncvarid].zaxistype = ZAXIS_GENERIC;
continue;
}
else if ( strcmp(ncvars[ncvarid].units, "cm") == 0 )
else if ( isDBLAxis(ncvars[ncvarid].units, ncvars[ncvarid].longname) )
{
if ( isDBLAxis(ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
continue;
}
else if ( strcmp(ncvars[ncvarid].units, "m") == 0 )
......
......@@ -2064,17 +2064,29 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev
}
case ZAXIS_DEPTH_BELOW_LAND:
{
char units[128];
long factor;
zaxisInqUnits(zaxisID, units);
if ( memcmp(units, "cm", 2) == 0 ) factor = 1;
else if ( memcmp(units, "dm", 2) == 0 ) factor = 10;
else factor = 100; // meter
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{
double level1, level2;
level1 = zaxisInqLbound(zaxisID, levelID);
level2 = zaxisInqUbound(zaxisID, levelID);
ISEC1_LevelType = GRIB1_LTYPE_LANDDEPTH_LAYER;
ISEC1_Level1 = (int) zaxisInqLbound(zaxisID, levelID);
ISEC1_Level2 = (int) zaxisInqUbound(zaxisID, levelID);
ISEC1_Level1 = (int) (level1*factor);
ISEC1_Level2 = (int) (level2*factor);
}
else
{
level = zaxisInqLevel(zaxisID, levelID);
ilevel = (int) level;
ilevel = (int) (level*factor);
ISEC1_LevelType = GRIB1_LTYPE_LANDDEPTH;
ISEC1_Level1 = ilevel;
ISEC1_Level2 = 0;
......
......@@ -542,10 +542,21 @@ static
double grib2GetLevel(grib_handle *gh, int leveltype)
{
double dlevel;
long factor;
GRIB_CHECK(grib_get_double(gh, "level", &dlevel), 0);
if ( leveltype == 100 ) dlevel *= 100;
if ( dlevel < -2.e9 || dlevel > 2.e9 ) dlevel = 0;
if ( leveltype == GRIB2_LTYPE_LANDDEPTH )
{
GRIB_CHECK(grib_get_long(gh, "scaleFactorOfFirstFixedSurface", &factor), 0);
GRIB_CHECK(grib_get_double(gh, "scaledValueOfFirstFixedSurface", &dlevel), 0);
if ( factor == 0 ) dlevel *= 100; // m to cm
else if ( factor == 1 ) dlevel *= 10; // dm to cm
}
else
{
GRIB_CHECK(grib_get_double(gh, "level", &dlevel), 0);
if ( leveltype == GRIB2_LTYPE_ISOBARIC ) dlevel *= 100;
if ( dlevel < -2.e9 || dlevel > 2.e9 ) dlevel = 0;
}
return (dlevel);
}
......@@ -2565,27 +2576,46 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID)
}
case ZAXIS_DEPTH_BELOW_LAND:
{
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
char units[128];
long factor;
zaxisInqUnits(zaxisID, units);
if ( editionNumber <= 1 )
{
GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_double(gh, "level", zaxisInqLbound(zaxisID, levelID)), 0);
GRIB_CHECK(grib_set_long(gh, "typeOfSecondFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_double(gh, "level", zaxisInqUbound(zaxisID, levelID)), 0);
/*
ISEC1_LevelType = GRIB2_LTYPE_LANDDEPTH_LAYER;
ISEC1_Level1 = (int) zaxisInqLbound(zaxisID, levelID);
ISEC1_Level2 = (int) zaxisInqUbound(zaxisID, levelID);
*/
if ( memcmp(units, "cm", 2) == 0 ) factor = 1;
else if ( memcmp(units, "dm", 2) == 0 ) factor = 10;
else factor = 100; // meter
GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_double(gh, "level", level*factor), 0);
}
else
{
level = zaxisInqLevel(zaxisID, levelID);
if ( memcmp(units, "cm", 2) == 0 ) factor = 2;
else if ( memcmp(units, "dm", 2) == 0 ) factor = 1;
else factor = 0; // meter
if ( editionNumber <= 1 )
GRIB_CHECK(grib_set_long(gh, "indicatorOfTypeOfLevel", GRIB1_LTYPE_LANDDEPTH), 0);
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{
double level1, level2;
level1 = zaxisInqLbound(zaxisID, levelID);
level2 = zaxisInqUbound(zaxisID, levelID);
GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0);
GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level1), 0);
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);
}
else
GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_double(gh, "level", level), 0);
{
level = zaxisInqLevel(zaxisID, levelID);
GRIB_CHECK(grib_set_long(gh, "typeOfFirstFixedSurface", GRIB2_LTYPE_LANDDEPTH), 0);
GRIB_CHECK(grib_set_long(gh, "scaleFactorOfFirstFixedSurface", factor), 0);
GRIB_CHECK(grib_set_double(gh, "scaledValueOfFirstFixedSurface", level), 0);
}
}
break;
......
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