Commit 532dbd4f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Use grid_mapping attribute for GRID_PROJECTION.

parent d2002765
......@@ -567,8 +567,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_put_att_int(fileID, ncvarid, "table", NC_INT, 1, &tablenum);
}
char coordinates[CDI_MAX_NAME];
coordinates[0] = 0;
char coordinates[CDI_MAX_NAME]; coordinates[0] = 0;
if ( zaxis_is_scalar )
{
......@@ -589,33 +588,26 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_put_att_text(fileID, ncvarid, "grid_type", len, gridNamePtr(gridtype));
}
if ( gridIsRotated(gridID) )
{
char mapping[] = "rotated_pole";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
if ( gridtype == GRID_PROJECTION )
{
char mapping[] = "dummy";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
else if ( gridtype == GRID_SINUSOIDAL )
{
char mapping[] = "sinusoidal";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
else if ( gridtype == GRID_LAEA )
{
char mapping[] = "laea";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
else if ( gridtype == GRID_LCC2 )
if ( gridtype == GRID_SINUSOIDAL ) strcpy(gmapvarname, "sinusoidal");
else if ( gridtype == GRID_LAEA ) strcpy(gmapvarname, "laea");
else if ( gridtype == GRID_LCC2 ) strcpy(gmapvarname, "Lambert_Conformal");
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) strcpy(gmapvarname, "rotated_pole");
else
{
char mapping[] = "Lambert_Conformal";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_MAPPING, CDI_MAX_NAME, mapping);
if ( mapping[0] )
{
cdiGridInqKeyStr(gridID, CDI_KEY_MAPNAME, CDI_MAX_NAME, gmapvarname);
if ( !gmapvarname[0] ) strcpy(gmapvarname, "dummy");
}
}
else if ( gridtype == GRID_TRAJECTORY )
if ( gmapvarname[0] ) cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(gmapvarname), gmapvarname);
if ( gridtype == GRID_TRAJECTORY )
{
cdf_put_att_text(fileID, ncvarid, "coordinates", 9, "tlon tlat" );
}
......@@ -1286,3 +1278,13 @@ void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nm
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
......@@ -2271,8 +2271,8 @@ bool cdf_read_coordinates(struct cdfLazyGrid *restrict lazyGrid, ncvar_t *ncvar,
int gmapvarid = ncvar->gmapid;
if ( gmapvarid != UNDEFID && cdfCheckAttText(ncvar->ncid, gmapvarid, "grid_mapping_name") )
{
enum {attstringlen = 256}; char attstring[attstringlen];
cdfGetAttText(ncvar->ncid, gmapvarid, "grid_mapping_name", attstringlen, attstring);
char attstring[CDI_MAX_NAME];
cdfGetAttText(ncvar->ncid, gmapvarid, "grid_mapping_name", CDI_MAX_NAME, attstring);
if ( strcmp(attstring, "latitude_longitude") == 0 ) gridtype = ncvar->gridtype;
}
}
......@@ -2435,8 +2435,8 @@ void cdf_read_mapping_atts(int ncid, int gmapvarid, int projID, const char *varn
{
if ( cdfCheckAttText(ncid, gmapvarid, "grid_mapping_name") )
{
enum {attstringlen = 256}; char attstring[attstringlen];
cdfGetAttText(ncid, gmapvarid, "grid_mapping_name", attstringlen, attstring);
char attstring[CDI_MAX_NAME];
cdfGetAttText(ncid, gmapvarid, "grid_mapping_name", CDI_MAX_NAME, attstring);
cdiGridDefKeyStr(projID, CDI_KEY_MAPPING, (int)(strlen(attstring)+1), attstring);
}
else
......
......@@ -1969,18 +1969,24 @@ void cdfDefPole(stream_t *streamptr, int gridID)
static
void cdf_def_mapping(stream_t *streamptr, int gridID)
{
int fileID = streamptr->fileID;
static const char varname[] = "dummy";
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_MAPPING, CDI_MAX_NAME, mapping);
if ( mapping[0] )
{
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_MAPNAME, CDI_MAX_NAME, gmapvarname);
if ( !gmapvarname[0] ) strcpy(gmapvarname, "dummy");
cdf_redef(fileID);
int fileID = streamptr->fileID;
cdf_redef(fileID);
int ncvarid;
int ncerrcode = nc_def_var(fileID, varname, (nc_type) NC_CHAR, 0, NULL, &ncvarid);
if ( ncerrcode == NC_NOERR )
cdfDefineAttributes(gridID, CDI_GLOBAL, fileID, ncvarid);
int ncvarid;
int ncerrcode = nc_def_var(fileID, gmapvarname, (nc_type) NC_CHAR, 0, NULL, &ncvarid);
if ( ncerrcode == NC_NOERR )
cdfDefineAttributes(gridID, CDI_GLOBAL, fileID, ncvarid);
cdf_enddef(fileID);
cdf_enddef(fileID);
}
}
static
......@@ -2116,7 +2122,7 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
if ( gridInqXsize(gridID) > 0 ) cdfDefXaxis(streamptr, gridID, ndims);
if ( gridInqYsize(gridID) > 0 ) cdfDefYaxis(streamptr, gridID, ndims);
if ( gridtype == GRID_PROJECTION ) cdf_def_mapping(streamptr, gridID);
cdf_def_mapping(streamptr, gridID);
}
if ( gridIsRotated(gridID) ) cdfDefPole(streamptr, gridID);
......@@ -2210,6 +2216,7 @@ void cdfDefVars(stream_t *streamptr)
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
......
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