Commit 89b180fc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function grbGetGridtype().

parent 6bdb6ebd
...@@ -1609,77 +1609,17 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg, ...@@ -1609,77 +1609,17 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg,
static static
void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridID) void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridID)
{ {
bool lrotated = false;
bool lcurvi = false;
memset(isec2, 0, 16*sizeof(int)); memset(isec2, 0, 16*sizeof(int));
ISEC1_Sec2Or3Flag = 128; ISEC1_Sec2Or3Flag = 128;
int gridtype = gridInqType(gridID);
ISEC1_GridDefinition = 255; ISEC1_GridDefinition = 255;
if ( gridtype == GRID_GENERIC )
{
int gridsize = (int)gridInqSize(gridID);
int xsize = (int)gridInqXsize(gridID);
int ysize = (int)gridInqYsize(gridID);
if ( (ysize == 32 || ysize == 48 || ysize == 64 ||
ysize == 96 || ysize == 160 || ysize == 192 ||
ysize == 240 || ysize == 320 || ysize == 384 ||
ysize == 480 || ysize == 768 ) &&
(xsize == 2*ysize || xsize == 1) )
{
gridtype = GRID_GAUSSIAN;
}
else if ( gridsize == 1 )
{
gridtype = GRID_LONLAT;
}
else if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
{
gridtype = GRID_LONLAT;
}
}
else if ( gridtype == GRID_CURVILINEAR )
{
int projID = gridInqProj(gridID);
if ( projID != CDI_UNDEFID && gridInqType(projID) == GRID_PROJECTION )
{
gridID = projID;
gridtype = GRID_PROJECTION;
}
else
{
static bool lwarning = true;
if ( lwarning && gridInqSize(gridID) > 1 )
{
lwarning = false;
Warning("Curvilinear grid is unsupported in GRIB1! Created wrong Grid Description Section!");
}
lcurvi = true;
gridtype = GRID_LONLAT;
}
}
if ( gridtype == GRID_PROJECTION )
{
if ( gridInqProjType(gridID) == CDI_PROJ_RLL )
{
gridtype = GRID_LONLAT;
lrotated = true;
}
else if ( gridInqProjType(gridID) == CDI_PROJ_LCC )
{
gridtype = GRID_LCC;
}
}
ISEC2_Reduced = false; ISEC2_Reduced = false;
ISEC2_ScanFlag = 0; ISEC2_ScanFlag = 0;
int gridsize = (int) gridInqSize(gridID);
bool gridIsRotated = false;
bool gridIsCurvilinear = false;
int gridtype = grbGetGridtype(gridID, gridsize, &gridIsRotated, &gridIsCurvilinear);
switch (gridtype) switch (gridtype)
{ {
case GRID_LONLAT: case GRID_LONLAT:
...@@ -1692,7 +1632,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1692,7 +1632,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_GridType = GRIB1_GTYPE_GAUSSIAN; ISEC2_GridType = GRIB1_GTYPE_GAUSSIAN;
else if ( gridtype == GRID_LONLAT && lrotated ) else if ( gridtype == GRID_LONLAT && gridIsRotated )
ISEC2_GridType = GRIB1_GTYPE_LATLON_ROT; ISEC2_GridType = GRIB1_GTYPE_LATLON_ROT;
else else
ISEC2_GridType = GRIB1_GTYPE_LATLON; ISEC2_GridType = GRIB1_GTYPE_LATLON;
...@@ -1712,7 +1652,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1712,7 +1652,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
else else
{ {
xfirst = gridInqXval(gridID, 0); xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, (lcurvi ? nlon*nlat : nlon) - 1); xlast = gridInqXval(gridID, (gridIsCurvilinear ? nlon*nlat : nlon) - 1);
xinc = fabs(gridInqXinc(gridID)); xinc = fabs(gridInqXinc(gridID));
} }
} }
...@@ -1721,7 +1661,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1721,7 +1661,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
else else
{ {
yfirst = gridInqYval(gridID, 0); yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, (lcurvi ? nlon*nlat : nlat) - 1); ylast = gridInqYval(gridID, (gridIsCurvilinear ? nlon*nlat : nlat) - 1);
yinc = fabs(gridInqYinc(gridID)); yinc = fabs(gridInqYinc(gridID));
} }
...@@ -1763,7 +1703,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1763,7 +1703,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
if ( ISEC2_LatIncr && ISEC2_LonIncr ) gribbyte_set_bit(&ISEC2_ResFlag, 1); if ( ISEC2_LatIncr && ISEC2_LonIncr ) gribbyte_set_bit(&ISEC2_ResFlag, 1);
if ( gridInqUvRelativeToGrid(gridID) ) gribbyte_set_bit(&ISEC2_ResFlag, 5); if ( gridInqUvRelativeToGrid(gridID) ) gribbyte_set_bit(&ISEC2_ResFlag, 5);
if ( lrotated ) if ( gridIsRotated )
{ {
double xpole = 0, ypole = 0, angle = 0; double xpole = 0, ypole = 0, angle = 0;
gridInqParamRLL(gridID, &xpole, &ypole, &angle); gridInqParamRLL(gridID, &xpole, &ypole, &angle);
......
...@@ -386,6 +386,71 @@ void streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum) ...@@ -386,6 +386,71 @@ void streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum)
grib_info_for_grads(recpos, (long)gribbuffersize, (unsigned char *) gribbuffer, intnum, fltnum, bignum); grib_info_for_grads(recpos, (long)gribbuffersize, (unsigned char *) gribbuffer, intnum, fltnum, bignum);
} }
} }
int grbGetGridtype(int gridID, size_t gridsize, bool *gridIsRotated, bool *gridIsCurvilinear)
{
int gridtype = gridInqType(gridID);
if ( gridtype == GRID_GENERIC )
{
int xsize = (int) gridInqXsize(gridID);
int ysize = (int) gridInqYsize(gridID);
if ( (ysize == 32 || ysize == 48 || ysize == 64 ||
ysize == 96 || ysize == 160 || ysize == 192 ||
ysize == 240 || ysize == 320 || ysize == 384 ||
ysize == 480 || ysize == 768 ) &&
(xsize == 2*ysize || xsize == 1) )
{
gridtype = GRID_GAUSSIAN;
}
else if ( gridsize == 1 )
{
gridtype = GRID_LONLAT;
}
else if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
{
gridtype = GRID_LONLAT;
}
}
else if ( gridtype == GRID_CURVILINEAR )
{
int projID = gridInqProj(gridID);
if ( projID != CDI_UNDEFID && gridInqType(projID) == GRID_PROJECTION )
{
gridID = projID;
gridtype = GRID_PROJECTION;
}
else
{
static bool lwarning = true;
if ( lwarning && gridsize > 1 )
{
lwarning = false;
Warning("Curvilinear grid is unsupported in GRIB format! Created wrong Grid Description Section!");
}
*gridIsCurvilinear = true;
gridtype = GRID_LONLAT;
}
}
if ( gridtype == GRID_PROJECTION )
{
if ( gridInqProjType(gridID) == CDI_PROJ_RLL )
{
gridtype = GRID_LONLAT;
*gridIsRotated = true;
}
else if ( gridInqProjType(gridID) == CDI_PROJ_LCC )
{
gridtype = GRID_LCC;
}
}
return gridtype;
}
/* /*
* Local Variables: * Local Variables:
* c-file-style: "Java" * c-file-style: "Java"
......
...@@ -28,6 +28,8 @@ int grib2ltypeToZaxisType(int grib_ltype); ...@@ -28,6 +28,8 @@ int grib2ltypeToZaxisType(int grib_ltype);
int zaxisTypeToGrib1ltype(int zaxistype); int zaxisTypeToGrib1ltype(int zaxistype);
int zaxisTypeToGrib2ltype(int zaxistype); int zaxisTypeToGrib2ltype(int zaxistype);
int grbGetGridtype(int gridID, size_t gridsize, bool *gridIsRotated, bool *gridIsCurvilinear);
struct cdiGribParamChange struct cdiGribParamChange
{ {
int code, ltype, lev; int code, ltype, lev;
......
...@@ -1894,67 +1894,10 @@ getGribApiCompTypeMsg(int comptype, size_t gridsize) ...@@ -1894,67 +1894,10 @@ getGribApiCompTypeMsg(int comptype, size_t gridsize)
static static
void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, bool lieee, int datatype) void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, bool lieee, int datatype)
{ {
bool lrotated = false;
bool lcurvi = false;
int gridtype = gridInqType(gridID);
size_t gridsize = gridInqSize(gridID); size_t gridsize = gridInqSize(gridID);
bool gridIsRotated = false;
if ( gridtype == GRID_GENERIC ) bool gridIsCurvilinear = false;
{ int gridtype = grbGetGridtype(gridID, gridsize, &gridIsRotated, &gridIsCurvilinear);
int xsize = (int) gridInqXsize(gridID);
int ysize = (int) gridInqYsize(gridID);
if ( (ysize == 32 || ysize == 48 || ysize == 64 ||
ysize == 96 || ysize == 160 || ysize == 192 ||
ysize == 240 || ysize == 320 || ysize == 384 ||
ysize == 480 || ysize == 768 ) &&
(xsize == 2*ysize || xsize == 1) )
{
gridtype = GRID_GAUSSIAN;
}
else if ( gridsize == 1 )
{
gridtype = GRID_LONLAT;
}
else if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
{
gridtype = GRID_LONLAT;
}
}
else if ( gridtype == GRID_CURVILINEAR )
{
int projID = gridInqProj(gridID);
if ( projID != CDI_UNDEFID && gridInqType(projID) == GRID_PROJECTION )
{
gridID = projID;
gridtype = GRID_PROJECTION;
}
else
{
static bool lwarning = true;
if ( lwarning && gridsize > 1 )
{
lwarning = false;
Warning("Curvilinear grid is unsupported in GRIB format! Created wrong Grid Description Section!");
}
lcurvi = true;
gridtype = GRID_LONLAT;
}
}
if ( gridtype == GRID_PROJECTION )
{
if ( gridInqProjType(gridID) == CDI_PROJ_RLL )
{
gridtype = GRID_LONLAT;
lrotated = true;
}
else if ( gridInqProjType(gridID) == CDI_PROJ_LCC )
{
gridtype = GRID_LCC;
}
}
if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN )
{ {
...@@ -1998,7 +1941,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -1998,7 +1941,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
len = sizeof(mesg_gaussian_reduced) - 1; len = sizeof(mesg_gaussian_reduced) - 1;
mesg = mesg_gaussian_reduced; mesg = mesg_gaussian_reduced;
} }
else if ( lrotated ) else if ( gridIsRotated )
{ {
static const char mesg_rot_lonlat[] = "rotated_ll"; static const char mesg_rot_lonlat[] = "rotated_ll";
len = sizeof(mesg_rot_lonlat) - 1; len = sizeof(mesg_rot_lonlat) - 1;
...@@ -2039,7 +1982,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2039,7 +1982,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
else else
{ {
xfirst = gridInqXval(gridID, 0); xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, (lcurvi ? nlon*nlat : nlon) - 1); xlast = gridInqXval(gridID, (gridIsCurvilinear ? nlon*nlat : nlon) - 1);
xinc = fabs(gridInqXinc(gridID)); xinc = fabs(gridInqXinc(gridID));
} }
} }
...@@ -2048,7 +1991,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2048,7 +1991,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
else else
{ {
yfirst = gridInqYval(gridID, 0); yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, (lcurvi ? nlon*nlat : nlat) - 1); ylast = gridInqYval(gridID, (gridIsCurvilinear ? nlon*nlat : nlat) - 1);
yinc = fabs(gridInqYinc(gridID)); yinc = fabs(gridInqYinc(gridID));
} }
...@@ -2086,7 +2029,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2086,7 +2029,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
GRIB_CHECK(my_grib_set_double(gh, "jDirectionIncrementInDegrees", yinc), 0); GRIB_CHECK(my_grib_set_double(gh, "jDirectionIncrementInDegrees", yinc), 0);
} }
if ( lrotated ) if ( gridIsRotated )
{ {
double xpole = 0, ypole = 0, angle = 0; double xpole = 0, ypole = 0, angle = 0;
gridInqParamRLL(gridID, &xpole, &ypole, &angle); gridInqParamRLL(gridID, &xpole, &ypole, &angle);
......
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