Commit 5c50743b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added struct grid_rll_t.

parent 3aa1515b
......@@ -753,14 +753,18 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
grid->isRotated = FALSE;
if ( gribapiGetIsRotated(gh) )
{
double xpole, ypole, angle;
grid->isRotated = TRUE;
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "latitudeOfSouthernPoleInDegrees", &grid->ypole);
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "longitudeOfSouthernPoleInDegrees", &grid->xpole);
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "angleOfRotation", &grid->angle);
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "latitudeOfSouthernPoleInDegrees", &ypole);
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "longitudeOfSouthernPoleInDegrees", &xpole);
FAIL_ON_GRIB_ERROR(grib_get_double, gh, "angleOfRotation", &angle);
/* change from south to north pole */
if ( fabs(grid->ypole) > 0 ) grid->ypole = -grid->ypole;
grid->xpole = grid->xpole - 180;
if ( fabs(grid->angle) > 0 ) grid->angle = -grid->angle;
if ( fabs(ypole) > 0 ) ypole = -ypole;
xpole = xpole - 180;
if ( fabs(angle) > 0 ) angle = -angle;
grid->rll.xpole = xpole;
grid->rll.ypole = ypole;
grid->rll.angle = angle;
}
grid->type = gridtype;
......
......@@ -137,6 +137,11 @@ void grid_init(grid_t *gridptr)
gridptr->gme.ni2 = 0;
gridptr->gme.ni3 = 0;
gridptr->isRotated = FALSE;
gridptr->rll.xpole = 0.0;
gridptr->rll.ypole = 0.0;
gridptr->rll.angle = 0.0;
gridptr->trunc = 0;
gridptr->nvertex = 0;
gridptr->number = 0;
......@@ -150,10 +155,7 @@ void grid_init(grid_t *gridptr)
gridptr->xdef = 0;
gridptr->ydef = 0;
gridptr->isCyclic = CDI_UNDEFID;
gridptr->isRotated = FALSE;
gridptr->xpole = 0.0;
gridptr->ypole = 0.0;
gridptr->angle = 0.0;
gridptr->lcomplex = false;
gridptr->hasdims = true;
gridptr->x.dimname[0] = 0;
......@@ -1826,7 +1828,7 @@ double gridInqXpole(int gridID)
// Xpole -> grid_north_pole_longitude
grid_t *gridptr = gridID2Ptr(gridID);
return gridptr->xpole;
return gridptr->rll.xpole;
}
/*
......@@ -1847,10 +1849,10 @@ void gridDefXpole(int gridID, double xpole)
if ( gridptr->x.stdname && memcmp(gridptr->x.stdname, "grid", 4) != 0 )
gridptr->x.stdname = xystdname_tab[grid_xystdname_grid_latlon][0];
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->xpole, xpole) )
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->rll.xpole, xpole) )
{
gridptr->isRotated = TRUE;
gridptr->xpole = xpole;
gridptr->rll.xpole = xpole;
gridMark4Update(gridID);
}
}
......@@ -1870,7 +1872,7 @@ double gridInqYpole(int gridID)
// Ypole -> grid_north_pole_latitude
grid_t *gridptr = gridID2Ptr(gridID);
return gridptr->ypole;
return gridptr->rll.ypole;
}
/*
......@@ -1891,10 +1893,10 @@ void gridDefYpole(int gridID, double ypole)
if ( gridptr->y.stdname && memcmp(gridptr->y.stdname, "grid", 4) != 0 )
gridptr->y.stdname = xystdname_tab[grid_xystdname_grid_latlon][1];
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->ypole, ypole) )
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->rll.ypole, ypole) )
{
gridptr->isRotated = TRUE;
gridptr->ypole = ypole;
gridptr->rll.ypole = ypole;
gridMark4Update(gridID);
}
}
......@@ -1914,7 +1916,7 @@ double gridInqAngle(int gridID)
// Angle -> north_pole_grid_longitude
grid_t *gridptr = gridID2Ptr(gridID);
return gridptr->angle;
return gridptr->rll.angle;
}
/*
......@@ -1932,10 +1934,10 @@ void gridDefAngle(int gridID, double angle)
// Angle -> north_pole_grid_longitude
grid_t *gridptr = gridID2Ptr(gridID);
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->angle, angle) )
if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->rll.angle, angle) )
{
gridptr->isRotated = TRUE;
gridptr->angle = angle;
gridptr->rll.angle = angle;
gridMark4Update(gridID);
}
}
......@@ -2480,9 +2482,9 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
if ( IS_NOT_EQUAL(g1->laea.lon_0 , g2->laea.lon_0) ) return differ;
if ( IS_NOT_EQUAL(g1->laea.lat_0 , g2->laea.lat_0) ) return differ;
if ( IS_NOT_EQUAL(g1->laea.a , g2->laea.a) ) return differ;
if ( IS_NOT_EQUAL(g1->xpole , g2->xpole) ) return differ;
if ( IS_NOT_EQUAL(g1->ypole , g2->ypole) ) return differ;
if ( IS_NOT_EQUAL(g1->angle , g2->angle) ) return differ;
if ( IS_NOT_EQUAL(g1->rll.xpole , g2->rll.xpole) ) return differ;
if ( IS_NOT_EQUAL(g1->rll.ypole , g2->rll.ypole) ) return differ;
if ( IS_NOT_EQUAL(g1->rll.angle , g2->rll.angle) ) return differ;
const double *restrict g1_xvals = g1->vtable->inqXValsPtr(g1),
*restrict g2_xvals = g2->vtable->inqXValsPtr(g2);
......@@ -2676,9 +2678,9 @@ void gridComplete(grid_t *grid)
if ( grid->x.units[0] == 0 ) gridDefXunits(gridID, "degrees");
if ( grid->y.units[0] == 0 ) gridDefYunits(gridID, "degrees");
gridDefXpole(gridID, grid->xpole);
gridDefYpole(gridID, grid->ypole);
gridDefAngle(gridID, grid->angle);
gridDefXpole(gridID, grid->rll.xpole);
gridDefYpole(gridID, grid->rll.ypole);
gridDefAngle(gridID, grid->rll.angle);
}
switch (gridtype)
......@@ -2824,9 +2826,9 @@ int gridGenerate(const grid_t *grid)
gridptr->ylast = grid->ylast;
gridptr->yinc = grid->yinc;
gridptr->isRotated = grid->isRotated;
gridptr->xpole = grid->xpole;
gridptr->ypole = grid->ypole;
gridptr->angle = grid->angle;
gridptr->rll.xpole = grid->rll.xpole;
gridptr->rll.ypole = grid->rll.ypole;
gridptr->rll.angle = grid->rll.angle;
if ( valdef_group1 && grid->area)
gridDefArea(gridID, grid->area);
gridptr->laea.a = grid->laea.a;
......@@ -3538,9 +3540,9 @@ void gridPrintKernel(grid_t *gridptr, int index, int opt, FILE *fp)
if ( gridptr->isRotated )
{
if ( xsize > 0 ) fprintf(fp, "xnpole = %.*g\n", dig, gridptr->xpole);
if ( ysize > 0 ) fprintf(fp, "ynpole = %.*g\n", dig, gridptr->ypole);
if ( IS_NOT_EQUAL(gridptr->angle, 0) ) fprintf(fp, "angle = %.*g\n", dig, gridptr->angle);
if ( xsize > 0 ) fprintf(fp, "xnpole = %.*g\n", dig, gridptr->rll.xpole);
if ( ysize > 0 ) fprintf(fp, "ynpole = %.*g\n", dig, gridptr->rll.ypole);
if ( IS_NOT_EQUAL(gridptr->rll.angle, 0) ) fprintf(fp, "angle = %.*g\n", dig, gridptr->rll.angle);
}
if ( xvals )
......@@ -4433,9 +4435,9 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
gridP->laea.lon_0 = doubleBuffer[18];
gridP->laea.lat_0 = doubleBuffer[19];
gridP->laea.a = doubleBuffer[20];
gridP->xpole = doubleBuffer[21];
gridP->ypole = doubleBuffer[22];
gridP->angle = doubleBuffer[23];
gridP->rll.xpole = doubleBuffer[21];
gridP->rll.ypole = doubleBuffer[22];
gridP->rll.angle = doubleBuffer[23];
}
int irregular = gridP->type == GRID_UNSTRUCTURED
......@@ -4639,9 +4641,9 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
doubleBuffer[18] = gridP->laea.lon_0;
doubleBuffer[19] = gridP->laea.lat_0;
doubleBuffer[20] = gridP->laea.a;
doubleBuffer[21] = gridP->xpole;
doubleBuffer[22] = gridP->ypole;
doubleBuffer[23] = gridP->angle;
doubleBuffer[21] = gridP->rll.xpole;
doubleBuffer[22] = gridP->rll.ypole;
doubleBuffer[23] = gridP->rll.angle;
serializePack(doubleBuffer, gridNdouble, DATATYPE_FLT64,
packBuffer, packBufferSize, packBufferPos, context);
......
......@@ -93,6 +93,11 @@ struct grid_gme_t {
int nd, ni, ni2, ni3; /* parameter for GRID_GME */
};
// Rotated LonLat
struct grid_rll_t {
double xpole, ypole, angle; /* rotated north pole */
};
struct grid_t {
int self;
int type; /* grid type */
......@@ -108,7 +113,7 @@ struct grid_t {
struct grid_lcc2_t lcc2;
struct grid_laea_t laea;
struct grid_gme_t gme;
double xpole, ypole, angle; /* rotated north pole */
struct grid_rll_t rll;
short isCyclic; /* TRUE for global cyclic grids */
short isRotated; /* TRUE for rotated grids */
short xdef; /* 0: undefined 1:xvals 2:x0+xinc */
......@@ -136,8 +141,7 @@ struct grid_t {
void grid_init(grid_t *gridptr);
void
cdiGridTypeInit(grid_t *gridptr, int gridtype, int size);
void cdiGridTypeInit(grid_t *gridptr, int gridtype, int size);
void grid_free(grid_t *gridptr);
grid_t *gridID2Ptr(int gridID);
extern const struct gridVirtTable cdiGridVtable;
......
......@@ -2522,15 +2522,15 @@ void cdf_set_proj_atts(int ncid, int gmapvarid, grid_t *grid)
}
else if ( strcmp(attname, "grid_north_pole_latitude") == 0 )
{
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->ypole);
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->rll.ypole);
}
else if ( strcmp(attname, "grid_north_pole_longitude") == 0 )
{
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->xpole);
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->rll.xpole);
}
else if ( strcmp(attname, "north_pole_grid_longitude") == 0 )
{
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->angle);
cdfGetAttDouble(ncid, gmapvarid, attname, 1, &grid->rll.angle);
}
}
}
......
......@@ -337,9 +337,9 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, double *fsec2, int *isec4,
if ( cgribexGetIsRotated(isec2) )
{
grid->isRotated = TRUE;
grid->ypole = - ISEC2_LatSP*0.001;
grid->xpole = ISEC2_LonSP*0.001 - 180;
grid->angle = - FSEC2_RotAngle;
grid->rll.ypole = - ISEC2_LatSP*0.001;
grid->rll.xpole = ISEC2_LonSP*0.001 - 180;
grid->rll.angle = - FSEC2_RotAngle;
}
grid->type = gridtype;
......
......@@ -710,9 +710,9 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
if ( IEG_G_GridType(gdb) == 10 )
{
grid->isRotated = TRUE;
grid->ypole = - IEG_G_LatSP(gdb) * resfac;
grid->xpole = IEG_G_LonSP(gdb) * resfac - 180;
grid->angle = 0;
grid->rll.ypole = - IEG_G_LatSP(gdb) * resfac;
grid->rll.xpole = IEG_G_LonSP(gdb) * resfac - 180;
grid->rll.angle = 0;
}
struct addIfNewRes gridAdded = cdiVlistAddGridIfNew(vlistID, grid, 0);
......
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