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 2015-03-29 Uwe Schulzweida
* vlistMerge: compare size of grids (bug fix) * vlistMerge: compare size of grids (bug fix)
......
...@@ -4789,6 +4789,12 @@ int isDBLAxis(/*const char *units,*/ const char *longname) ...@@ -4789,6 +4789,12 @@ int isDBLAxis(/*const char *units,*/ const char *longname)
return (status); return (status);
} }
static
int unitsIsMeter(const char *units)
{
return (*units == 'm' && (strcmp(units, "m") == 0 || strncmp(units, "meter", 5) == 0));
}
static static
int isDepthAxis(const char *stdname, const char *longname) 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 ...@@ -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; 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) ) if ( isDepthAxis(ncvars[ncvarid].stdname, ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA; ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA;
...@@ -5862,7 +5868,7 @@ void verify_coordinate_vars_2(int nvars, ncvar_t *ncvars) ...@@ -5862,7 +5868,7 @@ void verify_coordinate_vars_2(int nvars, ncvar_t *ncvars)
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND; ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_LAND;
continue; continue;
} }
else if ( strcmp(ncvars[ncvarid].units, "m") == 0 ) else if ( unitsIsMeter(ncvars[ncvarid].units) )
{ {
if ( isDepthAxis(ncvars[ncvarid].stdname, ncvars[ncvarid].longname) ) if ( isDepthAxis(ncvars[ncvarid].stdname, ncvars[ncvarid].longname) )
ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA; ncvars[ncvarid].zaxistype = ZAXIS_DEPTH_BELOW_SEA;
......
...@@ -2281,6 +2281,8 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -2281,6 +2281,8 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
zaxisDefUnits(zaxisID, "Pa"); zaxisDefUnits(zaxisID, "Pa");
} }
int grib2ltype = zaxisTypeToGrib2ltype(zaxistype);
switch (zaxistype) switch (zaxistype)
{ {
case ZAXIS_SURFACE: case ZAXIS_SURFACE:
...@@ -2292,11 +2294,14 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -2292,11 +2294,14 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
case ZAXIS_ISENTROPIC: case ZAXIS_ISENTROPIC:
{ {
if ( editionNumber <= 1 ) if ( editionNumber <= 1 )
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype)); {
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
GRIB_CHECK(my_grib_set_long(gh, "level", (long)level), 0);
}
else else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype)); {
grib2DefLevel(gh, gcinit, grib2ltype, grib2ltype, lbounds, level, dlevel1, dlevel2);
GRIB_CHECK(my_grib_set_long(gh, "level", (long)level), 0); }
break; break;
} }
...@@ -2312,27 +2317,22 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -2312,27 +2317,22 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
case ZAXIS_MIX_LAYER: case ZAXIS_MIX_LAYER:
case ZAXIS_ATMOSPHERE: case ZAXIS_ATMOSPHERE:
{ {
if ( lbounds ) if ( editionNumber <= 1 )
{ {
if ( editionNumber <= 1 ) gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype)); if ( lbounds )
{
GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
}
else else
{ {
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype)); GRIB_CHECK(my_grib_set_long(gh, "level", (long) level), 0);
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 else
{ {
if ( editionNumber <= 1 ) grib2DefLevel(gh, gcinit, grib2ltype, grib2ltype, lbounds, level, dlevel1, dlevel2);
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", zaxisTypeToGrib1ltype(zaxistype));
else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", zaxisTypeToGrib2ltype(zaxistype));
GRIB_CHECK(my_grib_set_long(gh, "level", (long) level), 0);
} }
break; break;
...@@ -2340,28 +2340,24 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -2340,28 +2340,24 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
case ZAXIS_HYBRID: case ZAXIS_HYBRID:
case ZAXIS_HYBRID_HALF: case ZAXIS_HYBRID_HALF:
{ {
if ( lbounds ) if ( editionNumber <= 1 )
{ {
if ( editionNumber <= 1 ) if ( lbounds )
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID_LAYER); {
else gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID_LAYER);
{ GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID); GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
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 else
gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_HYBRID); {
gribapiDefLevelType(gh, gcinit, "indicatorOfTypeOfLevel", GRIB1_LTYPE_HYBRID);
GRIB_CHECK(my_grib_set_long(gh, "level", (long) level), 0); 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 ) 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