Commit 55b2062c authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function gridVerifyProj().

parent d5f89159
...@@ -624,9 +624,9 @@ int cdfDefVar(stream_t *streamptr, int varID) ...@@ -624,9 +624,9 @@ int cdfDefVar(stream_t *streamptr, int varID)
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0; char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
if ( gridtype == GRID_SINUSOIDAL ) strcpy(gmapvarname, "sinusoidal"); if ( gridtype == GRID_SINUSOIDAL ) strcpy(gmapvarname, "Sinusoidal");
else if ( gridtype == GRID_LAEA ) strcpy(gmapvarname, "laea"); else if ( gridtype == GRID_LAEA ) strcpy(gmapvarname, "Lambert_AEA");
else if ( gridtype == GRID_LCC2 ) strcpy(gmapvarname, "Lambert_Conformal"); else if ( gridtype == GRID_LCC2 ) strcpy(gmapvarname, "Lambert_CC");
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) strcpy(gmapvarname, "rotated_pole"); else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) strcpy(gmapvarname, "rotated_pole");
else cdf_get_gmapvarname(gridID, gmapvarname); else cdf_get_gmapvarname(gridID, gmapvarname);
......
...@@ -145,6 +145,7 @@ extern "C" { ...@@ -145,6 +145,7 @@ extern "C" {
#define CDI_PROJ_RLL 21 /* Rotated Latitude Longitude */ #define CDI_PROJ_RLL 21 /* Rotated Latitude Longitude */
#define CDI_PROJ_LCC 22 /* Lambert Conformal Conic */ #define CDI_PROJ_LCC 22 /* Lambert Conformal Conic */
#define CDI_PROJ_LAEA 23 /* Lambert Azimuthal Equal Area */ #define CDI_PROJ_LAEA 23 /* Lambert Azimuthal Equal Area */
#define CDI_PROJ_SINU 24 /* Sinusoidal */
/* ZAXIS types */ /* ZAXIS types */
...@@ -724,12 +725,12 @@ void gridDestroy(int gridID); ...@@ -724,12 +725,12 @@ void gridDestroy(int gridID);
/* gridDuplicate: Duplicate a Grid */ /* gridDuplicate: Duplicate a Grid */
int gridDuplicate(int gridID); int gridDuplicate(int gridID);
/* gridDefProj: Define the projection ID of a Grid */
void gridDefProj(int gridID, int projID);
/* gridInqProj: Get the projection ID of a Grid */ /* gridInqProj: Get the projection ID of a Grid */
int gridInqProj(int gridID); int gridInqProj(int gridID);
/* gridDefProjType: Define the projection type */
void gridDefProjType(int gridID, int projtype);
/* gridInqProjType: Get the projection type */ /* gridInqProjType: Get the projection type */
int gridInqProjType(int gridID); int gridInqProjType(int gridID);
......
...@@ -200,8 +200,8 @@ void grid_free(grid_t *gridptr) ...@@ -200,8 +200,8 @@ void grid_free(grid_t *gridptr)
grid_init(gridptr); grid_init(gridptr);
} }
static grid_t * static
gridNewEntry(cdiResH resH) grid_t *gridNewEntry(cdiResH resH)
{ {
grid_t *gridptr = (grid_t*) Malloc(sizeof(grid_t)); grid_t *gridptr = (grid_t*) Malloc(sizeof(grid_t));
grid_init(gridptr); grid_init(gridptr);
...@@ -270,28 +270,31 @@ void gridGetString(char *name, const char *gridstrname, size_t len) ...@@ -270,28 +270,31 @@ void gridGetString(char *name, const char *gridstrname, size_t len)
name[len - 1] = 0; name[len - 1] = 0;
} }
static inline void static inline
gridSetName(char *gridstrname, const char *name) void gridSetName(char *gridstrname, const char *name)
{ {
strncpy(gridstrname, name, CDI_MAX_NAME); strncpy(gridstrname, name, CDI_MAX_NAME);
gridstrname[CDI_MAX_NAME - 1] = 0; gridstrname[CDI_MAX_NAME - 1] = 0;
} }
void
cdiGridTypeInit(grid_t *gridptr, int gridtype, int size) void cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
{ {
gridptr->type = gridtype; gridptr->type = gridtype;
gridptr->size = size; gridptr->size = size;
if ( gridtype == GRID_CURVILINEAR ) gridptr->nvertex = 4;
else if ( gridtype == GRID_UNSTRUCTURED ) gridptr->x.size = size;
switch (gridtype) switch (gridtype)
{ {
case GRID_CURVILINEAR:
gridptr->nvertex = 4;
/* Fall through */
case GRID_LONLAT: case GRID_LONLAT:
case GRID_GAUSSIAN: case GRID_GAUSSIAN:
case GRID_GAUSSIAN_REDUCED: case GRID_GAUSSIAN_REDUCED:
case GRID_TRAJECTORY: case GRID_TRAJECTORY:
case GRID_CURVILINEAR:
case GRID_UNSTRUCTURED:
case GRID_GME:
{ {
if ( gridtype == GRID_TRAJECTORY ) if ( gridtype == GRID_TRAJECTORY )
{ {
...@@ -303,71 +306,36 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size) ...@@ -303,71 +306,36 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "lon"); if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "lon");
if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "lat"); if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "lat");
} }
gridSetName(gridptr->x.longname, "longitude"); gridSetName(gridptr->x.longname, "longitude");
gridSetName(gridptr->y.longname, "latitude"); gridSetName(gridptr->y.longname, "latitude");
/*
if ( gridtype == GRID_CURVILINEAR )
{
gridptr->x.stdname = xystdname_tab[grid_xystdname_grid_latlon][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_grid_latlon][1];
gridDefXunits(gridID, "degrees");
gridDefYunits(gridID, "degrees");
}
else
*/
{
gridptr->x.stdname = xystdname_tab[grid_xystdname_latlon][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_latlon][1];
gridSetName(gridptr->x.units, "degrees_east");
gridSetName(gridptr->y.units, "degrees_north");
}
break;
}
case GRID_UNSTRUCTURED:
gridptr->x.size = size;
/* Fall through */
case GRID_GME:
{
if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "lon");
if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "lat");
gridptr->x.stdname = xystdname_tab[grid_xystdname_latlon][0]; gridptr->x.stdname = xystdname_tab[grid_xystdname_latlon][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_latlon][1]; gridptr->y.stdname = xystdname_tab[grid_xystdname_latlon][1];
gridSetName(gridptr->x.units, "degrees_east"); gridSetName(gridptr->x.units, "degrees_east");
gridSetName(gridptr->y.units, "degrees_north"); gridSetName(gridptr->y.units, "degrees_north");
break; break;
} }
case GRID_GENERIC: case GRID_GENERIC:
case GRID_PROJECTION: case GRID_PROJECTION:
case GRID_LCC2:
case GRID_SINUSOIDAL:
case GRID_LAEA:
{ {
if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "x"); if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "x");
if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "y"); if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "y");
if ( gridtype == GRID_PROJECTION ) if ( gridtype == GRID_PROJECTION )
{ {
gridSetName(gridptr->mapname, "Projection"); gridSetName(gridptr->mapname, "Projection");
} }
/* if ( gridtype != GRID_GENERIC )
strcpy(gridptr->x.stdname, "grid_longitude"); {
strcpy(gridptr->y.stdname, "grid_latitude"); gridptr->x.stdname = xystdname_tab[grid_xystdname_projection][0];
gridptr->x.stdname = xystdname_tab[grid_xystdname_grid_latlon][0]; gridptr->y.stdname = xystdname_tab[grid_xystdname_projection][1];
gridptr->y.stdname = xystdname_tab[grid_xystdname_grid_latlon][1]; gridSetName(gridptr->x.units, "m");
gridDefXunits(gridID, "degrees"); gridSetName(gridptr->y.units, "m");
gridDefYunits(gridID, "degrees"); }
*/
break;
}
case GRID_LCC2:
case GRID_SINUSOIDAL:
case GRID_LAEA:
{
if ( gridptr->x.name[0] == 0 ) gridSetName(gridptr->x.name, "x");
if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "y");
gridptr->x.stdname = xystdname_tab[grid_xystdname_projection][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_projection][1];
gridSetName(gridptr->x.units, "m");
gridSetName(gridptr->y.units, "m");
break; break;
} }
} }
...@@ -1037,6 +1005,22 @@ int gridInqProjType(int gridID) ...@@ -1037,6 +1005,22 @@ int gridInqProjType(int gridID)
return projtype; return projtype;
} }
void gridVerifyProj(int gridID)
{
grid_t *gridptr = gridID2Ptr(gridID);
int projtype = gridInqProjType(gridID);
if ( projtype == CDI_PROJ_RLL )
{
gridptr->x.stdname = xystdname_tab[grid_xystdname_grid_latlon][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_grid_latlon][1];
gridSetName(gridptr->x.units, "degrees");
gridSetName(gridptr->y.units, "degrees");
}
}
/* /*
@Function gridInqType @Function gridInqType
@Title Get the type of a Grid @Title Get the type of a Grid
......
...@@ -146,6 +146,8 @@ extern const struct gridVirtTable cdiGridVtable; ...@@ -146,6 +146,8 @@ extern const struct gridVirtTable cdiGridVtable;
unsigned cdiGridCount(void); unsigned cdiGridCount(void);
void gridVerifyProj(int gridID);
const double *gridInqXvalsPtr(int gridID); const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID); const double *gridInqYvalsPtr(int gridID);
......
...@@ -2725,6 +2725,7 @@ void cdf_define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2725,6 +2725,7 @@ void cdf_define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
const char *gmapname = ncvars[gmapvarid].name; const char *gmapname = ncvars[gmapvarid].name;
cdf_read_mapping_atts(ncid, gmapvarid, projID, gmapname); cdf_read_mapping_atts(ncid, gmapvarid, projID, gmapname);
cdiGridDefKeyStr(projID, CDI_KEY_MAPNAME, (int)(strlen(gmapname)+1), gmapname); cdiGridDefKeyStr(projID, CDI_KEY_MAPNAME, (int)(strlen(gmapname)+1), gmapname);
gridVerifyProj(projID);
} }
if ( grid->type == GRID_UNSTRUCTURED && gridfile[0] != 0 ) if ( grid->type == GRID_UNSTRUCTURED && gridfile[0] != 0 )
......
...@@ -1961,7 +1961,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID) ...@@ -1961,7 +1961,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
if ( gridInqType(gridID) == GRID_SINUSOIDAL ) if ( gridInqType(gridID) == GRID_SINUSOIDAL )
{ {
static const char varname[] = "sinusoidal"; static const char varname[] = "Sinusoidal";
static const char mapname[] = "sinusoidal"; static const char mapname[] = "sinusoidal";
cdf_redef(fileID); cdf_redef(fileID);
...@@ -1980,7 +1980,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID) ...@@ -1980,7 +1980,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
} }
else if ( gridInqType(gridID) == GRID_LAEA ) else if ( gridInqType(gridID) == GRID_LAEA )
{ {
static const char varname[] = "laea"; static const char varname[] = "Lambert_AEA";
static const char mapname[] = "lambert_azimuthal_equal_area"; static const char mapname[] = "lambert_azimuthal_equal_area";
cdf_redef(fileID); cdf_redef(fileID);
...@@ -2002,7 +2002,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID) ...@@ -2002,7 +2002,7 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
} }
else if ( gridInqType(gridID) == GRID_LCC2 ) else if ( gridInqType(gridID) == GRID_LCC2 )
{ {
static const char varname[] = "Lambert_Conformal"; static const char varname[] = "Lambert_CC";
static const char mapname[] = "lambert_conformal_conic"; static const char mapname[] = "lambert_conformal_conic";
cdf_redef(fileID); cdf_redef(fileID);
......
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