Commit df7d9e2d authored by Uwe Schulzweida's avatar Uwe Schulzweida

Added predefined zonal grid (experimental).

parent f1547440
Pipeline #6773 failed with stages
in 3 minutes and 23 seconds
......@@ -323,6 +323,66 @@ gen_grid_gea(GridDesciption &grid, const char *pline)
}
}
static void
gen_grid_zonal(GridDesciption &grid, const char *pline)
{
if (isdigit((int) *pline))
{
constexpr size_t nextra = 1;
grid.type = GRID_UNSTRUCTURED;
auto nlats = (size_t)atol(pline);
auto nlons = nlats * 2;
const auto gridsize = nlats;
grid.size = gridsize;
grid.xsize = gridsize;
grid.ysize = gridsize;
grid.xvals.resize(gridsize);
grid.yvals.resize(gridsize);
for (size_t i = 0; i < nlats; ++i) grid.xvals[i] = 180.0;
auto dlat = 180.0 / nlats;
auto dlon = 360.0 / nlons;
//printf("dlat %g dlon %g\n", dlat, dlon);
for (size_t i = 0; i < nlats; ++i) grid.yvals[i] = -90.0 + i * dlat + dlat / 2.0;
auto nv = (nlons + 1) * 2;
grid.nvertex = nv;
grid.xbounds.resize(nv * gridsize);
grid.ybounds.resize(nv * gridsize);
std::vector<double> xbounds(nlons + 1), ybounds(nlats + 1);
for (size_t i = 0; i <= nlons; ++i) xbounds[i] = 0.0 + i * dlon;
for (size_t i = 0; i <= nlats; ++i) ybounds[i] = -90.0 + i * dlat;
// for (size_t i = 0; i <= nlons; ++i) printf("lon %zu %g\n", i, xbounds[i]);
// for (size_t i = 0; i <= nlats; ++i) printf("lat %zu %g\n", i, ybounds[i]);
size_t k = 0;
for (size_t j = 0; j < nlats; j++)
{
for (size_t i = nlons; i > 0; i--)
{
grid.xbounds[k] = xbounds[i];
grid.ybounds[k] = ybounds[j + 1];
k++;
}
for (size_t i = 0; i < nextra; i++)
{
grid.xbounds[k] = xbounds[0];
grid.ybounds[k] = ybounds[j + 1];
k++;
}
for (size_t i = 0; i < nlons; i++)
{
grid.xbounds[k] = xbounds[i];
grid.ybounds[k] = ybounds[j];
k++;
}
for (size_t i = 0; i < nextra; i++)
{
grid.xbounds[k] = xbounds[nlons];
grid.ybounds[k] = ybounds[j];
k++;
}
}
}
}
static void
gen_grid_reg2d(GridDesciption &grid, const char *pline)
{
......@@ -447,6 +507,11 @@ gridFromName(const char *gridnameptr)
pline = &gridname[1];
gen_grid_reg2d(grid, pline);
}
else if (gridname[0] == 'z') // z<LAT>; zonal unstructured grid with <LAT> latitudes
{
pline = &gridname[1];
gen_grid_zonal(grid, pline);
}
else if (cdo_cmpstrLenRhs(gridname, "lon=", len)) // lon=<LON>_lat=<LAT>; one gridpoint
{
pline = &gridname[len];
......
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