[MOAB-dev] commit/MOAB: danwu: Some minor code changes to NC reader and writer. The default value of VarData::numLev is now set to 0.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri May 9 11:39:29 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/8e5f7908dc2b/
Changeset:   8e5f7908dc2b
Branch:      master
User:        danwu
Date:        2014-05-09 18:39:15
Summary:     Some minor code changes to NC reader and writer. The default value of VarData::numLev is now set to 0.

Affected #:  9 files

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 57f4792..59d6df4 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -388,6 +388,8 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
     for (unsigned int i = 0; i < vdatas.size(); i++) {
       vdatas[i].varTags.resize(tstep_nums.size(), 0);
       vdatas[i].varDatas.resize(tstep_nums.size());
+      // NC reader assumes that non-set variables always have timesteps
+      assert(std::find(vdatas[i].varDims.begin(), vdatas[i].varDims.end(), tDim) != vdatas[i].varDims.end());
       vdatas[i].has_tsteps = true;
     }
 
@@ -1214,7 +1216,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
           std::vector<char> tmpchardata(sz);
           success = NCFUNCAG(_vara_text)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
                                         &tmpchardata[0]);
-          if (vdatas[i].numLev != 1)
+          if (vdatas[i].numLev > 1)
             // Transpose (lev, lat, lon) to (lat, lon, lev)
             success = kji_to_jik(ni, nj, nk, data, &tmpchardata[0]);
           else {
@@ -1228,7 +1230,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
           std::vector<double> tmpdoubledata(sz);
           success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
                                           &tmpdoubledata[0]);
-          if (vdatas[i].numLev != 1)
+          if (vdatas[i].numLev > 1)
             // Transpose (lev, lat, lon) to (lat, lon, lev)
             success = kji_to_jik(ni, nj, nk, data, &tmpdoubledata[0]);
           else {
@@ -1242,7 +1244,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
           std::vector<float> tmpfloatdata(sz);
           success = NCFUNCAG(_vara_float)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
                                           &tmpfloatdata[0]);
-          if (vdatas[i].numLev != 1)
+          if (vdatas[i].numLev > 1)
             // Transpose (lev, lat, lon) to (lat, lon, lev)
             success = kji_to_jik(ni, nj, nk, data, &tmpfloatdata[0]);
           else {
@@ -1256,7 +1258,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
           std::vector<int> tmpintdata(sz);
           success = NCFUNCAG(_vara_int)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
                                         &tmpintdata[0]);
-          if (vdatas[i].numLev != 1)
+          if (vdatas[i].numLev > 1)
             // Transpose (lev, lat, lon) to (lat, lon, lev)
             success = kji_to_jik(ni, nj, nk, data, &tmpintdata[0]);
           else {
@@ -1270,7 +1272,7 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
           std::vector<short> tmpshortdata(sz);
           success = NCFUNCAG(_vara_short)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
                                           &tmpshortdata[0]);
-          if (vdatas[i].numLev != 1)
+          if (vdatas[i].numLev > 1)
             // Transpose (lev, lat, lon) to (lat, lon, lev)
             success = kji_to_jik(ni, nj, nk, data, &tmpshortdata[0]);
           else {

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index b117921..5bf8eec 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -324,14 +324,14 @@ ErrorCode NCHelperEuler::init_mesh_vals()
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
 
-    vd.entLoc = ReadNC::ENTLOCSET;
+    // Default entLoc is ENTLOCSET
     if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
       if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) &&
           (std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()))
         vd.entLoc = ReadNC::ENTLOCFACE;
     }
 
-    vd.numLev = 1;
+    // Default numLev is 0
     if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
   }

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index 7725b55..affd0ef 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -320,7 +320,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
 
-    vd.entLoc = ReadNC::ENTLOCSET;
+    // Default entLoc is ENTLOCSET
     if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
       if ((std::find(vd.varDims.begin(), vd.varDims.end(), iCDim) != vd.varDims.end()) &&
           (std::find(vd.varDims.begin(), vd.varDims.end(), jCDim) != vd.varDims.end()))
@@ -333,7 +333,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
         vd.entLoc = ReadNC::ENTLOCEWEDGE;
     }
 
-    vd.numLev = 1;
+    // Default numLev is 0
     if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
   }

diff --git a/src/io/NCHelperGCRM.cpp b/src/io/NCHelperGCRM.cpp
index 30f6b86..3bddecc 100644
--- a/src/io/NCHelperGCRM.cpp
+++ b/src/io/NCHelperGCRM.cpp
@@ -135,7 +135,7 @@ ErrorCode NCHelperGCRM::init_mesh_vals()
   for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
     ReadNC::VarData& vd = (*vmit).second;
 
-    vd.entLoc = ReadNC::ENTLOCSET;
+    // Default entLoc is ENTLOCSET
     if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
       if (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end())
         vd.entLoc = ReadNC::ENTLOCVERT;
@@ -145,7 +145,7 @@ ErrorCode NCHelperGCRM::init_mesh_vals()
         vd.entLoc = ReadNC::ENTLOCFACE;
     }
 
-    vd.numLev = 1;
+    // Default numLev is 0
     if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
     else {

diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index 53fa9ad..85f3a69 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -190,13 +190,13 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
   for (mit = varInfo.begin(); mit != varInfo.end(); ++mit) {
     ReadNC::VarData& vd = (*mit).second;
 
-    vd.entLoc = ReadNC::ENTLOCSET;
+    // Default entLoc is ENTLOCSET
     if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
       if (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end())
         vd.entLoc = ReadNC::ENTLOCVERT;
     }
 
-    vd.numLev = 1;
+    // Default numLev is 0
     if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
   }

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 9c70b80..4630216 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -164,7 +164,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   for (vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit) {
     ReadNC::VarData& vd = (*vmit).second;
 
-    vd.entLoc = ReadNC::ENTLOCSET;
+    // Default entLoc is ENTLOCSET
     if (std::find(vd.varDims.begin(), vd.varDims.end(), tDim) != vd.varDims.end()) {
       if (std::find(vd.varDims.begin(), vd.varDims.end(), vDim) != vd.varDims.end())
         vd.entLoc = ReadNC::ENTLOCVERT;
@@ -174,7 +174,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
         vd.entLoc = ReadNC::ENTLOCFACE;
     }
 
-    vd.numLev = 1;
+    // Default numLev is 0
     if (std::find(vd.varDims.begin(), vd.varDims.end(), levDim) != vd.varDims.end())
       vd.numLev = nLevels;
     else {
@@ -602,8 +602,8 @@ ErrorCode NCHelperMPAS::read_ucd_variable_to_nonset_allocate(std::vector<ReadNC:
         break;
     }
 
-    // Finally: nVertLevels or other optional levels, it is possible that there
-    // is no level dimension for this non-set variable
+    // Finally: nVertLevels or other optional levels, it is possible that there is no
+    // level dimension (numLev is 0) for this non-set variable, e.g. (Time, nCells)
     vdatas[i].readStarts[2] = 0;
     vdatas[i].readCounts[2] = vdatas[i].numLev;
 

diff --git a/src/io/NCWriteHelper.cpp b/src/io/NCWriteHelper.cpp
index f466677..1a8a7eb 100644
--- a/src/io/NCWriteHelper.cpp
+++ b/src/io/NCWriteHelper.cpp
@@ -84,9 +84,11 @@ ErrorCode NCWriteHelper::collect_variable_data(std::vector<std::string>& var_nam
     if (usedCoordinates.find(varname) != usedCoordinates.end())
       continue;
 
+    // Default has_tsteps is false
     if (std::find(currentVarData.varDims.begin(), currentVarData.varDims.end(), tDim) != currentVarData.varDims.end())
       currentVarData.has_tsteps = true;
 
+    // Default numLev is 0
     if ((std::find(currentVarData.varDims.begin(), currentVarData.varDims.end(), levDim) != currentVarData.varDims.end()))
       currentVarData.numLev = nLevels;
 

diff --git a/src/io/ReadNC.hpp b/src/io/ReadNC.hpp
index 80fb02a..1a0ae91 100644
--- a/src/io/ReadNC.hpp
+++ b/src/io/ReadNC.hpp
@@ -112,7 +112,7 @@ private:
   class VarData
   {
     public:
-    VarData() : varId(-1), numAtts(-1), entLoc(ENTLOCSET), numLev(1), sz(0), has_tsteps(false) {}
+    VarData() : varId(-1), numAtts(-1), entLoc(ENTLOCSET), numLev(0), sz(0), has_tsteps(false) {}
     int varId;
     int numAtts;
     nc_type varDataType;

diff --git a/src/io/WriteNC.hpp b/src/io/WriteNC.hpp
index 3db9dc2..586cad6 100644
--- a/src/io/WriteNC.hpp
+++ b/src/io/WriteNC.hpp
@@ -116,7 +116,7 @@ private:
 
   class VarData
   {
-    public:VarData() : varId(-1), numAtts(-1), entLoc(ENTLOCSET), numLev(1), sz(0), has_tsteps(false) {}
+    public:VarData() : varId(-1), numAtts(-1), entLoc(ENTLOCSET), numLev(0), sz(0), has_tsteps(false) {}
     int varId;
     int numAtts;
     nc_type varDataType;

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