[MOAB-dev] commit/MOAB: danwu: 1) Renamed dimVals to dimLens in ReadNC. Suppose a netCDF dimension has a length N, using dimVals could be confusing with the N values stored for that dimension. Similarly, renamed __DIM_VALUES tag to __DIM_LENS.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Aug 30 16:03:19 CDT 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/a1e8fba86da1/
Changeset:   a1e8fba86da1
Branch:      master
User:        danwu
Date:        2013-08-30 22:53:12
Summary:     1) Renamed dimVals to dimLens in ReadNC. Suppose a netCDF dimension has a length N, using dimVals could be confusing with the N values stored for that dimension. Similarly, renamed __DIM_VALUES tag to __DIM_LENS.
2) In init_mesh_vals() of NCHelperEuler and NCHelperFV, created __<dim_name>_LOC_VALS tags for spatial dimensions like lon or lat, as specified in Table 5 of metadata_info document.

Affected #:  7 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index b013472..c3b6b8b 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -57,7 +57,7 @@ NCHelper* NCHelper::get_nc_helper(ReadNC* readNC, int fileId, const FileOptions&
 ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums) {
   Interface*& mbImpl = _readNC->mbImpl;
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::AttData>& globalAtts = _readNC->globalAtts;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
   DebugOutput& dbgOut = _readNC->dbgOut;
@@ -94,7 +94,7 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   tag_name = "__DIM_NAMES";
   std::string dimnames;
   unsigned int dimNamesSz = dimNames.size();
-  for (unsigned int i = 0; i != dimNamesSz; ++i) {
+  for (unsigned int i = 0; i != dimNamesSz; i++) {
     dimnames.append(dimNames[i]);
     dimnames.push_back('\0');
   }
@@ -107,16 +107,15 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
-  // <__DIM_VALUES>
-  Tag dimValsTag = 0;
-  tag_name = "__DIM_VALUES";
-  int dimValsSz = (int)dimVals.size();
-
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, dimValsTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __DIM_VALUES tag.");
-  ptr = &(dimVals[0]);
-  rval = mbImpl->tag_set_by_ptr(dimValsTag, &_fileSet, 1, &ptr, &dimValsSz);
-  ERRORR(rval, "Trouble setting data for __DIM_VALUES tag.");
+  // <__DIM_LENS>
+  Tag dimLensTag = 0;
+  tag_name = "__DIM_LENS";
+  int dimLensSz = dimLens.size();
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, dimLensTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
+  ERRORR(rval, "Trouble creating __DIM_LENS tag.");
+  ptr = &(dimLens[0]);
+  rval = mbImpl->tag_set_by_ptr(dimLensTag, &_fileSet, 1, &ptr, &dimLensSz);
+  ERRORR(rval, "Trouble setting data for __DIM_LENS tag.");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -138,8 +137,8 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
-  // __<dim_name>_LOC_MINMAX
-  for (unsigned int i = 0; i != dimNamesSz; ++i) {
+  // __<dim_name>_LOC_MINMAX (for time)
+  for (unsigned int i = 0; i != dimNamesSz; i++) {
     if (dimNames[i] == "time") {
       std::stringstream ss_tag_name;
       ss_tag_name << "__" << dimNames[i] << "_LOC_MINMAX";
@@ -157,28 +156,28 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     }
   }
 
-  // __<dim_name>_LOC_VALS
-  for (unsigned int i = 0; i != dimNamesSz; ++i) {
-    if (dimNames[i] != "time")
-      continue;
-    std::vector<int> val;
-    if (!tstep_nums.empty())
-      val = tstep_nums;
-    else {
-      val.resize(tVals.size());
-      for (unsigned int j = 0; j != tVals.size(); ++j)
-        val[j] = j;
+  // __<dim_name>_LOC_VALS (for time)
+  for (unsigned int i = 0; i != dimNamesSz; i++) {
+    if (dimNames[i] == "time") {
+      std::vector<int> val;
+      if (!tstep_nums.empty())
+        val = tstep_nums;
+      else {
+        val.resize(tVals.size());
+        for (unsigned int j = 0; j != tVals.size(); j++)
+          val[j] = j;
+      }
+      Tag tagh = 0;
+      std::stringstream ss_tag_name;
+      ss_tag_name << "__" << dimNames[i] << "_LOC_VALS";
+      tag_name = ss_tag_name.str();
+      rval = mbImpl->tag_get_handle(tag_name.c_str(), val.size(), MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
+      ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
+      rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
+      ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
+      if (MB_SUCCESS == rval)
+        dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
     }
-    Tag tagh = 0;
-    std::stringstream ss_tag_name;
-    ss_tag_name << "__" << dimNames[i] << "_LOC_VALS";
-    tag_name = ss_tag_name.str();
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), val.size(), MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
-    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-    ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
-    if (MB_SUCCESS == rval)
-      dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
   // __<var_name>_DIMS
@@ -191,7 +190,7 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     if (varDimSz == 0)
       continue;
     varInfo[mapIter->first].varTags.resize(varDimSz, 0);
-    for (unsigned int i = 0; i != varDimSz; ++i) {
+    for (unsigned int i = 0; i != varDimSz; i++) {
       Tag tmptag = 0;
       std::string tmptagname = dimNames[varInfo[mapIter->first].varDims[i]];
       mbImpl->tag_get_handle(tmptagname.c_str(), 0, MB_TYPE_OPAQUE, tmptag, MB_TAG_ANY);
@@ -687,7 +686,7 @@ void NCHelper::init_dims_with_no_cvars_info()
 
 ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
@@ -706,7 +705,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
       }
 
       // Assume point-based values for now?
-      if (-1 == tDim || dimVals[tDim] <= (int) t)
+      if (-1 == tDim || dimLens[tDim] <= (int) t)
         ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number.");
 
       // Set up the dimensions and counts
@@ -736,7 +735,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           if (tDim != vdatas[i].varDims[idx]){
             // Push other variable dimensions, except time, which was already pushed
             vdatas[i].readStarts[t].push_back(0);
-            vdatas[i].readCounts[t].push_back(dimVals[vdatas[i].varDims[idx]]);
+            vdatas[i].readCounts[t].push_back(dimLens[vdatas[i].varDims[idx]]);
           }
         }
       }
@@ -1011,7 +1010,7 @@ ErrorCode ScdNCHelper::read_scd_variable_setup(std::vector<std::string>& var_nam
 ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
   Interface*& mbImpl = _readNC->mbImpl;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
@@ -1061,7 +1060,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
       }
 
       // Assume point-based values for now?
-      if (-1 == tDim || dimVals[tDim] <= (int) t) {
+      if (-1 == tDim || dimLens[tDim] <= (int) t) {
         ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number.");
       }
       else if (vdatas[i].varDims[0] != tDim) {

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index 7c80dc7..e5b3f08 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -53,7 +53,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
 {
   Interface*& mbImpl = _readNC->mbImpl;
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
   DebugOutput& dbgOut = _readNC->dbgOut;
   bool& isParallel = _readNC->isParallel;
@@ -71,7 +71,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
   }
   iCDim = idx;
   gCDims[0] = 0;
-  gCDims[3] = dimVals[idx] - 1;
+  gCDims[3] = dimLens[idx] - 1;
 
   // Check i periodicity and set globallyPeriodic[0]
   std::vector<double> til_vals(2);
@@ -92,7 +92,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
   }
   jCDim = idx;
   gCDims[1] = 0;
-  gCDims[4] = dimVals[idx] - 1;
+  gCDims[4] = dimLens[idx] - 1;
 
   // For Eul models, will always be non-periodic in j
   gDims[1] = 0;
@@ -111,7 +111,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'time' or 't' dimension.");
   }
   tDim = idx;
-  nTimeSteps = dimVals[idx];
+  nTimeSteps = dimLens[idx];
 
   // Look for level dimension
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "lev")) != dimNames.end())
@@ -122,7 +122,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'lev' or 'ilev' dimension.");
   }
   levDim = idx;
-  nLevels = dimVals[idx];
+  nLevels = dimLens[idx];
 
   // Parse options to get subset
   int rank = 0, procs = 1;
@@ -328,35 +328,49 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCFACE;
   }
 
-  // <coordinate_dim_name>
-  std::vector<std::string> ijdimNames(4);
-  ijdimNames[0] = "__slon";
-  ijdimNames[1] = "__slat";
-  ijdimNames[2] = "__lon";
-  ijdimNames[3] = "__lat";
+  std::vector<std::string> ijdimNames(2);
+  ijdimNames[0] = "__lon";
+  ijdimNames[1] = "__lat";
 
+  std::stringstream ss_tag_name;
   std::string tag_name;
-  int val_len = 0;
+  Tag tagh;
+
+  // __<dim_name>_LOC_MINMAX (for lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    tag_name = ijdimNames[i];
-    void* val = NULL;
-    if (tag_name == "__slon") {
-      val = &ilVals[0];
-      val_len = ilVals.size();
+    std::vector<int> val(2, 0);
+    if (ijdimNames[i] == "__lon") {
+      val[0] = lCDims[0];
+      val[1] = lCDims[3];
     }
-    else if (tag_name == "__slat") {
-      val = &jlVals[0];
-      val_len = jlVals.size();
+    else if (ijdimNames[i] == "__lat") {
+      val[0] = lCDims[1];
+      val[1] = lCDims[4];
     }
-    else if (tag_name == "__lon") {
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
+    tag_name = ss_tag_name.str();
+    rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
+    ERRORR(rval, "Trouble creating __<dim_name>_LOC_MINMAX tag.");
+    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
+    ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_MINMAX tag.");
+    if (MB_SUCCESS == rval)
+      dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+  }
+
+  // __<dim_name>_LOC_VALS (for lon and lat)
+  for (unsigned int i = 0; i != ijdimNames.size(); i++) {
+    void* val = NULL;
+    int val_len = 0;
+    if (ijdimNames[i] == "__lon") {
       val = &ilCVals[0];
       val_len = ilCVals.size();
     }
-    else if (tag_name == "__lat") {
+    else if (ijdimNames[i] == "__lat") {
       val = &jlCVals[0];
       val_len = jlCVals.size();
     }
-    Tag tagh = 0;
+
     DataType data_type;
 
     // Assume all has same data type as lon
@@ -378,61 +392,21 @@ ErrorCode NCHelperEuler::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_LOC_VALS";
+    tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-    ERRORR(rval, "Trouble creating <coordinate_dim_name> tag.");
+    ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
     rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len);
-    ERRORR(rval, "Trouble setting data for <coordinate_dim_name> tag.");
-    if (MB_SUCCESS == rval)
-      dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
-  }
-
-  // __<coordinate_dim_name>_LOC_MINMAX
-  for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    std::stringstream ss_tag_name;
-    ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
-    tag_name = ss_tag_name.str();
-    Tag tagh = 0;
-    std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__slon") {
-      val[0] = lDims[0];
-      val[1] = lDims[3];
-    }
-    else if (ijdimNames[i] == "__slat") {
-      val[0] = lDims[1];
-      val[1] = lDims[4];
-    }
-    else if (ijdimNames[i] == "__lon") {
-      val[0] = lCDims[0];
-      val[1] = lCDims[3];
-    }
-    else if (ijdimNames[i] == "__lat") {
-      val[0] = lCDims[1];
-      val[1] = lCDims[4];
-    }
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<coordinate_dim_name>_LOC_MINMAX tag.");
-    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-    ERRORR(rval, "Trouble setting data for __<coordinate_dim_name>_LOC_MINMAX tag.");
+    ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<coordinate_dim_name>_GLOBAL_MINMAX
+  // __<dim_name>_GLOBAL_MINMAX (for lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    std::stringstream ss_tag_name;
-    ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
-    tag_name = ss_tag_name.str();
-    Tag tagh = 0;
     std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__slon") {
-      val[0] = gDims[0];
-      val[1] = gDims[3];
-    }
-    else if (ijdimNames[i] == "__slat") {
-      val[0] = gDims[1];
-      val[1] = gDims[4];
-    }
-    else if (ijdimNames[i] == "__lon") {
+    if (ijdimNames[i] == "__lon") {
       val[0] = gCDims[0];
       val[1] = gCDims[3];
     }
@@ -440,10 +414,13 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
+    tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<coordinate_dim_name>_GLOBAL_MINMAX tag.");
+    ERRORR(rval, "Trouble creating __<dim_name>_GLOBAL_MINMAX tag.");
     rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-    ERRORR(rval, "Trouble setting data for __<coordinate_dim_name>_GLOBAL_MINMAX tag.");
+    ERRORR(rval, "Trouble setting data for __<dim_name>_GLOBAL_MINMAX tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index 8b21e36..dd555ff 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -46,7 +46,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
 {
   Interface*& mbImpl = _readNC->mbImpl;
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
   DebugOutput& dbgOut = _readNC->dbgOut;
   bool& isParallel = _readNC->isParallel;
@@ -64,7 +64,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
   }
   iDim = idx;
   gDims[0] = 0;
-  gDims[3] = dimVals[idx] - 1;
+  gDims[3] = dimLens[idx] - 1;
 
   // Then j
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "slat")) != dimNames.end())
@@ -74,7 +74,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
   }
   jDim = idx;
   gDims[1] = 0;
-  gDims[4] = dimVals[idx] - 1 + 2; // Add 2 for the pole points
+  gDims[4] = dimLens[idx] - 1 + 2; // Add 2 for the pole points
 
   // Look for names of center i/j dimensions
   // First i
@@ -85,7 +85,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
   }
   iCDim = idx;
   gCDims[0] = 0;
-  gCDims[3] = dimVals[idx] - 1;
+  gCDims[3] = dimLens[idx] - 1;
 
   // Check i periodicity and set globallyPeriodic[0]
   std::vector<double> til_vals(2);
@@ -106,7 +106,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
   }
   jCDim = idx;
   gCDims[1] = 0;
-  gCDims[4] = dimVals[idx] - 1;
+  gCDims[4] = dimLens[idx] - 1;
 
   // For FV models, will always be non-periodic in j
   assert(gDims[4] == gCDims[4] + 1);
@@ -124,7 +124,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'time' or 't' dimension.");
   }
   tDim = idx;
-  nTimeSteps = dimVals[idx];
+  nTimeSteps = dimLens[idx];
 
   // Get number of levels
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "lev")) != dimNames.end())
@@ -135,7 +135,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'lev' or 'ilev' dimension.");
   }
   levDim = idx;
-  nLevels = dimVals[idx];
+  nLevels = dimLens[idx];
 
   // Parse options to get subset
   int rank = 0, procs = 1;
@@ -330,35 +330,67 @@ ErrorCode NCHelperFV::init_mesh_vals()
       vd.entLoc = ReadNC::ENTLOCEWEDGE;
   }
 
-  // <coordinate_dim_name>
   std::vector<std::string> ijdimNames(4);
   ijdimNames[0] = "__slon";
   ijdimNames[1] = "__slat";
   ijdimNames[2] = "__lon";
   ijdimNames[3] = "__lat";
 
+  std::stringstream ss_tag_name;
   std::string tag_name;
-  int val_len = 0;
+  Tag tagh;
+
+  // __<dim_name>_LOC_MINMAX (for slon, slat, lon and lat)
+  for (unsigned int i = 0; i != ijdimNames.size(); i++) {
+    std::vector<int> val(2, 0);
+    if (ijdimNames[i] == "__slon") {
+      val[0] = lDims[0];
+      val[1] = lDims[3];
+    }
+    else if (ijdimNames[i] == "__slat") {
+      val[0] = lDims[1];
+      val[1] = lDims[4];
+    }
+    else if (ijdimNames[i] == "__lon") {
+      val[0] = lCDims[0];
+      val[1] = lCDims[3];
+    }
+    else if (ijdimNames[i] == "__lat") {
+      val[0] = lCDims[1];
+      val[1] = lCDims[4];
+    }
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
+    tag_name = ss_tag_name.str();
+    rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
+    ERRORR(rval, "Trouble creating __<dim_name>_LOC_MINMAX tag.");
+    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
+    ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_MINMAX tag.");
+    if (MB_SUCCESS == rval)
+      dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+  }
+
+  // __<dim_name>_LOC_VALS (for slon, slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    tag_name = ijdimNames[i];
     void* val = NULL;
-    if (tag_name == "__slon") {
+    int val_len = 0;
+    if (ijdimNames[i] == "__slon") {
       val = &ilVals[0];
       val_len = ilVals.size();
     }
-    else if (tag_name == "__slat") {
+    else if (ijdimNames[i] == "__slat") {
       val = &jlVals[0];
       val_len = jlVals.size();
     }
-    else if (tag_name == "__lon") {
+    else if (ijdimNames[i] == "__lon") {
       val = &ilCVals[0];
       val_len = ilCVals.size();
     }
-    else if (tag_name == "__lat") {
+    else if (ijdimNames[i] == "__lat") {
       val = &jlCVals[0];
       val_len = jlCVals.size();
     }
-    Tag tagh = 0;
+
     DataType data_type;
 
     // Assume all has same data type as lon
@@ -380,51 +412,19 @@ ErrorCode NCHelperFV::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_LOC_VALS";
+    tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-    ERRORR(rval, "Trouble creating <coordinate_dim_name> tag.");
+    ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
     rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len);
-    ERRORR(rval, "Trouble setting data for <coordinate_dim_name> tag.");
+    ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // __<coordinate_dim_name>_LOC_MINMAX
+  // __<dim_name>_GLOBAL_MINMAX (for slon, slat, lon and lat)
   for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    std::stringstream ss_tag_name;
-    ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
-    tag_name = ss_tag_name.str();
-    Tag tagh = 0;
-    std::vector<int> val(2, 0);
-    if (ijdimNames[i] == "__slon") {
-      val[0] = lDims[0];
-      val[1] = lDims[3];
-    }
-    else if (ijdimNames[i] == "__slat") {
-      val[0] = lDims[1];
-      val[1] = lDims[4];
-    }
-    else if (ijdimNames[i] == "__lon") {
-      val[0] = lCDims[0];
-      val[1] = lCDims[3];
-    }
-    else if (ijdimNames[i] == "__lat") {
-      val[0] = lCDims[1];
-      val[1] = lCDims[4];
-    }
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<coordinate_dim_name>_LOC_MINMAX tag.");
-    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-    ERRORR(rval, "Trouble setting data for __<coordinate_dim_name>_LOC_MINMAX tag.");
-    if (MB_SUCCESS == rval)
-      dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
-  }
-
-  // __<coordinate_dim_name>_GLOBAL_MINMAX
-  for (unsigned int i = 0; i != ijdimNames.size(); i++) {
-    std::stringstream ss_tag_name;
-    ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
-    tag_name = ss_tag_name.str();
-    Tag tagh = 0;
     std::vector<int> val(2, 0);
     if (ijdimNames[i] == "__slon") {
       val[0] = gDims[0];
@@ -442,10 +442,13 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
+    ss_tag_name.clear();
+    ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
+    tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<coordinate_dim_name>_GLOBAL_MINMAX tag.");
+    ERRORR(rval, "Trouble creating __<dim_name>_GLOBAL_MINMAX tag.");
     rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-    ERRORR(rval, "Trouble setting data for __<coordinate_dim_name>_GLOBAL_MINMAX tag.");
+    ERRORR(rval, "Trouble setting data for __<dim_name>_GLOBAL_MINMAX tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index 98aa9c6..f883bd7 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -59,7 +59,7 @@ bool NCHelperHOMME::can_read_file(ReadNC* readNC, int fileId)
 ErrorCode NCHelperHOMME::init_mesh_vals()
 {
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
 
   ErrorCode rval;
@@ -75,7 +75,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'time' or 't' dimension.");
   }
   tDim = idx;
-  nTimeSteps = dimVals[idx];
+  nTimeSteps = dimLens[idx];
 
   // Get number of vertices (labeled as number of columns)
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "ncol")) != dimNames.end())
@@ -84,7 +84,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'ncol' dimension.");
   }
   vDim = idx;
-  nVertices = dimVals[idx];
+  nVertices = dimLens[idx];
 
   // Set number of cells
   nCells = nVertices - 2;
@@ -98,7 +98,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'lev' or 'ilev' dimension.");
   }
   levDim = idx;
-  nLevels = dimVals[idx];
+  nLevels = dimLens[idx];
 
   // Store lon values in xVertVals
   std::map<std::string, ReadNC::VarData>::iterator vmit;
@@ -569,7 +569,7 @@ ErrorCode NCHelperHOMME::read_ucd_variable_setup(std::vector<std::string>& var_n
 ErrorCode NCHelperHOMME::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
   Interface*& mbImpl = _readNC->mbImpl;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
@@ -595,7 +595,7 @@ ErrorCode NCHelperHOMME::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC
       }
 
       // Assume point-based values for now?
-      if (-1 == tDim || dimVals[tDim] <= (int) t) {
+      if (-1 == tDim || dimLens[tDim] <= (int) t) {
         ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number.");
       }
       else if (vdatas[i].varDims[0] != tDim) {

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index c78956c..45d1b00 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -37,7 +37,7 @@ bool NCHelperMPAS::can_read_file(ReadNC* readNC)
 ErrorCode NCHelperMPAS::init_mesh_vals()
 {
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
 
   ErrorCode rval;
@@ -47,7 +47,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   // Get max edges per cell
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "maxEdges")) != dimNames.end()) {
     idx = vit - dimNames.begin();
-    maxCellEdges = dimVals[idx];
+    maxCellEdges = dimLens[idx];
     if (maxCellEdges > MAX_EDGES_PER_CELL) {
       ERRORR(MB_FAILURE, "maxEdges read from MPAS file has exceeded the limit");
     }
@@ -62,7 +62,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'Time' or 'time' dimension.");
   }
   tDim = idx;
-  nTimeSteps = dimVals[idx];
+  nTimeSteps = dimLens[idx];
 
   // Get number of cells
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nCells")) != dimNames.end())
@@ -71,7 +71,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'nCells' dimension.");
   }
   cDim = idx;
-  nCells = dimVals[idx];
+  nCells = dimLens[idx];
 
   // Get number of edges
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nEdges")) != dimNames.end())
@@ -80,7 +80,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'nEdges' dimension.");
   }
   eDim = idx;
-  nEdges = dimVals[idx];
+  nEdges = dimLens[idx];
 
   // Get number of vertices
   vDim = -1;
@@ -90,7 +90,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'nVertices' dimension.");
   }
   vDim = idx;
-  nVertices = dimVals[idx];
+  nVertices = dimLens[idx];
 
   // Get number of levels
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertLevels")) != dimNames.end())
@@ -99,7 +99,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     ERRORR(MB_FAILURE, "Couldn't find 'nVertLevels' dimension.");
   }
   levDim = idx;
-  nLevels = dimVals[idx];
+  nLevels = dimLens[idx];
 
   // Store xVertex values in xVertVals
   std::map<std::string, ReadNC::VarData>::iterator vmit;
@@ -697,7 +697,7 @@ ErrorCode NCHelperMPAS::read_ucd_variable_setup(std::vector<std::string>& var_na
 ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
   Interface*& mbImpl = _readNC->mbImpl;
-  std::vector<int>& dimVals = _readNC->dimVals;
+  std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
@@ -747,7 +747,7 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC:
       }
 
       // Assume point-based values for now?
-      if (-1 == tDim || dimVals[tDim] <= (int) t) {
+      if (-1 == tDim || dimLens[tDim] <= (int) t) {
         ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number.");
       }
       else if (vdatas[i].varDims[0] != tDim) {

diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index eee8a9e..50225df 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -294,9 +294,9 @@ ErrorCode ReadNC::read_header()
   dbgOut.tprintf(1, "Read %u attributes\n", (unsigned int) globalAtts.size());
 
   // Read in dimensions into dimVals
-  result = get_dimensions(fileId, dimNames, dimVals);
+  result = get_dimensions(fileId, dimNames, dimLens);
   ERRORR(result, "Getting dimensions.");
-  dbgOut.tprintf(1, "Read %u dimensions\n", (unsigned int) dimVals.size());
+  dbgOut.tprintf(1, "Read %u dimensions\n", (unsigned int) dimNames.size());
 
   // Read in variables into varInfo
   result = get_variables();
@@ -328,7 +328,7 @@ ErrorCode ReadNC::get_attributes(int var_id, int num_atts, std::map<std::string,
   return MB_SUCCESS;
 }
 
-ErrorCode ReadNC::get_dimensions(int file_id, std::vector<std::string>& dim_names, std::vector<int>& dim_vals)
+ErrorCode ReadNC::get_dimensions(int file_id, std::vector<std::string>& dim_names, std::vector<int>& dim_lens)
 {
   // Get the number of dimensions
   int num_dims;
@@ -341,18 +341,18 @@ ErrorCode ReadNC::get_dimensions(int file_id, std::vector<std::string>& dim_name
   }
 
   char dim_name[NC_MAX_NAME + 1];
-  NCDF_SIZE dum_len;
+  NCDF_SIZE dim_len;
   dim_names.resize(num_dims);
-  dim_vals.resize(num_dims);
+  dim_lens.resize(num_dims);
 
   for (int i = 0; i < num_dims; i++) {
-    success = NCFUNC(inq_dim)(file_id, i, dim_name, &dum_len);
+    success = NCFUNC(inq_dim)(file_id, i, dim_name, &dim_len);
     ERRORS(success, "Trouble getting dimension info.");
 
-    dim_vals[i] = dum_len;
     dim_names[i] = std::string(dim_name);
+    dim_lens[i] = dim_len;
 
-    dbgOut.tprintf(2, "Dimension %s, length=%u\n", dim_name, (unsigned int) dum_len);
+    dbgOut.tprintf(2, "Dimension %s, length=%u\n", dim_name, (unsigned int) dim_len);
   }
 
   return MB_SUCCESS;
@@ -367,7 +367,7 @@ ErrorCode ReadNC::get_variables()
 
   int ntimes = 0;
   if (vit != dimNames.end())
-    ntimes = dimVals[vit - dimNames.begin()];
+    ntimes = dimLens[vit - dimNames.begin()];
   if (!ntimes)
     ntimes = 1;
 

diff --git a/src/io/ReadNC.hpp b/src/io/ReadNC.hpp
index 41c866a..e8b1845 100644
--- a/src/io/ReadNC.hpp
+++ b/src/io/ReadNC.hpp
@@ -138,7 +138,7 @@ private:
                            const char *prefix = "");
 
   //! Get all dimensions in the file
-  ErrorCode get_dimensions(int file_id, std::vector<std::string>& dim_names, std::vector<int>& dim_vals);
+  ErrorCode get_dimensions(int file_id, std::vector<std::string>& dim_names, std::vector<int>& dim_lens);
 
   //! Get the variable names and other info defined for this file
   ErrorCode get_variables();
@@ -159,15 +159,15 @@ private:
   //! File numbers assigned by netcdf
   int fileId;
 
-  //! Dimensions
+  //! Dimension names
   std::vector<std::string> dimNames;
 
+  //! Dimension lengths
+  std::vector<int> dimLens;
+
   //! These should be taken out when we fix the dummy var info things
   std::set<std::string> dummyVarNames;
 
-  //! Dimension values
-  std::vector<int> dimVals;
-
   //! Global attribs
   std::map<std::string, AttData> globalAtts;

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list