From ff4790d3bbbbd833641f1bc5d746e89895d48636 Mon Sep 17 00:00:00 2001 From: John Clyne Date: Tue, 22 Feb 2022 13:20:04 -0700 Subject: [PATCH 1/2] Fixed #3046 - Failures converting data to VDC format --- apps/cfvdccreate/cfvdccreate.cpp | 2 ++ lib/vdc/VDC.cpp | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/cfvdccreate/cfvdccreate.cpp b/apps/cfvdccreate/cfvdccreate.cpp index ccca162382..f67b3bcf81 100644 --- a/apps/cfvdccreate/cfvdccreate.cpp +++ b/apps/cfvdccreate/cfvdccreate.cpp @@ -272,6 +272,8 @@ int main(int argc, char **argv) if (rc < 0) return (1); for (int i = 0; i < datanames.size(); i++) { + if (find(coordnames.begin(), coordnames.end(), datanames[i])!=coordnames.end()) continue; + DC::DataVar dvar; dccf.GetDataVarInfo(datanames[i], dvar); diff --git a/lib/vdc/VDC.cpp b/lib/vdc/VDC.cpp index 42ee7f0926..830a21d3a9 100644 --- a/lib/vdc/VDC.cpp +++ b/lib/vdc/VDC.cpp @@ -365,12 +365,13 @@ int VDC::DefineCoordVar(string varname, vector dim_names, string time_di return (-1); } - if (_mode == A) { - if (_coordVars.find(varname) != _coordVars.end()) { - SetErrMsg("Variable \"%s\" already defined", varname.c_str()); - return (-1); - } - } + // No dulicates. Overwrite previous definition + // + auto ditr = _dataVars.find(varname); + if (ditr != _dataVars.end()) _dataVars.erase(ditr); + + auto citr = _coordVars.find(varname); + if (citr != _coordVars.end()) _coordVars.erase(citr); if (axis == 3 && units.empty()) units = "seconds"; @@ -448,12 +449,13 @@ int VDC::_DefineDataVar(string varname, vector dim_names, vector return (-1); } - if (_mode == A) { - if (_dataVars.find(varname) != _dataVars.end()) { - SetErrMsg("Variable \"%s\" already defined", varname.c_str()); - return (-1); - } - } + // No dulicates. Overwrite previous definition + // + auto ditr = _dataVars.find(varname); + if (ditr != _dataVars.end()) _dataVars.erase(ditr); + + auto citr = _coordVars.find(varname); + if (citr != _coordVars.end()) _coordVars.erase(citr); int rc = _DefineImplicitCoordVars(dim_names, coord_vars, coord_vars); if (rc < 0) return (-1); From 7d5f29cffb8c47dff48e4da49391e7327ef9b9d8 Mon Sep 17 00:00:00 2001 From: John Clyne Date: Tue, 22 Feb 2022 13:20:35 -0700 Subject: [PATCH 2/2] clang-format pre-push hook --- apps/cfvdccreate/cfvdccreate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/cfvdccreate/cfvdccreate.cpp b/apps/cfvdccreate/cfvdccreate.cpp index f67b3bcf81..b05dc3bb3b 100644 --- a/apps/cfvdccreate/cfvdccreate.cpp +++ b/apps/cfvdccreate/cfvdccreate.cpp @@ -272,7 +272,7 @@ int main(int argc, char **argv) if (rc < 0) return (1); for (int i = 0; i < datanames.size(); i++) { - if (find(coordnames.begin(), coordnames.end(), datanames[i])!=coordnames.end()) continue; + if (find(coordnames.begin(), coordnames.end(), datanames[i]) != coordnames.end()) continue; DC::DataVar dvar; dccf.GetDataVarInfo(datanames[i], dvar);