[MOAB-dev] commit/MOAB: danwu: To handle merge conflicts, temporally updated a few files in error_handling_enhancement branch to latest versions in master branch.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jun 4 13:48:20 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/5bf581d3c484/
Changeset: 5bf581d3c484
Branch: error_handling_enhancement
User: danwu
Date: 2014-06-04 20:47:39
Summary: To handle merge conflicts, temporally updated a few files in error_handling_enhancement branch to latest versions in master branch.
Affected #: 3 files
diff --git a/examples/makefile b/examples/makefile
index f61c689..787c8d3 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -10,10 +10,9 @@ MESH_DIR="../MeshFiles/unittest"
EXAMPLES = HelloMOAB GetEntities SetsNTags LoadPartial structuredmesh StructuredMeshSimple DirectAccessWithHoles DirectAccessNoHoles point_in_elem_search DeformMeshRemap
PAREXAMPLES = HelloParMOAB ReduceExchangeTags LloydRelaxation CrystalRouterExample
EXOIIEXAMPLES = TestExodusII
-ERROREXAMPLES = TestErrorHandling TestErrorHandlingPar ErrorHandlingModel
F90EXAMPLES = DirectAccessNoHolesF90 PushParMeshIntoMoabF90
-default: ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${ERROREXAMPLES} ${F90EXAMPLES}
+default: ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES}
HelloMOAB: HelloMOAB.o ${MOAB_LIBDIR}/libMOAB.la
${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
@@ -66,17 +65,14 @@ PushParMeshIntoMoabF90: PushParMeshIntoMoabF90.o
DeformMeshRemap: DeformMeshRemap.o ${MOAB_LIBDIR}/libMOAB.la
${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} -lmbcoupler ${MOAB_LIBS_LINK}
-TestErrorHandling: TestErrorHandling.o ${MOAB_LIBDIR}/libMOAB.la
- ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
-
-TestErrorHandlingPar: TestErrorHandlingPar.o ${MOAB_LIBDIR}/libMOAB.la
- ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
-
-ErrorHandlingModel: ErrorHandlingModel.o ${MOAB_LIBDIR}/libMOAB.la
- ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+VisTags: VisTags.o ${MOAB_LIBDIR}/libMOAB.la
+ ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+ReadWriteTest: ReadWriteTest.o ${MOAB_LIBDIR}/libMOAB.la
+ ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+
clean:
- rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${ERROREXAMPLES} ${F90EXAMPLES}
+ rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES}
.cpp.o:
${MOAB_CXX} ${CXXFLAGS} ${MOAB_CXXFLAGS} ${MOAB_CPPFLAGS} ${MOAB_INCLUDES} -DMESH_DIR=\"${MESH_DIR}\" -c $<
diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 42bf23d..950d20c 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -3,12 +3,19 @@
#include "NCHelperFV.hpp"
#include "NCHelperHOMME.hpp"
#include "NCHelperMPAS.hpp"
+#include "NCHelperGCRM.hpp"
#include <sstream>
#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)
@@ -45,13 +52,17 @@ NCHelper* NCHelper::get_nc_helper(ReadNC* readNC, int fileId, const FileOptions&
// For a HOMME connectivity file, there might be no CF convention
else if (NCHelperHOMME::can_read_file(readNC, fileId))
return new (std::nothrow) NCHelperHOMME(readNC, fileId, opts, fileSet);
+ // gcrm reader
+ else if (NCHelperGCRM::can_read_file(readNC))
+ return new (std::nothrow) NCHelperGCRM(readNC, fileId, opts, fileSet);
}
// Unknown NetCDF grid (will fill this in later for POP, CICE and CLM)
return NULL;
}
-ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums) {
+ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
+{
Interface*& mbImpl = _readNC->mbImpl;
std::vector<std::string>& dimNames = _readNC->dimNames;
std::vector<int>& dimLens = _readNC->dimLens;
@@ -69,22 +80,22 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __NUM_DIMS tag.");
rval = mbImpl->tag_set_data(numDimsTag, &_fileSet, 1, &numDims);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __NUM_DIMS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__NUM_VARS>
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __NUM_VARS tag.");
rval = mbImpl->tag_set_data(numVarsTag, &_fileSet, 1, &numVars);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __NUM_VARS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__DIM_NAMES>
Tag dimNamesTag = 0;
@@ -97,24 +108,24 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
}
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __DIM_NAMES tag.");
const void* ptr = dimnames.c_str();
rval = mbImpl->tag_set_by_ptr(dimNamesTag, &_fileSet, 1, &ptr, &dimnamesSz);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __DIM_NAMES tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__DIM_LENS>
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __DIM_LENS tag.");
ptr = &(dimLens[0]);
rval = mbImpl->tag_set_by_ptr(dimLensTag, &_fileSet, 1, &ptr, &dimLensSz);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __DIM_LENS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__VAR_NAMES>
Tag varNamesTag = 0;
@@ -127,12 +138,12 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
}
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __VAR_NAMES tag.");
ptr = varnames.c_str();
rval = mbImpl->tag_set_by_ptr(varNamesTag, &_fileSet, 1, &ptr, &varnamesSz);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __VAR_NAMES tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// __<dim_name>_LOC_MINMAX (for time)
for (unsigned int i = 0; i != dimNamesSz; i++) {
@@ -145,11 +156,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __<dim_name>_LOC_MINMAX tag.");
rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_MINMAX tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
}
}
@@ -169,11 +180,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __<dim_name>_LOC_VALS tag.");
rval = mbImpl->tag_set_data(tagh, &_fileSet, 1, &val[0]);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __<dim_name>_LOC_VALS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
}
}
@@ -186,43 +197,45 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
unsigned int varDimSz = varInfo[mapIter->first].varDims.size();
if (varDimSz == 0)
continue;
- varInfo[mapIter->first].varTags.resize(varDimSz, 0);
+ std::vector<Tag> varDimTags(varDimSz);
for (unsigned int i = 0; i != varDimSz; i++) {
Tag tmptag = 0;
std::string tmptagname = dimNames[varInfo[mapIter->first].varDims[i]];
mbImpl->tag_get_handle(tmptagname.c_str(), 0, MB_TYPE_OPAQUE, tmptag, MB_TAG_ANY);
- varInfo[mapIter->first].varTags[i] = tmptag;
+ varDimTags[i] = tmptag;
}
rval = mbImpl->tag_get_handle(tag_name.c_str(), varDimSz, MB_TYPE_HANDLE, varNamesDimsTag, MB_TAG_SPARSE | MB_TAG_CREAT);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
- rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varInfo[mapIter->first].varTags[0]));
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __<var_name>_DIMS tag.");
+ rval = mbImpl->tag_set_data(varNamesDimsTag, &_fileSet, 1, &(varDimTags[0]));
+ ERRORR(rval, "Trouble setting data for __<var_name>_DIMS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
}
// <PARTITION_METHOD>
Tag part_tag = scdi->part_method_tag();
if (!part_tag)
- SET_ERR(MB_FAILURE, "Trouble getting PARTITION_METHOD tag");
+ ERRORR(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");
+ ERRORR(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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __GLOBAL_ATTRIBS tag.");
std::string gattVal;
std::vector<int> gattLen;
rval = create_attrib_string(globalAtts, gattVal, gattLen);
- CHK_ERR1(rval, "Trouble creating global attribute string");
+ ERRORR(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);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __GLOBAL_ATTRIBS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__GLOBAL_ATTRIBS_LEN>
tag_name = "__GLOBAL_ATTRIBS_LEN";
@@ -230,11 +243,11 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __GLOBAL_ATTRIBS_LEN tag.");
rval = mbImpl->tag_set_data(globalAttLenTag, &_fileSet, 1, &gattLen[0]);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __GLOBAL_ATTRIBS_LEN tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// __<var_name>_ATTRIBS and __<var_name>_ATTRIBS_LEN
for (mapIter = varInfo.begin(); mapIter != varInfo.end(); ++mapIter) {
@@ -243,29 +256,44 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS tag.");
+
std::string varAttVal;
std::vector<int> varAttLen;
- rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen);
- CHK_ERR1_STR(rval, "Trouble creating attribute string for variable " << mapIter->first);
+ if (mapIter->second.numAtts < 1) {
+ if (dummyVarNames.find(mapIter->first) != dummyVarNames.end()) {
+ // This variable is a dummy coordinate variable
+ varAttVal = "DUMMY_VAR";
+ }
+ else {
+ // This variable has no attributes
+ varAttVal = "NO_ATTRIBS";
+ }
+ }
+ else {
+ rval = create_attrib_string(mapIter->second.varAtts, varAttVal, varAttLen);
+ ERRORR(rval, "Trouble creating attribute string.");
+ }
const void* varAttPtr = varAttVal.c_str();
int varAttSz = varAttVal.size();
+ if (0 == varAttSz)
+ varAttSz = 1;
rval = mbImpl->tag_set_by_ptr(varAttTag, &_fileSet, 1, &varAttPtr, &varAttSz);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
- if (varAttLen.size() == 0)
- varAttLen.push_back(0);
ssTagName << "_LEN";
tag_name = ssTagName.str();
Tag varAttLenTag = 0;
+ if (0 == varAttLen.size())
+ varAttLen.push_back(0);
rval = mbImpl->tag_get_handle(tag_name.c_str(), varAttLen.size(), MB_TYPE_INTEGER, varAttLenTag, MB_TAG_SPARSE | MB_TAG_CREAT);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(rval, "Trouble creating __<var_name>_ATTRIBS_LEN tag.");
rval = mbImpl->tag_set_data(varAttLenTag, &_fileSet, 1, &varAttLen[0]);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __<var_name>_ATTRIBS_LEN tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
}
// <__VAR_NAMES_LOCATIONS>
@@ -274,14 +302,14 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(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]);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __VAR_NAMES_LOCATIONS tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
// <__MESH_TYPE>
Tag meshTypeTag = 0;
@@ -289,21 +317,75 @@ ErrorCode NCHelper::create_conventional_tags(const std::vector<int>& tstep_nums)
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);
- CHK_ERR1_STR(rval, "Trouble creating conventional tag " << tag_name);
+ ERRORR(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);
- CHK_ERR1_STR(rval, "Trouble setting data for conventional tag " << tag_name);
+ ERRORR(rval, "Trouble setting data for __MESH_TYPE tag.");
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Conventional tag %s is created.\n", tag_name.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.c_str());
+
+ return MB_SUCCESS;
+}
+
+ErrorCode NCHelper::update_time_tag_vals()
+{
+ Interface*& mbImpl = _readNC->mbImpl;
+ std::vector<std::string>& dimNames = _readNC->dimNames;
+
+ ErrorCode rval;
+
+ // The time tag might be a dummy one (e.g. 'Time' for MPAS)
+ std::string time_tag_name = dimNames[tDim];
+ if (dummyVarNames.find(time_tag_name) != dummyVarNames.end())
+ return MB_SUCCESS;
+
+ Tag time_tag = 0;
+ const void* data = NULL;
+ int time_tag_size = 0;
+ rval = mbImpl->tag_get_handle(time_tag_name.c_str(), 0, MB_TYPE_DOUBLE, time_tag, MB_TAG_VARLEN);
+ ERRORR(rval, "Trouble getting time tag.");
+ rval = mbImpl->tag_get_by_ptr(time_tag, &_fileSet, 1, &data, &time_tag_size);
+ ERRORR(rval, "Trouble getting values for time tag.");
+ const double* time_tag_vals = static_cast<const double*>(data);
+
+ // Merge tVals (read from current file) to existing time tag
+ // Assume that time_tag_vals and tVals are both sorted
+ std::vector<double> merged_time_vals;
+ merged_time_vals.reserve(time_tag_size + nTimeSteps);
+ int i = 0;
+ int j = 0;
+
+ // Merge time values from time_tag_vals and tVals
+ while (i < time_tag_size && j < nTimeSteps) {
+ if (time_tag_vals[i] < tVals[j])
+ merged_time_vals.push_back(time_tag_vals[i++]);
+ else
+ merged_time_vals.push_back(tVals[j++]);
+ }
+
+ // Append remaining time values of time_tag_vals (if any)
+ while (i < time_tag_size)
+ merged_time_vals.push_back(time_tag_vals[i++]);
+
+ // Append remaining time values of tVals (if any)
+ while (j < nTimeSteps)
+ merged_time_vals.push_back(tVals[j++]);
+
+ data = &merged_time_vals[0];
+ time_tag_size = merged_time_vals.size();
+ rval = mbImpl->tag_set_by_ptr(time_tag, &_fileSet, 1, &data, &time_tag_size);
+ ERRORR(rval, "Failed to set data for time tag.");
return MB_SUCCESS;
}
-ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, std::vector<int>& tstep_nums,
+ErrorCode NCHelper::read_variable_setup(std::vector<std::string>& var_names, std::vector<int>& tstep_nums,
std::vector<ReadNC::VarData>& vdatas, std::vector<ReadNC::VarData>& vsetdatas)
{
std::map<std::string, ReadNC::VarData>& varInfo = _readNC->varInfo;
+ std::vector<std::string>& dimNames = _readNC->dimNames;
+
std::map<std::string, ReadNC::VarData>::iterator mit;
// If empty read them all (except ignored variables)
@@ -312,11 +394,13 @@ ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, st
ReadNC::VarData vd = (*mit).second;
// If read all variables at once, skip ignored ones
- // Upon creation of dummy variables, tag values have already been set
- if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end() ||
- dummyVarNames.find(vd.varName) != dummyVarNames.end())
+ if (ignoredVarNames.find(vd.varName) != ignoredVarNames.end())
continue;
+ // Coordinate variables (include dummy ones) were read to the file set by default
+ if (std::find(dimNames.begin(), dimNames.end(), vd.varName) != dimNames.end())
+ continue;
+
if (vd.entLoc == ReadNC::ENTLOCSET)
vsetdatas.push_back(vd);
else
@@ -330,7 +414,7 @@ ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, st
if (mit != varInfo.end()) {
ReadNC::VarData vd = (*mit).second;
- // Upon creation of dummy variables, tag values have already been set
+ // Upon creation of dummy coordinate variables, tag values have already been set
if (dummyVarNames.find(vd.varName) != dummyVarNames.end())
continue;
@@ -340,7 +424,7 @@ ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, st
vdatas.push_back(vd);
}
else {
- SET_ERR_STR(MB_FAILURE, "Couldn't find specified variable " << var_names[i]);
+ ERRORR(MB_FAILURE, "Couldn't find variable.");
}
}
}
@@ -355,21 +439,21 @@ ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, st
for (unsigned int i = 0; i < vdatas.size(); i++) {
vdatas[i].varTags.resize(tstep_nums.size(), 0);
vdatas[i].varDatas.resize(tstep_nums.size());
+ // NC reader assumes that non-set variables always have timesteps
+ assert(std::find(vdatas[i].varDims.begin(), vdatas[i].varDims.end(), tDim) != vdatas[i].varDims.end());
vdatas[i].has_tsteps = true;
}
for (unsigned int i = 0; i < vsetdatas.size(); i++) {
if ((std::find(vsetdatas[i].varDims.begin(), vsetdatas[i].varDims.end(), tDim) != vsetdatas[i].varDims.end())
- && (vsetdatas[i].varDims.size() > 1)) {
- // Set variables with timesteps: time is the first dimension, followed
- // by other dimensions, e.g. xtime(Time, StrLen)
+ && (vsetdatas[i].varName != dimNames[tDim])) {
+ // Set variables with timesteps: e.g. xtime(Time) or xtime(Time, StrLen)
vsetdatas[i].varTags.resize(tstep_nums.size(), 0);
vsetdatas[i].varDatas.resize(tstep_nums.size());
vsetdatas[i].has_tsteps = true;
}
else {
- // Set variables without timesteps: no time dimension, or time is the only
- // dimension, e.g. lev(lev), xtime(Time)
+ // Set variables without timesteps: no time dimension, or time itself
vsetdatas[i].varTags.resize(1, 0);
vsetdatas[i].varDatas.resize(1);
vsetdatas[i].has_tsteps = false;
@@ -380,24 +464,24 @@ ErrorCode NCHelper::read_variables_setup(std::vector<std::string>& var_names, st
return MB_SUCCESS;
}
-ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
+ErrorCode NCHelper::read_variable_to_set(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
{
Interface*& mbImpl = _readNC->mbImpl;
DebugOutput& dbgOut = _readNC->dbgOut;
- ErrorCode rval = read_variables_to_set_allocate(vdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble allocating space to read set variables");
+ ErrorCode rval = read_variable_to_set_allocate(vdatas, tstep_nums);
+ ERRORR(rval, "Trouble allocating read variables to set.");
// Finally, read into that space
- int success = 0;
+ int success;
for (unsigned int i = 0; i < vdatas.size(); i++) {
- // Note, for most set variables without timesteps, loop one time and then break
+ // Note, for set variables without timesteps, loop one time and then break
for (unsigned int t = 0; t < tstep_nums.size(); t++) {
void* data = vdatas[i].varDatas[t];
- // Rare case: set variables with timesteps, e.g. xtime(Time, StrLen)
+ // Set variables with timesteps, e.g. xtime(Time) or xtime(Time, StrLen)
if (vdatas[i].has_tsteps) {
- // Set up readStart for each timestep along time dimension
+ // Set readStart for each timestep along time dimension
vdatas[i].readStarts[0] = tstep_nums[t];
}
@@ -406,44 +490,42 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
case NC_CHAR:
success = NCFUNCAG(_vara_text)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
&vdatas[i].readCounts[0], (char*) data);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read char data for set variable " << vdatas[i].varName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read double data for set variable " << vdatas[i].varName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read float data for set variable " << vdatas[i].varName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read int data for set variable " << vdatas[i].varName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read short data for set variable " << vdatas[i].varName);
+ ERRORS(success, "Failed to read short data.");
break;
default:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for set variable " << vdatas[i].varName);
+ success = 1;
}
- dbgOut.tprintf(2, "Converting set variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
+ 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);
- CHK_ERR1_STR(rval, "Failed to convert set variable " << vdatas[i].varName);
+ ERRORR(rval, "Failed to convert variable.");
- dbgOut.tprintf(2, "Setting tag data for set variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
+ 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);
- CHK_ERR1_STR(rval, "Failed to set tag data for set variable " << vdatas[i].varName);
+ ERRORR(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) {
@@ -464,7 +546,7 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
}
vdatas[i].varDatas[t] = NULL;
- // Note, loop continues only for set variables with timesteps, e.g. xtime(Time, StrLen)
+ // Loop continues only for set variables with timesteps, e.g. xtime(Time) or xtime(Time, StrLen)
if (!vdatas[i].has_tsteps)
break;
}
@@ -472,7 +554,7 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
- dbgOut.printf(1, "Read set variables: %s", vdatas.begin()->varName.c_str());
+ dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
for (unsigned int i = 1; i < vdatas.size(); i++)
dbgOut.printf(1, ", %s ", vdatas[i].varName.c_str());
dbgOut.tprintf(1, "\n");
@@ -493,6 +575,7 @@ 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;
@@ -514,10 +597,10 @@ ErrorCode NCHelper::convert_variable(ReadNC::VarData& var_data, int tstep_num)
idata[i] = sdata[i];
break;
default:
- break;
+ success = 1;
}
- if (2 <= dbgOut.get_verbosity()) {
+ if (2 <= dbgOut.get_verbosity() && !success) {
double dmin, dmax;
int imin, imax;
switch (var_data.varDataType) {
@@ -551,8 +634,12 @@ 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;
- default:
+ case NC_NAT:
+ case NC_BYTE:
+ case NC_CHAR:
break;
+ default: // Default case added to remove compiler warnings
+ success = 1;
}
}
@@ -563,15 +650,14 @@ 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) {
- SET_ERR_STR(MB_FAILURE, "Couldn't find coordinate variable " << var_name);
- }
+ if (varInfo.end() == vmit)
+ return MB_FAILURE;
assert(lmin >= 0 && lmax >= lmin);
NCDF_SIZE tstart = lmin;
NCDF_SIZE tcount = lmax - lmin + 1;
NCDF_DIFF dum_stride = 1;
- int success = 0;
+ int fail;
// Check size
if ((std::size_t)tcount != cvals.size())
@@ -579,19 +665,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) {
- success = NCFUNCAG(_vars_double)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &cvals[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to get double values for coordinate variable " << var_name);
+ fail = NCFUNCAG(_vars_double)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &cvals[0]);
+ if (fail)
+ ERRORS(MB_FAILURE, "Failed to get coordinate values.");
}
else if (NC_FLOAT == (*vmit).second.varDataType) {
std::vector<float> tcvals(tcount);
- success = NCFUNCAG(_vars_float)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &tcvals[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to get float values for coordinate variable " << var_name);
+ fail = NCFUNCAG(_vars_float)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &tcvals[0]);
+ if (fail)
+ ERRORS(MB_FAILURE, "Failed to get coordinate values.");
std::copy(tcvals.begin(), tcvals.end(), cvals.begin());
}
else {
- SET_ERR_STR(MB_FAILURE, "Wrong data type for coordinate variable " << var_name);
+ ERRORR(MB_FAILURE, "Wrong data type for coordinate variable.");
}
return MB_SUCCESS;
@@ -601,6 +687,10 @@ ErrorCode NCHelper::get_tag_to_set(ReadNC::VarData& var_data, int tstep_num, Tag
{
Interface*& mbImpl = _readNC->mbImpl;
DebugOutput& dbgOut = _readNC->dbgOut;
+ int& tStepBase = _readNC->tStepBase;
+
+ if (tStepBase > 0)
+ tstep_num += tStepBase;
std::ostringstream tag_name;
if (var_data.has_tsteps)
@@ -624,11 +714,12 @@ 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:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for set variable " << var_data.varName);
+ std::cerr << "Unrecognized data type for tag " << tag_name << std::endl;
+ rval = MB_FAILURE;
}
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag %s is created for set variable %s.\n", tag_name.str().c_str(), var_data.varName.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.str().c_str());
return rval;
}
@@ -637,6 +728,10 @@ ErrorCode NCHelper::get_tag_to_nonset(ReadNC::VarData& var_data, int tstep_num,
{
Interface*& mbImpl = _readNC->mbImpl;
DebugOutput& dbgOut = _readNC->dbgOut;
+ int& tStepBase = _readNC->tStepBase;
+
+ if (tStepBase > 0)
+ tstep_num += tStepBase;
std::ostringstream tag_name;
tag_name << var_data.varName << tstep_num;
@@ -657,18 +752,19 @@ 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:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for non-set variable " << var_data.varName);
+ std::cerr << "Unrecognized data type for tag " << tag_name.str() << std::endl;
+ rval = MB_FAILURE;
}
if (MB_SUCCESS == rval)
- dbgOut.tprintf(2, "Tag %s is created for non-set variable %s.\n", tag_name.str().c_str(), var_data.varName.c_str());
+ dbgOut.tprintf(2, "Tag created for variable %s\n", tag_name.str().c_str());
return rval;
}
ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::AttData>& attMap, std::string& attVal, std::vector<int>& attLen)
{
- int success = 0;
+ int success;
std::stringstream ssAtt;
unsigned int sz = 0;
std::map<std::string, ReadNC::AttData>::const_iterator attIt = attMap.begin();
@@ -682,44 +778,39 @@ 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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read char data for attribute " << attIt->second.attName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read double data for attribute " << attIt->second.attName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read float data for attribute " << attIt->second.attName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read int data for attribute " << attIt->second.attName);
+ ERRORS(success, "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);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read short data for attribute " << attIt->second.attName);
+ ERRORS(success, "Failed to read attribute short data.");
ssAtt << "short;";
break;
default:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for attribute " << attIt->second.attName);
+ success = 1;
}
char* tmpc = (char *) attData;
for (unsigned int counter = 0; counter != sz; ++counter)
@@ -743,17 +834,17 @@ ErrorCode NCHelper::create_dummy_variables()
// Hack: look at all dimensions, and see if we have one that does not appear in the list of varInfo names
// Right now, candidates are from unstructured meshes, such as ncol (HOMME) and nCells (MPAS)
- // For each of them, create a dummy variable with a sparse tag to store the dimension length
+ // For each of them, create a dummy coordinate variable with a sparse tag to store the dimension length
for (unsigned int i = 0; i < dimNames.size(); i++) {
// If there is a variable with this dimension name, skip
if (varInfo.find(dimNames[i]) != varInfo.end())
continue;
- // Create a dummy variable
+ // Create a dummy coordinate variable
int sizeTotalVar = varInfo.size();
std::string var_name(dimNames[i]);
ReadNC::VarData& data = varInfo[var_name];
- data.varName = var_name;
+ data.varName = std::string(var_name);
data.varId = sizeTotalVar;
data.varTags.resize(1, 0);
data.varDataType = NC_INT;
@@ -761,29 +852,29 @@ ErrorCode NCHelper::create_dummy_variables()
data.varDims[0] = (int)i;
data.numAtts = 0;
data.entLoc = ReadNC::ENTLOCSET;
- dummyVarNames.insert(var_name);
- dbgOut.tprintf(2, "Dummy variable created for dimension %s\n", var_name.c_str());
+ dummyVarNames.insert(dimNames[i]);
+ dbgOut.tprintf(2, "Dummy coordinate variable created for dimension %s\n", dimNames[i].c_str());
// Create a corresponding sparse tag
Tag tagh;
- ErrorCode rval = mbImpl->tag_get_handle(var_name.c_str(), 0, MB_TYPE_INTEGER, 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);
- CHK_ERR1_STR(rval, "Failed to create tag for dimension " << var_name);
+ ERRORR(rval, "Failed to create tag for a dummy coordinate 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);
- CHK_ERR1_STR(rval, "Failed to set tag data for dimension " << var_name);
+ ERRORR(rval, "Failed to set data for dimension tag.");
- dbgOut.tprintf(2, "Sparse tag is created for dimension %s\n", var_name.c_str());
+ dbgOut.tprintf(2, "Sparse tag created for dimension %s\n", dimNames[i].c_str());
}
return MB_SUCCESS;
}
-ErrorCode NCHelper::read_variables_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
+ErrorCode NCHelper::read_variable_to_set_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
{
std::vector<int>& dimLens = _readNC->dimLens;
DebugOutput& dbgOut = _readNC->dbgOut;
@@ -798,7 +889,7 @@ ErrorCode NCHelper::read_variables_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]]);
}
@@ -810,7 +901,7 @@ ErrorCode NCHelper::read_variables_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]]);
}
@@ -824,16 +915,16 @@ ErrorCode NCHelper::read_variables_to_set_allocate(std::vector<ReadNC::VarData>&
// Note, for set variables without timesteps, loop one time and then break
for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Reading set variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[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]) {
- SET_ERR_STR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number " << tstep_nums[t]);
+ ERRORR(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]);
- CHK_ERR1_STR(rval, "Trouble getting tag for set variable " << vdatas[i].varName);
+ ERRORR(rval, "Trouble getting tag for a set variable.");
}
switch (vdatas[i].varDataType) {
@@ -850,10 +941,11 @@ ErrorCode NCHelper::read_variables_to_set_allocate(std::vector<ReadNC::VarData>&
vdatas[i].varDatas[t] = new int[vdatas[i].sz];
break;
default:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for set variable " << vdatas[i].varName);
+ std::cerr << "Unrecognized data type for set variable tag values" << std::endl;
+ rval = MB_FAILURE;
}
- // Note, loop continues only for set variables with timesteps, e.g. xtime(Time, StrLen)
+ // Loop continues only for set variables with timesteps, e.g. xtime(Time) or xtime(Time, StrLen)
if (!vdatas[i].has_tsteps)
break;
}
@@ -868,7 +960,7 @@ 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);
- CHK_ERR1(rval, "Trouble getting number of vertices");
+ ERRORR(rval, "Trouble getting number of vertices.");
/*
// Check against parameters
@@ -876,7 +968,7 @@ 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) {
- SET_ERR(MB_FAILURE, "Number of vertices doesn't match");
+ ERRORR(MB_FAILURE, "Number of vertices doesn't match.");
}
}
*/
@@ -884,7 +976,7 @@ ErrorCode ScdNCHelper::check_existing_mesh() {
// Check the number of elements too
int num_elems;
rval = mbImpl->get_number_entities_by_dimension(_fileSet, (-1 == lCDims[2] ? 2 : 3), num_elems);
- CHK_ERR1(rval, "Trouble getting number of elements");
+ ERRORR(rval, "Trouble getting number of elements.");
/*
// Check against parameters
@@ -892,7 +984,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) {
- SET_ERR(MB_FAILURE, "Number of elements doesn't match");
+ ERRORR(MB_FAILURE, "Number of elements doesn't match.");
}
}
*/
@@ -914,7 +1006,7 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
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);
- CHK_ERR1(rval, "Trouble creating scd vertex sequence");
+ ERRORR(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);
@@ -923,11 +1015,11 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
int count;
void* data;
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");
+ ERRORR(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);
- CHK_ERR1(rval, "Failed to get tag iterator on global id tag");
+ ERRORR(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++)
@@ -938,21 +1030,21 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
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);
- CHK_ERR1(rval, "Couldn't add new vertices to current file set");
+ ERRORR(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);
- CHK_ERR1(rval, "Couldn't get vertex coordinate arrays");
+ ERRORR(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++) {
@@ -966,13 +1058,14 @@ 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]);
- CHK_ERR1(rval, "Trouble getting local gid values of vertices");
+ ERRORR(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
@@ -984,19 +1077,23 @@ ErrorCode ScdNCHelper::create_mesh(Range& faces)
assert(scd_box->boundary_complete());
EntityHandle dum_ent = scd_box->start_element();
rval = mbImpl->list_entities(&dum_ent, 1);
- CHK_ERR1(rval, "Trouble listing first hex");
+ ERRORR(rval, "Trouble listing first hex.");
std::vector<EntityHandle> connect;
rval = mbImpl->get_connectivity(&dum_ent, 1, connect);
- CHK_ERR1(rval, "Trouble getting connectivity");
+ ERRORR(rval, "Trouble getting connectivity.");
rval = mbImpl->list_entities(&connect[0], connect.size());
- CHK_ERR1(rval, "Trouble listing element connectivity");
+ ERRORR(rval, "Trouble listing element connectivity.");
}
Range edges;
mbImpl->get_adjacencies(faces, 1, true, edges, Interface::UNION);
+ // Create COORDS tag for quads
+ rval = create_quad_coordinate_tag();
+ ERRORR(rval, "Trouble creating coordinate tags to entities quads");
+
return MB_SUCCESS;
}
@@ -1005,26 +1102,23 @@ ErrorCode ScdNCHelper::read_variables(std::vector<std::string>& var_names, std::
std::vector<ReadNC::VarData> vdatas;
std::vector<ReadNC::VarData> vsetdatas;
- ErrorCode rval = read_variables_setup(var_names, tstep_nums, vdatas, vsetdatas);
- CHK_ERR1(rval, "Trouble setting up to read variables");
-
- rval = create_quad_coordinate_tag();
- CHK_ERR1(rval, "Trouble creating COORDS tag for quads");
+ ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas);
+ ERRORR(rval, "Trouble setting up read variable.");
if (!vsetdatas.empty()) {
- rval = read_variables_to_set(vsetdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble reading variables to set");
+ rval = read_variable_to_set(vsetdatas, tstep_nums);
+ ERRORR(rval, "Trouble read variables to set.");
}
if (!vdatas.empty()) {
- rval = read_scd_variables_to_nonset(vdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble reading variables to verts/edges/faces");
+ rval = read_scd_variable_to_nonset(vdatas, tstep_nums);
+ ERRORR(rval, "Trouble read variables to entities verts/edges/faces.");
}
return MB_SUCCESS;
}
-ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
+ErrorCode ScdNCHelper::read_scd_variable_to_nonset_allocate(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
{
Interface*& mbImpl = _readNC->mbImpl;
std::vector<int>& dimLens = _readNC->dimLens;
@@ -1037,14 +1131,18 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC:
// Get vertices in set
Range verts;
rval = mbImpl->get_entities_by_dimension(_fileSet, 0, verts);
- CHK_ERR1(rval, "Trouble getting vertices in current file set");
+ ERRORR(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.");
+
// Get faces in set
Range faces;
rval = mbImpl->get_entities_by_dimension(_fileSet, 2, faces);
- CHK_ERR1(rval, "Trouble getting faces in current file set");
+ ERRORR(rval, "Trouble getting faces in set.");
assert("Should only have a single face subrange, since they were read in one shot" &&
faces.psize() == 1);
@@ -1054,7 +1152,7 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC:
if (isParallel) {
ParallelComm*& myPcomm = _readNC->myPcomm;
rval = myPcomm->filter_pstatus(faces, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &faces_owned);
- CHK_ERR1(rval, "Trouble getting owned faces in current file set");
+ ERRORR(rval, "Trouble getting owned faces in set.");
}
else
faces_owned = faces; // Not running in parallel, but still with MPI
@@ -1090,9 +1188,11 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC:
range = &verts;
break;
case ReadNC::ENTLOCNSEDGE:
+ ERRORR(MB_FAILURE, "Reading edge data not implemented yet.");
+ break;
case ReadNC::ENTLOCEWEDGE:
- case ReadNC::ENTLOCEDGE:
- SET_GLB_ERR(MB_NOT_IMPLEMENTED, "Reading edge data is not implemented yet");
+ ERRORR(MB_FAILURE, "Reading edge data not implemented yet.");
+ break;
case ReadNC::ENTLOCFACE:
// Faces
vdatas[i].readStarts[2] = lCDims[1];
@@ -1105,28 +1205,32 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC:
range = &faces;
#endif
break;
+ case ReadNC::ENTLOCSET:
+ // Set
+ break;
default:
- SET_ERR_STR(MB_FAILURE, "Unexpected entity location type for non-set variable " << vdatas[i].varName);
+ ERRORR(MB_FAILURE, "Unrecognized entity location type.");
+ break;
}
for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Reading non-set variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[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]) {
- SET_ERR_STR(MB_INDEX_OUT_OF_RANGE, "Wrong value for timestep number " << tstep_nums[t]);
+ ERRORR(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);
- CHK_ERR1_STR(rval, "Trouble getting tag for non-set variable " << vdatas[i].varName);
+ ERRORR(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);
- CHK_ERR1_STR(rval, "Failed to get tag iterator for non-set variable " << vdatas[i].varName);
+ ERRORR(rval, "Failed to get tag iterator.");
assert((unsigned)count == range->size());
vdatas[i].varDatas[t] = data;
}
@@ -1140,15 +1244,15 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset_allocate(std::vector<ReadNC:
return rval;
}
-ErrorCode ScdNCHelper::read_scd_variables_to_nonset(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
+ErrorCode ScdNCHelper::read_scd_variable_to_nonset(std::vector<ReadNC::VarData>& vdatas, std::vector<int>& tstep_nums)
{
DebugOutput& dbgOut = _readNC->dbgOut;
- ErrorCode rval = read_scd_variables_to_nonset_allocate(vdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble allocating space to read non-set variables");
+ ErrorCode rval = read_scd_variable_to_nonset_allocate(vdatas, tstep_nums);
+ ERRORR(rval, "Trouble allocating read variables.");
// Finally, read into that space
- int success = 0;
+ int success;
for (unsigned int i = 0; i < vdatas.size(); i++) {
std::size_t sz = vdatas[i].sz;
@@ -1171,94 +1275,93 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset(std::vector<ReadNC::VarData>
std::vector<char> tmpchardata(sz);
success = NCFUNCAG(_vara_text)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
&tmpchardata[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read char data for non-set variable " << vdatas[i].varName);
- if (vdatas[i].numLev != 1)
+ if (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- kji_to_jik(ni, nj, nk, data, &tmpchardata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpchardata[0]);
else {
for (std::size_t idx = 0; idx != tmpchardata.size(); idx++)
((char*) data)[idx] = tmpchardata[idx];
}
+ ERRORS(success, "Failed to read char data.");
break;
}
case NC_DOUBLE: {
std::vector<double> tmpdoubledata(sz);
success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
&tmpdoubledata[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read double data for non-set variable " << vdatas[i].varName);
- if (vdatas[i].numLev != 1)
+ if (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- kji_to_jik(ni, nj, nk, data, &tmpdoubledata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpdoubledata[0]);
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: {
std::vector<float> tmpfloatdata(sz);
success = NCFUNCAG(_vara_float)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
&tmpfloatdata[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read float data for non-set variable " << vdatas[i].varName);
- if (vdatas[i].numLev != 1)
+ if (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- kji_to_jik(ni, nj, nk, data, &tmpfloatdata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpfloatdata[0]);
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: {
std::vector<int> tmpintdata(sz);
success = NCFUNCAG(_vara_int)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
&tmpintdata[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read int data for non-set variable " << vdatas[i].varName);
- if (vdatas[i].numLev != 1)
+ if (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- kji_to_jik(ni, nj, nk, data, &tmpintdata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpintdata[0]);
else {
for (std::size_t idx = 0; idx != tmpintdata.size(); idx++)
((int*) data)[idx] = tmpintdata[idx];
}
+ ERRORS(success, "Failed to read int data.");
break;
}
case NC_SHORT: {
std::vector<short> tmpshortdata(sz);
success = NCFUNCAG(_vara_short)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
&tmpshortdata[0]);
- if (success)
- SET_ERR_STR(MB_FAILURE, "Failed to read short data for non-set variable " << vdatas[i].varName);
- if (vdatas[i].numLev != 1)
+ if (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- kji_to_jik(ni, nj, nk, data, &tmpshortdata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpshortdata[0]);
else {
for (std::size_t idx = 0; idx != tmpshortdata.size(); idx++)
((short*) data)[idx] = tmpshortdata[idx];
}
+ ERRORS(success, "Failed to read short data.");
break;
}
default:
- SET_ERR_STR(MB_FAILURE, "Unrecognized data type for non-set variable " << vdatas[i].varName);
+ success = 1;
}
+
+ 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 non-set variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- rval = convert_variable(vdatas[i], t);
- CHK_ERR1_STR(rval, "Failed to convert non-set variable " << vdatas[i].varName);
+ 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;
}
}
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
- dbgOut.printf(1, "Read non-set variables: %s", vdatas.begin()->varName.c_str());
+ dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
for (unsigned int i = 1; i < vdatas.size(); i++)
dbgOut.printf(1, ", %s ", vdatas[i].varName.c_str());
dbgOut.tprintf(1, "\n");
@@ -1272,7 +1375,7 @@ ErrorCode ScdNCHelper::create_quad_coordinate_tag() {
Range ents;
ErrorCode rval = mbImpl->get_entities_by_type(_fileSet, moab::MBQUAD, ents);
- CHK_ERR1(rval, "Trouble getting quads");
+ ERRORR(rval, "Trouble getting QUAD entity.");
std::size_t numOwnedEnts = 0;
#ifdef USE_MPI
@@ -1281,7 +1384,7 @@ ErrorCode ScdNCHelper::create_quad_coordinate_tag() {
if (isParallel) {
ParallelComm*& myPcomm = _readNC->myPcomm;
rval = myPcomm->filter_pstatus(ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &ents_owned);
- CHK_ERR1(rval, "Trouble getting owned quads");
+ ERRORR(rval, "Trouble getting owned QUAD entity.");
numOwnedEnts = ents_owned.size();
}
else {
@@ -1309,17 +1412,16 @@ 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);
- CHK_ERR1(rval, "Trouble creating COORDS tag");
+ ERRORR(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);
- CHK_ERR1(rval, "Failed to get COORDS tag iterator on owned quads");
#else
rval = mbImpl->tag_iterate(tagh, ents.begin(), ents.end(), count, data);
- CHK_ERR1(rval, "Failed to get COORDS tag iterator on quads");
#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);
@@ -1332,24 +1434,23 @@ ErrorCode UcdNCHelper::read_variables(std::vector<std::string>& var_names, std::
std::vector<ReadNC::VarData> vdatas;
std::vector<ReadNC::VarData> vsetdatas;
- ErrorCode rval = read_variables_setup(var_names, tstep_nums, vdatas, vsetdatas);
- CHK_ERR1(rval, "Trouble setting up to read variables");
+ ErrorCode rval = read_variable_setup(var_names, tstep_nums, vdatas, vsetdatas);
+ ERRORR(rval, "Trouble setting up read variable.");
if (!vsetdatas.empty()) {
- rval = read_variables_to_set(vsetdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble reading variables to set");
+ rval = read_variable_to_set(vsetdatas, tstep_nums);
+ ERRORR(rval, "Trouble read variables to set.");
}
if (!vdatas.empty()) {
#ifdef PNETCDF_FILE
// With pnetcdf support, we will use async read
- rval = read_ucd_variables_to_nonset_async(vdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble reading variables to verts/edges/faces");
+ rval = read_ucd_variable_to_nonset_async(vdatas, tstep_nums);
#else
// Without pnetcdf support, we will use old read
- rval = read_ucd_variables_to_nonset(vdatas, tstep_nums);
- CHK_ERR1(rval, "Trouble reading variables to verts/edges/faces");
+ rval = read_ucd_variable_to_nonset(vdatas, tstep_nums);
#endif
+ ERRORR(rval, "Trouble read variables to entities verts/edges/faces.");
}
return MB_SUCCESS;
diff --git a/src/io/ReadNC.cpp b/src/io/ReadNC.cpp
index cfda41d..cd2c004 100644
--- a/src/io/ReadNC.cpp
+++ b/src/io/ReadNC.cpp
@@ -5,6 +5,12 @@
#include "MBTagConventions.hpp"
#include "moab/FileOptions.hpp"
+#define ERRORR(rval, str) \
+ if (MB_SUCCESS != rval) { readMeshIface->report_error("%s", str); return rval; }
+
+#define ERRORS(err, str) \
+ if (err) { readMeshIface->report_error("%s", str); return MB_FAILURE; }
+
namespace moab {
ReaderIface* ReadNC::factory(Interface* iface)
@@ -19,7 +25,7 @@ ReadNC::ReadNC(Interface* impl) :
myPcomm(NULL),
#endif
noMesh(false), noVars(false), spectralMesh(false), noMixedElements(false), noEdges(false),
- gatherSetRank(-1), myHelper(NULL)
+ gatherSetRank(-1), tStepBase(-1), myHelper(NULL)
{
assert(impl != NULL);
impl->query_interface(readMeshIface);
@@ -44,14 +50,16 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
// Get and cache predefined tag handles
int dum_val = 0;
- rval = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, mGlobalIdTag, MB_TAG_DENSE | MB_TAG_CREAT, &dum_val);CHK_ERR(rval);
+ rval = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, mGlobalIdTag, MB_TAG_DENSE | MB_TAG_CREAT, &dum_val);
+ if (MB_SUCCESS != rval)
+ return rval;
// Store the pointer to the tag; if not null, set when global id tag
// is set too, with the same data, duplicated
mpFileIdTag = file_id_tag;
rval = parse_options(opts, var_names, tstep_nums, tstep_vals);
- CHK_ERR1(rval, "Trouble parsing option string");
+ ERRORR(rval, "Trouble parsing option string.");
// Open the file
dbgOut.tprintf(1, "Opening file %s\n", file_name);
@@ -67,21 +75,20 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
success = NCFUNC(open)(file_name, 0, &fileId);
#endif
- if (success)
- SET_ERR(MB_FAILURE, "Trouble opening file");
+ ERRORS(success, "Trouble opening file.");
// Read the header (num dimensions, dimensions, num variables, global attribs)
rval = read_header();
- CHK_ERR1(rval, "Trouble reading file header");
+ ERRORR(rval, "Trouble reading file header.");
// Make sure there's a file set to put things in
EntityHandle tmp_set;
if (noMesh && !file_set) {
- SET_ERR(MB_FAILURE, "NOMESH option requires non-NULL file set on input");
+ ERRORR(MB_FAILURE, "NOMESH option requires non-NULL file set on input.\n");
}
else if (!file_set || (file_set && *file_set == 0)) {
rval = mbImpl->create_meshset(MESHSET_SET, tmp_set);
- CHK_ERR1(rval, "Trouble creating file set");
+ ERRORR(rval, "Trouble creating file set.");
}
else
tmp_set = *file_set;
@@ -98,41 +105,80 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
// Get appropriate NC helper instance based on information read from the header
myHelper = NCHelper::get_nc_helper(this, fileId, opts, tmp_set);
if (NULL == myHelper) {
- SET_ERR(MB_FAILURE, "Failed to get NCHelper class instance");
+ ERRORR(MB_FAILURE, "Failed to get NCHelper class instance.");
}
// Initialize mesh values
rval = myHelper->init_mesh_vals();
- CHK_ERR1(rval, "Trouble initializing mesh values");
+ ERRORR(rval, "Trouble initializing mesh values.");
// Check existing mesh from last read
if (noMesh && !noVars) {
rval = myHelper->check_existing_mesh();
- CHK_ERR1(rval, "Trouble checking mesh from last read");
+ ERRORR(rval, "Trouble checking mesh from last read.\n");
+ }
+
+ // Create some conventional tags, e.g. __NUM_DIMS
+ // For multiple reads to a specified file set, we assume a single file, or a series of
+ // files with separated timesteps. Keep a flag on the file set to prevent conventional
+ // tags from being created again on a second read
+ Tag convTagsCreated = 0;
+ int def_val = 0;
+ rval = mbImpl->tag_get_handle("__CONV_TAGS_CREATED", 1, MB_TYPE_INTEGER, convTagsCreated,
+ MB_TAG_SPARSE | MB_TAG_CREAT, &def_val);
+ ERRORR(rval, "Trouble getting _CONV_TAGS_CREATED tag.");
+ int create_conv_tags_flag = 0;
+ rval = mbImpl->tag_get_data(convTagsCreated, &tmp_set, 1, &create_conv_tags_flag);
+ // The first read to the file set
+ if (0 == create_conv_tags_flag) {
+ // Read dimensions (coordinate variables) by default to create tags like __<var_name>_DIMS
+ // This is done only once (assume that all files read to the file set have the same dimensions)
+ rval = myHelper->read_variables(dimNames, tstep_nums);
+ ERRORR(rval, "Trouble reading dimensions.");
+
+ rval = myHelper->create_conventional_tags(tstep_nums);
+ ERRORR(rval, "Trouble creating NC conventional tags.");
+
+ create_conv_tags_flag = 1;
+ rval = mbImpl->tag_set_data(convTagsCreated, &tmp_set, 1, &create_conv_tags_flag);
+ ERRORR(rval, "Trouble setting data for _CONV_TAGS_CREATED tag.");
+ }
+ // Another read to the file set
+ else {
+ if (tStepBase > -1) {
+ // If timesteps spread across files, merge time values read
+ // from current file to existing time tag
+ rval = myHelper->update_time_tag_vals();
+ ERRORR(rval, "Trouble updating time tag values.");
+ }
}
// Create mesh vertex/edge/face sequences
Range faces;
if (!noMesh) {
rval = myHelper->create_mesh(faces);
- CHK_ERR1(rval, "Trouble creating mesh");
+ ERRORR(rval, "Trouble creating mesh.");
}
- // Read variables onto grid
+ // Read specified variables onto grid
if (!noVars) {
- rval = myHelper->read_variables(var_names, tstep_nums);CHK_ERR(rval);
- }
- else {
- // Read dimension variables by default (the dimensions that are also variables)
- std::vector<std::string> dim_var_names;
- for (unsigned int i = 0; i < dimNames.size(); i++) {
- std::map<std::string, VarData>::iterator mit = varInfo.find(dimNames[i]);
- if (mit != varInfo.end())
- dim_var_names.push_back(dimNames[i]);
+ if (var_names.empty()) {
+ // If VARIABLE option is missing, read all variables
+ rval = myHelper->read_variables(var_names, tstep_nums);
+ ERRORR(rval, "Trouble reading all variables.");
}
-
- if (!dim_var_names.empty()) {
- rval = myHelper->read_variables(dim_var_names, tstep_nums);CHK_ERR(rval);
+ else {
+ // Exclude dimensions that are read to the file set by default
+ std::vector<std::string> non_dim_var_names;
+ for (unsigned int i = 0; i < var_names.size(); i++) {
+ if (std::find(dimNames.begin(), dimNames.end(), var_names[i]) == dimNames.end())
+ non_dim_var_names.push_back(var_names[i]);
+ }
+
+ if (!non_dim_var_names.empty()) {
+ rval = myHelper->read_variables(non_dim_var_names, tstep_nums);
+ ERRORR(rval, "Trouble reading specified variables.");
+ }
}
}
@@ -141,40 +187,35 @@ ErrorCode ReadNC::load_file(const char* file_name, const EntityHandle* file_set,
if (isParallel) {
EntityHandle partn_set;
rval = mbImpl->create_meshset(MESHSET_SET, partn_set);
- CHK_ERR1(rval, "Trouble creating partition set");
+ ERRORR(rval, "Trouble creating partition set.");
rval = mbImpl->add_entities(partn_set, faces);
- CHK_ERR1(rval, "Couldn't add new faces to partition set");
+ ERRORR(rval, "Couldn't add new faces to partition set.");
Range verts;
rval = mbImpl->get_connectivity(faces, verts);
- CHK_ERR1(rval, "Couldn't get verts of faces");
+ ERRORR(rval, "Couldn't get verts of faces");
rval = mbImpl->add_entities(partn_set, verts);
- CHK_ERR1(rval, "Couldn't add new verts to partition set");
+ ERRORR(rval, "Couldn't add new verts to partition set.");
myPcomm->partition_sets().insert(partn_set);
// Write partition tag name on partition set
Tag part_tag = myPcomm->partition_tag();
int dum_rank = myPcomm->proc_config().proc_rank();
- rval = mbImpl->tag_set_data(part_tag, &partn_set, 1, &dum_rank);CHK_ERR(rval);
+ rval = mbImpl->tag_set_data(part_tag, &partn_set, 1, &dum_rank);
+ if (MB_SUCCESS != rval)
+ return rval;
}
#endif
- // Create NC conventional tags when loading header info only
- if (noMesh && noVars) {
- rval = myHelper->create_conventional_tags(tstep_nums);
- CHK_ERR1(rval, "Trouble creating NC conventional tags");
- }
-
mbImpl->release_interface(scdi);
scdi = NULL;
// Close the file
success = NCFUNC(close)(fileId);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble closing file");
+ ERRORS(success, "Trouble closing file.");
return MB_SUCCESS;
}
@@ -193,8 +234,10 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
noVars = true;
else
noVars = false;
+
opts.get_ints_option("TIMESTEP", tstep_nums);
opts.get_reals_option("TIMEVAL", tstep_vals);
+
rval = opts.get_null_option("NOMESH");
if (MB_SUCCESS == rval)
noMesh = true;
@@ -218,12 +261,14 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
std::cerr << var_names[i];
std::cerr << std::endl;
}
+
if (!tstep_nums.empty()) {
std::cerr << "Timesteps requested: ";
for (unsigned int i = 0; i < tstep_nums.size(); i++)
std::cerr << tstep_nums[i];
std::cerr << std::endl;
}
+
if (!tstep_vals.empty()) {
std::cerr << "Time vals requested: ";
for (unsigned int i = 0; i < tstep_vals.size(); i++)
@@ -234,11 +279,18 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
rval = opts.get_int_option("GATHER_SET", 0, gatherSetRank);
if (MB_TYPE_OUT_OF_RANGE == rval) {
- SET_ERR(rval, "Invalid value for GATHER_SET option");
+ readMeshIface->report_error("Invalid value for GATHER_SET option");
+ return rval;
+ }
+
+ rval = opts.get_int_option("TIMESTEPBASE", 0, tStepBase);
+ if (MB_TYPE_OUT_OF_RANGE == rval) {
+ readMeshIface->report_error("Invalid value for TIMESTEPBASE option");
+ return rval;
}
#ifdef USE_MPI
- isParallel = (opts.match_option("PARALLEL", "READ_PART") != MB_ENTITY_NOT_FOUND);
+ isParallel = (opts.match_option("PARALLEL","READ_PART") != MB_ENTITY_NOT_FOUND);
if (!isParallel)
// Return success here, since rval still has _NOT_FOUND from not finding option
@@ -248,8 +300,9 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
int pcomm_no = 0;
rval = opts.get_int_option("PARALLEL_COMM", pcomm_no);
- if (MB_TYPE_OUT_OF_RANGE == rval) {
- SET_ERR(rval, "Invalid value for PARALLEL_COMM option");
+ if (rval == MB_TYPE_OUT_OF_RANGE) {
+ readMeshIface->report_error("Invalid value for PARALLEL_COMM option");
+ return rval;
}
myPcomm = ParallelComm::get_pcomm(mbImpl, pcomm_no);
if (0 == myPcomm) {
@@ -260,10 +313,11 @@ ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string
int dum;
rval = opts.match_option("PARTITION_METHOD", ScdParData::PartitionMethodNames, dum);
- if (MB_FAILURE == rval) {
- SET_ERR(rval, "Unknown partition method specified");
+ if (rval == MB_FAILURE) {
+ readMeshIface->report_error("Unknown partition method specified.");
+ partMethod = ScdParData::ALLJORKORI;
}
- else if (MB_ENTITY_NOT_FOUND == rval)
+ else if (rval == MB_ENTITY_NOT_FOUND)
partMethod = ScdParData::ALLJORKORI;
else
partMethod = dum;
@@ -280,22 +334,21 @@ ErrorCode ReadNC::read_header()
int numgatts;
int success;
success = NCFUNC(inq_natts )(fileId, &numgatts);
- if (success)
- SET_ERR(MB_FAILURE, "Couldn't get number of global attributes");
+ ERRORS(success, "Couldn't get number of global attributes.");
// Read attributes into globalAtts
ErrorCode result = get_attributes(NC_GLOBAL, numgatts, globalAtts);
- CHK_ERR1(result, "Trouble getting attributes");
+ ERRORR(result, "Getting attributes.");
dbgOut.tprintf(1, "Read %u attributes\n", (unsigned int) globalAtts.size());
// Read in dimensions into dimNames and dimLens
result = get_dimensions(fileId, dimNames, dimLens);
- CHK_ERR1(result, "Trouble getting dimensions");
+ ERRORR(result, "Getting dimensions.");
dbgOut.tprintf(1, "Read %u dimensions\n", (unsigned int) dimNames.size());
// Read in variables into varInfo
result = get_variables();
- CHK_ERR1(result, "Trouble getting variables");
+ ERRORR(result, "Getting variables.");
dbgOut.tprintf(1, "Read %u variables\n", (unsigned int) varInfo.size());
return MB_SUCCESS;
@@ -308,14 +361,12 @@ ErrorCode ReadNC::get_attributes(int var_id, int num_atts, std::map<std::string,
for (int i = 0; i < num_atts; i++) {
// Get the name
int success = NCFUNC(inq_attname)(fileId, var_id, i, dum_name);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting attribute name");
+ ERRORS(success, "Trouble getting attribute name.");
AttData &data = atts[std::string(dum_name)];
data.attName = std::string(dum_name);
success = NCFUNC(inq_att)(fileId, var_id, dum_name, &data.attDataType, &data.attLen);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting attribute info");
+ ERRORS(success, "Trouble getting attribute info.");
data.attVarId = var_id;
dbgOut.tprintf(2, "%sAttribute %s: length=%u, varId=%d, type=%d\n", (prefix ? prefix : ""), data.attName.c_str(),
@@ -330,11 +381,11 @@ ErrorCode ReadNC::get_dimensions(int file_id, std::vector<std::string>& dim_name
// Get the number of dimensions
int num_dims;
int success = NCFUNC(inq_ndims)(file_id, &num_dims);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting number of dimensions");
+ ERRORS(success, "Trouble getting number of dimensions.");
if (num_dims > NC_MAX_DIMS) {
- SET_ERR_STR(MB_FAILURE, "ReadNC: File contains " << num_dims << " dims but NetCDF library supports only " << NC_MAX_DIMS);
+ readMeshIface->report_error("ReadNC: File contains %d dims but NetCDF library supports only %d\n", num_dims, (int) NC_MAX_DIMS);
+ return MB_FAILURE;
}
char dim_name[NC_MAX_NAME + 1];
@@ -344,8 +395,7 @@ ErrorCode ReadNC::get_dimensions(int file_id, std::vector<std::string>& dim_name
for (int i = 0; i < num_dims; i++) {
success = NCFUNC(inq_dim)(file_id, i, dim_name, &dim_len);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting dimension info");
+ ERRORS(success, "Trouble getting dimension info.");
dim_names[i] = std::string(dim_name);
dim_lens[i] = dim_len;
@@ -372,11 +422,11 @@ ErrorCode ReadNC::get_variables()
// Get the number of variables
int num_vars;
int success = NCFUNC(inq_nvars)(fileId, &num_vars);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting number of variables");
+ ERRORS(success, "Trouble getting number of variables.");
if (num_vars > NC_MAX_VARS) {
- SET_ERR_STR(MB_FAILURE, "ReadNC: File contains " << num_vars << " vars but NetCDF library supports only " << NC_MAX_VARS);
+ readMeshIface->report_error("ReadNC: File contains %d vars but NetCDF library supports only %d\n", num_vars, (int) NC_MAX_VARS);
+ return MB_FAILURE;
}
char var_name[NC_MAX_NAME + 1];
@@ -385,8 +435,7 @@ ErrorCode ReadNC::get_variables()
for (int i = 0; i < num_vars; i++) {
// Get the name first, so we can allocate a map iterate for this var
success = NCFUNC(inq_varname )(fileId, i, var_name);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting var name");
+ ERRORS(success, "Trouble getting var name.");
VarData &data = varInfo[std::string(var_name)];
data.varName = std::string(var_name);
data.varId = i;
@@ -394,30 +443,26 @@ ErrorCode ReadNC::get_variables()
// Get the data type
success = NCFUNC(inq_vartype)(fileId, i, &data.varDataType);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting variable data type");
+ ERRORS(success, "Trouble getting variable data type.");
// Get the number of dimensions, then the dimensions
success = NCFUNC(inq_varndims)(fileId, i, &var_ndims);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting number of dims of a variable");
+ ERRORS(success, "Trouble getting number of dims of a variable.");
data.varDims.resize(var_ndims);
success = NCFUNC(inq_vardimid)(fileId, i, &data.varDims[0]);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting variable dimensions");
+ ERRORS(success, "Trouble getting variable dimensions.");
// Finally, get the number of attributes, then the attributes
success = NCFUNC(inq_varnatts)(fileId, i, &data.numAtts);
- if (success)
- SET_ERR(MB_FAILURE, "Trouble getting number of dims of a variable");
+ ERRORS(success, "Trouble getting number of dims of a variable.");
// Print debug info here so attribute info comes afterwards
dbgOut.tprintf(2, "Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.varName.c_str(), data.varId, data.numAtts,
data.varDataType, (unsigned int) data.varDims.size());
ErrorCode rval = get_attributes(i, data.numAtts, data.varAtts, " ");
- CHK_ERR1(rval, "Trouble getting attributes for a variable");
+ ERRORR(rval, "Trouble getting attributes for a variable.");
}
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