[MOAB-dev] commit/MOAB: danwu: Take out legacy dummy var info things. For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME, nCells for MPAS), create a sparse tag with the dimension name to store the dimension length. This is done directly in NCHelper::create_tags_for_dims_with_no_coord_vars(), and ReadNC::dummyVarNames is no longer used.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 13 15:33:28 CST 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/d96979b3285b/
Changeset:   d96979b3285b
Branch:      master
User:        danwu
Date:        2013-11-13 22:33:13
Summary:     Take out legacy dummy var info things. For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME, nCells for MPAS), create a sparse tag with the dimension name to store the dimension length. This is done directly in NCHelper::create_tags_for_dims_with_no_coord_vars(), and ReadNC::dummyVarNames is no longer used.

Affected #:  8 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index db0bfd4..18905a0 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -382,7 +382,6 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
 
 ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
-  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   Interface*& mbImpl = _readNC->mbImpl;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
@@ -392,11 +391,6 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
   // Finally, read into that space
   int success;
   for (unsigned int i = 0; i < vdatas.size(); i++) {
-    // This is a dummy variable for a dimension with no corresponding coordinate variable
-    // No need to set its tag data
-    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end())
-       continue;
-
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       void* data = vdatas[i].varDatas[t];
 
@@ -719,56 +713,47 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
   return MB_SUCCESS;
 }
 
-void NCHelper::init_dims_with_no_coord_vars_info()
+ErrorCode NCHelper::create_tags_for_dims_with_no_coord_vars()
 {
+  Interface*& mbImpl = _readNC->mbImpl;
   std::vector<std::string>& dimNames = _readNC->dimNames;
-  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
+  std::vector<int>& dimLens = _readNC->dimLens;
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   // Hack: look at all dimensions, and see if we have one that does not appear in the list of varInfo names
-  // Right now, candidates are from unstructured meshes, such as ncol(HOMME) and nCells(MPAS)
-  // For them, create dummy tags
+  // Right now, candidates are from unstructured meshes, such as ncol (HOMME) and nCells (MPAS)
+  // For each of them, create a sparse tag with the dimension name to store the dimension length
   for (unsigned int i = 0; i < dimNames.size(); i++) {
-    // If there is a variable with this dimension name, skip, we are fine; if not, create a dummy varInfo
+    // If there is a variable with this dimension name, skip
     if (varInfo.find(dimNames[i]) != varInfo.end())
       continue;
 
-    int sizeTotalVar = varInfo.size();
-    std::string var_name(dimNames[i]);
-    ReadNC::VarData& data = varInfo[var_name];
-    data.varName = std::string(var_name);
-    data.varId = sizeTotalVar;
-    data.varTags.resize(1, 0);
-    data.varDataType = NC_DOUBLE; // Could be int, actually, but we do not really need the type
-    data.varDims.resize(1);
-    data.varDims[0] = (int)i;
-    data.numAtts = 0;
-    data.entLoc = ReadNC::ENTLOCSET;
-    dbgOut.tprintf(2, "Dummy varInfo created for dimension %s\n", dimNames[i].c_str());
-    dummyVarNames.insert(dimNames[i]);
+    Tag tagh;
+    ErrorCode rval = mbImpl->tag_get_handle(dimNames[i].c_str(), 1, MB_TYPE_INTEGER, tagh,
+                                            MB_TAG_SPARSE | MB_TAG_CREAT | MB_TAG_EXCL);
+    // If the tag already exists, skip
+    if (MB_ALREADY_ALLOCATED == rval)
+      continue;
+    ERRORR(rval, "Failed to create dimension tag.");
+
+    rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &dimLens[i]);
+    ERRORR(rval, "Failed to set data for dimension tag.");
+
+    dbgOut.tprintf(2, "Sparse tag created for dimension %s\n", dimNames[i].c_str());
   }
+
+  return MB_SUCCESS;
 }
 
 ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
 {
-  std::set<std::string>& dummyVarNames = _readNC->dummyVarNames;
   std::vector<int>& dimLens = _readNC->dimLens;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
   ErrorCode rval = MB_SUCCESS;
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
-    // This is a dummy variable for a dimension with no corresponding coordinate variable
-    // No need to allocate memory to read it
-    if (dummyVarNames.find(vdatas[i].varName) != dummyVarNames.end()) {
-      if (!vdatas[i].varTags[0]) {
-        rval = get_tag_to_set(vdatas[i], 0, vdatas[i].varTags[0]);
-        ERRORR(rval, "Trouble getting dummy tag.");
-      }
-      continue;
-    }
-
     if ((std::find(vdatas[i].varDims.begin(), vdatas[i].varDims.end(), tDim) != vdatas[i].varDims.end()))
       vdatas[i].has_t = true;
 

diff --git a/src/io/NCHelper.hpp b/src/io/NCHelper.hpp
index dcb006e..e4d37cb 100644
--- a/src/io/NCHelper.hpp
+++ b/src/io/NCHelper.hpp
@@ -64,9 +64,9 @@ protected:
                                  std::string& attString,
                                  std::vector<int>& attLen);
 
-  //! Initialize information for dimensions that don't have corresponding
-  //! coordinate variables - this information is used for creating dummy tags
-  void init_dims_with_no_coord_vars_info();
+  //! For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME), create
+  //! a sparse tag with the dimension name to store the dimension length
+  ErrorCode create_tags_for_dims_with_no_coord_vars();
 
 private:
   //! Used by read_variable_to_set()

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index 5082c2e..f70ded1 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -459,8 +459,9 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
-  init_dims_with_no_coord_vars_info();
+  // Hack: create tags, if needed, for dimensions with no corresponding coordinate variables
+  rval = create_tags_for_dims_with_no_coord_vars();
+  ERRORR(rval, "Failed to create tags for dimensions with no coordinate variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index 488a511..b640298 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -460,8 +460,9 @@ ErrorCode NCHelperFV::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // Hack: create dummy tags, if needed, for dimensions with no corresponding coordinate variables
-  init_dims_with_no_coord_vars_info();
+  // Hack: create tags, if needed, for dimensions with no corresponding coordinate variables
+  rval = create_tags_for_dims_with_no_coord_vars();
+  ERRORR(rval, "Failed to create tags for dimensions with no coordinate variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index ba504e6..dc586c5 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -167,8 +167,9 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
       vd.numLev = nLevels;
   }
 
-  // Hack: create dummy tags for dimensions (like ncol) with no corresponding coordinate variables
-  init_dims_with_no_coord_vars_info();
+  // Hack: create tags for dimensions (like ncol) with no corresponding coordinate variables
+  rval = create_tags_for_dims_with_no_coord_vars();
+  ERRORR(rval, "Failed to create tags for dimensions with no coordinate variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 9d50ffe..b79fafb 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -190,8 +190,9 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
       ignoredVarNames.insert(vd.varName);
   }
 
-  // Hack: create dummy tags for dimensions (like nCells) with no corresponding coordinate variables
-  init_dims_with_no_coord_vars_info();
+  // Hack: create tags for dimensions (like nCells) with no corresponding coordinate variables
+  rval = create_tags_for_dims_with_no_coord_vars();
+  ERRORR(rval, "Failed to create tags for dimensions with no coordinate variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index e930930..d48612d 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -302,7 +302,7 @@ ErrorCode ReadNC::read_header()
   ERRORR(result, "Getting attributes.");
   dbgOut.tprintf(1, "Read %u attributes\n", (unsigned int) globalAtts.size());
 
-  // Read in dimensions into dimVals
+  // Read in dimensions into dimNames and dimLens
   result = get_dimensions(fileId, dimNames, dimLens);
   ERRORR(result, "Getting dimensions.");
   dbgOut.tprintf(1, "Read %u dimensions\n", (unsigned int) dimNames.size());

diff --git a/src/io/ReadNC.hpp b/src/io/ReadNC.hpp
index fc75140..c452716 100644
--- a/src/io/ReadNC.hpp
+++ b/src/io/ReadNC.hpp
@@ -165,9 +165,6 @@ private:
   //! Dimension lengths
   std::vector<int> dimLens;
 
-  //! These should be taken out when we fix the dummy var info things
-  std::set<std::string> dummyVarNames;
-
   //! 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