[MOAB-dev] commit/MOAB: danwu: Replaced ERRORR and ERRORS macros with new error handling macros in NCHelper.cpp.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Mar 12 18:56:45 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/252454a23db6/
Changeset:   252454a23db6
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-03-13 00:56:29
Summary:     Replaced ERRORR and ERRORS macros with new error handling macros in NCHelper.cpp.

Affected #:  1 file

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index a83284b..85afdba 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -9,12 +9,6 @@
 #include "moab/ReadUtilIface.hpp"
 #include "MBTagConventions.hpp"
 
-#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 {
 
 NCHelper* NCHelper::get_nc_helper(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
@@ -74,10 +68,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   Tag numDimsTag = 0;
   tag_name = "__NUM_DIMS";
   int numDims = dimNames.size();
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 1, MB_TYPE_INTEGER, numDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-  ERRORR(rval, "Trouble creating __NUM_DIMS tag.");
-  rval = mbImpl->tag_set_data(numDimsTag, &_fileSet, 1, &numDims);
-  ERRORR(rval, "Trouble setting data for __NUM_DIMS tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 1, MB_TYPE_INTEGER, numDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+  CHK_ERR1(rval, "Trouble creating __NUM_DIMS tag");
+  rval = mbImpl->tag_set_data(numDimsTag, &_fileSet, 1, &numDims); \
+  CHK_ERR1(rval, "Trouble setting data for __NUM_DIMS tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -85,10 +79,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   Tag numVarsTag = 0;
   tag_name = "__NUM_VARS";
   int numVars = varInfo.size();
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 1, MB_TYPE_INTEGER, numVarsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-  ERRORR(rval, "Trouble creating __NUM_VARS tag.");
-  rval = mbImpl->tag_set_data(numVarsTag, &_fileSet, 1, &numVars);
-  ERRORR(rval, "Trouble setting data for __NUM_VARS tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 1, MB_TYPE_INTEGER, numVarsTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+  CHK_ERR1(rval, "Trouble creating __NUM_VARS tag");
+  rval = mbImpl->tag_set_data(numVarsTag, &_fileSet, 1, &numVars); \
+  CHK_ERR1(rval, "Trouble setting data for __NUM_VARS tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -102,11 +96,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     dimnames.push_back('\0');
   }
   int dimnamesSz = dimnames.size();
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, dimNamesTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __DIM_NAMES tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, dimNamesTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+  CHK_ERR1(rval, "Trouble creating __DIM_NAMES tag");
   const void* ptr = dimnames.c_str();
-  rval = mbImpl->tag_set_by_ptr(dimNamesTag, &_fileSet, 1, &ptr, &dimnamesSz);
-  ERRORR(rval, "Trouble setting data for __DIM_NAMES tag.");
+  rval = mbImpl->tag_set_by_ptr(dimNamesTag, &_fileSet, 1, &ptr, &dimnamesSz); \
+  CHK_ERR1(rval, "Trouble setting data for __DIM_NAMES tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -114,11 +108,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   Tag dimLensTag = 0;
   tag_name = "__DIM_LENS";
   int dimLensSz = dimLens.size();
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, dimLensTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __DIM_LENS tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_INTEGER, dimLensTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+  CHK_ERR1(rval, "Trouble creating __DIM_LENS tag");
   ptr = &(dimLens[0]);
-  rval = mbImpl->tag_set_by_ptr(dimLensTag, &_fileSet, 1, &ptr, &dimLensSz);
-  ERRORR(rval, "Trouble setting data for __DIM_LENS tag.");
+  rval = mbImpl->tag_set_by_ptr(dimLensTag, &_fileSet, 1, &ptr, &dimLensSz); \
+  CHK_ERR1(rval, "Trouble setting data for __DIM_LENS tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -132,11 +126,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     varnames.push_back('\0');
   }
   int varnamesSz = varnames.size();
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varNamesTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __VAR_NAMES tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varNamesTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+  CHK_ERR1(rval, "Trouble creating __VAR_NAMES tag");
   ptr = varnames.c_str();
-  rval = mbImpl->tag_set_by_ptr(varNamesTag, &_fileSet, 1, &ptr, &varnamesSz);
-  ERRORR(rval, "Trouble setting data for __VAR_NAMES tag.");
+  rval = mbImpl->tag_set_by_ptr(varNamesTag, &_fileSet, 1, &ptr, &varnamesSz); \
+  CHK_ERR1(rval, "Trouble setting data for __VAR_NAMES tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -150,10 +144,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
       std::vector<int> val(2, 0);
       val[0] = 0;
       val[1] = nTimeSteps - 1;
-      rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-      ERRORR(rval, "Trouble creating __<dim_name>_LOC_MINMAX tag.");
-      rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-      ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_MINMAX tag.");
+      rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT); \
+      CHK_ERR1(rval, "Trouble creating __<dim_name>_LOC_MINMAX tag");
+      rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+      CHK_ERR1(rval, "Trouble setting data for __<dim_name>_LOC_MINMAX tag");
       if (MB_SUCCESS == rval)
         dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
     }
@@ -174,10 +168,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
       std::stringstream ss_tag_name;
       ss_tag_name << "__" << dimNames[i] << "_LOC_VALS";
       tag_name = ss_tag_name.str();
-      rval = mbImpl->tag_get_handle(tag_name.c_str(), val.size(), MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
-      ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
-      rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
-      ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
+      rval = mbImpl->tag_get_handle(tag_name.c_str(), val.size(), MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT); \
+      CHK_ERR1(rval, "Trouble creating __<dim_name>_LOC_VALS tag");
+      rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+      CHK_ERR1(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag");
       if (MB_SUCCESS == rval)
         dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
     }
@@ -199,10 +193,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
       mbImpl->tag_get_handle(tmptagname.c_str(), 0, MB_TYPE_OPAQUE, tmptag, MB_TAG_ANY);
       varInfo[mapIter->first].varTags[i] = tmptag;
     }
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), varDimSz, MB_TYPE_HANDLE, varNamesDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<var_name>_DIMS tag.");
-    rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varInfo[mapIter->first].varTags[0]));
-    ERRORR(rval, "Trouble setting data for __<var_name>_DIMS tag.");
+    rval = mbImpl->tag_get_handle(tag_name.c_str(), varDimSz, MB_TYPE_HANDLE, varNamesDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+    CHK_ERR1(rval, "Trouble creating __<var_name>_DIMS tag");
+    rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varInfo[mapIter->first].varTags[0])); \
+    CHK_ERR1(rval, "Trouble setting data for __<var_name>_DIMS tag");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
@@ -210,25 +204,25 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   // <PARTITION_METHOD>
   Tag part_tag = scdi->part_method_tag();
   if (!part_tag)
-    ERRORR(MB_FAILURE, "Trouble getting partition method tag.");
-  rval = mbImpl->tag_set_data(part_tag, &_fileSet, 1, &partMethod);
-  ERRORR(rval, "Trouble setting data for PARTITION_METHOD tag.");
+    SET_ERR(MB_FAILURE, "Trouble getting partition method tag");
+  rval = mbImpl->tag_set_data(part_tag, &_fileSet, 1, &partMethod); \
+  CHK_ERR1(rval, "Trouble setting data for PARTITION_METHOD tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
   // <__GLOBAL_ATTRIBS>
   tag_name = "__GLOBAL_ATTRIBS";
   Tag globalAttTag = 0;
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, globalAttTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __GLOBAL_ATTRIBS tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, globalAttTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+  CHK_ERR1(rval, "Trouble creating __GLOBAL_ATTRIBS tag");
   std::string gattVal;
   std::vector<int> gattLen;
-  rval = create_attrib_string(globalAtts, gattVal, gattLen);
-  ERRORR(rval, "Trouble creating attribute strings.");
+  rval = create_attrib_string(globalAtts, gattVal, gattLen); \
+  CHK_ERR1(rval, "Trouble creating attribute strings");
   const void* gattptr = gattVal.c_str();
   int globalAttSz = gattVal.size();
-  rval = mbImpl->tag_set_by_ptr(globalAttTag, &_fileSet, 1, &gattptr, &globalAttSz);
-  ERRORR(rval, "Trouble setting data for __GLOBAL_ATTRIBS tag.");
+  rval = mbImpl->tag_set_by_ptr(globalAttTag, &_fileSet, 1, &gattptr, &globalAttSz); \
+  CHK_ERR1(rval, "Trouble setting data for __GLOBAL_ATTRIBS tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -237,10 +231,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   Tag globalAttLenTag = 0;
   if (gattLen.size() == 0)
     gattLen.push_back(0);
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), gattLen.size(), MB_TYPE_INTEGER, globalAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-  ERRORR(rval, "Trouble creating __GLOBAL_ATTRIBS_LEN tag.");
-  rval = mbImpl->tag_set_data(globalAttLenTag, &_fileSet, 1, &gattLen[0]);
-  ERRORR(rval, "Trouble setting data for __GLOBAL_ATTRIBS_LEN tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), gattLen.size(), MB_TYPE_INTEGER, globalAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+  CHK_ERR1(rval, "Trouble creating __GLOBAL_ATTRIBS_LEN tag");
+  rval = mbImpl->tag_set_data(globalAttLenTag, &_fileSet, 1, &gattLen[0]); \
+  CHK_ERR1(rval, "Trouble setting data for __GLOBAL_ATTRIBS_LEN tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -250,16 +244,16 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     ssTagName << "__" << mapIter->first << "_ATTRIBS";
     tag_name = ssTagName.str();
     Tag varAttTag = 0;
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varAttTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-    ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS tag.");
+    rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, varAttTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+    CHK_ERR1(rval, "Trouble creating __<var_name>_ATTRIBS tag");
     std::string varAttVal;
     std::vector<int> varAttLen;
-    rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen);
-    ERRORR(rval, "Trouble creating attribute strings.");
+    rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen); \
+    CHK_ERR1(rval, "Trouble creating attribute strings");
     const void* varAttPtr = varAttVal.c_str();
     int varAttSz = varAttVal.size();
-    rval = mbImpl->tag_set_by_ptr(varAttTag, &_fileSet, 1, &varAttPtr, &varAttSz);
-    ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS tag.");
+    rval = mbImpl->tag_set_by_ptr(varAttTag, &_fileSet, 1, &varAttPtr, &varAttSz); \
+    CHK_ERR1(rval, "Trouble setting data for __<var_name>_ATTRIBS tag");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
     if (varAttLen.size() == 0)
@@ -267,10 +261,10 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
     ssTagName << "_LEN";
     tag_name = ssTagName.str();
     Tag varAttLenTag = 0;
-    rval = mbImpl->tag_get_handle(tag_name.c_str(), varAttLen.size(), MB_TYPE_INTEGER, varAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT);
-    ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS_LEN tag.");
-    rval = mbImpl->tag_set_data(varAttLenTag, &_fileSet, 1, &varAttLen[0]);
-    ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS_LEN tag.");
+    rval = mbImpl->tag_get_handle(tag_name.c_str(), varAttLen.size(), MB_TYPE_INTEGER, varAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT); \
+    CHK_ERR1(rval, "Trouble creating __<var_name>_ATTRIBS_LEN tag");
+    rval = mbImpl->tag_set_data(varAttLenTag, &_fileSet, 1, &varAttLen[0]); \
+    CHK_ERR1(rval, "Trouble setting data for __<var_name>_ATTRIBS_LEN tag");
     if (MB_SUCCESS == rval)
       dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
   }
@@ -280,13 +274,13 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   Tag varNamesLocsTag = 0;
   std::vector<int> varNamesLocs(varInfo.size());
   rval = mbImpl->tag_get_handle(tag_name.c_str(), varNamesLocs.size(), MB_TYPE_INTEGER, varNamesLocsTag, MB_TAG_CREAT
-      | MB_TAG_SPARSE);
-  ERRORR(rval, "Trouble creating __VAR_NAMES_LOCATIONS tag.");
+      | MB_TAG_SPARSE); \
+  CHK_ERR1(rval, "Trouble creating __VAR_NAMES_LOCATIONS tag");
   for (mapIter = varInfo.begin(); mapIter != varInfo.end(); ++mapIter) {
     varNamesLocs[std::distance(varInfo.begin(), mapIter)] = mapIter->second.entLoc;
   }
-  rval = mbImpl->tag_set_data(varNamesLocsTag, &_fileSet, 1, &varNamesLocs[0]);
-  ERRORR(rval, "Trouble setting data for __VAR_NAMES_LOCATIONS tag.");
+  rval = mbImpl->tag_set_data(varNamesLocsTag, &_fileSet, 1, &varNamesLocs[0]); \
+  CHK_ERR1(rval, "Trouble setting data for __VAR_NAMES_LOCATIONS tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -295,12 +289,12 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
   tag_name = "__MESH_TYPE";
   std::string meshTypeName = get_mesh_type_name();
 
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, meshTypeTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-  ERRORR(rval, "Trouble creating __MESH_TYPE tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_OPAQUE, meshTypeTag, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+  CHK_ERR1(rval, "Trouble creating __MESH_TYPE tag");
   ptr = meshTypeName.c_str();
   int leng = meshTypeName.size();
-  rval = mbImpl->tag_set_by_ptr(meshTypeTag, &_fileSet, 1, &ptr, &leng);
-  ERRORR(rval, "Trouble setting data for __MESH_TYPE tag.");
+  rval = mbImpl->tag_set_by_ptr(meshTypeTag, &_fileSet, 1, &ptr, &leng); \
+  CHK_ERR1(rval, "Trouble setting data for __MESH_TYPE tag");
   if (MB_SUCCESS == rval)
     dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
 
@@ -347,7 +341,7 @@ ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std
           vdatas.push_back(vd);
       }
       else {
-        ERRORR(MB_FAILURE, "Couldn't find variable.");
+        SET_ERR_STR(MB_FAILURE, "Couldn't find variable " << var_names[i]);
       }
     }
   }
@@ -392,11 +386,11 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
   Interface*& mbImpl = _readNC->mbImpl;
   DebugOutput& dbgOut = _readNC->dbgOut;
 
-  ErrorCode rval = read_variable_to_set_allocate(vdatas, tstep_nums);
-  ERRORR(rval, "Trouble allocating read variables to set.");
+  ErrorCode rval = read_variable_to_set_allocate(vdatas, tstep_nums); \
+  CHK_ERR1(rval, "Trouble allocating space to read set variables");
 
   // Finally, read into that space
-  int success;
+  int success = 0;
   for (unsigned int i = 0; i < vdatas.size(); i++) {
     // Note, for set variables without timesteps, loop one time and then break
     for (unsigned int t = 0; t < tstep_nums.size(); t++) {
@@ -413,42 +407,44 @@ ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, s
         case NC_CHAR:
           success = NCFUNCAG(_vara_text)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
                                         &vdatas[i].readCounts[0], (char*) data);
-          ERRORS(success, "Failed to read char data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read char data");
           break;
         case NC_DOUBLE:
           success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
                                         &vdatas[i].readCounts[0], (double*) data);
-          ERRORS(success, "Failed to read double data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read double data");
           break;
         case NC_FLOAT:
           success = NCFUNCAG(_vara_float)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
                                         &vdatas[i].readCounts[0], (float*) data);
-          ERRORS(success, "Failed to read float data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read float data");
           break;
         case NC_INT:
           success = NCFUNCAG(_vara_int)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
                                         &vdatas[i].readCounts[0], (int*) data);
-          ERRORS(success, "Failed to read int data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read int data");
           break;
         case NC_SHORT:
           success = NCFUNCAG(_vara_short)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
                                         &vdatas[i].readCounts[0], (short*) data);
-          ERRORS(success, "Failed to read short data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read short data");
           break;
         default:
-          success = 1;
+          SET_ERR_STR(MB_FAILURE, "Unrecognized data type for set variable " << vdatas[i].varName);
       }
 
-      if (success)
-        ERRORR(MB_FAILURE, "Trouble reading variable.");
-
       dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      rval = convert_variable(vdatas[i], t);
-      ERRORR(rval, "Failed to convert variable.");
+      rval = convert_variable(vdatas[i], t); \
+      CHK_ERR1(rval, "Failed to convert variable");
 
       dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
-      rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &data, &vdatas[i].sz);
-      ERRORR(rval, "Failed to set data for variable.");
+      rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &data, &vdatas[i].sz); \
+      CHK_ERR1(rval, "Failed to set data for variable");
 
       // Memory pointed by pointer data can be deleted, as tag_set_by_ptr() has already copied the tag values
       switch (vdatas[i].varDataType) {
@@ -498,7 +494,6 @@ ErrorCode NCHelper::convert_variable(ReadNC::VarData& var_data, int tstep_num)
   assert(sz > 0);
 
   // Finally, read into that space
-  int success = 0;
   int* idata;
   double* ddata;
   float* fdata;
@@ -520,10 +515,10 @@ ErrorCode NCHelper::convert_variable(ReadNC::VarData& var_data, int tstep_num)
         idata[i] = sdata[i];
       break;
     default:
-      success = 1;
+      break;
   }
 
-  if (2 <= dbgOut.get_verbosity() && !success) {
+  if (2 <= dbgOut.get_verbosity()) {
     double dmin, dmax;
     int imin, imax;
     switch (var_data.varDataType) {
@@ -557,12 +552,8 @@ ErrorCode NCHelper::convert_variable(ReadNC::VarData& var_data, int tstep_num)
         }
         dbgOut.tprintf(2, "Variable %s (int): min = %d, max = %d\n", var_data.varName.c_str(), imin, imax);
         break;
-      case NC_NAT:
-      case NC_BYTE:
-      case NC_CHAR:
+      default:
         break;
-      default: // Default case added to remove compiler warnings
-        success = 1;
     }
   }
 
@@ -573,14 +564,15 @@ ErrorCode NCHelper::read_coordinate(const char* var_name, int lmin, int lmax, st
 {
   std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
   std::map<std::string, ReadNC::VarData>::iterator vmit = varInfo.find(var_name);
-  if (varInfo.end() == vmit)
-    return MB_FAILURE;
+  if (varInfo.end() == vmit) {
+    SET_ERR_STR(MB_FAILURE, "Couldn't find variable " << var_name);
+  }
 
   assert(lmin >= 0 && lmax >= lmin);
   NCDF_SIZE tstart = lmin;
   NCDF_SIZE tcount = lmax - lmin + 1;
   NCDF_DIFF dum_stride = 1;
-  int fail;
+  int success = 0;
 
   // Check size
   if ((std::size_t)tcount != cvals.size())
@@ -588,19 +580,19 @@ ErrorCode NCHelper::read_coordinate(const char* var_name, int lmin, int lmax, st
 
   // Check to make sure it's a float or double
   if (NC_DOUBLE == (*vmit).second.varDataType) {
-    fail = NCFUNCAG(_vars_double)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &cvals[0]);
-    if (fail)
-      ERRORS(MB_FAILURE, "Failed to get coordinate values.");
+    success = NCFUNCAG(_vars_double)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &cvals[0]);
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to get coordinate values");
   }
   else if (NC_FLOAT == (*vmit).second.varDataType) {
     std::vector<float> tcvals(tcount);
-    fail = NCFUNCAG(_vars_float)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &tcvals[0]);
-    if (fail)
-      ERRORS(MB_FAILURE, "Failed to get coordinate values.");
+    success = NCFUNCAG(_vars_float)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &tcvals[0]);
+    if (success)
+      SET_ERR(MB_FAILURE, "Failed to get coordinate values");
     std::copy(tcvals.begin(), tcvals.end(), cvals.begin());
   }
   else {
-    ERRORR(MB_FAILURE, "Wrong data type for coordinate variable.");
+    SET_ERR(MB_FAILURE, "Wrong data type for coordinate variable");
   }
 
   return MB_SUCCESS;
@@ -633,8 +625,7 @@ ErrorCode NCHelper::get_tag_to_set(ReadNC::VarData& var_data, int tstep_num, Tag
       rval = mbImpl->tag_get_handle(tag_name.str().c_str(), 0, MB_TYPE_INTEGER, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
       break;
     default:
-      std::cerr << "Unrecognized data type for tag " << tag_name << std::endl;
-      rval = MB_FAILURE;
+      SET_ERR_STR(MB_FAILURE, "Unrecognized data type for tag " << tag_name.str());
   }
 
   if (MB_SUCCESS == rval)
@@ -667,8 +658,7 @@ ErrorCode NCHelper::get_tag_to_nonset(ReadNC::VarData& var_data, int tstep_num,
       rval = mbImpl->tag_get_handle(tag_name.str().c_str(), num_lev, MB_TYPE_INTEGER, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
       break;
     default:
-      std::cerr << "Unrecognized data type for tag " << tag_name.str() << std::endl;
-      rval = MB_FAILURE;
+      SET_ERR_STR(MB_FAILURE, "Unrecognized data type for tag " << tag_name.str());
   }
 
   if (MB_SUCCESS == rval)
@@ -679,7 +669,7 @@ ErrorCode NCHelper::get_tag_to_nonset(ReadNC::VarData& var_data, int tstep_num,
 
 ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::AttData>& attMap, std::string& attVal, std::vector<int>& attLen)
 {
-  int success;
+  int success = 0;
   std::stringstream ssAtt;
   unsigned int sz = 0;
   std::map<std::string, ReadNC::AttData>::const_iterator attIt = attMap.begin();
@@ -693,39 +683,44 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
         sz = attIt->second.attLen;
         attData = (char *) malloc(sz);
         success = NCFUNC(get_att_text)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (char*) attData);
-        ERRORS(success, "Failed to read attribute char data.");
+        if (success)
+          SET_ERR(MB_FAILURE, "Failed to read attribute char data");
         ssAtt << "char;";
         break;
       case NC_DOUBLE:
         sz = attIt->second.attLen * sizeof(double);
         attData = (double *) malloc(sz);
         success = NCFUNC(get_att_double)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (double*) attData);
-        ERRORS(success, "Failed to read attribute double data.");
+        if (success)
+          SET_ERR(MB_FAILURE, "Failed to read attribute double data");
         ssAtt << "double;";
         break;
       case NC_FLOAT:
         sz = attIt->second.attLen * sizeof(float);
         attData = (float *) malloc(sz);
         success = NCFUNC(get_att_float)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (float*) attData);
-        ERRORS(success, "Failed to read attribute float data.");
+        if (success)
+          SET_ERR(MB_FAILURE, "Failed to read attribute float data");
         ssAtt << "float;";
         break;
       case NC_INT:
         sz = attIt->second.attLen * sizeof(int);
         attData = (int *) malloc(sz);
         success = NCFUNC(get_att_int)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (int*) attData);
-        ERRORS(success, "Failed to read attribute int data.");
+        if (success)
+          SET_ERR(MB_FAILURE, "Failed to read attribute int data");
         ssAtt << "int;";
         break;
       case NC_SHORT:
         sz = attIt->second.attLen * sizeof(short);
         attData = (short *) malloc(sz);
         success = NCFUNC(get_att_short)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (short*) attData);
-        ERRORS(success, "Failed to read attribute short data.");
+        if (success)
+          SET_ERR(MB_FAILURE, "Failed to read attribute short data");
         ssAtt << "short;";
         break;
       default:
-        success = 1;
+        SET_ERR_STR(MB_FAILURE, "Unrecognized data type for attribute " << attIt->second.attName);
     }
     char* tmpc = (char *) attData;
     for (unsigned int counter = 0; counter != sz; ++counter)
@@ -773,15 +768,15 @@ ErrorCode NCHelper::create_dummy_variables()
     // Create a corresponding sparse tag
     Tag tagh;
     ErrorCode rval = mbImpl->tag_get_handle(dimNames[i].c_str(), 0, MB_TYPE_INTEGER, tagh,
-                                            MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
-    ERRORR(rval, "Failed to create tag for a dummy dimension variable.");
+                                            MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+    CHK_ERR1(rval, "Failed to create tag for a dummy dimension variable");
 
     // Tag value is the dimension length
     const void* ptr = &dimLens[i];
     // Tag size is 1
     int size = 1;
-    rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &ptr, &size);
-    ERRORR(rval, "Failed to set data for dimension tag.");
+    rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &ptr, &size); \
+    CHK_ERR1(rval, "Failed to set data for dimension tag");
 
     dbgOut.tprintf(2, "Sparse tag created for dimension %s\n", dimNames[i].c_str());
   }
@@ -804,7 +799,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
       vdatas[i].readCounts.push_back(1);
 
       // Next: other dimensions
-      for (unsigned int idx = 1; idx != vdatas[i].varDims.size(); idx++){
+      for (unsigned int idx = 1; idx != vdatas[i].varDims.size(); idx++) {
         vdatas[i].readStarts.push_back(0);
         vdatas[i].readCounts.push_back(dimLens[vdatas[i].varDims[idx]]);
       }
@@ -816,7 +811,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
         vdatas[i].readCounts.push_back(1);
       }
       else {
-        for (unsigned int idx = 0; idx != vdatas[i].varDims.size(); idx++){
+        for (unsigned int idx = 0; idx != vdatas[i].varDims.size(); idx++) {
           vdatas[i].readStarts.push_back(0);
           vdatas[i].readCounts.push_back(dimLens[vdatas[i].varDims[idx]]);
         }
@@ -833,13 +828,13 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
       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(MB_INDEX_OUT_OF_RANGE, "Wrong value for a timestep number");
       }
 
       // Get the tag to read into
       if (!vdatas[i].varTags[t]) {
-        rval = get_tag_to_set(vdatas[i], tstep_nums[t], vdatas[i].varTags[t]);
-        ERRORR(rval, "Trouble getting tag for a set variable.");
+        rval = get_tag_to_set(vdatas[i], tstep_nums[t], vdatas[i].varTags[t]); \
+        CHK_ERR1(rval, "Trouble getting tag for a set variable");
       }
 
       switch (vdatas[i].varDataType) {
@@ -856,8 +851,7 @@ ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>&
           vdatas[i].varDatas[t] = new int[vdatas[i].sz];
           break;
         default:
-          std::cerr << "Unrecognized data type for set variable tag values" << std::endl;
-          rval = MB_FAILURE;
+          SET_ERR_STR(MB_FAILURE, "Unrecognized data type for tag values of set variable " << vdatas[i].varName);
       }
 
       // Loop continues only for set variables with timesteps, e.g. xtime(Time, StrLen)
@@ -874,8 +868,8 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
 
   // Get the number of vertices
   int num_verts;
-  ErrorCode rval = mbImpl->get_number_entities_by_dimension(_fileSet, 0, num_verts);
-  ERRORR(rval, "Trouble getting number of vertices.");
+  ErrorCode rval = mbImpl->get_number_entities_by_dimension(_fileSet, 0, num_verts); \
+  CHK_ERR1(rval, "Trouble getting number of vertices");
 
   /*
   // Check against parameters
@@ -883,15 +877,15 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   if (num_verts > 0) {
     int expected_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1);
     if (num_verts != expected_verts) {
-      ERRORR(MB_FAILURE, "Number of vertices doesn't match.");
+      SET_ERR(MB_FAILURE, "Number of vertices doesn't match");
     }
   }
   */
 
   // Check the number of elements too
   int num_elems;
-  rval = mbImpl->get_number_entities_by_dimension(_fileSet, (-1 == lCDims[2] ? 2 : 3), num_elems);
-  ERRORR(rval, "Trouble getting number of elements.");
+  rval = mbImpl->get_number_entities_by_dimension(_fileSet, (-1 == lCDims[2] ? 2 : 3), num_elems); \
+  CHK_ERR1(rval, "Trouble getting number of elements");
 
   /*
   // Check against parameters
@@ -899,7 +893,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
   if (num_elems > 0) {
     int expected_elems = (lCDims[3] - lCDims[0] + 1) * (lCDims[4] - lCDims[1] + 1) * (-1 == lCDims[2] ? 1 : (lCDims[5] - lCDims[2] + 1));
     if (num_elems != expected_elems) {
-      ERRORR(MB_FAILURE, "Number of elements doesn't match.");
+      SET_ERR(MB_FAILURE, "Number of elements doesn't match");
     }
   }
   */
@@ -920,8 +914,8 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
   ScdBox* scd_box;
 
   ErrorCode rval = scdi->construct_box(HomCoord(lDims[0], lDims[1], lDims[2], 1), HomCoord(lDims[3], lDims[4], lDims[5], 1), 
-                                       NULL, 0, scd_box, locallyPeriodic, &parData, true);
-  ERRORR(rval, "Trouble creating scd vertex sequence.");
+                                       NULL, 0, scd_box, locallyPeriodic, &parData, true); \
+  CHK_ERR1(rval, "Trouble creating scd vertex sequence");
 
   // Add verts to tmp_range first, so we can duplicate global ids in vertex ids
   tmp_range.insert(scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1);
@@ -929,12 +923,12 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
   if (mpFileIdTag) {
     int count;
     void* data;
-    rval = mbImpl->tag_iterate(*mpFileIdTag, tmp_range.begin(), tmp_range.end(), count, data);
-    ERRORR(rval, "Failed to get tag iterator on file id tag.");
+    rval = mbImpl->tag_iterate(*mpFileIdTag, tmp_range.begin(), tmp_range.end(), count, data); \
+    CHK_ERR1(rval, "Failed to get tag iterator on file id tag");
     assert(count == scd_box->num_vertices());
     int* fid_data = (int*) data;
-    rval = mbImpl->tag_iterate(mGlobalIdTag, tmp_range.begin(), tmp_range.end(), count, data);
-    ERRORR(rval, "Failed to get tag iterator on global id tag.");
+    rval = mbImpl->tag_iterate(mGlobalIdTag, tmp_range.begin(), tmp_range.end(), count, data); \
+    CHK_ERR1(rval, "Failed to get tag iterator on global id tag");
     assert(count == scd_box->num_vertices());
     int* gid_data = (int*) data;
     for (int i = 0; i < count; i++)
@@ -944,22 +938,22 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
   // Then add box set and elements to the range, then to the file set
   tmp_range.insert(scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1);
   tmp_range.insert(scd_box->box_set());
-  rval = mbImpl->add_entities(_fileSet, tmp_range);
-  ERRORR(rval, "Couldn't add new vertices to file set.");
+  rval = mbImpl->add_entities(_fileSet, tmp_range); \
+  CHK_ERR1(rval, "Couldn't add new vertices to file set");
 
   dbgOut.tprintf(1, "scdbox %d quads, %d vertices\n", scd_box->num_elements(), scd_box->num_vertices());
 
   // Set the vertex coordinates
   double *xc, *yc, *zc;
-  rval = scd_box->get_coordinate_arrays(xc, yc, zc);
-  ERRORR(rval, "Couldn't get vertex coordinate arrays.");
+  rval = scd_box->get_coordinate_arrays(xc, yc, zc); \
+  CHK_ERR1(rval, "Couldn't get vertex coordinate arrays");
 
   int i, j, k, il, jl, kl;
   int dil = lDims[3] - lDims[0] + 1;
   int djl = lDims[4] - lDims[1] + 1;
   assert(dil == (int)ilVals.size() && djl == (int)jlVals.size() &&
       (-1 == lDims[2] || lDims[5] - lDims[2] + 1 == (int)levVals.size()));
-//#define INDEX(i, j, k) ()
+
   for (kl = lDims[2]; kl <= lDims[5]; kl++) {
     k = kl - lDims[2];
     for (jl = lDims[1]; jl <= lDims[4]; jl++) {
@@ -973,14 +967,13 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
       }
     }
   }
-//#undef INDEX
 
 #ifndef NDEBUG
   int num_verts = (lDims[3] - lDims[0] + 1) * (lDims[4] - lDims[1] + 1) * (-1 == lDims[2] ? 1 : lDims[5] - lDims[2] + 1);
   std::vector<int> gids(num_verts);
   Range verts(scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1);
-  rval = mbImpl->tag_get_data(mGlobalIdTag, verts, &gids[0]);
-  ERRORR(rval, "Trouble getting gid values.");
+  rval = mbImpl->tag_get_data(mGlobalIdTag, verts, &gids[0]); \
+  CHK_ERR1(rval, "Trouble getting gid values");
   int vmin = *(std::min_element(gids.begin(), gids.end())), vmax = *(std::max_element(gids.begin(), gids.end()));
   dbgOut.tprintf(1, "Vertex gids %d-%d\n", vmin, vmax);
 #endif
@@ -991,15 +984,15 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
   if (2 <= dbgOut.get_verbosity()) {
     assert(scd_box->boundary_complete());
     EntityHandle dum_ent = scd_box->start_element();
-    rval = mbImpl->list_entities(&dum_ent, 1);
-    ERRORR(rval, "Trouble listing first hex.");
+    rval = mbImpl->list_entities(&dum_ent, 1); \
+    CHK_ERR1(rval, "Trouble listing first hex");
 
     std::vector<EntityHandle> connect;
-    rval = mbImpl->get_connectivity(&dum_ent, 1, connect);
-    ERRORR(rval, "Trouble getting connectivity.");
+    rval = mbImpl->get_connectivity(&dum_ent, 1, connect); \
+    CHK_ERR1(rval, "Trouble getting connectivity");
 
-    rval = mbImpl->list_entities(&connect[0], connect.size());
-    ERRORR(rval, "Trouble listing element connectivity.");
+    rval = mbImpl->list_entities(&connect[0], connect.size()); \
+    CHK_ERR1(rval, "Trouble listing element connectivity");
   }
 
   Range edges;
@@ -1013,16 +1006,16 @@ ErrorCode ScdNCHelper::read_variables(std::vector<std::string>& var_names, std::
   std::vector<ReadNC::VarData> vdatas;
   std::vector<ReadNC::VarData> vsetdatas;
 
-  ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas);
-  ERRORR(rval, "Trouble setting up read variable.");
+  ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas); \
+  CHK_ERR1(rval, "Trouble setting up read variable");
 
   // Create COORDS tag for quads
-  rval = create_quad_coordinate_tag();
-  ERRORR(rval, "Trouble creating coordinate tags to entities quads");
+  rval = create_quad_coordinate_tag(); \
+  CHK_ERR1(rval, "Trouble creating coordinate tags to entities quads");
 
   if (!vsetdatas.empty()) {
-    rval = read_variable_to_set(vsetdatas, tstep_nums);
-    ERRORR(rval, "Trouble read variables to set.");
+    rval = read_variable_to_set(vsetdatas, tstep_nums); \
+    CHK_ERR1(rval, "Trouble read variables to set");
   }
 
   if (!vdatas.empty()) {
@@ -1046,19 +1039,19 @@ ErrorCode ScdNCHelper::read_scd_variable_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 set");
   assert("Should only have a single vertex subrange, since they were read in one shot" &&
       verts.psize() == 1);
 
   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 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 set");
   assert("Should only have a single face subrange, since they were read in one shot" &&
       faces.psize() == 1);
 
@@ -1067,8 +1060,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
   bool& isParallel = _readNC->isParallel;
   if (isParallel) {
     ParallelComm*& myPcomm = _readNC->myPcomm;
-    rval = myPcomm->filter_pstatus(faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &faces_owned);
-    ERRORR(rval, "Trouble getting owned faces in set.");
+    rval = myPcomm->filter_pstatus(faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &faces_owned); \
+    CHK_ERR1(rval, "Trouble getting owned faces in set");
   }
   else
     faces_owned = faces; // Not running in parallel, but still with MPI
@@ -1122,28 +1115,27 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::
         // Set
         break;
       default:
-        ERRORR(MB_FAILURE, "Unrecognized entity location type.");
-        break;
+        SET_ERR(MB_FAILURE, "Unrecognized entity location type");
     }
 
     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]);
 
       if (tstep_nums[t] >= dimLens[tDim]) {
-        ERRORR(MB_INDEX_OUT_OF_RANGE, "Wrong value for a timestep number.");
+        SET_ERR(MB_INDEX_OUT_OF_RANGE, "Wrong value for a timestep number");
       }
 
       // 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.");
+        rval = get_tag_to_nonset(vdatas[i], tstep_nums[t], vdatas[i].varTags[t], vdatas[i].numLev); \
+        CHK_ERR1(rval, "Trouble getting tag");
       }
 
       // Get ptr to tag space
       void* data;
       int count;
-      rval = mbImpl->tag_iterate(vdatas[i].varTags[t], range->begin(), range->end(), count, data);
-      ERRORR(rval, "Failed to get tag iterator.");
+      rval = mbImpl->tag_iterate(vdatas[i].varTags[t], range->begin(), range->end(), count, data); \
+      CHK_ERR1(rval, "Failed to get tag iterator");
       assert((unsigned)count == range->size());
       vdatas[i].varDatas[t] = data;
     }
@@ -1161,12 +1153,11 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
 {
   DebugOutput& dbgOut = _readNC->dbgOut;
 
-  ErrorCode rval = read_scd_variable_to_nonset_allocate(vdatas, tstep_nums);
-  if (MB_SUCCESS != rval)
-    SET_ERR(rval, "Trouble allocating space to read variables");
+  ErrorCode rval = read_scd_variable_to_nonset_allocate(vdatas, tstep_nums); \
+  CHK_ERR1(rval, "Trouble allocating space to read non-set variables");
 
   // Finally, read into that space
-  int success;
+  int success = 0;
   for (unsigned int i = 0; i < vdatas.size(); i++) {
     std::size_t sz = vdatas[i].sz;
 
@@ -1196,7 +1187,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
             for (std::size_t idx = 0; idx != tmpchardata.size(); idx++)
               ((char*) data)[idx] = tmpchardata[idx];
           }
-          ERRORS(success, "Failed to read char data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read char data");
           break;
         }
         case NC_DOUBLE: {
@@ -1210,7 +1202,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
             for (std::size_t idx = 0; idx != tmpdoubledata.size(); idx++)
               ((double*) data)[idx] = tmpdoubledata[idx];
           }
-          ERRORS(success, "Failed to read double data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read double data");
           break;
         }
         case NC_FLOAT: {
@@ -1224,7 +1217,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
             for (std::size_t idx = 0; idx != tmpfloatdata.size(); idx++)
               ((float*) data)[idx] = tmpfloatdata[idx];
           }
-          ERRORS(success, "Failed to read float data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read float data");
           break;
         }
         case NC_INT: {
@@ -1238,7 +1232,8 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
             for (std::size_t idx = 0; idx != tmpintdata.size(); idx++)
               ((int*) data)[idx] = tmpintdata[idx];
           }
-          ERRORS(success, "Failed to read int data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read int data");
           break;
         }
         case NC_SHORT: {
@@ -1252,24 +1247,20 @@ ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>&
             for (std::size_t idx = 0; idx != tmpshortdata.size(); idx++)
               ((short*) data)[idx] = tmpshortdata[idx];
           }
-          ERRORS(success, "Failed to read short data.");
+          if (success)
+            SET_ERR(MB_FAILURE, "Failed to read short data");
           break;
         }
         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 i = 0; i < vdatas.size(); i++) {
     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_ERR(rval);
     }
   }
 
@@ -1288,8 +1279,8 @@ ErrorCode ScdNCHelper::create_quad_coordinate_tag() {
   Interface*& mbImpl = _readNC->mbImpl;
 
   Range ents;
-  ErrorCode rval = mbImpl->get_entities_by_type(_fileSet, moab::MBQUAD, ents);
-  ERRORR(rval, "Trouble getting QUAD entity.");
+  ErrorCode rval = mbImpl->get_entities_by_type(_fileSet, moab::MBQUAD, ents); \
+  CHK_ERR1(rval, "Trouble getting QUAD entity");
 
   std::size_t numOwnedEnts = 0;
 #ifdef USE_MPI
@@ -1297,12 +1288,11 @@ ErrorCode ScdNCHelper::create_quad_coordinate_tag() {
   bool& isParallel = _readNC->isParallel;
   if (isParallel) {
     ParallelComm*& myPcomm = _readNC->myPcomm;
-    rval = myPcomm->filter_pstatus(ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &ents_owned);
-    ERRORR(rval, "Trouble getting owned QUAD entity.");
+    rval = myPcomm->filter_pstatus(ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &ents_owned); \
+    CHK_ERR1(rval, "Trouble getting owned QUAD entity");
     numOwnedEnts = ents_owned.size();
   }
-  else
-  {
+  else {
     numOwnedEnts = ents.size();
     ents_owned = ents;
   }
@@ -1326,17 +1316,18 @@ ErrorCode ScdNCHelper::create_quad_coordinate_tag() {
   }
   std::string tag_name = "COORDS";
   Tag tagh = 0;
-  rval = mbImpl->tag_get_handle(tag_name.c_str(), 3, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
-  ERRORR(rval, "Trouble creating COORDS tag.");
+  rval = mbImpl->tag_get_handle(tag_name.c_str(), 3, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT); \
+  CHK_ERR1(rval, "Trouble creating COORDS tag");
 
   void *data;
   int count;
 #ifdef USE_MPI
-  rval = mbImpl->tag_iterate(tagh, ents_owned.begin(), ents_owned.end(), count, data);
+  rval = mbImpl->tag_iterate(tagh, ents_owned.begin(), ents_owned.end(), count, data); \
+  CHK_ERR1(rval, "Failed to get COORDS tag iterator");
 #else
-  rval = mbImpl->tag_iterate(tagh, ents.begin(), ents.end(), count, data);
+  rval = mbImpl->tag_iterate(tagh, ents.begin(), ents.end(), count, data); \
+  CHK_ERR1(rval, "Failed to get COORDS tag iterator");
 #endif
-  ERRORR(rval, "Failed to get COORDS tag iterator.");
   assert(count == (int)numOwnedEnts);
   double* quad_data = (double*) data;
   std::copy(coords.begin(), coords.end(), quad_data);
@@ -1349,23 +1340,24 @@ ErrorCode UcdNCHelper::read_variables(std::vector<std::string>& var_names, std::
   std::vector<ReadNC::VarData> vdatas;
   std::vector<ReadNC::VarData> vsetdatas;
 
-  ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas);
-  ERRORR(rval, "Trouble setting up read variable.");
+  ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas); \
+  CHK_ERR1(rval, "Trouble setting up to read variables");
 
   if (!vsetdatas.empty()) {
-    rval = read_variable_to_set(vsetdatas, tstep_nums);
-    ERRORR(rval, "Trouble read variables to set.");
+    rval = read_variable_to_set(vsetdatas, tstep_nums); \
+    CHK_ERR1(rval, "Trouble reading variables to set");
   }
 
   if (!vdatas.empty()) {
 #ifdef PNETCDF_FILE
     // With pnetcdf support, we will use async read
-    rval = read_ucd_variable_to_nonset_async(vdatas, tstep_nums);
+    rval = read_ucd_variable_to_nonset_async(vdatas, tstep_nums); \
+    CHK_ERR1(rval, "Trouble reading variables to entities verts/edges/faces");
 #else
     // Without pnetcdf support, we will use old read
-    rval = read_ucd_variable_to_nonset(vdatas, tstep_nums);
+    rval = read_ucd_variable_to_nonset(vdatas, tstep_nums); \
+    CHK_ERR1(rval, "Trouble reading variables to entities verts/edges/faces");
 #endif
-    ERRORR(rval, "Trouble read variables to entities verts/edges/faces.");
   }
 
   return MB_SUCCESS;

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