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

gridToCurvilinear(): Set xy dimname for projection.

parent 3dbd8925
...@@ -38,18 +38,18 @@ ...@@ -38,18 +38,18 @@
static void static void
changeGrid(const int vlistID1, const int vlistID2, const int gridID2) changeGrid(const int vlistID1, const int vlistID2, const int gridID2)
{ {
const auto gridsize2 = gridInqSize(gridID2);
int found = 0; int found = 0;
const auto ngrids = vlistNgrids(vlistID1); const auto ngrids = vlistNgrids(vlistID1);
for (int index = 0; index < ngrids; index++) for (int index = 0; index < ngrids; index++)
{ {
const auto gridID1 = vlistGrid(vlistID1, index); if (gridsize2 == gridInqSize(vlistGrid(vlistID1, index)))
if (gridInqSize(gridID1) == gridInqSize(gridID2))
{ {
vlistChangeGridIndex(vlistID2, index, gridID2); vlistChangeGridIndex(vlistID2, index, gridID2);
found++; found++;
} }
} }
if (!found) cdoWarning("No horizontal grid with %zu cells found!", gridInqSize(gridID2)); if (!found) cdoWarning("No horizontal grid with %zu cells found!", gridsize2);
} }
static void static void
...@@ -57,7 +57,7 @@ setGridtype(const int vlistID1, const int vlistID2, const int gridtype, const st ...@@ -57,7 +57,7 @@ setGridtype(const int vlistID1, const int vlistID2, const int gridtype, const st
const bool lregularnn, const bool ldereference, const bool lbounds, std::vector<int> &grid2_vgpm) const bool lregularnn, const bool ldereference, const bool lbounds, std::vector<int> &grid2_vgpm)
{ {
int gridID2; int gridID2;
bool lrgrid = false; auto lrgrid = false;
const auto ngrids = vlistNgrids(vlistID1); const auto ngrids = vlistNgrids(vlistID1);
for (int index = 0; index < ngrids; index++) for (int index = 0; index < ngrids; index++)
{ {
...@@ -219,13 +219,13 @@ setProjParams(const int vlistID1, const int vlistID2, const char *projparams) ...@@ -219,13 +219,13 @@ setProjParams(const int vlistID1, const int vlistID2, const char *projparams)
static void static void
readAreaFromFile(const std::string &areafile, Varray<double> &gridcellArea) readAreaFromFile(const std::string &areafile, Varray<double> &gridcellArea)
{ {
bool searchName = false; auto searchName = false;
std::string filename = areafile; std::string filename = areafile;
std::string varname; std::string varname;
if (!fileExists(areafile.c_str())) if (!fileExists(areafile.c_str()))
{ {
auto const pos = filename.find_last_of(':'); const auto pos = filename.find_last_of(':');
if (pos > 1 && pos < (filename.size() - 1)) if (pos > 1 && pos < (filename.size() - 1))
{ {
varname = filename.substr(pos + 1); varname = filename.substr(pos + 1);
...@@ -256,9 +256,9 @@ readAreaFromFile(const std::string &areafile, Varray<double> &gridcellArea) ...@@ -256,9 +256,9 @@ readAreaFromFile(const std::string &areafile, Varray<double> &gridcellArea)
} }
const auto nrecs = streamInqTimestep(streamID, 0); const auto nrecs = streamInqTimestep(streamID, 0);
int varID, levelID;
for (int recID = 0; recID < nrecs; ++recID) for (int recID = 0; recID < nrecs; ++recID)
{ {
int varID, levelID;
streamInqRecord(streamID, &varID, &levelID); streamInqRecord(streamID, &varID, &levelID);
if (varID == svarID) if (varID == svarID)
{ {
......
...@@ -113,7 +113,6 @@ grid_print_attributes(FILE *fp, int gridID) ...@@ -113,7 +113,6 @@ grid_print_attributes(FILE *fp, int gridID)
for (int iatt = 0; iatt < natts; ++iatt) for (int iatt = 0; iatt < natts; ++iatt)
{ {
cdiInqAtt(cdiID, varID, iatt, attname, &atttype, &attlen); cdiInqAtt(cdiID, varID, iatt, attname, &atttype, &attlen);
if (attlen == 0) continue; if (attlen == 0) continue;
if (cdo_cmpstr(attname, "grid_mapping_name")) continue; if (cdo_cmpstr(attname, "grid_mapping_name")) continue;
......
...@@ -967,6 +967,21 @@ gridToCurvilinear(int gridID1, int lbounds) ...@@ -967,6 +967,21 @@ gridToCurvilinear(int gridID1, int lbounds)
if (lprojection) check_units("x", xunits); if (lprojection) check_units("x", xunits);
if (lprojection) check_units("y", yunits); if (lprojection) check_units("y", yunits);
if (lprojection || projection == Projection::proj_params)
{
char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME];
length = CDI_MAX_NAME;
cdiInqKeyString(gridID1, CDI_XAXIS, CDI_KEY_NAME, xname, &length);
length = CDI_MAX_NAME;
cdiInqKeyString(gridID1, CDI_YAXIS, CDI_KEY_NAME, yname, &length);
if (xname[0] && yname[0])
{
cdiDefKeyString(gridID2, CDI_XAXIS, CDI_KEY_DIMNAME, xname);
cdiDefKeyString(gridID2, CDI_YAXIS, CDI_KEY_DIMNAME, yname);
}
}
const double xscale = (xunits[0] == 'k' && xunits[1] == 'm') ? 1000 : 1; const double xscale = (xunits[0] == 'k' && xunits[1] == 'm') ? 1000 : 1;
const double yscale = (yunits[0] == 'k' && yunits[1] == 'm') ? 1000 : 1; const double yscale = (yunits[0] == 'k' && yunits[1] == 'm') ? 1000 : 1;
......
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