[MOAB-dev] commit/MOAB: danwu: Updated NC writer to dispatch write_values() to the helper classes.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Apr 10 14:38:19 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/1bdf2937a375/
Changeset:   1bdf2937a375
Branch:      ncwriter
User:        danwu
Date:        2014-04-10 21:37:59
Summary:     Updated NC writer to dispatch write_values() to the helper classes.

Affected #:  12 files

diff --git a/src/io/NCWriteEuler.cpp b/src/io/NCWriteEuler.cpp
index f17727b..70d5bdd 100644
--- a/src/io/NCWriteEuler.cpp
+++ b/src/io/NCWriteEuler.cpp
@@ -5,6 +5,13 @@
  */
 
 #include "NCWriteEuler.hpp"
+#include "moab/WriteUtilIface.hpp"
+
+#define ERRORR(rval, str) \
+  if (MB_SUCCESS != rval) { _writeNC->mWriteIface->report_error("%s", str); return rval; }
+
+#define ERRORS(err, str) \
+  if (err) { _writeNC->mWriteIface->report_error("%s", str); return MB_FAILURE; }
 
 namespace moab {
 
@@ -13,4 +20,150 @@ NCWriteEuler::~NCWriteEuler()
   // TODO Auto-generated destructor stub
 }
 
+ErrorCode NCWriteEuler::write_values(std::vector<std::string>& var_names, EntityHandle fileSet)
+{
+  Interface*& mbImpl = _writeNC->mbImpl;
+  std::set<std::string>& usedCoordinates = _writeNC->usedCoordinates;
+  std::map<std::string, WriteNC::VarData>& varInfo = _writeNC->varInfo;
+
+  // Start with coordinates
+  for (std::set<std::string>::iterator setIt = usedCoordinates.begin();
+      setIt != usedCoordinates.end(); ++setIt) {
+    std::string coordName = *setIt; // Deep copy
+
+    std::map<std::string, WriteNC::VarData>::iterator vit = varInfo.find(coordName);
+    if (vit == varInfo.end())
+      ERRORR(MB_FAILURE, "Can't find one coordinate variable.");
+
+    WriteNC::VarData& varCoordData = vit->second;
+
+    int success = 0;
+    switch (varCoordData.varDataType) {
+      case NC_DOUBLE:
+        success = NCFUNCAP(_vara_double)(_fileId, varCoordData.varId, &varCoordData.writeStarts[0],
+                  &varCoordData.writeCounts[0], (double*)(varCoordData.memoryHogs[0]));
+        ERRORS(success, "Failed to write double data.");
+        break;
+      case NC_INT:
+        success = NCFUNCAP(_vara_int)(_fileId, varCoordData.varId, &varCoordData.writeStarts[0],
+                  &varCoordData.writeCounts[0], (int*)(varCoordData.memoryHogs[0]));
+        ERRORS(success, "Failed to write int data.");
+        break;
+      default:
+        success = 1;
+        break;
+    }
+ }
+
+  // Now look at requested var_names; if they have time, we will have a list, and write one at a time
+  // We may also need to gather, and transpose stuff
+  // Get all entities of dimension 2 from set
+  // Need to reorder stuff in the order from the file, also transpose from lev dimension
+  ErrorCode rval;
+
+  // For each variable tag in the indexed lists, write a time step data
+  // Assume the first dimension is time (need to check); if not, just write regularly
+  for (size_t i = 0; i < var_names.size(); i++) {
+    std::map<std::string, WriteNC::VarData>::iterator vit = varInfo.find(var_names[i]);
+    if (vit == varInfo.end())
+      ERRORR(MB_FAILURE, "Can't find variable requested.");
+
+    WriteNC::VarData& variableData = vit->second;
+    int numTimeSteps = (int)variableData.varTags.size();
+    if (variableData.has_tsteps) {
+      // Get entities of this variable
+      Range ents;
+      switch (variableData.entLoc) {
+        case WriteNC::ENTLOCVERT:
+          // Vertices
+          rval = mbImpl->get_entities_by_dimension(fileSet, 0, ents);
+          ERRORR(rval, "Can't get entities for vertices.");
+          break;
+        case WriteNC::ENTLOCFACE:
+          // Faces
+          rval = mbImpl->get_entities_by_dimension(fileSet, 2, ents);
+          ERRORR(rval, "Can't get entities for faces.");
+          break;
+        case WriteNC::ENTLOCNSEDGE:
+        case WriteNC::ENTLOCEWEDGE:
+        case WriteNC::ENTLOCEDGE:
+          // Edges
+          rval = mbImpl->get_entities_by_dimension(fileSet, 1, ents);
+          ERRORR(rval, "Can't get entities for edges.");
+          break;
+        default:
+          break;
+      }
+
+      // FIXME: assume now the variable has 4 dimensions as (time, lev, lat, lon)
+      // At each timestep, we need to transpose tag format (lat, lon, lev) back
+      // to NC format (lev, lat, lon) for writing
+      size_t ni = variableData.writeCounts[3]; // lon
+      size_t nj = variableData.writeCounts[2]; // lat
+      size_t nk = variableData.writeCounts[1]; // lev
+
+      variableData.writeCounts[0] = 1; // We will write one time step
+      for (int j = 0; j < numTimeSteps; j++) {
+        // We will write one time step, and count will be one; start will be different
+        // We will write values directly from tag_iterate, but we should also transpose for level
+        // so that means deep copy for transpose
+        variableData.writeStarts[0] = j; // This is time, again
+        int count;
+        void* dataptr;
+        rval = mbImpl->tag_iterate(variableData.varTags[j], ents.begin(), ents.end(), count, dataptr);
+        assert(count == (int)ents.size());
+
+        // Now write from memory directly
+        // FIXME: we need to gather for multiple processors
+        int success = 0;
+        switch (variableData.varDataType) {
+          case NC_DOUBLE: {
+            std::vector<double> tmpdoubledata(ni*nj*nk);
+            // Transpose (lat, lon, lev) back to (lev, lat, lon)
+            jik_to_kji(ni, nj, nk, &tmpdoubledata[0], (double*)(dataptr));
+            success = NCFUNCAP(_vara_double)(_fileId, variableData.varId,
+                      &variableData.writeStarts[0], &variableData.writeCounts[0],
+                      &tmpdoubledata[0]);
+            ERRORS(success, "Failed to write double data.");
+            break;
+          }
+          case NC_INT: {
+            std::vector<int> tmpintdata(ni*nj*nk);
+            // Transpose (lat, lon, lev) back to (lev, lat, lon)
+            jik_to_kji(ni, nj, nk, &tmpintdata[0], (int*)(dataptr));
+            success = NCFUNCAP(_vara_int)(_fileId, variableData.varId,
+                      &variableData.writeStarts[0], &variableData.writeCounts[0],
+                      &tmpintdata[0]);
+            ERRORS(success, "Failed to write int data.");
+            break;
+          }
+          default:
+            success = 1;
+            break;
+        }
+      }
+    }
+    else {
+      int success = 0;
+      switch (variableData.varDataType) {
+        case NC_DOUBLE:
+          success = NCFUNCAP(_vara_double)(_fileId, variableData.varId, &variableData.writeStarts[0],
+                    &variableData.writeCounts[0], (double*)(variableData.memoryHogs[0]));
+          ERRORS(success, "Failed to write double data.");
+          break;
+        case NC_INT:
+          success = NCFUNCAP(_vara_int)(_fileId, variableData.varId, &variableData.writeStarts[0],
+                    &variableData.writeCounts[0], (int*)(variableData.memoryHogs[0]));
+          ERRORS(success, "Failed to write int data.");
+          break;
+        default:
+          success = 1;
+          break;
+      }
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
 } /* namespace moab */

diff --git a/src/io/NCWriteEuler.hpp b/src/io/NCWriteEuler.hpp
index 3e7f728..b1c5c78 100644
--- a/src/io/NCWriteEuler.hpp
+++ b/src/io/NCWriteEuler.hpp
@@ -16,10 +16,15 @@ namespace moab {
 class NCWriteEuler: public NCWriteHelper
 {
 public:
-  NCWriteEuler(WriteNC* writeNC,  const FileOptions& opts, EntityHandle fileSet) :
-    NCWriteHelper(writeNC, opts, fileSet) {};
+  NCWriteEuler(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet) :
+    NCWriteHelper(writeNC, fileId, opts, fileSet) {}
+
   virtual ~NCWriteEuler();
+
+private:
+  ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet);
 };
 
-} /* namespace moab */
-#endif /* NCWRITEEULER_HPP_ */
+} // namespace moab
+
+#endif

diff --git a/src/io/NCWriteFV.cpp b/src/io/NCWriteFV.cpp
index a5df58d..1eca105 100644
--- a/src/io/NCWriteFV.cpp
+++ b/src/io/NCWriteFV.cpp
@@ -5,6 +5,13 @@
  */
 
 #include "NCWriteFV.hpp"
+#include "moab/WriteUtilIface.hpp"
+
+#define ERRORR(rval, str) \
+  if (MB_SUCCESS != rval) { _writeNC->mWriteIface->report_error("%s", str); return rval; }
+
+#define ERRORS(err, str) \
+  if (err) { _writeNC->mWriteIface->report_error("%s", str); return MB_FAILURE; }
 
 namespace moab {
 
@@ -13,4 +20,9 @@ NCWriteFV::~NCWriteFV()
   // TODO Auto-generated destructor stub
 }
 
+ErrorCode NCWriteFV::write_values(std::vector<std::string>& var_names, EntityHandle fileSet)
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
 } /* namespace moab */

diff --git a/src/io/NCWriteFV.hpp b/src/io/NCWriteFV.hpp
index 5ecb49d..6d7f022 100644
--- a/src/io/NCWriteFV.hpp
+++ b/src/io/NCWriteFV.hpp
@@ -16,11 +16,15 @@ namespace moab {
 class NCWriteFV: public NCWriteHelper
 {
 public:
-  NCWriteFV(WriteNC* writeNC,  const FileOptions& opts, EntityHandle fileSet) :
-    NCWriteHelper(writeNC, opts, fileSet) {};
+  NCWriteFV(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet) :
+    NCWriteHelper(writeNC, fileId, opts, fileSet) {}
 
   virtual ~NCWriteFV();
+
+private:
+  ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet);
 };
 
-} /* namespace moab */
-#endif /* NCWRITEFV_HPP_ */
+} // namespace moab
+
+#endif // NCWRITEFV_HPP_

diff --git a/src/io/NCWriteHOMME.cpp b/src/io/NCWriteHOMME.cpp
index 3b6b1fc..3b500b5 100644
--- a/src/io/NCWriteHOMME.cpp
+++ b/src/io/NCWriteHOMME.cpp
@@ -5,6 +5,13 @@
  */
 
 #include "NCWriteHOMME.hpp"
+#include "moab/WriteUtilIface.hpp"
+
+#define ERRORR(rval, str) \
+  if (MB_SUCCESS != rval) { _writeNC->mWriteIface->report_error("%s", str); return rval; }
+
+#define ERRORS(err, str) \
+  if (err) { _writeNC->mWriteIface->report_error("%s", str); return MB_FAILURE; }
 
 namespace moab {
 
@@ -13,4 +20,9 @@ NCWriteHOMME::~NCWriteHOMME()
   // TODO Auto-generated destructor stub
 }
 
+ErrorCode NCWriteHOMME::write_values(std::vector<std::string>& var_names, EntityHandle fileSet)
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
 } /* namespace moab */

diff --git a/src/io/NCWriteHOMME.hpp b/src/io/NCWriteHOMME.hpp
index e8abd64..c0db566 100644
--- a/src/io/NCWriteHOMME.hpp
+++ b/src/io/NCWriteHOMME.hpp
@@ -16,11 +16,15 @@ namespace moab {
 class NCWriteHOMME: public NCWriteHelper
 {
 public:
-  NCWriteHOMME(WriteNC* writeNC,  const FileOptions& opts, EntityHandle fileSet) :
-    NCWriteHelper(writeNC, opts, fileSet) {};
+  NCWriteHOMME(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet) :
+    NCWriteHelper(writeNC, fileId, opts, fileSet) {}
 
   virtual ~NCWriteHOMME();
+
+private:
+  ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet);
 };
 
-} /* namespace moab */
-#endif /* NCWRITEHOMME_HPP_ */
+} // namespace moab
+
+#endif

diff --git a/src/io/NCWriteHelper.cpp b/src/io/NCWriteHelper.cpp
index bb9cce6..e70b701 100644
--- a/src/io/NCWriteHelper.cpp
+++ b/src/io/NCWriteHelper.cpp
@@ -14,21 +14,20 @@
 namespace moab {
 
 //! Get appropriate helper instance for WriteNC class; based on some info in the file set
-NCWriteHelper* NCWriteHelper::get_nc_helper(WriteNC* writeNC, const FileOptions& opts, EntityHandle fileSet)
+NCWriteHelper* NCWriteHelper::get_nc_helper(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
 {
   std::string& grid_type = writeNC->grid_type;
   if (grid_type == "CAM_EUL")
-    return new (std::nothrow) NCWriteEuler(writeNC, opts, fileSet);
+    return new (std::nothrow) NCWriteEuler(writeNC, fileId, opts, fileSet);
   else if (grid_type == "CAM_FV")
-    return new (std::nothrow) NCWriteFV(writeNC, opts, fileSet);
+    return new (std::nothrow) NCWriteFV(writeNC, fileId, opts, fileSet);
   else if (grid_type == "CAM_SE")
-    return new (std::nothrow) NCWriteHOMME(writeNC, opts, fileSet);
+    return new (std::nothrow) NCWriteHOMME(writeNC, fileId, opts, fileSet);
   else if (grid_type == "MPAS")
-    return new (std::nothrow) NCWriteMPAS(writeNC, opts, fileSet);
+    return new (std::nothrow) NCWriteMPAS(writeNC, fileId, opts, fileSet);
 
   // Unknown NetCDF grid
   return NULL;
 }
 
-
 } /* namespace moab */

diff --git a/src/io/NCWriteHelper.hpp b/src/io/NCWriteHelper.hpp
index c88eb22..157c2dc 100644
--- a/src/io/NCWriteHelper.hpp
+++ b/src/io/NCWriteHelper.hpp
@@ -15,190 +15,35 @@ namespace moab {
 class NCWriteHelper
 {
 public:
-  NCWriteHelper(WriteNC* writeNC, const FileOptions& opts, EntityHandle fileSet)
-  :_writeNC(writeNC), _opts(opts), _fileSet(fileSet),
-    nTimeSteps(0), nLevels(1), tDim(-1), levDim(-1) {}
+  NCWriteHelper(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
+  :_writeNC(writeNC), _fileId(fileId), _opts(opts), _fileSet(fileSet) {}
+
   virtual ~NCWriteHelper() {};
 
   //! Get appropriate helper instance for WriteNC class; based on some info in the file set
-  static NCWriteHelper* get_nc_helper(WriteNC* writeNC, const FileOptions& opts, EntityHandle fileSet);
-
-  //! process NC conventional tags
-  ErrorCode process_conventional_tags(EntityHandle fileSet);
-protected:
-  //! Allow NCWriteHelper to directly access members of WriteNC
-  WriteNC* _writeNC;
-
-  const FileOptions& _opts;
-  EntityHandle _fileSet;
-
-  //! Dimensions of time and level
-  int nTimeSteps, nLevels;
-
-  //! Values for time and level
-  std::vector<double> tVals, levVals;
-
-  //! Dimension numbers for time and level
-  int tDim, levDim;
-
-  //! Ignored variables
-  std::set<std::string> ignoredVarNames;
-
-  //! Dummy variables
-  std::set<std::string> dummyVarNames;
-};
-
-#if 0
-
-//! Child helper class for scd mesh, e.g. CAM_EL or CAM_FV
-class ScdNCHelper : public NCHelper
-{
-public:
-  ScdNCHelper(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
-: NCHelper(readNC, fileId, opts, fileSet),
-  iDim(-1), jDim(-1), iCDim(-1), jCDim(-1)
-  {
-    for (unsigned int i = 0; i < 6; i++) {
-      gDims[i] = -1;
-      lDims[i] = -1;
-      gCDims[i] = -1;
-      lCDims[i] = -1;
-    }
-
-    locallyPeriodic[0] = locallyPeriodic[1] = locallyPeriodic[2] = 0;
-    globallyPeriodic[0] = globallyPeriodic[1] = globallyPeriodic[2] = 0;
-  }
-  virtual ~ScdNCHelper() {}
-
-private:
-  //! Implementation of NCHelper::check_existing_mesh()
-  virtual ErrorCode check_existing_mesh();
-  //! Implementation of NCHelper::create_mesh()
-  virtual ErrorCode create_mesh(Range& faces);
-  //! Implementation of NCHelper::read_variables()
-  virtual ErrorCode read_variables(std::vector<std::string>& var_names, std::vector<int>& tstep_nums);
-
-  //! Read non-set variables for scd mesh
-  ErrorCode read_scd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas,
-                                                 std::vector<int>& tstep_nums);
-  ErrorCode read_scd_variable_to_nonset(std::vector<ReadNC::VarData>& vdatas,
-                                        std::vector<int>& tstep_nums);
-
-  //! Create COORDS tag for quads coordinate
-  ErrorCode create_quad_coordinate_tag();
-
-  template <typename T> ErrorCode kji_to_jik(size_t ni, size_t nj, size_t nk, void* dest, T* source)
-  {
-    size_t nik = ni * nk, nij = ni * nj;
-    T* tmp_data = reinterpret_cast<T*>(dest);
-    for (std::size_t j = 0; j != nj; j++)
-      for (std::size_t i = 0; i != ni; i++)
-        for (std::size_t k = 0; k != nk; k++)
-          tmp_data[j*nik + i*nk + k] = source[k*nij + j*ni + i];
-    return MB_SUCCESS;
-  }
-
-protected:
-  //! Dimensions of global grid in file
-  int gDims[6];
-
-  //! Dimensions of my local part of grid
-  int lDims[6];
-
-  //! Center dimensions of global grid in file
-  int gCDims[6];
-
-  //! Center dimensions of my local part of grid
-  int lCDims[6];
-
-  //! Values for i/j
-  std::vector<double> ilVals, jlVals;
+  static NCWriteHelper* get_nc_helper(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet);
 
-  //! Center values for i/j
-  std::vector<double> ilCVals, jlCVals;
-
-  //! Dimension numbers for i/j
-  int iDim, jDim;
-
-  //! Center dimension numbers for i/j
-  int iCDim, jCDim;
-
-  //! Whether mesh is locally periodic in i or j or k
-  int locallyPeriodic[3];
-
-  //! Whether mesh is globally periodic in i or j or k
-  int globallyPeriodic[3];
-};
-
-//! Child helper class for ucd mesh, e.g. CAM_SE (HOMME) or MPAS
-class UcdNCHelper : public NCHelper
-{
-public:
-  UcdNCHelper(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
-: NCHelper(readNC, fileId, opts, fileSet),
-  nCells(0), nEdges(0), nVertices(0),
-  nLocalCells(0), nLocalEdges(0), nLocalVertices(0),
-  cDim(-1), eDim(-1), vDim(-1) {}
-  virtual ~UcdNCHelper() {}
-
-private:
-  //! Implementation of NCHelper::read_variables()
-  virtual ErrorCode read_variables(std::vector<std::string>& var_names,
-                                   std::vector<int> &tstep_nums);
-
-  //! Read non-set variables for ucd mesh (implemented differently in child classes)
-  virtual ErrorCode read_ucd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas,
-                                                         std::vector<int>& tstep_nums) = 0;
-#ifdef PNETCDF_FILE
-  virtual ErrorCode read_ucd_variable_to_nonset_async(std::vector<ReadNC::VarData>& vdatas,
-                                                      std::vector<int>& tstep_nums) = 0;
-#else
-  virtual ErrorCode read_ucd_variable_to_nonset(std::vector<ReadNC::VarData>& vdatas,
-                                                std::vector<int>& tstep_nums) = 0;
-#endif
+  //! Take the info from VarData and write first the coordinates, then the actual variables
+  virtual ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet) = 0;
 
 protected:
-  //! This version takes as input the moab range, from which we actually need just the
-  //! size of each sequence, for a proper transpose of the data
-  template <typename T> ErrorCode kji_to_jik_stride(size_t , size_t nj, size_t nk, void* dest, T* source, Range& localGid)
+  template <typename T> void jik_to_kji(size_t ni, size_t nj, size_t nk, T* dest, T* source)
   {
-    std::size_t idxInSource = 0; // Position of the start of the stride
-    // For each subrange, we will transpose a matrix of size
-    // subrange*nj*nk (subrange takes the role of ni)
-    T* tmp_data = reinterpret_cast<T*>(dest);
-    for (Range::pair_iterator pair_iter = localGid.pair_begin();
-        pair_iter != localGid.pair_end(); ++pair_iter) {
-      std::size_t size_range = pair_iter->second - pair_iter->first + 1;
-      std::size_t nik = size_range * nk, nij = size_range * nj;
+    size_t nik = ni * nk, nij = ni * nj;
+    for (std::size_t k = 0; k != nk; k++)
       for (std::size_t j = 0; j != nj; j++)
-        for (std::size_t i = 0; i != size_range; i++)
-          for (std::size_t k = 0; k != nk; k++)
-            tmp_data[idxInSource + j*nik + i*nk + k] = source[idxInSource + k*nij + j*size_range + i];
-      idxInSource += (size_range*nj*nk);
-    }
-    return MB_SUCCESS;
+        for (std::size_t i = 0; i != ni; i++)
+          dest[k*nij + j*ni + i] = source[j*nik + i*nk + k];
   }
 
-  //! Dimensions of global grid in file
-  int nCells;
-  int nEdges;
-  int nVertices;
-
-  //! Dimensions of my local part of grid
-  int nLocalCells;
-  int nLocalEdges;
-  int nLocalVertices;
-
-  //! Coordinate values for vertices
-  std::vector<double> xVertVals, yVertVals, zVertVals;
-
-  //! Dimension numbers for nCells, nEdges and nVertices
-  int cDim, eDim, vDim;
+  //! Allow NCWriteHelper to directly access members of WriteNC
+  WriteNC* _writeNC;
 
-  //! Local global ID for cells, edges and vertices
-  Range localGidCells, localGidEdges, localGidVerts;
+  //! Cache some information from ReadNC
+  int _fileId;
+  const FileOptions& _opts;
+  EntityHandle _fileSet;
 };
-#endif
 
 } // namespace moab
 

diff --git a/src/io/NCWriteMPAS.cpp b/src/io/NCWriteMPAS.cpp
index 4c102a6..a385968 100644
--- a/src/io/NCWriteMPAS.cpp
+++ b/src/io/NCWriteMPAS.cpp
@@ -5,6 +5,13 @@
  */
 
 #include "NCWriteMPAS.hpp"
+#include "moab/WriteUtilIface.hpp"
+
+#define ERRORR(rval, str) \
+  if (MB_SUCCESS != rval) { _writeNC->mWriteIface->report_error("%s", str); return rval; }
+
+#define ERRORS(err, str) \
+  if (err) { _writeNC->mWriteIface->report_error("%s", str); return MB_FAILURE; }
 
 namespace moab {
 
@@ -13,4 +20,9 @@ NCWriteMPAS::~NCWriteMPAS()
   // TODO Auto-generated destructor stub
 }
 
+ErrorCode NCWriteMPAS::write_values(std::vector<std::string>& var_names, EntityHandle fileSet)
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
 } /* namespace moab */

diff --git a/src/io/NCWriteMPAS.hpp b/src/io/NCWriteMPAS.hpp
index d7d941b..815292a 100644
--- a/src/io/NCWriteMPAS.hpp
+++ b/src/io/NCWriteMPAS.hpp
@@ -16,11 +16,15 @@ namespace moab {
 class NCWriteMPAS: public NCWriteHelper
 {
 public:
-  NCWriteMPAS(WriteNC* writeNC,  const FileOptions& opts, EntityHandle fileSet) :
-    NCWriteHelper(writeNC, opts, fileSet) {};
+  NCWriteMPAS(WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet) :
+    NCWriteHelper(writeNC, fileId, opts, fileSet) {}
 
   virtual ~NCWriteMPAS();
+
+private:
+  ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet);
 };
 
-} /* namespace moab */
-#endif /* NCWRITEMPAS_HPP_ */
+} // namespace moab
+
+#endif

diff --git a/src/io/WriteNC.cpp b/src/io/WriteNC.cpp
index cecc162..825f3dd 100644
--- a/src/io/WriteNC.cpp
+++ b/src/io/WriteNC.cpp
@@ -105,7 +105,7 @@ ErrorCode WriteNC::write_file(const char* file_name,
     delete myHelper;
 
   // Get appropriate helper instance for WriteNC class based on some info in the file set
-  myHelper = NCWriteHelper::get_nc_helper(this, options, *file_set);
+  myHelper = NCWriteHelper::get_nc_helper(this, fileId, options, *file_set);
   if (NULL == myHelper) {
     ERRORR(MB_FAILURE, "Failed to get NCWriteHelper class instance.");
   }
@@ -116,7 +116,7 @@ ErrorCode WriteNC::write_file(const char* file_name,
   rval = initialize_file(var_names);
   ERRORR(rval, "Failed to initialize file.");
 
-  rval = write_values(var_names, *file_set);
+  rval = myHelper->write_values(var_names, *file_set);
   ERRORR(rval, "Failed to write values.");
 
   success = NCFUNC(close)(fileId);
@@ -741,151 +741,4 @@ ErrorCode WriteNC::initialize_file(std::vector<std::string>& var_names)
   return MB_SUCCESS;
 }
 
-ErrorCode WriteNC::write_values(std::vector<std::string>& var_names, EntityHandle fileSet)
-{
-  /*
-  * Write an Array of Values: nc_put_vara_ type
-  * int nc_put_vara_double(int ncid, int varid, const size_t start[],
-                           const size_t count[], const double *dp);
-  */
-  // Start with coordinates
-  for (std::set<std::string>::iterator setIt = usedCoordinates.begin();
-      setIt != usedCoordinates.end(); setIt++) {
-    std::string coordName = *setIt; // Deep copy
-
-    std::map<std::string, VarData>::iterator vit = varInfo.find(coordName);
-    if (vit == varInfo.end())
-      ERRORR(MB_FAILURE, "Can't find one coordinate variable.");
-
-    VarData& varCoordData = vit->second;
-
-    int success = 0;
-    switch (varCoordData.varDataType) {
-      case NC_DOUBLE:
-        success = NCFUNCAP(_vara_double)(fileId, varCoordData.varId, &varCoordData.writeStarts[0],
-                  &varCoordData.writeCounts[0], (double*)(varCoordData.memoryHogs[0]));
-        ERRORS(success, "Failed to write double data.");
-        break;
-      case NC_INT:
-        success = NCFUNCAP(_vara_int)(fileId, varCoordData.varId, &varCoordData.writeStarts[0],
-                  &varCoordData.writeCounts[0], (int*)(varCoordData.memoryHogs[0]));
-        ERRORS(success, "Failed to write int data.");
-        break;
-      default:
-        success = 1;
-        break;
-    }
- }
-
-  // Now look at requested var_names; if they have time, we will have a list, and write one at a time
-  // We may also need to gather, and transpose stuff
-  // Get all entities of dimension 2 from set
-  // Need to reorder stuff in the order from the file, also transpose from lev dimension
-  ErrorCode rval;
-
-  // For each variable tag in the indexed lists, write a time step data
-  // Assume the first dimension is time (need to check); if not, just write regularly
-  for (size_t i = 0; i < var_names.size(); i++) {
-    std::map<std::string, VarData>::iterator vit = varInfo.find(var_names[i]);
-    if (vit == varInfo.end())
-      ERRORR(MB_FAILURE, "Can't find variable requested.");
-
-    VarData& variableData = vit->second;
-    int numTimeSteps = (int)variableData.varTags.size();
-    if (variableData.has_tsteps) {
-      // Get entities of this variable
-      Range ents;
-      switch (variableData.entLoc) {
-        case WriteNC::ENTLOCVERT:
-          // Vertices
-          rval = mbImpl->get_entities_by_dimension(fileSet, 0, ents);
-          ERRORR(rval, "Can't get entities for vertices.");
-          break;
-        case WriteNC::ENTLOCFACE:
-          // Faces
-          rval = mbImpl->get_entities_by_dimension(fileSet, 2, ents);
-          ERRORR(rval, "Can't get entities for faces.");
-          break;
-        case WriteNC::ENTLOCNSEDGE:
-        case WriteNC::ENTLOCEWEDGE:
-        case WriteNC::ENTLOCEDGE:
-          // Edges
-          rval = mbImpl->get_entities_by_dimension(fileSet, 1, ents);
-          ERRORR(rval, "Can't get entities for edges.");
-          break;
-        default:
-          break;
-      }
-
-      // FIXME: assume now the variable has 4 dimensions as (time, lev, lat, lon)
-      // At each timestep, we need to transpose tag format (lat, lon, lev) back
-      // to NC format (lev, lat, lon) for writing
-      size_t ni = variableData.writeCounts[3]; // lon
-      size_t nj = variableData.writeCounts[2]; // lat
-      size_t nk = variableData.writeCounts[1]; // lev
-
-      variableData.writeCounts[0] = 1; // We will write one time step
-      for (int j = 0; j < numTimeSteps; j++) {
-        // We will write one time step, and count will be one; start will be different
-        // We will write values directly from tag_iterate, but we should also transpose for level
-        // so that means deep copy for transpose
-        variableData.writeStarts[0] = j; // This is time, again
-        int count;
-        void* dataptr;
-        rval = mbImpl->tag_iterate(variableData.varTags[j], ents.begin(), ents.end(), count, dataptr);
-        assert(count == (int)ents.size());
-
-        // Now write from memory directly
-        // FIXME: we need to gather for multiple processors
-        int success = 0;
-        switch (variableData.varDataType) {
-          case NC_DOUBLE: {
-            std::vector<double> tmpdoubledata(ni*nj*nk);
-            // Transpose (lat, lon, lev) back to (lev, lat, lon)
-            jik_to_kji(ni, nj, nk, &tmpdoubledata[0], (double*)(dataptr));
-            success = NCFUNCAP(_vara_double)(fileId, variableData.varId,
-                      &variableData.writeStarts[0], &variableData.writeCounts[0],
-                      &tmpdoubledata[0]);
-            ERRORS(success, "Failed to write double data.");
-            break;
-          }
-          case NC_INT: {
-            std::vector<int> tmpintdata(ni*nj*nk);
-            // Transpose (lat, lon, lev) back to (lev, lat, lon)
-            jik_to_kji(ni, nj, nk, &tmpintdata[0], (int*)(dataptr));
-            success = NCFUNCAP(_vara_int)(fileId, variableData.varId,
-                      &variableData.writeStarts[0], &variableData.writeCounts[0],
-                      &tmpintdata[0]);
-            ERRORS(success, "Failed to write int data.");
-            break;
-          }
-          default:
-            success = 1;
-            break;
-        }
-      }
-    }
-    else {
-      int success = 0;
-      switch (variableData.varDataType) {
-        case NC_DOUBLE:
-          success = NCFUNCAP(_vara_double)(fileId, variableData.varId, &variableData.writeStarts[0],
-                    &variableData.writeCounts[0], (double*)(variableData.memoryHogs[0]));
-          ERRORS(success, "Failed to write double data.");
-          break;
-        case NC_INT:
-          success = NCFUNCAP(_vara_int)(fileId, variableData.varId, &variableData.writeStarts[0],
-                    &variableData.writeCounts[0], (int*)(variableData.memoryHogs[0]));
-          ERRORS(success, "Failed to write int data.");
-          break;
-        default:
-          success = 1;
-          break;
-      }
-    }
-  }
-
-  return MB_SUCCESS;
-}
-
 } // namespace moab

diff --git a/src/io/WriteNC.hpp b/src/io/WriteNC.hpp
index 36207d7..4f6d94d 100644
--- a/src/io/WriteNC.hpp
+++ b/src/io/WriteNC.hpp
@@ -3,7 +3,7 @@
  * storing and accessing finite element mesh data.
  *
  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
  * retains certain rights in this software.
  *
  * This library is free software; you can redistribute it and/or
@@ -64,6 +64,9 @@ class WriteNC : public WriterIface
 {
   friend class NCWriteHelper;
   friend class NCWriteEuler;
+  friend class NCWriteFV;
+  friend class NCWriteHOMME;
+  friend class NCWriteMPAS;
 
 public:
 
@@ -162,18 +165,6 @@ private:
   // the VarData dimension ids are filled up after define
   ErrorCode initialize_file(std::vector<std::string>& var_names); // These are from options
 
-  // Take the info from VarData and write first the coordinates, then the actual variables
-  ErrorCode write_values(std::vector<std::string>& var_names, EntityHandle fileSet);
-
-  template <typename T> void jik_to_kji(size_t ni, size_t nj, size_t nk, T* dest, T* source)
-  {
-    size_t nik = ni * nk, nij = ni * nj;
-    for (std::size_t k = 0; k != nk; k++)
-      for (std::size_t j = 0; j != nj; j++)
-        for (std::size_t i = 0; i != ni; i++)
-          dest[k*nij + j*ni + i] = source[j*nik + i*nk + k];
-  }
-
   // 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