[MOAB-dev] commit/MOAB: danwu: Applied error handling code to NCHelperEuler.cpp and NCHelperFV.cpp
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Mar 19 15:02:46 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/ed51df2291cb/
Changeset: ed51df2291cb
Branch: error_handling_enhancement
User: danwu
Date: 2014-03-19 21:02:27
Summary: Applied error handling code to NCHelperEuler.cpp and NCHelperFV.cpp
Affected #: 2 files
diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index b117921..fe15c6e 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -5,12 +5,6 @@
#include <cmath>
#include <sstream>
-#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 {
bool NCHelperEuler::can_read_file(ReadNC* readNC, int fileId)
@@ -67,7 +61,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "lon")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lon' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lon' dimension");
}
iCDim = idx;
gCDims[0] = 0;
@@ -75,8 +69,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
// Check i periodicity and set globallyPeriodic[0]
std::vector<double> til_vals(2);
- ErrorCode rval = read_coordinate("lon", gCDims[3] - 1, gCDims[3], til_vals);
- ERRORR(rval, "Trouble reading 'lon' variable.");
+ ErrorCode rval = read_coordinate("lon", gCDims[3] - 1, gCDims[3], til_vals); \
+ CHK_ERR1(rval, "Trouble reading 'lon' variable");
if (std::fabs(2 * til_vals[1] - til_vals[0] - 360) < 0.001)
globallyPeriodic[0] = 1;
@@ -88,7 +82,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "lat")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lat' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lat' dimension");
}
jCDim = idx;
gCDims[1] = 0;
@@ -108,7 +102,7 @@ ErrorCode NCHelperEuler::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];
@@ -119,7 +113,7 @@ ErrorCode NCHelperEuler::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];
@@ -141,9 +135,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
parData.partMethod = partMethod;
int pdims[3];
- rval = ScdInterface::compute_partition(procs, rank, parData, lDims, locallyPeriodic, pdims);
- if (MB_SUCCESS != rval)
- return rval;
+ rval = ScdInterface::compute_partition(procs, rank, parData, lDims, locallyPeriodic, pdims); \
+ CHK_ERR1(rval, "Error returned from compute_partition");
for (int i = 0; i < 3; i++)
parData.pDims[i] = pdims[i];
@@ -192,21 +185,21 @@ ErrorCode NCHelperEuler::init_mesh_vals()
std::map<std::string, ReadNC::VarData>::iterator vmit;
if (-1 != lCDims[0]) {
if ((vmit = varInfo.find("lon")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("lon", lCDims[0], lCDims[3], ilCVals);
- ERRORR(rval, "Trouble reading 'lon' variable.");
+ rval = read_coordinate("lon", lCDims[0], lCDims[3], ilCVals); \
+ 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");
}
}
if (-1 != lCDims[1]) {
if ((vmit = varInfo.find("lat")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("lat", lCDims[1], lCDims[4], jlCVals);
- ERRORR(rval, "Trouble reading 'lat' variable.");
+ rval = read_coordinate("lat", lCDims[1], lCDims[4], jlCVals); \
+ 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");
}
}
@@ -221,7 +214,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
ilVals[i] = ilCVals[i - 1] + dif;
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lon' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lon' variable");
}
}
@@ -230,8 +223,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
if (!isParallel || ((gDims[4] - gDims[1]) == (lDims[4] - lDims[1]))) {
std::string gwName("gw");
std::vector<double> gwVals(lDims[4] - lDims[1] - 1);
- rval = read_coordinate(gwName.c_str(), lDims[1], lDims[4] - 2, gwVals);
- ERRORR(rval, "Trouble reading 'gw' variable.");
+ rval = read_coordinate(gwName.c_str(), lDims[1], lDims[4] - 2, gwVals); \
+ CHK_ERR1(rval, "Trouble reading 'gw' variable");
// Copy the correct piece
jlVals[0] = -(M_PI / 2) * 180 / M_PI;
std::size_t i = 0;
@@ -249,8 +242,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
// If this is the first row
if (lDims[1] == gDims[1]) {
std::vector<double> gwVals(lDims[4]);
- rval = read_coordinate(gwName.c_str(), 0, lDims[4] - 1, gwVals);
- ERRORR(rval, "Trouble reading 'gw' variable.");
+ rval = read_coordinate(gwName.c_str(), 0, lDims[4] - 1, gwVals); \
+ CHK_ERR1(rval, "Trouble reading 'gw' variable");
// Copy the correct piece
jlVals[0] = -(M_PI / 2) * 180 / M_PI;
gwSum = -1;
@@ -262,8 +255,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
// Or if it's the last row
else if (lDims[4] == gDims[4]) {
std::vector<double> gwVals(lDims[4] - 1);
- rval = read_coordinate(gwName.c_str(), 0, lDims[4] - 2, gwVals);
- ERRORR(rval, "Trouble reading 'gw' variable.");
+ rval = read_coordinate(gwName.c_str(), 0, lDims[4] - 2, gwVals); \
+ CHK_ERR1(rval, "Trouble reading 'gw' variable");
// copy the correct piece
gwSum = -1;
for (int j = 0; j != lDims[1] - 1; j++)
@@ -280,8 +273,8 @@ ErrorCode NCHelperEuler::init_mesh_vals()
int start = lDims[1] - 1;
int end = lDims[4] - 1;
std::vector<double> gwVals(end);
- rval = read_coordinate(gwName.c_str(), 0, end - 1, gwVals);
- ERRORR(rval, "Trouble reading 'gw' variable.");
+ rval = read_coordinate(gwName.c_str(), 0, end - 1, gwVals); \
+ CHK_ERR1(rval, "Trouble reading 'gw' variable");
gwSum = -1;
for (int j = 0; j != start - 1; j++)
gwSum += gwVals[j];
@@ -294,19 +287,19 @@ ErrorCode NCHelperEuler::init_mesh_vals()
}
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lat' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lat' variable");
}
}
// Store time coordinate values in tVals
if (nTimeSteps > 0) {
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
@@ -368,15 +361,24 @@ ErrorCode NCHelperEuler::init_mesh_vals()
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
tag_name = ss_tag_name.str();
- 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_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// __<dim_name>_LOC_VALS (for virtual slon, virtual slat, lon and lat)
+ // Assume all have the same data type as lon (expected type is float or double)
+ switch (varInfo["lon"].varDataType) {
+ case NC_DOUBLE:
+ case NC_FLOAT:
+ break;
+ default:
+ SET_ERR(MB_FAILURE, "Unexpected data type for coordinate variable 'lon'");
+ }
+
for (unsigned int i = 0; i != ijdimNames.size(); i++) {
void* val = NULL;
int val_len = 0;
@@ -397,36 +399,15 @@ ErrorCode NCHelperEuler::init_mesh_vals()
val_len = jlCVals.size();
}
- DataType data_type;
-
- // Assume all has same data type as lon
- switch (varInfo["lon"].varDataType) {
- case NC_BYTE:
- case NC_CHAR:
- case NC_DOUBLE:
- data_type = MB_TYPE_DOUBLE;
- break;
- case NC_FLOAT:
- data_type = MB_TYPE_DOUBLE;
- break;
- case NC_INT:
- data_type = MB_TYPE_INTEGER;
- break;
- case NC_SHORT:
- default:
- std::cerr << "Unrecognized data type for tag " << tag_name << std::endl;
- ERRORR(MB_FAILURE, "Unrecognized data type");
- break;
- }
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_LOC_VALS";
tag_name = ss_tag_name.str();
- rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
- ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
- rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len);
- ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
+ rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_DOUBLE, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+ CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// __<dim_name>_GLOBAL_MINMAX (for virtual slon, virtual slat, lon and lat)
@@ -451,17 +432,17 @@ ErrorCode NCHelperEuler::init_mesh_vals()
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
tag_name = ss_tag_name.str();
- 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>_GLOBAL_MINMAX tag.");
- rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
- ERRORR(rval, "Trouble setting data for __<dim_name>_GLOBAL_MINMAX tag.");
+ rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT); \
+ CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// Hack: create dummy variables, if needed, for dimensions 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;
}
diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index 7725b55..1120866 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -5,9 +5,6 @@
#include <cmath>
#include <sstream>
-#define ERRORR(rval, str) \
- if (MB_SUCCESS != rval) {_readNC->readMeshIface->report_error("%s", str); return rval;}
-
namespace moab {
bool NCHelperFV::can_read_file(ReadNC* readNC, int fileId)
@@ -60,7 +57,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "slon")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'slon' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'slon' variable");
}
iDim = idx;
gDims[0] = 0;
@@ -70,7 +67,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "slat")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'slat' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'slat' variable");
}
jDim = idx;
gDims[1] = 0;
@@ -81,7 +78,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "lon")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lon' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lon' variable");
}
iCDim = idx;
gCDims[0] = 0;
@@ -89,8 +86,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
// Check i periodicity and set globallyPeriodic[0]
std::vector<double> til_vals(2);
- ErrorCode rval = read_coordinate("lon", gCDims[3] - 1, gCDims[3], til_vals);
- ERRORR(rval, "Trouble reading 'lon' variable.");
+ ErrorCode rval = read_coordinate("lon", gCDims[3] - 1, gCDims[3], til_vals); \
+ CHK_ERR1(rval, "Trouble reading 'lon' variable");
if (std::fabs(2 * til_vals[1] - til_vals[0] - 360) < 0.001)
globallyPeriodic[0] = 1;
if (globallyPeriodic[0])
@@ -102,7 +99,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
if ((vit = std::find(dimNames.begin(), dimNames.end(), "lat")) != dimNames.end())
idx = vit - dimNames.begin();
else {
- ERRORR(MB_FAILURE, "Couldn't find 'lat' dimension.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'lat' dimension");
}
jCDim = idx;
gCDims[1] = 0;
@@ -121,7 +118,7 @@ ErrorCode NCHelperFV::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];
@@ -132,7 +129,7 @@ ErrorCode NCHelperFV::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];
@@ -154,9 +151,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
parData.partMethod = partMethod;
int pdims[3];
- rval = ScdInterface::compute_partition(procs, rank, parData, lDims, locallyPeriodic, pdims);
- if (MB_SUCCESS != rval)
- return rval;
+ rval = ScdInterface::compute_partition(procs, rank, parData, lDims, locallyPeriodic, pdims); \
+ CHK_ERR1(rval, "Error returned from compute_partition");
for (int i = 0; i < 3; i++)
parData.pDims[i] = pdims[i];
@@ -205,21 +201,21 @@ ErrorCode NCHelperFV::init_mesh_vals()
std::map<std::string, ReadNC::VarData>::iterator vmit;
if (-1 != lCDims[0]) {
if ((vmit = varInfo.find("lon")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("lon", lCDims[0], lCDims[3], ilCVals);
- ERRORR(rval, "Trouble reading 'lon' variable.");
+ rval = read_coordinate("lon", lCDims[0], lCDims[3], ilCVals); \
+ 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");
}
}
if (-1 != lCDims[1]) {
if ((vmit = varInfo.find("lat")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
- rval = read_coordinate("lat", lCDims[1], lCDims[4], jlCVals);
- ERRORR(rval, "Trouble reading 'lat' variable.");
+ rval = read_coordinate("lat", lCDims[1], lCDims[4], jlCVals); \
+ 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");
}
}
@@ -237,12 +233,12 @@ ErrorCode NCHelperFV::init_mesh_vals()
ilVals[i] = ilVals[i - 1] + dif;
}
else {
- rval = read_coordinate("slon", lDims[0], lDims[3], ilVals);
- ERRORR(rval, "Trouble reading 'slon' variable.");
+ rval = read_coordinate("slon", lDims[0], lDims[3], ilVals); \
+ CHK_ERR1(rval, "Trouble reading 'slon' variable");
}
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'slon' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'slon' variable");
}
}
@@ -250,8 +246,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
if ((vmit = varInfo.find("slat")) != varInfo.end() && (*vmit).second.varDims.size() == 1) {
if (!isParallel || ((gDims[4] - gDims[1]) == (lDims[4] - lDims[1]))) {
std::vector<double> dummyVar(lDims[4] - lDims[1] - 1);
- rval = read_coordinate("slat", lDims[1], lDims[4] - 2, dummyVar);
- ERRORR(rval, "Trouble reading 'slat' variable.");
+ rval = read_coordinate("slat", lDims[1], lDims[4] - 2, dummyVar); \
+ CHK_ERR1(rval, "Trouble reading 'slat' variable");
// Copy the correct piece
jlVals[0] = -90.0;
std::size_t i = 0;
@@ -264,8 +260,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
// Need to read one less then available and read it into a dummy var
if (lDims[1] == gDims[1]) {
std::vector<double> dummyVar(lDims[4] - lDims[1]);
- rval = read_coordinate("slat", lDims[1], lDims[4] - 1, dummyVar);
- ERRORR(rval, "Trouble reading 'slat' variable.");
+ rval = read_coordinate("slat", lDims[1], lDims[4] - 1, dummyVar); \
+ CHK_ERR1(rval, "Trouble reading 'slat' variable");
// Copy the correct piece
jlVals[0] = -90.0;
for (int i = 1; i < lDims[4] + 1; i++)
@@ -274,8 +270,8 @@ ErrorCode NCHelperFV::init_mesh_vals()
// Or if it's the last row
else if (lDims[4] == gDims[4]) {
std::vector<double> dummyVar(lDims[4] - lDims[1]);
- rval = read_coordinate("slat", lDims[1] - 1, lDims[4] - 2, dummyVar);
- ERRORR(rval, "Trouble reading 'slat' variable.");
+ rval = read_coordinate("slat", lDims[1] - 1, lDims[4] - 2, dummyVar); \
+ CHK_ERR1(rval, "Trouble reading 'slat' variable");
// Copy the correct piece
std::size_t i = 0;
for (i = 0; i != dummyVar.size(); i++)
@@ -284,25 +280,25 @@ ErrorCode NCHelperFV::init_mesh_vals()
}
// It's in the middle
else {
- rval = read_coordinate("slat", lDims[1] - 1, lDims[4] - 1, jlVals);
- ERRORR(rval, "Trouble reading 'slat' variable.");
+ rval = read_coordinate("slat", lDims[1] - 1, lDims[4] - 1, jlVals); \
+ CHK_ERR1(rval, "Trouble reading 'slat' variable");
}
}
}
else {
- ERRORR(MB_FAILURE, "Couldn't find 'slat' variable.");
+ SET_ERR(MB_FAILURE, "Couldn't find 'slat' variable");
}
}
// Store time coordinate values in tVals
if (nTimeSteps > 0) {
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
@@ -369,15 +365,24 @@ ErrorCode NCHelperFV::init_mesh_vals()
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
tag_name = ss_tag_name.str();
- 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_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// __<dim_name>_LOC_VALS (for slon, slat, lon and lat)
+ // Assume all have the same data type as lon (expected type is float or double)
+ switch (varInfo["lon"].varDataType) {
+ case NC_DOUBLE:
+ case NC_FLOAT:
+ break;
+ default:
+ SET_ERR(MB_FAILURE, "Unexpected data type for coordinate variable 'lon'");
+ }
+
for (unsigned int i = 0; i != ijdimNames.size(); i++) {
void* val = NULL;
int val_len = 0;
@@ -398,36 +403,15 @@ ErrorCode NCHelperFV::init_mesh_vals()
val_len = jlCVals.size();
}
- DataType data_type;
-
- // Assume all has same data type as lon
- switch (varInfo["lon"].varDataType) {
- case NC_BYTE:
- case NC_CHAR:
- case NC_DOUBLE:
- data_type = MB_TYPE_DOUBLE;
- break;
- case NC_FLOAT:
- data_type = MB_TYPE_DOUBLE;
- break;
- case NC_INT:
- data_type = MB_TYPE_INTEGER;
- break;
- case NC_SHORT:
- default:
- std::cerr << "Unrecognized data type for tag " << tag_name << std::endl;
- ERRORR(MB_FAILURE, "Unrecognized data type");
- break;
- }
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_LOC_VALS";
tag_name = ss_tag_name.str();
- rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
- ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
- rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len);
- ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
+ rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, MB_TYPE_DOUBLE, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN); \
+ CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_by_ptr(tagh, &_fileSet, 1, &val, &val_len); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// __<dim_name>_GLOBAL_MINMAX (for slon, slat, lon and lat)
@@ -452,17 +436,17 @@ ErrorCode NCHelperFV::init_mesh_vals()
std::stringstream ss_tag_name;
ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
tag_name = ss_tag_name.str();
- 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>_GLOBAL_MINMAX tag.");
- rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
- ERRORR(rval, "Trouble setting data for __<dim_name>_GLOBAL_MINMAX tag.");
+ rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT); \
+ CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]); \
+ CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
}
// Hack: create dummy variables, if needed, for dimensions 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;
}
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