Commit 9ae75618 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

gribapiDefLevel: use function grib2DefLevel() to write grib2 levels

parent efb0b5c0
2015-03-30 Uwe Schulzweida
* gribapiDefLevel: use function grib2DefLevel() to write grib2 levels
2015-03-29 Uwe Schulzweida
* vlistMerge: compare size of grids (bug fix)
......
......@@ -4789,6 +4789,12 @@ int isDBLAxis(/*const char *units,*/ const char *longname)
return (status);
}
static
int unitsIsMeter(const char *units)
{
return (*units == 'm' && (strcmp(units, "m") == 0 || strncmp(units, "meter", 5) == 0));
}
static
int isDepthAxis(const char *stdname, const char *longname)
{
......@@ -5775,7 +5781,7 @@ void verify_coordinate_vars_1(int ndims, ncdim_t *ncdims, ncvar_t *ncvars, int t
{
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
}
else if ( strcmp(ncvars[ncvarid].units, "m") == 0 )
else if ( unitsIsMeter(ncvars[ncvarid].units) )
{
if ( isDepthAxis(ncvars[ncvarid].stdname, ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA;
......@@ -5862,7 +5868,7 @@ void verify_coordinate_vars_2(int nvars, ncvar_t *ncvars)
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
continue;
}
else if ( strcmp(ncvars[ncvarid].units, "m") == 0 )
else if ( unitsIsMeter(ncvars[ncvarid].units) )
{
if ( isDepthAxis(ncvars[ncvarid].stdname, ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA;
......
......@@ -2281,6 +2281,8 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
zaxisDefUnits(zaxisID, "Pa");
}
int grib2ltype = zaxisTypeToGrib2ltype(zaxistype);
switch (zaxistype)
{
case ZAXIS_SURFACE:
......@@ -2292,11 +2294,14 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
case ZAXIS_ISENTROPIC:
{
if ( editionNumber <= 1 )
{
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype));
GRIB_CHECK(my_grib_set_long(gh, "level", (long)level), 0);
}
else
{
grib2DefLevel(gh, gcinit, grib2ltype, grib2ltype, lbounds, level, dlevel1, dlevel2);
}
break;
}
......@@ -2311,57 +2316,48 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
case ZAXIS_SEDIMENT_BOTTOM_TW:
case ZAXIS_MIX_LAYER:
case ZAXIS_ATMOSPHERE:
{
if ( lbounds )
{
if ( editionNumber <= 1 )
{
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
else
if ( lbounds )
{
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype));
gribapiDefLevelType(gh, gcinit, "typeOfSecondFixedSurface", zaxisTypeToGrib2ltype(zaxistype));
}
GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
}
else
{
if ( editionNumber <= 1 )
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype));
GRIB_CHECK(my_grib_set_long(gh, "level", (long) level), 0);
}
}
else
{
grib2DefLevel(gh, gcinit, grib2ltype, grib2ltype, lbounds, level, dlevel1, dlevel2);
}
break;
}
case ZAXIS_HYBRID:
case ZAXIS_HYBRID_HALF:
{
if ( editionNumber <= 1 )
{
if ( lbounds )
{
if ( editionNumber <= 1 )
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID_LAYER);
else
{
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID);
gribapiDefLevelType(gh, gcinit, "typeOfSecondFixedSurface", GRIB2_LTYPE_HYBRID);
}
GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
}
else
{
if ( editionNumber <= 1 )
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID);
else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID);
GRIB_CHECK(my_grib_set_long(gh, "level", (long) level), 0);
}
}
else
{
grib2DefLevel(gh, gcinit, GRIB2_LTYPE_HYBRID, GRIB2_LTYPE_HYBRID, lbounds, level, dlevel1, dlevel2);
}
if ( !gcinit )
{
......
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