[MOAB-dev] commit/MOAB: danwu: Applied error handling code to NCHelperMPAS.cpp

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Mar 21 14:09:28 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/aa5cf2be6072/
Changeset:   aa5cf2be6072
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-03-21 20:09:15
Summary:     Applied error handling code to NCHelperMPAS.cpp

Affected #:  1 file

diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index 58093e3..3d777c2 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -10,12 +10,6 @@
 
 #include <cmath>
 
-#define ERRORR(rval, str) \
-  if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
-
-#define ERRORS(err, str) \
-  if (err) {_readNC->readMeshIface->report_error("%s", str); return MB_FAILURE;}
-
 namespace moab {
 
 const int DEFAULT_MAX_EDGES_PER_CELL = 10;
@@ -70,7 +64,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     idx = vit - dimNames.begin();
     maxEdgesPerCell = dimLens[idx];
     if (maxEdgesPerCell > DEFAULT_MAX_EDGES_PER_CELL) {
-      ERRORR(MB_FAILURE, "maxEdgesPerCell read from the MPAS file header has exceeded DEFAULT_MAX_EDGES_PER_CELL.");
+      SET_ERR(MB_FAILURE, "maxEdgesPerCell read from the MPAS file header has exceeded DEFAULT_MAX_EDGES_PER_CELL");
     }
   }
 
@@ -80,7 +74,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   else if ((vit = std::find(dimNames.begin(), dimNames.end(), "time")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
-    ERRORR(MB_FAILURE, "Couldn't find 'Time' or 'time' dimension.");
+    SET_ERR(MB_FAILURE, "Couldn't find 'Time' or 'time' dimension");
   }
   tDim = idx;
   nTimeSteps = dimLens[idx];
@@ -89,7 +83,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nCells")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
-    ERRORR(MB_FAILURE, "Couldn't find 'nCells' dimension.");
+    SET_ERR(MB_FAILURE, "Couldn't find 'nCells' dimension");
   }
   cDim = idx;
   nCells = dimLens[idx];
@@ -98,7 +92,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nEdges")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
-    ERRORR(MB_FAILURE, "Couldn't find 'nEdges' dimension.");
+    SET_ERR(MB_FAILURE, "Couldn't find 'nEdges' dimension");
   }
   eDim = idx;
   nEdges = dimLens[idx];
@@ -108,7 +102,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertices")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
-    ERRORR(MB_FAILURE, "Couldn't find 'nVertices' dimension.");
+    SET_ERR(MB_FAILURE, "Couldn't find 'nVertices' dimension");
   }
   vDim = idx;
   nVertices = dimLens[idx];
@@ -117,7 +111,7 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   if ((vit = std::find(dimNames.begin(), dimNames.end(), "nVertLevels")) != dimNames.end())
     idx = vit - dimNames.begin();
   else {
-    ERRORR(MB_FAILURE, "Couldn't find 'nVertLevels' dimension.");
+    SET_ERR(MB_FAILURE, "Couldn't find 'nVertLevels' dimension");
   }
   levDim = idx;
   nLevels = dimLens[idx];
@@ -150,8 +144,8 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
     // Note, two possible types for xtime variable: double(Time) or char(Time, StrLen)
     if ((vmit = varInfo.find("xtime")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
       // If xtime variable is double type, read time coordinate values to tVals
-      rval = read_coordinate("xtime", 0, nTimeSteps - 1, tVals);
-      ERRORR(rval, "Trouble reading 'xtime' variable.");
+      rval = read_coordinate("xtime", 0, nTimeSteps - 1, tVals); \
+      CHK_ERR1(rval, "Trouble reading 'xtime' variable");
     }
     else {
       // If xtime variable does not exist, or it is string type, set dummy values to tVals
@@ -193,8 +187,8 @@ ErrorCode NCHelperMPAS::init_mesh_vals()
   }
 
   // Hack: create dummy variables for dimensions (like nCells) with no corresponding coordinate variables
-  rval = create_dummy_variables();
-  ERRORR(rval, "Failed to create dummy variables.");
+  rval = create_dummy_variables(); \
+  CHK_ERR1(rval, "Failed to create dummy variables");
 
   return MB_SUCCESS;
 }
@@ -335,8 +329,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     start_cell_idx++; // 0 based -> 1 based
 
     // Redistribute local cells after trivial partition (e.g. apply Zoltan partition)
-    ErrorCode rval = redistribute_local_cells(start_cell_idx);
-    ERRORR(rval, "Failed to redistribute local cells after trivial partition.");
+    ErrorCode rval = redistribute_local_cells(start_cell_idx); \
+    CHK_ERR1(rval, "Failed to redistribute local cells after trivial partition");
   }
   else {
     nLocalCells = nCells;
@@ -346,7 +340,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   // Read number of edges on each local cell, to calculate actual maxEdgesPerCell
   int nEdgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "nEdgesOnCell", &nEdgesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of nEdgesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of nEdgesOnCell");
   std::vector<int> num_edges_on_local_cells(nLocalCells);
 #ifdef PNETCDF_FILE
   size_t nb_reads = localGidCells.psize();
@@ -371,7 +366,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     success = NCFUNCAG(_vara_int)(_fileId, nEdgesOnCellVarId, &read_start, &read_count,
                                       &(num_edges_on_local_cells[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read nEdgesOnCell data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read nEdgesOnCell data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1);
@@ -380,7 +376,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Get local maxEdgesPerCell on this proc
@@ -405,7 +402,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
   // Read vertices on each local cell, to get localGidVerts and cell connectivity later
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of verticesOnCell");
   std::vector<int> vertices_on_local_cells(nLocalCells * maxEdgesPerCell);
 #ifdef PNETCDF_FILE
   idxReq = 0;
@@ -428,7 +426,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
     success = NCFUNCAG(_vara_int)(_fileId, verticesOnCellVarId, read_starts, read_counts,
                                       &(vertices_on_local_cells[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read verticesOnCell data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read verticesOnCell data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1) * maxEdgesPerCell;
@@ -437,7 +436,8 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Correct local cell vertices array, replace the padded vertices with the last vertices
@@ -453,56 +453,56 @@ ErrorCode NCHelperMPAS::create_mesh(Range& faces)
 
   // Create local vertices
   EntityHandle start_vertex;
-  ErrorCode rval = create_local_vertices(vertices_on_local_cells, start_vertex);
-  ERRORR(rval, "Failed to create local vertices for MPAS mesh.");
+  ErrorCode rval = create_local_vertices(vertices_on_local_cells, start_vertex); \
+  CHK_ERR1(rval, "Failed to create local vertices for MPAS mesh");
 
   // Create local edges (unless NO_EDGES read option is set)
   if (!noEdges) {
-    rval = create_local_edges(start_vertex, num_edges_on_local_cells);
-    ERRORR(rval, "Failed to create local edges for MPAS mesh.");
+    rval = create_local_edges(start_vertex, num_edges_on_local_cells); \
+    CHK_ERR1(rval, "Failed to create local edges for MPAS mesh");
   }
 
   // Create local cells, either unpadded or padded
   if (noMixedElements) {
-    rval = create_padded_local_cells(vertices_on_local_cells, start_vertex, faces);
-    ERRORR(rval, "Failed to create padded local cells for MPAS mesh.");
+    rval = create_padded_local_cells(vertices_on_local_cells, start_vertex, faces); \
+    CHK_ERR1(rval, "Failed to create padded local cells for MPAS mesh");
   }
   else {
-    rval = create_local_cells(vertices_on_local_cells, num_edges_on_local_cells, start_vertex, faces);
-    ERRORR(rval, "Failed to create local cells for MPAS mesh.");
+    rval = create_local_cells(vertices_on_local_cells, num_edges_on_local_cells, start_vertex, faces); \
+    CHK_ERR1(rval, "Failed to create local cells for MPAS mesh");
   }
 
   // Set tag for numCellGroups
   Tag numCellGroupsTag = 0;
-  rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-  ERRORR(rval, "Failed to get __NUM_CELL_GROUPS tag.");
-  rval = mbImpl->tag_set_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups);
-  ERRORR(rval, "Failed to set data for __NUM_CELL_GROUPS tag.");
+  rval = mbImpl->tag_get_handle("__NUM_CELL_GROUPS", 1, MB_TYPE_INTEGER, numCellGroupsTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+  CHK_ERR1(rval, "Failed to get __NUM_CELL_GROUPS tag");
+  rval = mbImpl->tag_set_data(numCellGroupsTag, &_fileSet, 1, &numCellGroups); \
+  CHK_ERR1(rval, "Failed to set data for __NUM_CELL_GROUPS tag");
 
   if (createGatherSet) {
     EntityHandle gather_set;
-    rval = _readNC->readMeshIface->create_gather_set(gather_set);
-    ERRORR(rval, "Failed to create gather set.");
+    rval = _readNC->readMeshIface->create_gather_set(gather_set); \
+    CHK_ERR1(rval, "Failed to create gather set");
 
     // Create gather set vertices
     EntityHandle start_gather_set_vertex;
-    rval = create_gather_set_vertices(gather_set, start_gather_set_vertex);
-    ERRORR(rval, "Failed to create gather set vertices for MPAS mesh");
+    rval = create_gather_set_vertices(gather_set, start_gather_set_vertex); \
+    CHK_ERR1(rval, "Failed to create gather set vertices for MPAS mesh");
 
     // Create gather set edges (unless NO_EDGES read option is set)
     if (!noEdges) {
-      rval = create_gather_set_edges(gather_set, start_gather_set_vertex);
-      ERRORR(rval, "Failed to create gather set edges for MPAS mesh.");
+      rval = create_gather_set_edges(gather_set, start_gather_set_vertex); \
+      CHK_ERR1(rval, "Failed to create gather set edges for MPAS mesh");
     }
 
     // Create gather set cells, either unpadded or padded
     if (noMixedElements) {
-      rval = create_padded_gather_set_cells(gather_set, start_gather_set_vertex);
-      ERRORR(rval, "Failed to create padded gather set cells for MPAS mesh.");
+      rval = create_padded_gather_set_cells(gather_set, start_gather_set_vertex); \
+      CHK_ERR1(rval, "Failed to create padded gather set cells for MPAS mesh");
     }
     else {
-      rval = create_gather_set_cells(gather_set, start_gather_set_vertex);
-      ERRORR(rval, "Failed to create gather set cells for MPAS mesh.");
+      rval = create_gather_set_cells(gather_set, start_gather_set_vertex); \
+      CHK_ERR1(rval, "Failed to create gather set cells for MPAS mesh");
     }
   }
 
@@ -522,28 +522,28 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_allocate(std::vector<ReadNC
 
   // Get vertices in set
   Range verts;
-  rval = mbImpl->get_entities_by_dimension(_fileSet, 0, verts);
-  ERRORR(rval, "Trouble getting vertices in set.");
+  rval = mbImpl->get_entities_by_dimension(_fileSet, 0, verts); \
+  CHK_ERR1(rval, "Trouble getting vertices in current file set");
   assert("Should only have a single vertex subrange, since they were read in one shot" &&
       verts.psize() == 1);
 
   // Get edges in set
   Range edges;
-  rval = mbImpl->get_entities_by_dimension(_fileSet, 1, edges);
-  ERRORR(rval, "Trouble getting edges in set.");
+  rval = mbImpl->get_entities_by_dimension(_fileSet, 1, edges); \
+  CHK_ERR1(rval, "Trouble getting edges in current file set");
 
   // Get faces in set
   Range faces;
-  rval = mbImpl->get_entities_by_dimension(_fileSet, 2, faces);
-  ERRORR(rval, "Trouble getting faces in set.");
+  rval = mbImpl->get_entities_by_dimension(_fileSet, 2, faces); \
+  CHK_ERR1(rval, "Trouble getting faces in current file set");
   // Note, for MPAS faces.psize() can be more than 1
 
 #ifdef USE_MPI
   bool& isParallel = _readNC->isParallel;
   if (isParallel) {
     ParallelComm*& myPcomm = _readNC->myPcomm;
-    rval = myPcomm->filter_pstatus(faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &facesOwned);
-    ERRORR(rval, "Trouble getting owned faces in set.");
+    rval = myPcomm->filter_pstatus(faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &facesOwned); \
+    CHK_ERR1(rval, "Trouble getting owned faces in current file set");
   }
   else
     facesOwned = faces; // not running in parallel, but still with MPI
@@ -598,8 +598,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_allocate(std::vector<ReadNC
         range = &edges;
         break;
       default:
-        ERRORR(MB_FAILURE, "Unexpected entity location type for MPAS non-set variable.");
-        break;
+        SET_ERR_STR(MB_FAILURE, "Unexpected entity location type for non-set variable " << vdatas[i].varName);
     }
 
     // Finally: nVertLevels or other optional levels, it is possible that there
@@ -616,13 +615,13 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_allocate(std::vector<ReadNC
       dbgOut.tprintf(2, "Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
 
       if (tstep_nums[t] >= dimLens[tDim]) {
-        ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for a timestep number.");
+        SET_ERR_STR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number " << tstep_nums[t]);
       }
 
       // Get the tag to read into
       if (!vdatas[i].varTags[t]) {
         rval = get_tag_to_nonset(vdatas[i], tstep_nums[t], vdatas[i].varTags[t], vdatas[i].numLev);
-        ERRORR(rval, "Trouble getting tag.");
+        CHK_ERR1_STR(rval, "Trouble getting tag for non-set variable " << vdatas[i].varName);
       }
 
       // Get ptr to tag space
@@ -635,7 +634,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_allocate(std::vector<ReadNC
         void* data;
         int count;
         rval = mbImpl->tag_iterate(vdatas[i].varTags[t], range->begin(), range->end(), count, data);
-        ERRORR(rval, "Failed to iterate tag.");
+        CHK_ERR1_STR(rval, "Failed to get tag iterator for non-set variable " << vdatas[i].varName);
         assert((unsigned)count == range->size());
         vdatas[i].varDatas[t] = data;
       }
@@ -652,8 +651,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
   bool& noEdges = _readNC->noEdges;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
-  ErrorCode rval = read_ucd_variables_to_nonset_allocate(vdatas, tstep_nums);
-  ERRORR(rval, "Trouble allocating read variables.");
+  ErrorCode rval = read_ucd_variables_to_nonset_allocate(vdatas, tstep_nums); \
+  CHK_ERR1(rval, "Trouble allocating space to read non-set variables");
 
   // Finally, read into that space
   int success;
@@ -675,8 +674,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
         pLocalGid = &localGidEdges;
         break;
       default:
-        ERRORR(MB_FAILURE, "Unrecognized entity location type.");
-        break;
+        SET_ERR_STR(MB_FAILURE, "Unexpected entity location type for non-set variable " << vdatas[i].varName);
     }
 
     std::size_t sz = vdatas[i].sz;
@@ -694,9 +692,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
       switch (vdatas[i].varDataType) {
         case NC_BYTE:
         case NC_CHAR: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
-        }
+          SET_ERR(MB_FAILURE, "Reading byte or char type variables is not implemented yet");
+         }
         case NC_DOUBLE: {
           std::vector<double> tmpdoubledata(sz);
 
@@ -721,7 +718,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
             success = NCFUNCREQG(_vara_double)(_fileId, vdatas[i].varId,
                 &(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
                             &(tmpdoubledata[indexInDoubleArray]), &requests[idxReq++]);
-            ERRORS(success, "Failed to read double data in loop");
+            if (success)
+              SET_ERR_STR(MB_FAILURE, "Failed to read double data in a loop for non-set variable " << vdatas[i].varName);
             // We need to increment the index in double array for the
             // next subrange
             indexInDoubleArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
@@ -729,7 +727,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
           assert(ic == pLocalGid->psize());
 
           success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-          ERRORS(success, "Failed on wait_all.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed on wait_all");
 
           if (vdatas[i].entLoc == ReadNC::ENTLOCFACE && numCellGroups > 1) {
             // For a cell variable that is NOT on one contiguous chunk of faces, allocate tag space for
@@ -738,8 +737,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
             while (iter != facesOwned.end()) {
               int count;
               void* ptr;
-              rval = mbImpl->tag_iterate(vdatas[i].varTags[t], iter, facesOwned.end(), count, ptr);
-              ERRORR(rval, "Failed to iterate tag on owned faces.");
+              rval = mbImpl->tag_iterate(vdatas[i].varTags[t], iter, facesOwned.end(), count, ptr); \
+              CHK_ERR1(rval, "Failed to iterate tag on owned faces");
 
               for (int j = 0; j < count; j++) {
                 int global_cell_idx = cellHandleToGlobalID[*(iter + j)]; // Global cell index, 1 based
@@ -761,25 +760,19 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
           break;
         }
         case NC_FLOAT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading float type variables is not implemented yet");
         }
         case NC_INT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading int type variables is not implemented yet");
         }
         case NC_SHORT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading short type variables is not implemented yet");
         }
         default:
-          success = 1;
+          SET_ERR_STR(MB_FAILURE, "Unrecognized data type for non-set variable " << vdatas[i].varName);
       }
-
-      if (success)
-        ERRORR(MB_FAILURE, "Trouble reading variable.");
-    }
-  }
+    } // for (unsigned int t = 0; t < tstep_nums.size(); t++)
+  } // for (unsigned int i = 0; i < vdatas.size(); i++)
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
     if (noEdges && vdatas[i].entLoc == ReadNC::ENTLOCEDGE)
@@ -787,9 +780,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
 
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = convert_variable(vdatas[i], t);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
+      rval = convert_variable(vdatas[i], t); \
+      CHK_ERR1_STR(rval, "Failed to convert non-set variable " << vdatas[i].varName);
     }
   }
   // Debug output, if requested
@@ -809,8 +801,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
   bool& noEdges = _readNC->noEdges;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
-  ErrorCode rval = read_ucd_variables_to_nonset_allocate(vdatas, tstep_nums);
-  ERRORR(rval, "Trouble allocating read variables.");
+  ErrorCode rval = read_ucd_variables_to_nonset_allocate(vdatas, tstep_nums); \
+  CHK_ERR1(rval, "Trouble allocating space to read non-set variables");
 
   // Finally, read into that space
   int success;
@@ -832,8 +824,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
         pLocalGid = &localGidEdges;
         break;
       default:
-        ERRORR(MB_FAILURE, "Unrecognized entity location type.");
-        break;
+        SET_ERR_STR(MB_FAILURE, "Unexpected entity location type for non-set variable " << vdatas[i].varName);
     }
 
     std::size_t sz = vdatas[i].sz;
@@ -845,8 +836,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
       switch (vdatas[i].varDataType) {
         case NC_BYTE:
         case NC_CHAR: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading byte or char type variables is not implemented yet");
         }
         case NC_DOUBLE: {
           std::vector<double> tmpdoubledata(sz);
@@ -869,7 +859,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
             success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId,
                 &(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
                             &(tmpdoubledata[indexInDoubleArray]));
-            ERRORS(success, "Failed to read double data in loop");
+            if (success)
+              SET_ERR_STR(MB_FAILURE, "Failed to read double data in a loop for non-set variable " << vdatas[i].varName);
             // We need to increment the index in double array for the
             // next subrange
             indexInDoubleArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
@@ -883,8 +874,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
             while (iter != facesOwned.end()) {
               int count;
               void* ptr;
-              rval = mbImpl->tag_iterate(vdatas[i].varTags[t], iter, facesOwned.end(), count, ptr);
-              ERRORR(rval, "Failed to iterate tag on owned faces.");
+              rval = mbImpl->tag_iterate(vdatas[i].varTags[t], iter, facesOwned.end(), count, ptr); \
+              CHK_ERR1(rval, "Failed to iterate tag on owned faces");
 
               for (int j = 0; j < count; j++) {
                 int global_cell_idx = cellHandleToGlobalID[*(iter + j)]; // Global cell index, 1 based
@@ -906,25 +897,19 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
           break;
         }
         case NC_FLOAT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading float type variables is not implemented yet");
         }
         case NC_INT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading int type variables is not implemented yet");
         }
         case NC_SHORT: {
-          ERRORR(MB_FAILURE, "not implemented");
-          break;
+          SET_ERR(MB_FAILURE, "Reading short type variables is not implemented yet");
         }
         default:
-          success = 1;
+          SET_ERR_STR(MB_FAILURE, "Unrecognized data type for non-set variable " << vdatas[i].varName);
       }
-
-      if (success)
-        ERRORR(MB_FAILURE, "Trouble reading variable.");
-    }
-  }
+    } // for (unsigned int t = 0; t < tstep_nums.size(); t++)
+  } // for (unsigned int i = 0; i < vdatas.size(); i++)
 
   for (unsigned int i = 0; i < vdatas.size(); i++) {
     if (noEdges && vdatas[i].entLoc == ReadNC::ENTLOCEDGE)
@@ -932,9 +917,8 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
 
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
       dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      ErrorCode tmp_rval = convert_variable(vdatas[i], t);
-      if (MB_SUCCESS != tmp_rval)
-        rval = tmp_rval;
+      rval = convert_variable(vdatas[i], t); \
+      CHK_ERR1_STR(rval, "Failed to convert non-set variable " << vdatas[i].varName);
     }
   }
 
@@ -958,37 +942,43 @@ ErrorCode NCHelperMPAS::redistribute_local_cells(int start_cell_idx)
     // Read x coordinates of cell centers
     int xCellVarId;
     int success = NCFUNC(inq_varid)(_fileId, "xCell", &xCellVarId);
-    ERRORS(success, "Failed to get variable id of xCell.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to get variable id of xCell");
     std::vector<double> xCell(nLocalCells);
     NCDF_SIZE read_start = static_cast<NCDF_SIZE>(start_cell_idx - 1);
     NCDF_SIZE read_count = static_cast<NCDF_SIZE>(nLocalCells);
     success = NCFUNCAG(_vara_double)(_fileId, xCellVarId, &read_start, &read_count, &xCell[0]);
-    ERRORS(success, "Failed to read xCell data.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read xCell data");
 
     // Read y coordinates of cell centers
     int yCellVarId;
     success = NCFUNC(inq_varid)(_fileId, "yCell", &yCellVarId);
-    ERRORS(success, "Failed to get variable id of yCell.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to get variable id of yCell");
     std::vector<double> yCell(nLocalCells);
     success = NCFUNCAG(_vara_double)(_fileId, yCellVarId, &read_start, &read_count, &yCell[0]);
-    ERRORS(success, "Failed to read yCell data.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read yCell data");
 
     // Read z coordinates of cell centers
     int zCellVarId;
     success = NCFUNC(inq_varid)(_fileId, "zCell", &zCellVarId);
-    ERRORS(success, "Failed to get variable id of zCell.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to get variable id of zCell");
     std::vector<double> zCell(nLocalCells);
     success = NCFUNCAG(_vara_double)(_fileId, zCellVarId, &read_start, &read_count, &zCell[0]);
-    ERRORS(success, "Failed to read zCell data.");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read zCell data");
 
     // Zoltan partition using RCB; maybe more studies would be good, as to which partition
     // is better
     Interface*& mbImpl = _readNC->mbImpl;
     DebugOutput& dbgOut = _readNC->dbgOut;
     MBZoltan* mbZTool = new MBZoltan(mbImpl, false, 0, NULL);
-    ErrorCode rval = mbZTool->repartition(xCell, yCell, zCell, start_cell_idx, "RCB", localGidCells);
-    delete mbZTool;
-    ERRORR(rval, "Error in Zoltan partitioning.");
+    ErrorCode rval = mbZTool->repartition(xCell, yCell, zCell, start_cell_idx, "RCB", localGidCells); \
+    delete mbZTool; \
+    CHK_ERR1(rval, "Error in Zoltan partitioning");
 
     dbgOut.tprintf(1, "After Zoltan partitioning, localGidCells.psize() = %d\n", (int)localGidCells.psize());
     dbgOut.tprintf(1, "                           localGidCells.size() = %d\n", (int)localGidCells.size());
@@ -1026,27 +1016,27 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
   std::vector<double*> arrays;
   ErrorCode rval = _readNC->readMeshIface->get_node_coords(3, nLocalVertices, 0, start_vertex, arrays,
                                                           // Might have to create gather mesh later
-                                                          (createGatherSet ? nLocalVertices + nVertices : nLocalVertices));
-  ERRORR(rval, "Failed to create local vertices.");
+                                                          (createGatherSet ? nLocalVertices + nVertices : nLocalVertices)); \
+  CHK_ERR1(rval, "Failed to create local vertices");
 
-  // Add local vertices to the file set
+  // Add local vertices to current file set
   Range local_verts_range(start_vertex, start_vertex + nLocalVertices - 1);
-  rval = _readNC->mbImpl->add_entities(_fileSet, local_verts_range);
-  ERRORR(rval, "Failed to add local vertices to the file set.");
+  rval = _readNC->mbImpl->add_entities(_fileSet, local_verts_range); \
+  CHK_ERR1(rval, "Failed to add local vertices to current file set");
 
   // Get ptr to GID memory for local vertices
   int count = 0;
   void* data = NULL;
-  rval = mbImpl->tag_iterate(mGlobalIdTag, local_verts_range.begin(), local_verts_range.end(), count, data);
-  ERRORR(rval, "Failed to iterate global id tag on local vertices.");
+  rval = mbImpl->tag_iterate(mGlobalIdTag, local_verts_range.begin(), local_verts_range.end(), count, data); \
+  CHK_ERR1(rval, "Failed to iterate global id tag on local vertices");
   assert(count == nLocalVertices);
   int* gid_data = (int*) data;
   std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
 
   // Duplicate GID data, which will be used to resolve sharing
   if (mpFileIdTag) {
-    rval = mbImpl->tag_iterate(*mpFileIdTag, local_verts_range.begin(), local_verts_range.end(), count, data);
-    ERRORR(rval, "Failed to iterate file id tag on local vertices.");
+    rval = mbImpl->tag_iterate(*mpFileIdTag, local_verts_range.begin(), local_verts_range.end(), count, data); \
+    CHK_ERR1(rval, "Failed to iterate file id tag on local vertices");
     assert(count == nLocalVertices);
     gid_data = (int*) data;
     std::copy(localGidVerts.begin(), localGidVerts.end(), gid_data);
@@ -1063,7 +1053,8 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
   double* xptr = arrays[0];
   int xVertexVarId;
   int success = NCFUNC(inq_varid)(_fileId, "xVertex", &xVertexVarId);
-  ERRORS(success, "Failed to get variable id of xVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of xVertex");
   size_t indexInArray = 0;
   for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
        pair_iter != localGidVerts.pair_end();
@@ -1081,7 +1072,8 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
     success = NCFUNCAG(_vara_double)(_fileId, xVertexVarId, &read_start, &read_count,
                                       &(xptr[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read xVertex data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read xVertex data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1);
@@ -1090,14 +1082,16 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Read y coordinates for local vertices
   double* yptr = arrays[1];
   int yVertexVarId;
   success = NCFUNC(inq_varid)(_fileId, "yVertex", &yVertexVarId);
-  ERRORS(success, "Failed to get variable id of yVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of yVertex");
 #ifdef PNETCDF_FILE
   idxReq = 0;
 #endif
@@ -1118,7 +1112,8 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
     success = NCFUNCAG(_vara_double)(_fileId, yVertexVarId, &read_start, &read_count,
                                       &(yptr[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read yVertex data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read yVertex data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1);
@@ -1127,14 +1122,16 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Read z coordinates for local vertices
   double* zptr = arrays[2];
   int zVertexVarId;
   success = NCFUNC(inq_varid)(_fileId, "zVertex", &zVertexVarId);
-  ERRORS(success, "Failed to get variable id of zVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of zVertex");
 #ifdef PNETCDF_FILE
   idxReq = 0;
 #endif
@@ -1155,7 +1152,8 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
     success = NCFUNCAG(_vara_double)(_fileId, zVertexVarId, &read_start, &read_count,
                                       &(zptr[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read zVertex data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read zVertex data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1);
@@ -1164,7 +1162,8 @@ ErrorCode NCHelperMPAS::create_local_vertices(const std::vector<int>& vertices_o
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   return MB_SUCCESS;
@@ -1179,7 +1178,8 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
   // Read edges on each local cell, to get localGidEdges
   int edgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "edgesOnCell", &edgesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of edgesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of edgesOnCell");
 
   std::vector<int> edges_on_local_cells(nLocalCells * maxEdgesPerCell);
   dbgOut.tprintf(1, "   edges_on_local_cells.size() = %d\n", (int)edges_on_local_cells.size());
@@ -1207,7 +1207,8 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
     success = NCFUNCAG(_vara_int)(_fileId, edgesOnCellVarId, read_starts, read_counts,
                                       &(edges_on_local_cells[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read edgesOnCell data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read edgesOnCell data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1) * maxEdgesPerCell;
@@ -1216,7 +1217,8 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Correct local cell edges array in the same way as local cell vertices array, replace the
@@ -1242,19 +1244,19 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
   EntityHandle* conn_arr_edges = NULL;
   ErrorCode rval = _readNC->readMeshIface->get_element_connect(nLocalEdges, 2, MBEDGE, 0, start_edge, conn_arr_edges,
                                                     // Might have to create gather mesh later
-                                                    (createGatherSet ? nLocalEdges + nEdges : nLocalEdges));
-  ERRORR(rval, "Failed to create edges.");
+                                                    (createGatherSet ? nLocalEdges + nEdges : nLocalEdges)); \
+  CHK_ERR1(rval, "Failed to create edges");
 
-  // Add local edges to the file set
+  // Add local edges to current file set
   Range local_edges_range(start_edge, start_edge + nLocalEdges - 1);
-  rval = _readNC->mbImpl->add_entities(_fileSet, local_edges_range);
-  ERRORR(rval, "Failed to add local edges to the file set.");
+  rval = _readNC->mbImpl->add_entities(_fileSet, local_edges_range); \
+  CHK_ERR1(rval, "Failed to add local edges to current file set");
 
   // Get ptr to GID memory for edges
   int count = 0;
   void* data = NULL;
-  rval = mbImpl->tag_iterate(mGlobalIdTag, local_edges_range.begin(), local_edges_range.end(), count, data);
-  ERRORR(rval, "Failed to iterate global id tag on local edges.");
+  rval = mbImpl->tag_iterate(mGlobalIdTag, local_edges_range.begin(), local_edges_range.end(), count, data); \
+  CHK_ERR1(rval, "Failed to iterate global id tag on local edges");
   assert(count == nLocalEdges);
   int* gid_data = (int*) data;
   std::copy(localGidEdges.begin(), localGidEdges.end(), gid_data);
@@ -1263,7 +1265,9 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
 
   // Read vertices on each local edge, to get edge connectivity
   success = NCFUNC(inq_varid)(_fileId, "verticesOnEdge", &verticesOnEdgeVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnEdge.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of verticesOnEdge");
+
   // Utilize the memory storage pointed by conn_arr_edges
   int* vertices_on_local_edges = (int*) conn_arr_edges;
 #ifdef PNETCDF_FILE
@@ -1289,7 +1293,8 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
     success = NCFUNCAG(_vara_int)(_fileId, verticesOnEdgeVarId, read_starts, read_counts,
                                     &(vertices_on_local_edges[indexInArray]));
 #endif
-    ERRORS(success, "Failed to read verticesOnEdge data in a loop");
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to read verticesOnEdge data in a loop");
 
     // Increment the index for next subrange
     indexInArray += (endh - starth + 1) * 2;
@@ -1298,7 +1303,8 @@ ErrorCode NCHelperMPAS::create_local_edges(EntityHandle start_vertex, const std:
 #ifdef PNETCDF_FILE
   // Wait outside the loop
   success = NCFUNC(wait_all)(_fileId, requests.size(), &requests[0], &statuss[0]);
-  ERRORS(success, "Failed on wait_all.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed on wait_all");
 #endif
 
   // Populate connectivity data for local edges
@@ -1344,20 +1350,20 @@ ErrorCode NCHelperMPAS::create_local_cells(const std::vector<int>& vertices_on_l
     // Create local cells for each non-empty cell group
     EntityHandle start_element;
     ErrorCode rval = _readNC->readMeshIface->get_element_connect(num_group_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
-                                                       conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells);
-    ERRORR(rval, "Failed to create cells");
+                                                       conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells); \
+    CHK_ERR1(rval, "Failed to create cells");
     faces.insert(start_element, start_element + num_group_cells - 1);
 
-    // Add local cells to the file set
+    // Add local cells to current file set
     Range local_cells_range(start_element, start_element + num_group_cells - 1);
-    rval = _readNC->mbImpl->add_entities(_fileSet, local_cells_range);
-    ERRORR(rval, "Failed to add local cells to the file set.");
+    rval = _readNC->mbImpl->add_entities(_fileSet, local_cells_range); \
+    CHK_ERR1(rval, "Failed to add local cells to current file set");
 
     // Get ptr to gid memory for local cells
     int count = 0;
     void* data = NULL;
-    rval = mbImpl->tag_iterate(mGlobalIdTag, local_cells_range.begin(), local_cells_range.end(), count, data);
-    ERRORR(rval, "Failed to iterate global id tag on local cells.");
+    rval = mbImpl->tag_iterate(mGlobalIdTag, local_cells_range.begin(), local_cells_range.end(), count, data); \
+    CHK_ERR1(rval, "Failed to iterate global id tag on local cells");
     assert(count == num_group_cells);
     int* gid_data = (int*) data;
     std::copy(local_cells_with_n_edges[num_edges_per_cell].begin(), local_cells_with_n_edges[num_edges_per_cell].end(), gid_data);
@@ -1400,20 +1406,20 @@ ErrorCode NCHelperMPAS::create_padded_local_cells(const std::vector<int>& vertic
   EntityHandle* conn_arr_local_cells = NULL;
   ErrorCode rval = _readNC->readMeshIface->get_element_connect(nLocalCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_local_cells,
                                                     // Might have to create gather mesh later
-                                                    (createGatherSet ? nLocalCells + nCells : nLocalCells));
-  ERRORR(rval, "Failed to create cells.");
+                                                    (createGatherSet ? nLocalCells + nCells : nLocalCells)); \
+  CHK_ERR1(rval, "Failed to create cells");
   faces.insert(start_element, start_element + nLocalCells - 1);
 
-  // Add local cells to the file set
+  // Add local cells to current file set
   Range local_cells_range(start_element, start_element + nLocalCells - 1);
-  rval = _readNC->mbImpl->add_entities(_fileSet, local_cells_range);
-  ERRORR(rval, "Failed to add local cells to the file set.");
+  rval = _readNC->mbImpl->add_entities(_fileSet, local_cells_range); \
+  CHK_ERR1(rval, "Failed to add local cells to current file set");
 
   // Get ptr to GID memory for local cells
   int count = 0;
   void* data = NULL;
-  rval = mbImpl->tag_iterate(mGlobalIdTag, local_cells_range.begin(), local_cells_range.end(), count, data);
-  ERRORR(rval, "Failed to iterate global id tag on local cells.");
+  rval = mbImpl->tag_iterate(mGlobalIdTag, local_cells_range.begin(), local_cells_range.end(), count, data); \
+  CHK_ERR1(rval, "Failed to iterate global id tag on local cells");
   assert(count == nLocalCells);
   int* gid_data = (int*) data;
   std::copy(localGidCells.begin(), localGidCells.end(), gid_data);
@@ -1442,75 +1448,90 @@ ErrorCode NCHelperMPAS::create_gather_set_vertices(EntityHandle gather_set, Enti
   // Create gather set vertices
   std::vector<double*> arrays;
   // Don't need to specify allocation number here, because we know enough vertices were created before
-  ErrorCode rval = _readNC->readMeshIface->get_node_coords(3, nVertices, 0, gather_set_start_vertex, arrays);
-  ERRORR(rval, "Failed to create vertices.");
+  ErrorCode rval = _readNC->readMeshIface->get_node_coords(3, nVertices, 0, gather_set_start_vertex, arrays); \
+  CHK_ERR1(rval, "Failed to create vertices");
 
   // Add vertices to the gather set
   Range gather_set_verts_range(gather_set_start_vertex, gather_set_start_vertex + nVertices - 1);
-  rval = mbImpl->add_entities(gather_set, gather_set_verts_range);
-  ERRORR(rval, "Failed to add vertices to the gather set.");
+  rval = mbImpl->add_entities(gather_set, gather_set_verts_range); \
+  CHK_ERR1(rval, "Failed to add vertices to the gather set");
 
   // Read x coordinates for gather set vertices
   double* xptr = arrays[0];
   int xVertexVarId;
   int success = NCFUNC(inq_varid)(_fileId, "xVertex", &xVertexVarId);
-  ERRORS(success, "Failed to get variable id of xVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of xVertex");
   NCDF_SIZE read_start = 0;
   NCDF_SIZE read_count = static_cast<NCDF_SIZE>(nVertices);
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_double)(_fileId, xVertexVarId, &read_start, &read_count, xptr);
-  ERRORS(success, "Failed to read xVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read xVertex data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_double)(_fileId, xVertexVarId, &read_start, &read_count, xptr);
-  ERRORS(success, "Failed to read xVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read xVertex data");
 #endif
 
   // Read y coordinates for gather set vertices
   double* yptr = arrays[1];
   int yVertexVarId;
   success = NCFUNC(inq_varid)(_fileId, "yVertex", &yVertexVarId);
-  ERRORS(success, "Failed to get variable id of yVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of yVertex");
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_double)(_fileId, yVertexVarId, &read_start, &read_count, yptr);
-  ERRORS(success, "Failed to read yVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read yVertex data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_double)(_fileId, yVertexVarId, &read_start, &read_count, yptr);
-  ERRORS(success, "Failed to read yVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read yVertex data");
 #endif
 
   // Read z coordinates for gather set vertices
   double* zptr = arrays[2];
   int zVertexVarId;
   success = NCFUNC(inq_varid)(_fileId, "zVertex", &zVertexVarId);
-  ERRORS(success, "Failed to get variable id of zVertex.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of zVertex");
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_double)(_fileId, zVertexVarId, &read_start, &read_count, zptr);
-  ERRORS(success, "Failed to read zVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read zVertex data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_double)(_fileId, zVertexVarId, &read_start, &read_count, zptr);
-  ERRORS(success, "Failed to read zVertex data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read zVertex data");
 #endif
 
   // Get ptr to GID memory for gather set vertices
   int count = 0;
   void* data = NULL;
-  rval = mbImpl->tag_iterate(mGlobalIdTag, gather_set_verts_range.begin(), gather_set_verts_range.end(), count, data);
-  ERRORR(rval, "Failed to iterate global id tag on gather set vertices.");
+  rval = mbImpl->tag_iterate(mGlobalIdTag, gather_set_verts_range.begin(), gather_set_verts_range.end(), count, data); \
+  CHK_ERR1(rval, "Failed to iterate global id tag on gather set vertices");
   assert(count == nVertices);
   int* gid_data = (int*) data;
   for (int j = 1; j <= nVertices; j++)
@@ -1518,8 +1539,8 @@ ErrorCode NCHelperMPAS::create_gather_set_vertices(EntityHandle gather_set, Enti
 
   // Set the file id tag too, it should be bigger something not interfering with global id
   if (mpFileIdTag) {
-    rval = mbImpl->tag_iterate(*mpFileIdTag, gather_set_verts_range.begin(), gather_set_verts_range.end(), count, data);
-    ERRORR(rval, "Failed to iterate file id tag on gather set vertices.");
+    rval = mbImpl->tag_iterate(*mpFileIdTag, gather_set_verts_range.begin(), gather_set_verts_range.end(), count, data); \
+    CHK_ERR1(rval, "Failed to iterate file id tag on gather set vertices");
     assert(count == nVertices);
     gid_data = (int*) data;
     for (int j = 1; j <= nVertices; j++)
@@ -1537,18 +1558,19 @@ ErrorCode NCHelperMPAS::create_gather_set_edges(EntityHandle gather_set, EntityH
   EntityHandle start_edge;
   EntityHandle* conn_arr_gather_set_edges = NULL;
   // Don't need to specify allocation number here, because we know enough edges were created before
-  ErrorCode rval = _readNC->readMeshIface->get_element_connect(nEdges, 2, MBEDGE, 0, start_edge, conn_arr_gather_set_edges);
-  ERRORR(rval, "Failed to create edges.");
+  ErrorCode rval = _readNC->readMeshIface->get_element_connect(nEdges, 2, MBEDGE, 0, start_edge, conn_arr_gather_set_edges); \
+  CHK_ERR1(rval, "Failed to create edges");
 
   // Add edges to the gather set
   Range gather_set_edges_range(start_edge, start_edge + nEdges - 1);
-  rval = mbImpl->add_entities(gather_set, gather_set_edges_range);
-  ERRORR(rval, "Failed to add edges to the gather set.");
+  rval = mbImpl->add_entities(gather_set, gather_set_edges_range); \
+  CHK_ERR1(rval, "Failed to add edges to the gather set");
 
   // Read vertices on each edge
   int verticesOnEdgeVarId;
   int success = NCFUNC(inq_varid)(_fileId, "verticesOnEdge", &verticesOnEdgeVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnEdge.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of verticesOnEdge");
   // Utilize the memory storage pointed by conn_arr_gather_set_edges
   int* vertices_on_gather_set_edges = (int*) conn_arr_gather_set_edges;
   NCDF_SIZE read_starts[2] = {0, 0};
@@ -1556,14 +1578,18 @@ ErrorCode NCHelperMPAS::create_gather_set_edges(EntityHandle gather_set, EntityH
  #ifdef PNETCDF_FILE
    // Enter independent I/O mode, since this read is only for the gather processor
    success = NCFUNC(begin_indep_data)(_fileId);
-   ERRORS(success, "Failed to begin independent I/O mode.");
+   if (success)
+     SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
    success = NCFUNCG(_vara_int)(_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges);
-   ERRORS(success, "Failed to read verticesOnEdge data.");
+   if (success)
+     SET_ERR(MB_FAILURE, "Failed to read verticesOnEdge data");
    success = NCFUNC(end_indep_data)(_fileId);
-   ERRORS(success, "Failed to end independent I/O mode.");
+   if (success)
+     SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
  #else
    success = NCFUNCG(_vara_int)(_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges);
-   ERRORS(success, "Failed to read verticesOnEdge data.");
+   if (success)
+     SET_ERR(MB_FAILURE, "Failed to read verticesOnEdge data");
  #endif
 
    // Populate connectivity data for gather set edges
@@ -1586,41 +1612,51 @@ ErrorCode NCHelperMPAS::create_gather_set_cells(EntityHandle gather_set, EntityH
   // Read number of edges on each gather set cell
   int nEdgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "nEdgesOnCell", &nEdgesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of nEdgesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of nEdgesOnCell");
   std::vector<int> num_edges_on_gather_set_cells(nCells);
   NCDF_SIZE read_start = 0;
   NCDF_SIZE read_count = static_cast<NCDF_SIZE>(nCells);
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read nEdgesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read nEdgesOnCell data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read nEdgesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read nEdgesOnCell data");
 #endif
 
   // Read vertices on each gather set cell (connectivity)
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of verticesOnCell");
   std::vector<int> vertices_on_gather_set_cells(nCells * maxEdgesPerCell);
   NCDF_SIZE read_starts[2] = {0, 0};
   NCDF_SIZE read_counts[2] = {static_cast<NCDF_SIZE>(nCells), static_cast<NCDF_SIZE>(maxEdgesPerCell)};
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, read_starts, read_counts, &vertices_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read verticesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read verticesOnCell data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, read_starts, read_counts, &vertices_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read verticesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read verticesOnCell data");
 #endif
 
   // Divide gather set cells into groups based on the number of edges
@@ -1638,13 +1674,13 @@ ErrorCode NCHelperMPAS::create_gather_set_cells(EntityHandle gather_set, EntityH
     if (num_group_cells > 0) {
       EntityHandle start_element;
       ErrorCode rval = _readNC->readMeshIface->get_element_connect(num_group_cells, num_edges_per_cell, MBPOLYGON, 0, start_element,
-                                                         conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell], num_group_cells);
-      ERRORR(rval, "Failed to create cells.");
+                                                         conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell], num_group_cells); \
+      CHK_ERR1(rval, "Failed to create cells");
 
       // Add cells to the gather set
       Range gather_set_cells_range(start_element, start_element + num_group_cells - 1);
-      rval = mbImpl->add_entities(gather_set, gather_set_cells_range);
-      ERRORR(rval, "Failed to add cells to the gather set.");
+      rval = mbImpl->add_entities(gather_set, gather_set_cells_range); \
+      CHK_ERR1(rval, "Failed to add cells to the gather set");
 
       for (int j = 0; j < num_group_cells; j++) {
         int gather_set_cell_idx = gather_set_cells_with_n_edges[num_edges_per_cell][j]; // Global cell index, 1 based
@@ -1672,39 +1708,46 @@ ErrorCode NCHelperMPAS::create_padded_gather_set_cells(EntityHandle gather_set,
   // Read number of edges on each gather set cell
   int nEdgesOnCellVarId;
   int success = NCFUNC(inq_varid)(_fileId, "nEdgesOnCell", &nEdgesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of nEdgesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of nEdgesOnCell");
   std::vector<int> num_edges_on_gather_set_cells(nCells);
   NCDF_SIZE read_start = 0;
   NCDF_SIZE read_count = static_cast<NCDF_SIZE>(nCells);
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read nEdgesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read nEdgesOnCell data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_int)(_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0]);
-  ERRORS(success, "Failed to read nEdgesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read nEdgesOnCell data");
 #endif
 
   // Create gather set cells
   EntityHandle start_element;
   EntityHandle* conn_arr_gather_set_cells = NULL;
   // Don't need to specify allocation number here, because we know enough cells were created before
-  ErrorCode rval = _readNC->readMeshIface->get_element_connect(nCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_gather_set_cells);
-  ERRORR(rval, "Failed to create cells.");
+  ErrorCode rval = _readNC->readMeshIface->get_element_connect(nCells, maxEdgesPerCell, MBPOLYGON, 0, start_element, conn_arr_gather_set_cells); \
+  CHK_ERR1(rval, "Failed to create cells");
 
   // Add cells to the gather set
   Range gather_set_cells_range(start_element, start_element + nCells - 1);
-  rval = mbImpl->add_entities(gather_set, gather_set_cells_range);
-  ERRORR(rval, "Failed to add cells to the gather set.");
+  rval = mbImpl->add_entities(gather_set, gather_set_cells_range); \
+  CHK_ERR1(rval, "Failed to add cells to the gather set");
 
   // Read vertices on each gather set cell (connectivity)
   int verticesOnCellVarId;
   success = NCFUNC(inq_varid)(_fileId, "verticesOnCell", &verticesOnCellVarId);
-  ERRORS(success, "Failed to get variable id of verticesOnCell.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to get variable id of verticesOnCell");
+
   // Utilize the memory storage pointed by conn_arr_gather_set_cells
   int* vertices_on_gather_set_cells = (int*) conn_arr_gather_set_cells;
   NCDF_SIZE read_starts[2] = {0, 0};
@@ -1712,14 +1755,18 @@ ErrorCode NCHelperMPAS::create_padded_gather_set_cells(EntityHandle gather_set,
 #ifdef PNETCDF_FILE
   // Enter independent I/O mode, since this read is only for the gather processor
   success = NCFUNC(begin_indep_data)(_fileId);
-  ERRORS(success, "Failed to begin independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to begin independent I/O mode");
   success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells);
-  ERRORS(success, "Failed to read verticesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read verticesOnCell data");
   success = NCFUNC(end_indep_data)(_fileId);
-  ERRORS(success, "Failed to end independent I/O mode.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to end independent I/O mode");
 #else
   success = NCFUNCG(_vara_int)(_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells);
-  ERRORS(success, "Failed to read verticesOnCell data.");
+  if (success)
+    SET_ERR(MB_FAILURE, "Failed to read verticesOnCell data");
 #endif
 
   // Correct gather set cell vertices array in the same way as local cell vertices array,

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