[MOAB-dev] commit/MOAB: danwu: Updated NC writer to collect dummy dimension variables. These dummy variables are created for dimensions that have no corresponding coordinate variables. They do not have attributes and we should not dump them to a file.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Apr 11 23:27:17 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/f957e2c9392f/
Changeset:   f957e2c9392f
Branch:      ncwriter
User:        danwu
Date:        2014-04-12 06:27:02
Summary:     Updated NC writer to collect dummy dimension variables. These dummy variables are created for dimensions that have no corresponding coordinate variables. They do not have attributes and we should not dump them to a file.

Affected #:  3 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index d29aedd..0e970d9 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -252,21 +252,37 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     Tag varAttTag = 0;
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varAttTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
     ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS tag.");
+
     std::string varAttVal;
     std::vector<int> varAttLen;
-    rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen);
-    ERRORR(rval, "Trouble creating attribute strings.");
+    if (mapIter->second.numAtts < 1) {
+      if (dummyVarNames.find(mapIter->first) != dummyVarNames.end()) {
+        // This variable is a dummy dimension variable
+        varAttVal = "DUMMY_VAR";
+      }
+      else {
+        // This variable has no attributes
+        varAttVal = "NO_ATTRIBS";
+      }
+    }
+    else {
+      rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen);
+      ERRORR(rval, "Trouble creating attribute string.");
+    }
     const void* varAttPtr = varAttVal.c_str();
     int varAttSz = varAttVal.size();
+    if (0 == varAttSz)
+      varAttSz = 1;
     rval = mbImpl->tag_set_by_ptr(varAttTag, &_fileSet, 1, &varAttPtr, &varAttSz);
     ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS tag.");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
-    if (varAttLen.size() == 0)
-      varAttLen.push_back(0);
+
     ssTagName << "_LEN";
     tag_name = ssTagName.str();
     Tag varAttLenTag = 0;
+    if (0 == varAttLen.size())
+      varAttLen.push_back(0);
     rval = mbImpl->tag_get_handle(tag_name.c_str(), varAttLen.size(), MB_TYPE_INTEGER, varAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT);
     ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS_LEN tag.");
     rval = mbImpl->tag_set_data(varAttLenTag, &_fileSet, 1, &varAttLen[0]);

diff --git a/src/io/WriteNC.cpp b/src/io/WriteNC.cpp
index 825f3dd..d359c83 100644
--- a/src/io/WriteNC.cpp
+++ b/src/io/WriteNC.cpp
@@ -375,34 +375,44 @@ ErrorCode WriteNC::process_conventional_tags(EntityHandle fileSet)
       Tag varAttTag = 0;
       rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varAttTag, MB_TAG_SPARSE | MB_TAG_VARLEN);
       ERRORR(rval, "Trouble getting __<var_name>_ATTRIBS tag.");
-      std::string varAttVal;
-      std::vector<int> varAttLen;
       const void* varAttPtr = NULL;
       int varAttSz = 0;
       rval = mbImpl->tag_get_by_ptr(varAttTag, &fileSet, 1, &varAttPtr, &varAttSz);
-      ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS tag.");
+      ERRORR(rval, "Trouble getting data for __<var_name>_ATTRIBS tag.");
       if (MB_SUCCESS == rval)
         dbgOut.tprintf(2, "Tag retrieved for variable %s\n", tag_name.c_str());
 
-      ssTagName << "_LEN";
-      tag_name = ssTagName.str();
-      Tag varAttLenTag = 0;
-      rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, varAttLenTag, MB_TAG_ANY);
-      ERRORR(rval, "Trouble getting __<var_name>_ATTRIBS_LEN tag.");
-      int varAttLenSz = 0;
-      rval = mbImpl->tag_get_length(varAttLenTag, varAttLenSz);
-      ERRORR(rval, "Trouble getting __<var_name>_ATTRIBS_LEN length.");
-      varAttLen.resize(varAttLenSz);
-
-      rval = mbImpl->tag_get_data(varAttLenTag, &fileSet, 1, &varAttLen[0]);
-      ERRORR(rval, "Trouble getting data for __<var_name>_ATTRIBS_LEN tag.");
-
-      rval = process_concatenated_attribute(varAttPtr, varAttSz, varAttLen, variableDataStruct.varAtts);
-      ERRORR(rval, "Trouble processing global attributes.");
-
-      if (MB_SUCCESS == rval)
-        dbgOut.tprintf(2, "Tag metadata for variable %s\n", tag_name.c_str());
+      std::string attribString((char*)varAttPtr, (char*)varAttPtr + varAttSz);
+      if (attribString == "NO_ATTRIBS") {
+        // This variable has no attributes
+        variableDataStruct.numAtts = 0;
+      }
+      else if (attribString == "DUMMY_VAR") {
+        // This variable is a dummy dimension variable
+        variableDataStruct.numAtts = 0;
+        dummyVarNames.insert(variableDataStruct.varName);
+      }
+      else {
+        ssTagName << "_LEN";
+        tag_name = ssTagName.str();
+        Tag varAttLenTag = 0;
+        rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, varAttLenTag, MB_TAG_ANY);
+        ERRORR(rval, "Trouble getting __<var_name>_ATTRIBS_LEN tag.");
+        int varAttLenSz = 0;
+        rval = mbImpl->tag_get_length(varAttLenTag, varAttLenSz);
+        ERRORR(rval, "Trouble getting __<var_name>_ATTRIBS_LEN length.");
+        std::vector<int> varAttLen(varAttLenSz);
+        rval = mbImpl->tag_get_data(varAttLenTag, &fileSet, 1, &varAttLen[0]);
+        ERRORR(rval, "Trouble getting data for __<var_name>_ATTRIBS_LEN tag.");
+
+        rval = process_concatenated_attribute(varAttPtr, varAttSz, varAttLen, variableDataStruct.varAtts);
+        ERRORR(rval, "Trouble processing a variable's attributes.");
+
+        if (MB_SUCCESS == rval)
+          dbgOut.tprintf(2, "Tag metadata for variable %s\n", tag_name.c_str());
+      }
       // End attribute
+
       start = i + 1;
       idxVar++;
     } // if (p[i] == '\0')
@@ -446,14 +456,15 @@ ErrorCode WriteNC::process_conventional_tags(EntityHandle fileSet)
 }
 
 // Reverse process from create_attrib_string
-ErrorCode WriteNC::process_concatenated_attribute(const void* gattptr, int globalAttSz, std::vector<int>& gattLen,
+ErrorCode WriteNC::process_concatenated_attribute(const void* attPtr, int attSz,
+                                                  std::vector<int>& attLen,
                                                   std::map<std::string, AttData>& attributes)
 {
   std::size_t start = 0;
   std::size_t att_counter = 0;
-  std::string concatString((char*)gattptr, (char*)gattptr + globalAttSz);
+  std::string concatString((char*)attPtr, (char*)attPtr + attSz);
 
-  for (std::size_t i = 0; i != (size_t)globalAttSz; i++) {
+  for (std::size_t i = 0; i != (size_t)attSz; i++) {
     if (concatString[i] == '\0') {
       std::string att_name(&concatString[start], i - start);
       start = i + 1;
@@ -462,7 +473,7 @@ ErrorCode WriteNC::process_concatenated_attribute(const void* gattptr, int globa
       std::string data_type(&concatString[start], i - start);
       ++i;
       start = i;
-      i = gattLen[att_counter];
+      i = attLen[att_counter];
       if (concatString[i] != ';')
         ERRORR(MB_FAILURE, "Error parsing attributes.");
 

diff --git a/src/io/WriteNC.hpp b/src/io/WriteNC.hpp
index 4f6d94d..855bc6e 100644
--- a/src/io/WriteNC.hpp
+++ b/src/io/WriteNC.hpp
@@ -126,16 +126,19 @@ private:
     bool has_tsteps; // Indicate whether timestep numbers are appended to tag names
   };
 
-  // This info will be reconstructed from metadata stored on conventional fileSet tags
+  //! This info will be reconstructed from metadata stored on conventional fileSet tags
   //! Dimension names
   std::vector<std::string> dimNames;
 
   //! Dimension lengths
   std::vector<int> dimLens;
 
-  // Will collect used dimensions (coordinate variables)
+  //! Will collect used dimensions (coordinate variables)
   std::set<std::string> usedCoordinates;
 
+  //! Dummy variables (for dimensions that have no corresponding coordinate variables)
+  std::set<std::string> dummyVarNames;
+
   //! Global attribs
   std::map<std::string, AttData> globalAtts;
 
@@ -152,20 +155,20 @@ private:
    */
   ErrorCode process_conventional_tags(EntityHandle fileSet);
 
-  ErrorCode process_concatenated_attribute(const void* gattptr, int globalAttSz,
-                                           std::vector<int>& gattLen,
-                                           std::map<std::string, AttData>& globalAtts);
+  ErrorCode process_concatenated_attribute(const void* attPtr, int attSz,
+                                           std::vector<int>& attLen,
+                                           std::map<std::string, AttData>& attributes);
 
-  // Will collect data; it should be only on gather processor, but for the time being, collect
-  // for everybody
+  //! Will collect data; it should be only on gather processor, but for the time being, collect
+  //! for everybody
   ErrorCode collect_variable_data(std::vector<std::string>& var_names, std::vector<int>& tstep_nums,
                                   std::vector<double>& tstep_vals, EntityHandle fileSet);
 
-  // Initialize file: this is where all defines are done
-  // the VarData dimension ids are filled up after define
+  //! Initialize file: this is where all defines are done
+  //! the VarData dimension ids are filled up after define
   ErrorCode initialize_file(std::vector<std::string>& var_names); // These are from options
 
-  // Interface instance
+  //! Interface instance
   Interface* mbImpl;
   WriteUtilIface* mWriteIface;

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