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

grb2 write: added support for projection CDI_PROJ_RLL.

parent 1c3e51bc
2016-08-01 Uwe Schulzweida 2016-08-01 Uwe Schulzweida
* grb write: added support for projection CDI_PROJ_RLL * grb, grb2 write: added support for projection CDI_PROJ_RLL
* grb, grb2, ieg read: added support for projection CDI_PROJ_RLL * grb, grb2, ieg read: added support for projection CDI_PROJ_RLL
2016-07-30 Uwe Schulzweida 2016-07-30 Uwe Schulzweida
......
...@@ -1612,7 +1612,6 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg, ...@@ -1612,7 +1612,6 @@ 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)
{ {
static bool lwarning = true;
bool lrotated = false; bool lrotated = false;
bool lcurvi = false; bool lcurvi = false;
...@@ -1652,6 +1651,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1652,6 +1651,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
} }
else if ( gridtype == GRID_CURVILINEAR ) else if ( gridtype == GRID_CURVILINEAR )
{ {
static bool lwarning = true;
if ( lwarning && gridInqSize(gridID) > 1 ) if ( lwarning && gridInqSize(gridID) > 1 )
{ {
lwarning = false; lwarning = false;
...@@ -1699,25 +1699,19 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI ...@@ -1699,25 +1699,19 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
} }
else else
{ {
if ( nlon == 0 ) if ( nlon == 0 ) nlon = 1;
{
nlon = 1;
}
else else
{ {
xfirst = gridInqXval(gridID, 0); xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, (lcurvi ? nlon*nlat : nlon) - 1); xlast = gridInqXval(gridID, (lcurvi ? nlon*nlat : nlon) - 1);
xinc = gridInqXinc(gridID); xinc = gridInqXinc(gridID);
} }
} }
if ( nlat == 0 ) if ( nlat == 0 ) nlat = 1;
{
nlat = 1;
}
else else
{ {
yfirst = gridInqYval(gridID, 0); yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, (lcurvi ? nlon*nlat : nlat) - 1); ylast = gridInqYval(gridID, (lcurvi ? nlon*nlat : nlat) - 1);
yinc = fabs(gridInqYinc(gridID)); yinc = fabs(gridInqYinc(gridID));
} }
......
...@@ -1881,6 +1881,8 @@ static ...@@ -1881,6 +1881,8 @@ static
void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, bool lieee, int datatype, int nmiss, int gcinit) void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype, bool lieee, int datatype, int nmiss, int gcinit)
{ {
UNUSED(nmiss); UNUSED(nmiss);
bool lrotated = false;
bool lcurvi = false;
int gridtype = gridInqType(gridID); int gridtype = gridInqType(gridID);
int gridsize = gridInqSize(gridID); int gridsize = gridInqSize(gridID);
...@@ -1916,13 +1918,20 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -1916,13 +1918,20 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
} }
else if ( gridtype == GRID_CURVILINEAR ) else if ( gridtype == GRID_CURVILINEAR )
{ {
static bool lwarn = true; static bool lwarning = true;
if ( lwarn && gridsize > 1 ) if ( lwarning && gridsize > 1 )
{ {
lwarn = false; lwarning = false;
Warning("Curvilinear grids are unsupported in GRIB format! Created wrong Grid Description Section!"); Warning("Curvilinear grids are unsupported in GRIB format! Created wrong Grid Description Section!");
} }
gridtype = GRID_LONLAT; gridtype = GRID_LONLAT;
lcurvi = true;
}
if ( gridtype == GRID_PROJECTION && gridInqProjType(gridID) == CDI_PROJ_RLL )
{
gridtype = GRID_LONLAT;
lrotated = true;
} }
if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN )
...@@ -1952,43 +1961,39 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -1952,43 +1961,39 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
double yfirst = 0, ylast = 0, yinc = 0; double yfirst = 0, ylast = 0, yinc = 0;
double latIncr; double latIncr;
{ const char *mesg;
const char *mesg; size_t len;
size_t len; if ( gridtype == GRID_GAUSSIAN )
if ( gridtype == GRID_GAUSSIAN ) {
{ static const char mesg_gaussian[] = "regular_gg";
static const char mesg_gaussian[] = "regular_gg"; len = sizeof(mesg_gaussian) - 1;
len = sizeof (mesg_gaussian) - 1; mesg = mesg_gaussian;
mesg = mesg_gaussian; }
} else if ( gridtype == GRID_GAUSSIAN_REDUCED )
else if ( gridtype == GRID_GAUSSIAN_REDUCED ) {
{ static const char mesg_gaussian_reduced[] = "reduced_gg";
static const char mesg_gaussian_reduced[] = "reduced_gg"; len = sizeof(mesg_gaussian_reduced) - 1;
len = sizeof (mesg_gaussian_reduced) - 1; mesg = mesg_gaussian_reduced;
mesg = mesg_gaussian_reduced; }
} else if ( gridtype == GRID_LONLAT && (gridIsRotated(gridID) || lrotated) )
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) {
{ 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; mesg = mesg_rot_lonlat;
mesg = mesg_rot_lonlat; }
} else
else {
{ static const char mesg_regular_ll[] = "regular_ll";
static const char mesg_regular_ll[] = "regular_ll"; len = sizeof(mesg_regular_ll) - 1;
len = sizeof (mesg_regular_ll) - 1; mesg = mesg_regular_ll;
mesg = mesg_regular_ll; }
} GRIB_CHECK(my_grib_set_string(gh, "gridType", mesg, &len), 0);
GRIB_CHECK(my_grib_set_string(gh, "gridType", mesg, &len), 0);
}
long nlon = gridInqXsize(gridID); long nlon = gridInqXsize(gridID);
long nlat = gridInqYsize(gridID); long nlat = gridInqYsize(gridID);
if ( gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN_REDUCED )
{ {
//GRIB_CHECK(my_grib_set_long(gh, "numberOfValues", gridsize), 0);
nlon = 0; nlon = 0;
int *rowlon = (int *) Malloc((size_t)nlat*sizeof(int)); int *rowlon = (int *) Malloc((size_t)nlat*sizeof(int));
...@@ -2007,26 +2012,20 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2007,26 +2012,20 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
} }
else else
{ {
if ( nlon == 0 ) if ( nlon == 0 ) nlon = 1;
{
nlon = 1;
}
else else
{ {
xfirst = gridInqXval(gridID, 0); xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, nlon-1); xlast = gridInqXval(gridID, (lcurvi ? nlon*nlat : nlon) - 1);
xinc = gridInqXinc(gridID); xinc = gridInqXinc(gridID);
} }
} }
if ( nlat == 0 ) if ( nlat == 0 ) nlat = 1;
{
nlat = 1;
}
else else
{ {
yfirst = gridInqYval(gridID, 0); yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, nlat-1); ylast = gridInqYval(gridID, (lcurvi ? nlon*nlat : nlat) - 1);
yinc = gridInqYinc(gridID); yinc = gridInqYinc(gridID);
} }
...@@ -2044,10 +2043,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2044,10 +2043,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
if ( yfirst < ylast ) jscan = 1; if ( yfirst < ylast ) jscan = 1;
GRIB_CHECK(my_grib_set_long(gh, "jScansPositively", jscan), 0); GRIB_CHECK(my_grib_set_long(gh, "jScansPositively", jscan), 0);
} }
/*
if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON )
ISEC2_LonIncr = 0;
*/
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
{ {
int np = gridInqNP(gridID); int np = gridInqNP(gridID);
...@@ -2059,67 +2055,46 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2059,67 +2055,46 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
latIncr = yinc; latIncr = yinc;
if ( latIncr < 0 ) latIncr = -latIncr; if ( latIncr < 0 ) latIncr = -latIncr;
GRIB_CHECK(my_grib_set_double(gh, "jDirectionIncrementInDegrees", latIncr), 0); GRIB_CHECK(my_grib_set_double(gh, "jDirectionIncrementInDegrees", latIncr), 0);
/*
if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON )
ISEC2_LatIncr = 0;
*/
} }
/*
if ( ISEC2_NumLon > 1 && ISEC2_NumLat == 1 )
if ( ISEC2_LonIncr != 0 && ISEC2_LatIncr == 0 ) ISEC2_LatIncr = ISEC2_LonIncr;
if ( ISEC2_NumLon == 1 && ISEC2_NumLat > 1 )
if ( ISEC2_LonIncr == 0 && ISEC2_LatIncr != 0 ) ISEC2_LonIncr = ISEC2_LatIncr;
if ( ISEC2_LatIncr == 0 || ISEC2_LonIncr == 0 ) if ( gridIsRotated(gridID) || lrotated )
ISEC2_ResFlag = 0;
else
ISEC2_ResFlag = 128;
*/
if ( gridIsRotated(gridID) )
{ {
double xpole = gridInqXpole(gridID); double xpole = 0, ypole = 0, angle = 0;
double ypole = gridInqYpole(gridID); if ( gridIsRotated(gridID) )
double angle = gridInqAngle(gridID); {
/* change from north to south pole */ xpole = gridInqXpole(gridID);
if ( fabs(ypole) > 0 ) ypole = -ypole; ypole = gridInqYpole(gridID);
xpole = xpole + 180; angle = gridInqAngle(gridID);
if ( fabs(angle) > 0 ) angle = -angle; }
GRIB_CHECK(my_grib_set_double(gh, "latitudeOfSouthernPoleInDegrees", ypole), 0); else
GRIB_CHECK(my_grib_set_double(gh, "longitudeOfSouthernPoleInDegrees", xpole), 0); gridInqProjParamRLL(gridID, &xpole, &ypole, &angle);
GRIB_CHECK(my_grib_set_double(gh, "angleOfRotation", angle), 0);
}
/* East -> West */
//if ( ISEC2_LastLon < ISEC2_FirstLon ) ISEC2_ScanFlag += 128;
/* South -> North */ xpole = xpole + 180;
//if ( ISEC2_LastLat > ISEC2_FirstLat ) ISEC2_ScanFlag += 64; if ( fabs(ypole) > 0 ) ypole = -ypole; // change from north to south pole
if ( fabs(angle) > 0 ) angle = -angle;
GRIB_CHECK(my_grib_set_double(gh, "latitudeOfSouthernPoleInDegrees", ypole), 0);
GRIB_CHECK(my_grib_set_double(gh, "longitudeOfSouthernPoleInDegrees", xpole), 0);
GRIB_CHECK(my_grib_set_double(gh, "angleOfRotation", angle), 0);
}
if ( editionNumber != 2 ) { lieee = false; comptype = 0; } if ( editionNumber != 2 ) { lieee = false; comptype = 0; }
{ if ( lieee )
const char *mesg; {
size_t len; static const char mesg_grid_ieee[] = "grid_ieee";
if ( lieee ) len = sizeof (mesg_grid_ieee) - 1;
{ mesg = mesg_grid_ieee;
static const char mesg_grid_ieee[] = "grid_ieee"; }
len = sizeof (mesg_grid_ieee) - 1; else
mesg = mesg_grid_ieee; {
} struct gribApiMsg gaMsg = getGribApiCompTypeMsg(gh, comptype, gridsize);
else len = gaMsg.msgLen;
{ mesg = gaMsg.msg;
struct gribApiMsg gaMsg }
= getGribApiCompTypeMsg(gh, comptype, gridsize); GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
len = gaMsg.msgLen; if ( lieee )
mesg = gaMsg.msg; GRIB_CHECK(my_grib_set_long(gh, "precision",
} datatype == DATATYPE_FLT64 ? 2 : 1), 0);
GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
if ( lieee )
GRIB_CHECK(my_grib_set_long(gh, "precision",
datatype == DATATYPE_FLT64 ? 2 : 1), 0);
}
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