[MOAB-dev] commit/MOAB: danwu: For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME, nCells for MPAS), besides a sparse tag to store the dimension length, a dummy variable in ReadNC::varInfo is still needed to create some conventional tags like __<var_name>_DIMS.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Nov 14 15:13:51 CST 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/2d57da1edae8/
Changeset:   2d57da1edae8
Branch:      master
User:        danwu
Date:        2013-11-14 22:13:37
Summary:     For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME, nCells for MPAS), besides a sparse tag to store the dimension length, a dummy variable in ReadNC::varInfo is still needed to create some conventional tags like __<var_name>_DIMS.

Affected #:  7 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 18905a0..ebf149c 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -315,8 +315,10 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
     for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
       ReadNC::VarData vd = (*mit).second;
 
-      // This variable will not be read
-      if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end())
+      // No need to read ignored variables. Upon creation of dummy variables,
+      // tag values have already been set
+      if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end() ||
+          dummyVarNames.find(vd.varName) != dummyVarNames.end())
          continue;
 
       if (vd.entLoc == ReadNC::ENTLOCSET)
@@ -331,8 +333,10 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
       if (mit != varInfo.end()) {
         ReadNC::VarData vd = (*mit).second;
 
-        // This variable will not be read
-        if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end())
+        // No need to read ignored variables. Upon creation of dummy variables,
+        // tag values have already been set
+        if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end() ||
+            dummyVarNames.find(vd.varName) != dummyVarNames.end())
            continue;
 
         if (vd.entLoc == ReadNC::ENTLOCSET)
@@ -713,7 +717,7 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
   return MB_SUCCESS;
 }
 
-ErrorCode NCHelper::create_tags_for_dims_with_no_coord_vars()
+ErrorCode NCHelper::create_dummy_variables()
 {
   Interface*& mbImpl = _readNC->mbImpl;
   std::vector<std::string>& dimNames = _readNC->dimNames;
@@ -723,12 +727,28 @@ ErrorCode NCHelper::create_tags_for_dims_with_no_coord_vars()
 
   // 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 each of them, create a sparse tag with the dimension name to store the dimension length
+  // For each of them, create a dummy variable with a sparse tag to store the dimension length
   for (unsigned int i = 0; i < dimNames.size(); i++) {
     // If there is a variable with this dimension name, skip
     if (varInfo.find(dimNames[i]) != varInfo.end())
       continue;
 
+    // Create a dummy variable
+    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_INT;
+    data.varDims.resize(1);
+    data.varDims[0] = (int)i;
+    data.numAtts = 0;
+    data.entLoc = ReadNC::ENTLOCSET;
+    dummyVarNames.insert(dimNames[i]);
+    dbgOut.tprintf(2, "Dummy variable created for dimension %s\n", dimNames[i].c_str());
+
+    // Create a sparse tag to store the dimension length
     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);

diff --git a/src/io/NCHelper.hpp b/src/io/NCHelper.hpp
index e4d37cb..817257c 100644
--- a/src/io/NCHelper.hpp
+++ b/src/io/NCHelper.hpp
@@ -55,18 +55,18 @@ protected:
 
   ErrorCode get_tag_to_nonset(ReadNC::VarData& var_data, int tstep_num, Tag& tagh, int num_lev);
 
-  //! Create a character string attString of attMap.  with '\0'
+  //! Create a character string attString of attMap. with '\0'
   //! terminating each attribute name, ';' separating the data type
   //! and value, and ';' separating one name/data type/value from
-  //! the next'.  attLen stores the end position for each name/data
+  //! the next'. attLen stores the end position for each name/data
   //! type/ value.
   ErrorCode create_attrib_string(const std::map<std::string, ReadNC::AttData>& attMap,
                                  std::string& attString,
                                  std::vector<int>& attLen);
 
-  //! 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();
+  //! For a dimension that does not have a corresponding coordinate variable (e.g. ncol for HOMME),
+  //! create a dummy variable with a sparse tag to store the dimension length
+  ErrorCode create_dummy_variables();
 
 private:
   //! Used by read_variable_to_set()
@@ -90,8 +90,11 @@ protected:
   //! Dimension numbers for time and level
   int tDim, levDim;
 
-  //! Skip unexpected variables
+  //! Ignored variables
   std::set<std::string> ignoredVarNames;
+
+  //! Dummy variables
+  std::set<std::string> dummyVarNames;
 };
 
 //! Child helper class for scd mesh, e.g. CAM_EL or CAM_FV

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index f70ded1..b117921 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -459,9 +459,9 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // 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.");
+  // Hack: create dummy variables, if needed, for dimensions with no corresponding coordinate variables
+  rval = create_dummy_variables();
+  ERRORR(rval, "Failed to create dummy variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index b640298..7725b55 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -460,9 +460,9 @@ ErrorCode NCHelperFV::init_mesh_vals()
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
 
-  // 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.");
+  // Hack: create dummy variables, if needed, for dimensions with no corresponding coordinate variables
+  rval = create_dummy_variables();
+  ERRORR(rval, "Failed to create dummy variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index dc586c5..25c4441 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -167,9 +167,9 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
       vd.numLev = nLevels;
   }
 
-  // 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.");
+  // Hack: create dummy variables for dimensions (like ncol) with no corresponding coordinate variables
+  rval = create_dummy_variables();
+  ERRORR(rval, "Failed to create dummy variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index b79fafb..c803bf3 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -190,9 +190,9 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
       ignoredVarNames.insert(vd.varName);
   }
 
-  // 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.");
+  // Hack: create dummy variables for dimensions (like nCells) with no corresponding coordinate variables
+  rval = create_dummy_variables();
+  ERRORR(rval, "Failed to create dummy variables.");
 
   return MB_SUCCESS;
 }

diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index d48612d..a0e02b4 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -132,16 +132,16 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
       return rval;
   }
   else {
-    // Read dimension variable by default, the ones that are also variables
-    std::vector<std::string> filteredDimNames;
+    // Read dimension variables by default (the dimensions that are also variables)
+    std::vector<std::string> dim_var_names;
     for (unsigned int i = 0; i < dimNames.size(); i++) {
       std::map<std::string, VarData>::iterator mit = varInfo.find(dimNames[i]);
       if (mit != varInfo.end())
-        filteredDimNames.push_back(dimNames[i]);
+        dim_var_names.push_back(dimNames[i]);
     }
 
-    if (!filteredDimNames.empty()) {
-      rval = myHelper->read_variables(filteredDimNames, tstep_nums);
+    if (!dim_var_names.empty()) {
+      rval = myHelper->read_variables(dim_var_names, tstep_nums);
       if (MB_FAILURE == rval)
         return rval;
     }

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