Commit 1d8eb8c4 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

grid_from_name::gen_grid_reg2d: set delimiter to x.

parent 6fe0fa84
......@@ -213,6 +213,72 @@ gen_grid_lonlat(GridDesciption &grid, const char *pline, double inc, double lon1
}
}
static void
gen_grid_gme(GridDesciption &grid, const char *pline)
{
if (isdigit((int) *pline))
{
char *endptr = (char *) pline;
const long ni = strtol(pline, &endptr, 10);
if (*endptr == 0)
{
grid.type = GRID_GME;
grid.ni = ni;
grid.nd = 10;
gme_factorni(grid.ni, &grid.ni2, &grid.ni3);
grid.size = (grid.ni + 1) * (grid.ni + 1) * 10;
}
}
}
static void
gen_grid_reg2d(GridDesciption &grid, const char *pline)
{
if (isdigit((int) *pline))
{
grid.type = GRID_LONLAT;
grid.xsize = atoi(pline);
while (isdigit((int) *pline)) pline++;
if (*pline == 'x' || *pline == '/' || *pline == '_') pline++;
else
{
grid.type = CDI_UNDEFID;
return;
}
grid.ysize = atoi(pline);
while (isdigit((int) *pline)) pline++;
grid.def_xfirst = true;
grid.def_yfirst = true;
}
}
static void
gen_grid_point(GridDesciption &grid, const char *pline)
{
if (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-')
{
grid.type = GRID_LONLAT;
grid.xsize = 1;
grid.ysize = 1;
grid.xvals.resize(1);
grid.yvals.resize(1);
grid.xvals[0] = atof(pline);
while (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-') pline++;
if (*pline == '_') pline++;
if (strncmp(pline, "lat=", 4) != 0)
{
grid.type = CDI_UNDEFID;
return;
}
pline += 4;
if (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-')
grid.yvals[0] = atof(pline);
else
grid.type = CDI_UNDEFID;
}
}
int
gridFromName(const char *gridnameptr)
{
......@@ -272,75 +338,25 @@ gridFromName(const char *gridnameptr)
}
}
}
else if (gridname[0] == 'r') // r<LON>x<LAT>
else if (gridname[0] == 'r') // r<LON>x<LAT>; regular 2D grid
{
pline = &gridname[1];
if (isdigit((int) *pline))
{
grid.type = GRID_LONLAT;
grid.xsize = atoi(pline);
while (isdigit((int) *pline)) pline++;
pline++;
grid.ysize = atoi(pline);
while (isdigit((int) *pline)) pline++;
grid.def_xfirst = true;
grid.def_yfirst = true;
}
gen_grid_reg2d(grid, pline);
}
else if (gridname[0] == 'l' && gridname[1] == 'o' && gridname[2] == 'n' && gridname[3] == '=') // lon=<LON>_lat=<LAT>
else if (cmpstrlen(gridname, "lon=", len) == 0) // lon=<LON>_lat=<LAT>; one gridpoint
{
// only one gridpoint
pline = &gridname[4];
if (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-')
{
grid.type = GRID_LONLAT;
grid.xsize = 1;
grid.ysize = 1;
grid.xvals.resize(1);
grid.yvals.resize(1);
grid.xvals[0] = atof(pline);
while (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-') pline++;
if (*pline == '_') pline++;
if (!(pline[0] == 'l' && pline[1] == 'a' && pline[2] == 't' && pline[3] == '=')) return CDI_UNDEFID;
pline += 4;
if (isdigit((int) *pline) || ispunct((int) *pline) || *pline == '-')
grid.yvals[0] = atof(pline);
else
return CDI_UNDEFID;
}
pline = &gridname[len];
gen_grid_point(grid, pline);
}
else if (gridname[0] == 'g' && gridname[1] == 'm' && gridname[2] == 'e') // gme<NI>
{
pline = &gridname[3];
if (isdigit((int) *pline))
{
const long ni = strtol(pline, &endptr, 10);
if (*endptr == 0)
{
grid.type = GRID_GME;
grid.ni = ni;
grid.nd = 10;
gme_factorni(grid.ni, &grid.ni2, &grid.ni3);
grid.size = (grid.ni + 1) * (grid.ni + 1) * 10;
}
}
gen_grid_gme(grid, pline);
}
else if (gridname[0] == 'n' && gridname[1] == 'i') // ni<NI>
{
pline = &gridname[2];
if (isdigit((int) *pline))
{
const long ni = strtol(pline, &endptr, 10);
if (*endptr == 0)
{
grid.type = GRID_GME;
grid.ni = ni;
grid.nd = 10;
gme_factorni(grid.ni, &grid.ni2, &grid.ni3);
grid.size = (grid.ni + 1) * (grid.ni + 1) * 10;
}
}
gen_grid_gme(grid, pline);
}
else if (gridname[0] == 'n') // N<xxx>
{
......
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