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

remap: added support for grid_mapping attribute proj4_params (bug fix).

parent 2440d917
......@@ -3,6 +3,10 @@
* Using CDI library version 1.9.1
* Version 1.9.1 release
2017-09-16 Uwe Schulzweida
* remap: added support for grid_mapping attribute proj4_params (bug fix)
2017-09-11 Uwe Schulzweida
* ap2pl: added support for input data on half levels
......
......@@ -499,8 +499,10 @@ int set_remapgrids(int filetype, int vlistID, int ngrids, std::vector<bool>& rem
int gridID = vlistGrid(vlistID, index);
int gridtype = gridInqType(gridID);
int projtype = (gridtype == GRID_PROJECTION) ? gridInqProjType(gridID) : -1;
bool lproj4param = (gridtype == GRID_PROJECTION) && grid_has_proj4param(gridID);
if ( gridtype != GRID_LONLAT &&
!lproj4param &&
projtype != CDI_PROJ_RLL &&
projtype != CDI_PROJ_LAEA &&
projtype != CDI_PROJ_SINU &&
......@@ -513,9 +515,9 @@ int set_remapgrids(int filetype, int vlistID, int ngrids, std::vector<bool>& rem
if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
if ( !cdoRegulargrid && filetype == CDI_FILETYPE_GRB )
cdoAbort("Unsupported grid type: %s, use CDO option -R to convert reduced to regular grid!", gridNamePtr(gridtype));
cdoAbort("Unsupported grid type: %s, use CDO option -R to convert reduced to regular Gaussian grid!", gridNamePtr(gridtype));
else
cdoAbort("Unsupported grid type: %s, use CDO operator -setgridtype,regular to convert reduced to regular grid!", gridNamePtr(gridtype));
cdoAbort("Unsupported grid type: %s, use CDO operator -setgridtype,regular to convert reduced to regular Gaussian grid!", gridNamePtr(gridtype));
}
else if ( gridtype == GRID_GENERIC && gridInqSize(gridID) <= 2 )
{
......@@ -523,13 +525,15 @@ int set_remapgrids(int filetype, int vlistID, int ngrids, std::vector<bool>& rem
}
else
{
int nvars = vlistNvars(vlistID);
int varID;
for ( varID = 0; varID < nvars; ++varID )
if ( gridID == vlistInqVarGrid(vlistID, varID) ) break;
char varname[CDI_MAX_NAME];
vlistInqVarName(vlistID, varID, varname);
cdoAbort("Variable %s has an unsupported %s grid!", varname, gridNamePtr(gridtype));
int nvars = vlistNvars(vlistID);
for ( int varID = 0; varID < nvars; ++varID )
if ( gridID == vlistInqVarGrid(vlistID, varID) )
{
vlistInqVarName(vlistID, varID, varname);
break;
}
cdoAbort("Unsupported %s coordinates (Variable: %s)!", gridNamePtr(gridtype), varname);
}
}
}
......
......@@ -814,6 +814,47 @@ bool check_range(long n, double *vals, double valid_min, double valid_max)
}
bool grid_has_proj4param(int gridID)
{
bool has_proj4param = false;
int gridtype = gridInqType(gridID);
if ( gridtype == GRID_PROJECTION )
{
int atttype, attlen, atttxtlen = 0;
char *atttxt = NULL;
char attname[CDI_MAX_NAME+1];
int natts;
cdiInqNatts(gridID, CDI_GLOBAL, &natts);
for ( int iatt = 0; iatt < natts; ++iatt )
{
cdiInqAtt(gridID, CDI_GLOBAL, iatt, attname, &atttype, &attlen);
if ( atttype == CDI_DATATYPE_TXT )
{
if ( attlen > atttxtlen )
{
atttxt = (char*) Realloc(atttxt, (attlen+1));
atttxtlen = attlen;
}
cdiInqAttTxt(gridID, CDI_GLOBAL, attname, attlen, atttxt);
atttxt[attlen] = 0;
if ( strcmp(attname, "proj4_params") == 0 )
{
has_proj4param = true;
break;
}
}
}
if ( atttxt ) Free(atttxt);
}
return has_proj4param;
}
static
char *grid_get_proj4param(int gridID)
{
char *proj4param = NULL;
......
......@@ -94,6 +94,8 @@ void usvs_to_uv(double us, double vs, double phi, double rla,
void cdo_print_grid(int gridID, int opt);
bool grid_has_proj4param(int gridID);
// Define a de-staggered grid for U and V
int cdo_define_destagered_grid(int gridID_u_stag, int gridID_v_stag, double *destagGridOffsets);
......
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