[MOAB-dev] commit/MOAB: danwu: Updated NC reader to create conventional tags by default. Before this change, these tags were created only if the "no mesh, no variable" option is used for ReadNC::load_file(). We also prevent conventional tags from being created again on a second read, by checking a special tag (__CONV_TAGS_CREATED) on the file set.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Apr 9 14:44:41 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/2775a9278d6d/
Changeset:   2775a9278d6d
Branch:      ncwriter
User:        danwu
Date:        2014-04-09 21:44:25
Summary:     Updated NC reader to create conventional tags by default. Before this change, these tags were created only if the "no mesh, no variable" option is used for ReadNC::load_file(). We also prevent conventional tags from being created again on a second read, by checking a special tag (__CONV_TAGS_CREATED) on the file set.

Affected #:  3 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 9ef1332..d29aedd 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -192,16 +192,16 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     unsigned int varDimSz = varInfo[mapIter->first].varDims.size();
     if (varDimSz == 0)
       continue;
-    varInfo[mapIter->first].varTags.resize(varDimSz, 0);
+    std::vector<Tag> varDimTags(varDimSz);
     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);
-      varInfo[mapIter->first].varTags[i] = tmptag;
+      varDimTags[i] = tmptag;
     }
     rval = mbImpl->tag_get_handle(tag_name.c_str(), varDimSz, MB_TYPE_HANDLE, varNamesDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
     ERRORR(rval, "Trouble creating __<var_name>_DIMS tag.");
-    rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varInfo[mapIter->first].varTags[0]));
+    rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varDimTags[0]));
     ERRORR(rval, "Trouble setting data for __<var_name>_DIMS tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
@@ -324,6 +324,11 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
           dummyVarNames.find(vd.varName) != dummyVarNames.end())
          continue;
 
+      // Dimension variables were read before creating conventional tags
+      std::vector<std::string>& dimNames = _readNC->dimNames;
+      if (std::find(dimNames.begin(), dimNames.end(), vd.varName) != dimNames.end())
+        continue;
+
       if (vd.entLoc == ReadNC::ENTLOCSET)
         vsetdatas.push_back(vd);
       else

diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index a0e02b4..0a41cfa 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -118,6 +118,28 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
     ERRORR(rval, "Trouble checking mesh from last read.\n");
   }
 
+  // Create some conventional tags, e.g. __NUM_DIMS
+  // Keep a flag on the file set to prevent conventional tags from being created again on a second read
+  Tag convTagsCreated = 0;
+  int def_val = 0;
+  rval = mbImpl->tag_get_handle("__CONV_TAGS_CREATED", 1, MB_TYPE_INTEGER, convTagsCreated,
+                                MB_TAG_SPARSE | MB_TAG_CREAT, &def_val);
+  ERRORR(rval, "Trouble getting _CONV_TAGS_CREATED tag.");
+  int create_conv_tags_flag = 0;
+  rval = mbImpl->tag_get_data(convTagsCreated, &tmp_set, 1, &create_conv_tags_flag);
+  if (0 == create_conv_tags_flag) {
+    // Read dimension variables to create tags like __<var_name>_DIMS
+    rval = myHelper->read_variables(dimNames, tstep_nums);
+    ERRORR(rval, "Trouble reading dimension variables.");
+
+    rval = myHelper->create_conventional_tags(tstep_nums);
+    ERRORR(rval, "Trouble creating NC conventional tags.");
+
+    create_conv_tags_flag = 1;
+    rval = mbImpl->tag_set_data(convTagsCreated, &tmp_set, 1, &create_conv_tags_flag);
+    ERRORR(rval, "Trouble setting data for _CONV_TAGS_CREATED tag.");
+  }
+
   // Create mesh vertex/edge/face sequences
   Range faces;
   if (!noMesh) {
@@ -125,26 +147,10 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
     ERRORR(rval, "Trouble creating mesh.");
   }
 
-  // Read variables onto grid
+  // Read specified variables onto grid
   if (!noVars) {
     rval = myHelper->read_variables(var_names, tstep_nums);
-    if (MB_FAILURE == rval)
-      return rval;
-  }
-  else {
-    // 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())
-        dim_var_names.push_back(dimNames[i]);
-    }
-
-    if (!dim_var_names.empty()) {
-      rval = myHelper->read_variables(dim_var_names, tstep_nums);
-      if (MB_FAILURE == rval)
-        return rval;
-    }
+    ERRORR(rval, "Trouble reading specified variables.");
   }
 
 #ifdef USE_MPI
@@ -175,12 +181,6 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
   }
 #endif
 
-  // Create NC conventional tags when loading header info only
-  if (noMesh && noVars) {
-    rval = myHelper->create_conventional_tags(tstep_nums);
-    ERRORR(rval, "Trouble creating NC conventional tags.");
-  }
-
   mbImpl->release_interface(scdi);
   scdi = NULL;
 

diff --git a/test/io/write_nc.cpp b/test/io/write_nc.cpp
index 58c1095..de42ae7 100644
--- a/test/io/write_nc.cpp
+++ b/test/io/write_nc.cpp
@@ -54,24 +54,12 @@ void test_read_write_T_gw()
   ErrorCode rval = get_options(orig);
   CHECK_ERR(rval);
 
-  // We will have to read without mesh and without var first, to create some conventional tags that we need
-  // later when we write
-  std::string opts;
-  opts = orig + std::string(";DEBUG_IO=3;NOMESH;VARIABLE=");
-
-  // Need a set for nomesh to work right
-  // This set will have as tags a lot of header information, that will be used for writing back the file
   EntityHandle set;
   rval = mb.create_meshset(MESHSET_SET, set);
   CHECK_ERR(rval);
 
-  // Load header info only (no mesh, no variables)
-  // This will create some conventional tags
-  rval = mb.load_file(example_eul, &set, opts.c_str());
-  CHECK_ERR(rval);
-
   // Load non-set variable T, set variable gw, and the mesh
-  opts= orig + std::string(";DEBUG_IO=3;VARIABLE=T,gw");
+  std::string opts = orig + std::string(";DEBUG_IO=3;VARIABLE=T,gw");
   rval = mb.load_file(example_eul, &set, opts.c_str());
   CHECK_ERR(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