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

cgribexDefGrid: added support for generic grid with nlon/nlat=0

parent b159979c
...@@ -2645,7 +2645,7 @@ void gridCompress(int gridID) ...@@ -2645,7 +2645,7 @@ void gridCompress(int gridID)
} }
} }
else else
Warning(func, "%s grid unsupported!", gridNamePtr(gridtype)); Warning(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
} }
...@@ -3214,7 +3214,7 @@ void gridPrint(int gridID, int opt) ...@@ -3214,7 +3214,7 @@ void gridPrint(int gridID, int opt)
} }
default: default:
{ {
fprintf(stderr, "%s grid unsupported\n", gridNamePtr(type)); fprintf(stderr, "Unsupported grid type: %s\n", gridNamePtr(type));
} }
} }
} }
......
...@@ -2506,7 +2506,7 @@ void cdfDefGrid(int streamID, int gridID) ...@@ -2506,7 +2506,7 @@ void cdfDefGrid(int streamID, int gridID)
*/ */
else else
{ {
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
} }
#endif #endif
} }
......
...@@ -437,7 +437,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f ...@@ -437,7 +437,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
} }
default: default:
{ {
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
break; break;
} }
} }
...@@ -1702,7 +1702,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1702,7 +1702,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
gridtype = GRID_GAUSSIAN; gridtype = GRID_GAUSSIAN;
gridChangeType(gridID, gridtype); gridChangeType(gridID, gridtype);
} }
else if ( xsize == 1 && ysize == 1 ) else if ( (xsize == 1 && ysize == 1) || (xsize == 0 && ysize == 0) )
{ {
gridtype = GRID_LONLAT; gridtype = GRID_LONLAT;
gridChangeType(gridID, gridtype); gridChangeType(gridID, gridtype);
...@@ -1735,6 +1735,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1735,6 +1735,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
case GRID_TRAJECTORY: case GRID_TRAJECTORY:
{ {
int nlon = 0, nlat; int nlon = 0, nlat;
double xfirst = 0, xlast = 0, xinc = 0;
double yfirst = 0, ylast = 0, yinc = 0;
if ( gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN_REDUCED )
{ {
...@@ -1745,9 +1747,30 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1745,9 +1747,30 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
else else
{ {
nlon = gridInqXsize(gridID); nlon = gridInqXsize(gridID);
if ( nlon == 0 )
{
nlon = 1;
}
else
{
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, nlon-1);
xinc = gridInqXinc(gridID);
}
} }
nlat = gridInqYsize(gridID); nlat = gridInqYsize(gridID);
if ( nlat == 0 )
{
nlat = 1;
}
else
{
yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, nlat-1);
yinc = gridInqYinc(gridID);
}
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_GridType = GTYPE_GAUSSIAN; ISEC2_GridType = GTYPE_GAUSSIAN;
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) )
...@@ -1757,8 +1780,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1757,8 +1780,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
ISEC2_NumLon = nlon; ISEC2_NumLon = nlon;
ISEC2_NumLat = nlat; ISEC2_NumLat = nlat;
ISEC2_FirstLat = NINT(gridInqYval(gridID, 0)*1000); ISEC2_FirstLat = NINT(yfirst*1000);
ISEC2_LastLat = NINT(gridInqYval(gridID, nlat-1)*1000); ISEC2_LastLat = NINT(ylast*1000);
if ( gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN_REDUCED )
{ {
ISEC2_FirstLon = 0; ISEC2_FirstLon = 0;
...@@ -1767,19 +1790,19 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1767,19 +1790,19 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
} }
else else
{ {
ISEC2_FirstLon = NINT(gridInqXval(gridID, 0)*1000); ISEC2_FirstLon = NINT(xfirst*1000);
ISEC2_LastLon = NINT(gridInqXval(gridID, nlon-1)*1000); ISEC2_LastLon = NINT(xlast*1000);
ISEC2_LonIncr = NINT(gridInqXinc(gridID)*1000); ISEC2_LonIncr = NINT(xinc*1000);
} }
if ( fabs(gridInqXinc(gridID)*1000 - ISEC2_LonIncr) > FLT_EPSILON ) if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON )
ISEC2_LonIncr = 0; ISEC2_LonIncr = 0;
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_NumPar = nlat/2; ISEC2_NumPar = nlat/2;
else else
{ {
ISEC2_LatIncr = NINT(gridInqYinc(gridID)*1000); ISEC2_LatIncr = NINT(yinc*1000);
if ( fabs(gridInqYinc(gridID)*1000 - ISEC2_LatIncr) > FLT_EPSILON ) if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON )
ISEC2_LatIncr = 0; ISEC2_LatIncr = 0;
if ( ISEC2_LatIncr < 0 ) ISEC2_LatIncr = -ISEC2_LatIncr; if ( ISEC2_LatIncr < 0 ) ISEC2_LatIncr = -ISEC2_LatIncr;
...@@ -1878,7 +1901,10 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1878,7 +1901,10 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
break; break;
} }
default: default:
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); {
Warning(func, "The GRIB library can not store fields on the used grid!");
Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
}
} }
} }
...@@ -2075,7 +2101,7 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev ...@@ -2075,7 +2101,7 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev
} }
default: default:
{ {
Error(func, "zaxistype >%s< unsupported", zaxisNamePtr(zaxistype)); Error(func, "Unsupported zaxis type: %s", zaxisNamePtr(zaxistype));
break; break;
} }
} }
......
...@@ -547,7 +547,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh, ...@@ -547,7 +547,7 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh,
} }
default: default:
{ {
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
break; break;
} }
} }
...@@ -1895,7 +1895,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -1895,7 +1895,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
gridtype = GRID_GAUSSIAN; gridtype = GRID_GAUSSIAN;
gridChangeType(gridID, gridtype); gridChangeType(gridID, gridtype);
} }
else if ( xsize == 1 && ysize == 1 ) else if ( (xsize == 1 && ysize == 1) || (xsize == 0 && ysize == 0) )
{ {
gridtype = GRID_LONLAT; gridtype = GRID_LONLAT;
gridChangeType(gridID, gridtype); gridChangeType(gridID, gridtype);
...@@ -1928,6 +1928,8 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -1928,6 +1928,8 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
case GRID_TRAJECTORY: case GRID_TRAJECTORY:
{ {
int nlon = 0, nlat; int nlon = 0, nlat;
double xfirst = 0, xlast = 0, xinc = 0;
double yfirst = 0, ylast = 0, yinc = 0;
double latIncr; double latIncr;
if ( gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN_REDUCED )
...@@ -1939,9 +1941,30 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -1939,9 +1941,30 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
else else
{ {
nlon = gridInqXsize(gridID); nlon = gridInqXsize(gridID);
if ( nlon == 0 )
{
nlon = 1;
}
else
{
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, nlon-1);
xinc = gridInqXinc(gridID);
}
} }
nlat = gridInqYsize(gridID); nlat = gridInqYsize(gridID);
if ( nlat == 0 )
{
nlat = 1;
}
else
{
yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, nlat-1);
yinc = gridInqYinc(gridID);
}
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
GRIB_CHECK(grib_set_long(gh, "gridDefinitionTemplateNumber", GRIBAPI_GTYPE_GAUSSIAN), 0); GRIB_CHECK(grib_set_long(gh, "gridDefinitionTemplateNumber", GRIBAPI_GTYPE_GAUSSIAN), 0);
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) )
...@@ -1951,24 +1974,24 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -1951,24 +1974,24 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
GRIB_CHECK(grib_set_long(gh, "Ni", nlon), 0); GRIB_CHECK(grib_set_long(gh, "Ni", nlon), 0);
GRIB_CHECK(grib_set_long(gh, "Nj", nlat), 0); GRIB_CHECK(grib_set_long(gh, "Nj", nlat), 0);
GRIB_CHECK(grib_set_double(gh, "longitudeOfFirstGridPointInDegrees", gridInqXval(gridID, 0)), 0); GRIB_CHECK(grib_set_double(gh, "longitudeOfFirstGridPointInDegrees", xfirst), 0);
GRIB_CHECK(grib_set_double(gh, "longitudeOfLastGridPointInDegrees", gridInqXval(gridID, nlon-1)), 0); GRIB_CHECK(grib_set_double(gh, "longitudeOfLastGridPointInDegrees", xlast), 0);
GRIB_CHECK(grib_set_double(gh, "latitudeOfFirstGridPointInDegrees", gridInqYval(gridID, 0)), 0); GRIB_CHECK(grib_set_double(gh, "latitudeOfFirstGridPointInDegrees", yfirst), 0);
GRIB_CHECK(grib_set_double(gh, "latitudeOfLastGridPointInDegrees", gridInqYval(gridID, nlat-1)), 0); GRIB_CHECK(grib_set_double(gh, "latitudeOfLastGridPointInDegrees", ylast), 0);
GRIB_CHECK(grib_set_double(gh, "iDirectionIncrementInDegrees", gridInqXinc(gridID)), 0); GRIB_CHECK(grib_set_double(gh, "iDirectionIncrementInDegrees", xinc), 0);
/* /*
if ( fabs(gridInqXinc(gridID)*1000 - ISEC2_LonIncr) > FLT_EPSILON ) if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON )
ISEC2_LonIncr = 0; ISEC2_LonIncr = 0;
*/ */
if ( gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_GAUSSIAN )
GRIB_CHECK(grib_set_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", nlat/2), 0); GRIB_CHECK(grib_set_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", nlat/2), 0);
else else
{ {
latIncr = gridInqYinc(gridID); latIncr = yinc;
if ( latIncr < 0 ) latIncr = -latIncr; if ( latIncr < 0 ) latIncr = -latIncr;
GRIB_CHECK(grib_set_double(gh, "jDirectionIncrementInDegrees", latIncr), 0); GRIB_CHECK(grib_set_double(gh, "jDirectionIncrementInDegrees", latIncr), 0);
/* /*
if ( fabs(gridInqYinc(gridID)*1000 - ISEC2_LatIncr) > FLT_EPSILON ) if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON )
ISEC2_LatIncr = 0; ISEC2_LatIncr = 0;
*/ */
} }
...@@ -2103,7 +2126,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -2103,7 +2126,7 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
} }
*/ */
default: default:
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
} }
} }
#endif #endif
...@@ -2282,7 +2305,7 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID) ...@@ -2282,7 +2305,7 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID)
} }
default: default:
{ {
Error(func, "zaxistype >%s< unsupported", zaxisNamePtr(zaxistype)); Error(func, "Unsupported zaxis type: %s", zaxisNamePtr(zaxistype));
break; break;
} }
} }
......
...@@ -250,8 +250,28 @@ void iegDefGrid(int *gdb, int gridID) ...@@ -250,8 +250,28 @@ void iegDefGrid(int *gdb, int gridID)
if ( gridtype == GRID_GENERIC ) if ( gridtype == GRID_GENERIC )
{ {
gridtype = GRID_LONLAT; int xsize, ysize;
gridChangeType(gridID, gridtype);
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
if ( (ysize == 32 || ysize == 48 || ysize == 64 ||
ysize == 96 || ysize == 160) &&
(xsize == 2*ysize || xsize == 1) )
{
gridtype = GRID_GAUSSIAN;
gridChangeType(gridID, gridtype);
}
else if ( (xsize == 1 && ysize == 1) || (xsize == 0 && ysize == 0) )
{
gridtype = GRID_LONLAT;
gridChangeType(gridID, gridtype);
}
else if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
{
gridtype = GRID_LONLAT;
gridChangeType(gridID, gridtype);
}
} }
else if ( gridtype == GRID_CURVILINEAR ) else if ( gridtype == GRID_CURVILINEAR )
{ {
...@@ -261,11 +281,34 @@ void iegDefGrid(int *gdb, int gridID) ...@@ -261,11 +281,34 @@ void iegDefGrid(int *gdb, int gridID)
if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN )
{ {
int nlon, nlat; int nlon, nlat;
double xfirst = 0, xlast = 0, xinc = 0;
double yfirst = 0, ylast = 0, yinc = 0;
nlon = (int) gridInqXsize(gridID); nlon = (int) gridInqXsize(gridID);
nlat = (int) gridInqYsize(gridID); nlat = (int) gridInqYsize(gridID);
if ( nlon == 0 )
{
nlon = 1;
}
else
{
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, nlon-1);
xinc = gridInqXinc(gridID);
}
if ( nlat == 0 )
{
nlat = 1;
}
else
{
yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, nlat-1);
yinc = gridInqYinc(gridID);
}
if ( gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_GAUSSIAN )
IEG_G_GridType(gdb) = 4; IEG_G_GridType(gdb) = 4;
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) )
...@@ -275,20 +318,20 @@ void iegDefGrid(int *gdb, int gridID) ...@@ -275,20 +318,20 @@ void iegDefGrid(int *gdb, int gridID)
IEG_G_NumLon(gdb) = nlon; IEG_G_NumLon(gdb) = nlon;
IEG_G_NumLat(gdb) = nlat; IEG_G_NumLat(gdb) = nlat;
IEG_G_FirstLat(gdb) = NINT(gridInqYval(gridID, 0)*1000); IEG_G_FirstLat(gdb) = NINT(yfirst*1000);
IEG_G_LastLat(gdb) = NINT(gridInqYval(gridID, nlat-1)*1000); IEG_G_LastLat(gdb) = NINT(ylast*1000);
IEG_G_FirstLon(gdb) = NINT(gridInqXval(gridID, 0)*1000); IEG_G_FirstLon(gdb) = NINT(xfirst*1000);
IEG_G_LastLon(gdb) = NINT(gridInqXval(gridID, nlon-1)*1000); IEG_G_LastLon(gdb) = NINT(xlast*1000);
IEG_G_LonIncr(gdb) = NINT(gridInqXinc(gridID)*1000); IEG_G_LonIncr(gdb) = NINT(xinc*1000);
if ( fabs(gridInqXinc(gridID)*1000 - IEG_G_LonIncr(gdb)) > FLT_EPSILON ) if ( fabs(xinc*1000 - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
IEG_G_LonIncr(gdb) = 0; IEG_G_LonIncr(gdb) = 0;
if ( gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_GAUSSIAN )
IEG_G_LatIncr(gdb) = nlat/2; IEG_G_LatIncr(gdb) = nlat/2;
else else
{ {
IEG_G_LatIncr(gdb) = NINT(gridInqYinc(gridID)*1000); IEG_G_LatIncr(gdb) = NINT(yinc*1000);
if ( fabs(gridInqYinc(gridID)*1000 - IEG_G_LatIncr(gdb)) > FLT_EPSILON ) if ( fabs(yinc*1000 - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
IEG_G_LatIncr(gdb) = 0; IEG_G_LatIncr(gdb) = 0;
if ( IEG_G_LatIncr(gdb) < 0 ) IEG_G_LatIncr(gdb) = -IEG_G_LatIncr(gdb); if ( IEG_G_LatIncr(gdb) < 0 ) IEG_G_LatIncr(gdb) = -IEG_G_LatIncr(gdb);
...@@ -318,7 +361,7 @@ void iegDefGrid(int *gdb, int gridID) ...@@ -318,7 +361,7 @@ void iegDefGrid(int *gdb, int gridID)
} }
else else
{ {
Error(func, "%s grid unsupported!", gridNamePtr(gridtype)); Error(func, "Unsupported grid type: %s", gridNamePtr(gridtype));
} }
IEG_G_ScanFlag(gdb) = 64; IEG_G_ScanFlag(gdb) = 64;
...@@ -488,7 +531,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID) ...@@ -488,7 +531,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID)
} }
default: default:
{ {
Error(func, "leveltype >%s< unsupported", zaxisNamePtr(leveltype)); Error(func, "Unsupported zaxis type: %s", zaxisNamePtr(leveltype));
break; 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