[MOAB-dev] commit/MOAB: danwu: Applied error handling code to NCHelperHOMME.cpp
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Mar 24 14:58:43 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/42613b31f03a/
Changeset: 42613b31f03a
Branch: error_handling_enhancement
User: danwu
Date: 2014-03-24 20:58:23
Summary: Applied error handling code to NCHelperHOMME.cpp
Affected #: 1 file
diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index b2dea5e..8da3e60 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -5,12 +5,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 {
NCHelperHOMME::NCHelperHOMME(ReadNC* readNC, int fileId, const FileOptions& opts, EntityHandle fileSet)
@@ -90,7 +84,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
else if ((vit = std::find(dimNames.begin(), dimNames.end(), "t")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'time' or 't' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'time' or 't' dimension");
}
tDim = idx;
nTimeSteps = dimLens[idx];
@@ -100,7 +94,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "ncol")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'ncol' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'ncol' dimension");
}
vDim = idx;
nVertices = dimLens[idx];
@@ -118,7 +112,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
else if ((vit = std::find(dimNames.begin(), dimNames.end(), "ilev")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lev' or 'ilev' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lev' or 'ilev' dimension");
}
levDim = idx;
nLevels = dimLens[idx];
@@ -128,19 +122,19 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
std::map<std::string, ReadNC::VarData>::iterator vmit;
if ((vmit = varInfo.find("lon")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
rval = read_coordinate("lon", 0, nVertices - 1, xVertVals);
- ERRORR(rval, "Trouble reading 'lon' variable.");
+ CHK_ERR1(rval, "Trouble reading 'lon' variable");
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lon' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lon' variable");
}
// Store lat values in yVertVals
if ((vmit = varInfo.find("lat")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
rval = read_coordinate("lat", 0, nVertices - 1, yVertVals);
- ERRORR(rval, "Trouble reading 'lat' variable.");
+ CHK_ERR1(rval, "Trouble reading 'lat' variable");
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lat' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lat' variable");
}
// Store lev values in levVals
@@ -150,7 +144,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
else {
if ((vmit = varInfo.find("lev")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
rval = read_coordinate("lev", 0, nLevels - 1, levVals);
- ERRORR(rval, "Trouble reading 'lev' variable.");
+ CHK_ERR1(rval, "Trouble reading 'lev' variable");
// Decide whether down is positive
char posval[10];
@@ -161,7 +155,7 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
}
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lev' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lev' variable");
}
}
@@ -171,15 +165,15 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
}
else {
if ((vmit = varInfo.find("time")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("time", 0, nTimeSteps - 1, tVals);
- ERRORR(rval, "Trouble reading 'time' variable.");
+ rval = read_coordinate("time", 0, nTimeSteps - 1, tVals); \
+ CHK_ERR1(rval, "Trouble reading 'time' variable");
}
else if ((vmit = varInfo.find("t")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("t", 0, nTimeSteps - 1, tVals);
- ERRORR(rval, "Trouble reading 't' variable.");
+ rval = read_coordinate("t", 0, nTimeSteps - 1, tVals); \
+ CHK_ERR1(rval, "Trouble reading 't' variable");
}
else {
- // If expected time variable is not available, set dummy time coordinate values to tVals
+ // If expected time variable does not exist, set dummy values to tVals
for (int t = 0; t < nTimeSteps; t++)
tVals.push_back((double)t);
}
@@ -202,8 +196,8 @@ ErrorCode NCHelperHOMME::init_mesh_vals()
}
// Hack: create dummy variables for dimensions (like ncol) 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;
}
@@ -219,26 +213,22 @@ ErrorCode NCHelperHOMME::check_existing_mesh()
bool& noMesh = _readNC->noMesh;
if (noMesh && localGidVerts.empty()) {
- // We need to populate localGidVerts range with the gids of vertices from the tmp_set
+ // We need to populate localGidVerts range with the gids of vertices from current file set
// localGidVerts is important in reading the variable data into the nodes
// also, for our purposes, localGidVerts is truly the GLOBAL_ID tag data, not other
// file_id tags that could get passed around in other scenarios for parallel reading
- // for nodal_partition, this local gid is easier, should be initialized with only
- // the owned nodes
- // We need to get all vertices from tmp_set (it is the input set in no_mesh scenario)
+ // Get all vertices from current file set (it is the input set in no_mesh scenario)
Range local_verts;
- ErrorCode rval = mbImpl->get_entities_by_dimension(_fileSet, 0, local_verts);
- if (MB_FAILURE == rval)
- return rval;
+ ErrorCode rval = mbImpl->get_entities_by_dimension(_fileSet, 0, local_verts); \
+ CHK_ERR1(rval, "Trouble getting local vertices in current file set");
if (!local_verts.empty()) {
std::vector<int> gids(local_verts.size());
// !IMPORTANT : this has to be the GLOBAL_ID tag
- rval = mbImpl->tag_get_data(mGlobalIdTag, local_verts, &gids[0]);
- if (MB_FAILURE == rval)
- return rval;
+ rval = mbImpl->tag_get_data(mGlobalIdTag, local_verts, &gids[0]); \
+ CHK_ERR1(rval, "Trouble getting local gid values of vertices");
// Restore localGidVerts
std::copy(gids.rbegin(), gids.rend(), range_inserter(localGidVerts));
@@ -304,13 +294,14 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
#else
success = NCFUNC(open)(conn_fname.c_str(), 0, &connectId);
#endif
- ERRORS(success, "Failed on open.");
+ if (success)
+ SET_ERR(MB_FAILURE, "Failed on open");
}
std::vector<std::string> conn_names;
std::vector<int> conn_vals;
- rval = _readNC->get_dimensions(connectId, conn_names, conn_vals);
- ERRORR(rval, "Failed to get dimensions for connectivity.");
+ rval = _readNC->get_dimensions(connectId, conn_names, conn_vals); \
+ CHK_ERR1(rval, "Failed to get dimensions for connectivity");
// Read connectivity into temporary variable
int num_fine_quads = 0;
@@ -323,7 +314,7 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
else if ((vit = std::find(conn_names.begin(), conn_names.end(), "ncenters")) != conn_names.end())
idx = vit - conn_names.begin();
else {
- ERRORR(MB_FAILURE, "Failed to get number of quads.");
+ SET_ERR(MB_FAILURE, "Failed to get number of quads");
}
int num_quads = conn_vals[idx];
if (!isConnFile && num_quads != nCells) {
@@ -334,18 +325,21 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
// Get the connectivity into tmp_conn2 and permute into tmp_conn
int cornerVarId;
success = NCFUNC(inq_varid)(connectId, "element_corners", &cornerVarId);
- ERRORS(success, "Failed to get variable id.");
+ if (success)
+ SET_ERR(MB_FAILURE, "Failed to get variable id of 'element_corners'");
NCDF_SIZE tmp_starts[2] = {0, 0};
NCDF_SIZE tmp_counts[2] = {4, static_cast<NCDF_SIZE>(num_quads)};
std::vector<int> tmp_conn(4 * num_quads), tmp_conn2(4 * num_quads);
success = NCFUNCAG(_vara_int)(connectId, cornerVarId, tmp_starts, tmp_counts, &tmp_conn2[0]);
- ERRORS(success, "Failed to get temporary connectivity.");
+ if (success)
+ SET_ERR(MB_FAILURE, "Failed to get temporary connectivity");
if (isConnFile) {
// This data/connectivity file will be closed later in ReadNC::load_file()
}
else {
success = NCFUNC(close)(connectId);
- ERRORS(success, "Failed on close.");
+ if (success)
+ SET_ERR(MB_FAILURE, "Failed on close");
}
// Permute the connectivity
for (int i = 0; i < num_quads; i++) {
@@ -389,21 +383,21 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
rval = _readNC->readMeshIface->get_element_connect(num_coarse_quads, 4,
MBQUAD, 0, start_quad, conn_arr,
// Might have to create gather mesh later
- (create_gathers ? num_coarse_quads + num_quads : num_coarse_quads));
- ERRORR(rval, "Failed to create quads.");
+ (create_gathers ? num_coarse_quads + num_quads : num_coarse_quads)); \
+ CHK_ERR1(rval, "Failed to create quads");
tmp_range.insert(start_quad, start_quad + num_coarse_quads - 1);
std::copy(&tmp_conn[start_idx], &tmp_conn[start_idx + 4 * num_fine_quads], conn_arr);
std::copy(conn_arr, conn_arr + 4 * num_fine_quads, range_inserter(localGidVerts));
}
else {
- rval = smt.create_spectral_elems(&tmp_conn[0], num_fine_quads, 2, tmp_range, start_idx, &localGidVerts);
- ERRORR(rval, "Failed to create spectral elements.");
+ rval = smt.create_spectral_elems(&tmp_conn[0], num_fine_quads, 2, tmp_range, start_idx, &localGidVerts); \
+ CHK_ERR1(rval, "Failed to create spectral elements");
int count, v_per_e;
- rval = mbImpl->connect_iterate(tmp_range.begin(), tmp_range.end(), conn_arr, v_per_e, count);
- ERRORR(rval, "Failed to get connectivity of spectral elements.");
+ rval = mbImpl->connect_iterate(tmp_range.begin(), tmp_range.end(), conn_arr, v_per_e, count); \
+ CHK_ERR1(rval, "Failed to get connectivity of spectral elements.");
rval = mbImpl->tag_iterate(smt.spectral_vertices_tag(true), tmp_range.begin(), tmp_range.end(),
- count, (void*&)sv_ptr);
- ERRORR(rval, "Failed to get fine connectivity of spectral elements.");
+ count, (void*&)sv_ptr); \
+ CHK_ERR1(rval, "Failed to get fine connectivity of spectral elements");
}
// Create vertices
@@ -411,8 +405,8 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
std::vector<double*> arrays;
rval = _readNC->readMeshIface->get_node_coords(3, nLocalVertices, 0, start_vertex, arrays,
// Might have to create gather mesh later
- (create_gathers ? nLocalVertices + nVertices : nLocalVertices));
- ERRORR(rval, "Couldn't create vertices in HOMME mesh.");
+ (create_gathers ? nLocalVertices + nVertices : nLocalVertices)); \
+ CHK_ERR1(rval, "Failed to create vertices");
// Set vertex coordinates
Range::iterator rit;
@@ -443,16 +437,16 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
Range vert_range(start_vertex, start_vertex + nLocalVertices - 1);
void* data;
int count;
- rval = mbImpl->tag_iterate(mGlobalIdTag, vert_range.begin(), vert_range.end(), count, data);
- ERRORR(rval, "Failed to get tag iterator.");
+ rval = mbImpl->tag_iterate(mGlobalIdTag, vert_range.begin(), vert_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 global id data, which will be used to resolve sharing
if (mpFileIdTag) {
- rval = mbImpl->tag_iterate(*mpFileIdTag, vert_range.begin(), vert_range.end(), count, data);
- ERRORR(rval, "Failed to get tag iterator on file id tag.");
+ rval = mbImpl->tag_iterate(*mpFileIdTag, vert_range.begin(), vert_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);
@@ -476,29 +470,29 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
}
}
- // Add new vertices and elements to the set
+ // Add new vertices and quads to current file set
faces.merge(tmp_range);
tmp_range.insert(start_vertex, start_vertex + nLocalVertices - 1);
rval = mbImpl->add_entities(_fileSet, tmp_range);
- ERRORR(rval, "Couldn't add new vertices and quads to file set.");
+ CHK_ERR1(rval, "Failed to add new vertices and quads to current file set.");
// Mark the set with the spectral order
Tag sporder;
- rval = mbImpl->tag_get_handle("SPECTRAL_ORDER", 1, MB_TYPE_INTEGER, sporder, MB_TAG_CREAT | MB_TAG_SPARSE);
- ERRORR(rval, "Couldn't create spectral order tag.");
- rval = mbImpl->tag_set_data(sporder, &_fileSet, 1, &_spectralOrder);
- ERRORR(rval, "Couldn't set value for spectral order tag.");
+ rval = mbImpl->tag_get_handle("SPECTRAL_ORDER", 1, MB_TYPE_INTEGER, sporder, MB_TAG_CREAT | MB_TAG_SPARSE); \
+ CHK_ERR1(rval, "Failed to get SPECTRAL_ORDER tag");
+ rval = mbImpl->tag_set_data(sporder, &_fileSet, 1, &_spectralOrder); \
+ CHK_ERR1(rval, "Failed to set data for SPECTRAL_ORDER tag");
if (create_gathers) {
EntityHandle gather_set;
- rval = _readNC->readMeshIface->create_gather_set(gather_set);
- ERRORR(rval, "Trouble creating gather set.");
+ rval = _readNC->readMeshIface->create_gather_set(gather_set); \
+ CHK_ERR1(rval, "Failed to create gather set");
// Create vertices
arrays.clear();
// Don't need to specify allocation number here, because we know enough verts were created before
- rval = _readNC->readMeshIface->get_node_coords(3, nVertices, 0, start_vertex, arrays);
- ERRORR(rval, "Couldn't create vertices in HOMME mesh for gather set.");
+ rval = _readNC->readMeshIface->get_node_coords(3, nVertices, 0, start_vertex, arrays); \
+ CHK_ERR1(rval, "Failed to create gather set vertices");
xptr = arrays[0];
yptr = arrays[1];
@@ -514,38 +508,38 @@ ErrorCode NCHelperHOMME::create_mesh(Range& faces)
}
// Get ptr to gid memory for vertices
- Range gather_verts(start_vertex, start_vertex + nVertices - 1);
- rval = mbImpl->tag_iterate(mGlobalIdTag, gather_verts.begin(), gather_verts.end(), count, data);
- ERRORR(rval, "Failed to get tag iterator.");
+ Range gather_set_verts_range(start_vertex, start_vertex + nVertices - 1);
+ 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);
gid_data = (int*) data;
for (int j = 1; j <= nVertices; j++)
gid_data[j - 1] = j;
// Set the file id tag too, it should be bigger something not interfering with global id
if (mpFileIdTag) {
- rval = mbImpl->tag_iterate(*mpFileIdTag, gather_verts.begin(), gather_verts.end(), count, data);
- ERRORR(rval, "Failed to get tag iterator in file id tag.");
+ 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++)
gid_data[j - 1] = nVertices + j; // bigger than global id tag
}
- rval = mbImpl->add_entities(gather_set, gather_verts);
- ERRORR(rval, "Couldn't add vertices to gather set.");
+ rval = mbImpl->add_entities(gather_set, gather_set_verts_range); \
+ CHK_ERR1(rval, "Failed to add vertices to the gather set");
// Create quads
- Range gather_quads;
+ Range gather_set_quads_range;
// Don't need to specify allocation number here, because we know enough quads were created before
rval = _readNC->readMeshIface->get_element_connect(num_quads, 4,
- MBQUAD, 0, start_quad, conn_arr);
- ERRORR(rval, "Failed to create quads.");
- gather_quads.insert(start_quad, start_quad + num_quads - 1);
+ MBQUAD, 0, start_quad, conn_arr); \
+ CHK_ERR1(rval, "Failed to create gather set quads");
+ gather_set_quads_range.insert(start_quad, start_quad + num_quads - 1);
std::copy(&tmp_conn[0], &tmp_conn[4 * num_quads], conn_arr);
for (i = 0; i != 4 * num_quads; i++)
conn_arr[i] += start_vertex - 1; // Connectivity array is shifted by where the gather verts start
- rval = mbImpl->add_entities(gather_set, gather_quads);
- ERRORR(rval, "Couldn't add quads to gather set.");
+ rval = mbImpl->add_entities(gather_set, gather_set_quads_range); \
+ CHK_ERR1(rval, "Failed to add quads to the gather set");
}
return MB_SUCCESS;
@@ -563,8 +557,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_allocate(std::vector<ReadN
// 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);
@@ -598,8 +592,7 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_allocate(std::vector<ReadN
range = &verts;
break;
default:
- ERRORR(MB_FAILURE, "Unexpected entity location type for HOMME non-set variable.");
- break;
+ SET_ERR_STR(MB_FAILURE, "Unexpected entity location type for non-set variable " << vdatas[i].varName);
}
// Get variable size
@@ -611,20 +604,20 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_allocate(std::vector<ReadN
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
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.");
+ 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;
}
@@ -638,8 +631,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
{
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;
@@ -669,8 +662,7 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
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: {
// Copied from float case
@@ -696,7 +688,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
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;
@@ -704,16 +697,17 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
assert(ic == localGidVerts.psize());
success = ncmpi_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].numLev != 1)
// Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpdoubledata[0], localGidVerts);
+ kji_to_jik_stride(ni, nj, nk, data, &tmpdoubledata[0], localGidVerts);
else {
for (std::size_t idx = 0; idx != tmpdoubledata.size(); idx++)
((double*) data)[idx] = tmpdoubledata[idx];
}
- ERRORS(success, "Failed to read double data.");
+
break;
}
case NC_FLOAT: {
@@ -739,7 +733,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
success = NCFUNCREQG(_vara_float)(_fileId, vdatas[i].varId,
&(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
&(tmpfloatdata[indexInFloatArray]), &requests[idxReq++]);
- ERRORS(success, "Failed to read float data in loop");
+ if (success)
+ SET_ERR_STR(MB_FAILURE, "Failed to read float data in a loop for non-set variable " << vdatas[i].varName);
// We need to increment the index in float array for the
// next subrange
indexInFloatArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
@@ -747,41 +742,36 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
assert(ic == localGidVerts.psize());
success = ncmpi_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].numLev != 1)
// Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
+ kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
else {
for (std::size_t idx = 0; idx != tmpfloatdata.size(); idx++)
((float*) data)[idx] = tmpfloatdata[idx];
}
- ERRORS(success, "Failed to read float data.");
+
break;
}
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++) {
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);
}
}
@@ -800,8 +790,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
{
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;
@@ -824,8 +814,7 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
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: {
// Copied from float case
@@ -849,7 +838,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId,
&(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
&(tmpdoubledata[indexInDoubleArray]));
- ERRORS(success, "Failed to read float 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;
@@ -858,12 +848,12 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
if (vdatas[i].numLev != 1)
// Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpdoubledata[0], localGidVerts);
+ kji_to_jik_stride(ni, nj, nk, data, &tmpdoubledata[0], localGidVerts);
else {
for (std::size_t idx = 0; idx != tmpdoubledata.size(); idx++)
((double*) data)[idx] = tmpdoubledata[idx];
}
- ERRORS(success, "Failed to read double data.");
+
break;
}
case NC_FLOAT: {
@@ -887,7 +877,8 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
success = NCFUNCAG(_vara_float)(_fileId, vdatas[i].varId,
&(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
&(tmpfloatdata[indexInFloatArray]));
- ERRORS(success, "Failed to read float data in loop");
+ if (success)
+ SET_ERR_STR(MB_FAILURE, "Failed to read float data in a loop for non-set variable " << vdatas[i].varName);
// We need to increment the index in float array for the
// next subrange
indexInFloatArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
@@ -896,37 +887,31 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
if (vdatas[i].numLev != 1)
// Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
+ kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
else {
for (std::size_t idx = 0; idx != tmpfloatdata.size(); idx++)
((float*) data)[idx] = tmpfloatdata[idx];
}
- ERRORS(success, "Failed to read float data.");
+
break;
}
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++) {
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
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