[MOAB-dev] commit/MOAB: danwu: Besides nVertLevels, should support other optional levels (e.g. nVertLevelsP1) for MPAS reader, in progress.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Nov 11 17:09:22 CST 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/c79a9de34e28/
Changeset:   c79a9de34e28
Branch:      master
User:        danwu
Date:        2013-11-12 00:08:35
Summary:     Besides nVertLevels, should support other optional levels (e.g. nVertLevelsP1) for MPAS reader, in progress.

Affected #:  1 file

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 54ba598..6c728aa 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -97,7 +97,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   vDim = idx;
   nVertices = dimLens[idx];
 
-  // Get number of levels
+  // Get number of vertex levels
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertLevels")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
@@ -106,6 +106,27 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   levDim = idx;
   nLevels = dimLens[idx];
 
+  // Dimension numbers for other optional levels
+  std::vector<unsigned int> opt_lev_dims;
+
+  // Get number of vertex levels P1
+  if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertLevelsP1")) != dimNames.end()) {
+    idx = vit - dimNames.begin();
+    opt_lev_dims.push_back(idx);
+  }
+
+  // Get number of vertex levels P2
+  if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertLevelsP2")) != dimNames.end()) {
+    idx = vit - dimNames.begin();
+    opt_lev_dims.push_back(idx);
+  }
+
+  // Get number of soil levels
+  if ((vit = std::find(dimNames.begin(), dimNames.end(), "nSoilLevels")) != dimNames.end()) {
+    idx = vit - dimNames.begin();
+    opt_lev_dims.push_back(idx);
+  }
+
   std::map<std::string, ReadNC::VarData>::iterator vmit;
 
   // Store time coordinate values in tVals
@@ -124,17 +145,37 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   // Determine the entity location type of a variable
   for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
     ReadNC::VarData& vd = (*vmit).second;
-    if ((std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end()) &&
-      (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end()))
+    vd.entLoc = ReadNC::ENTLOCSET;
+
+    if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) &&
+      (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end()))
       vd.entLoc = ReadNC::ENTLOCVERT;
-    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), eDim) != vd.varDims.end()) &&
-      (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end()))
+    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) &&
+      (std::find(vd.varDims.begin(), vd.varDims.end(), eDim) != vd.varDims.end()))
       vd.entLoc = ReadNC::ENTLOCEDGE;
-    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), cDim) != vd.varDims.end()) &&
-      (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end()))
+    else if ((std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) &&
+      (std::find(vd.varDims.begin(), vd.varDims.end(), cDim) != vd.varDims.end()))
       vd.entLoc = ReadNC::ENTLOCFACE;
   }
 
+  // Determine number of levels of a variable
+  for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
+    ReadNC::VarData& vd = (*vmit).second;
+    vd.numLev = 1;
+
+    if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end()) {
+      vd.numLev = nLevels;
+      continue;
+    }
+
+    for (unsigned int i = 0; i < opt_lev_dims.size(); i++) {
+      if (std::find(vd.varDims.begin(), vd.varDims.end(), opt_lev_dims[i]) != vd.varDims.end()) {
+        vd.numLev = dimLens[opt_lev_dims[i]];
+        break;
+      }
+    }
+  }
+
   // Hack: create dummy tags for dimensions (like nCells) with no corresponding coordinate variables
   init_dims_with_no_coord_vars_info();
 
@@ -585,8 +626,6 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC:
     if (noEdges && vdatas[i].entLoc == ReadNC::ENTLOCEDGE)
       continue;
 
-    vdatas[i].numLev = nLevels;
-
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
       // Get the tag to read into

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