[MOAB-dev] commit/MOAB: danwu: For HOMME and MPAS, we can read float type data as double type (we have already done so for GRCM), since netcdf/pnetcdf is able to do the conversion automatically when reading. Then there is no need to call convert_variable() for float to double type conversion.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Jun 13 14:16:11 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/1402bef9bdfd/
Changeset: 1402bef9bdfd
Branch: master
User: danwu
Date: 2014-06-13 21:15:19
Summary: For HOMME and MPAS, we can read float type data as double type (we have already done so for GRCM), since netcdf/pnetcdf is able to do the conversion automatically when reading. Then there is no need to call convert_variable() for float to double type conversion.
Affected #: 2 files
diff --git a/src/io/NCHelperHOMME.cpp b/src/io/NCHelperHOMME.cpp
index 4aade2f..73f09c8 100644
--- a/src/io/NCHelperHOMME.cpp
+++ b/src/io/NCHelperHOMME.cpp
@@ -678,8 +678,14 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
ERRORR(MB_FAILURE, "not implemented");
break;
}
+ case NC_SHORT:
+ case NC_INT: {
+ ERRORR(MB_FAILURE, "not implemented");
+ break;
+ }
+ case NC_FLOAT:
case NC_DOUBLE: {
- // Copied from float case
+ // Read float as double
std::vector<double> tmpdoubledata(sz);
// In the case of ucd mesh, and on multiple proc,
@@ -691,14 +697,14 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
size_t ic = 0;
for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
pair_iter != localGidVerts.pair_end();
- pair_iter++, ic++) {
+ ++pair_iter, ic++) {
EntityHandle starth = pair_iter->first;
- EntityHandle endh = pair_iter->second; // inclusive
+ EntityHandle endh = pair_iter->second; // Inclusive
vdatas[i].readStarts[2] = (NCDF_SIZE) (starth - 1);
vdatas[i].readCounts[2] = (NCDF_SIZE) (endh - starth + 1);
// Do a partial read, in each subrange
- // wait outside this loop
+ // Wait outside this loop
success = NCFUNCREQG(_vara_double)(_fileId, vdatas[i].varId,
&(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
&(tmpdoubledata[indexInDoubleArray]), &requests[idxReq++]);
@@ -722,57 +728,6 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
ERRORS(success, "Failed to read double data.");
break;
}
- case NC_FLOAT: {
- std::vector<float> tmpfloatdata(sz);
-
- // In the case of ucd mesh, and on multiple proc,
- // we need to read as many times as subranges we have in the
- // localGidVerts range;
- // basically, we have to give a different point
- // for data to start, for every subrange :(
- size_t indexInFloatArray = 0;
- size_t ic = 0;
- for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
- pair_iter != localGidVerts.pair_end();
- pair_iter++, ic++) {
- EntityHandle starth = pair_iter->first;
- EntityHandle endh = pair_iter->second; // inclusive
- vdatas[i].readStarts[2] = (NCDF_SIZE) (starth - 1);
- vdatas[i].readCounts[2] = (NCDF_SIZE) (endh - starth + 1);
-
- // Do a partial read, in each subrange
- // wait outside this loop
- success = NCFUNCREQG(_vara_float)(_fileId, vdatas[i].varId,
- &(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
- &(tmpfloatdata[indexInFloatArray]), &requests[idxReq++]);
- ERRORS(success, "Failed to read float data in loop");
- // We need to increment the index in float array for the
- // next subrange
- indexInFloatArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
- }
- assert(ic == localGidVerts.psize());
-
- success = ncmpi_wait_all(_fileId, requests.size(), &requests[0], &statuss[0]);
- ERRORS(success, "Failed on wait_all.");
-
- if (vdatas[i].numLev != 1)
- // Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
- else {
- for (std::size_t idx = 0; idx != tmpfloatdata.size(); idx++)
- ((float*) data)[idx] = tmpfloatdata[idx];
- }
- ERRORS(success, "Failed to read float data.");
- break;
- }
- case NC_INT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_SHORT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
default:
success = 1;
}
@@ -782,15 +737,6 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset_async(std::vector<ReadNC::
}
}
- for (unsigned int i = 0; i < vdatas.size(); i++) {
- for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- ErrorCode tmp_rval = convert_variable(vdatas[i], t);
- if (MB_SUCCESS != tmp_rval)
- rval = tmp_rval;
- }
- }
-
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
@@ -833,8 +779,14 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
ERRORR(MB_FAILURE, "not implemented");
break;
}
+ case NC_SHORT:
+ case NC_INT: {
+ ERRORR(MB_FAILURE, "not implemented");
+ break;
+ }
+ case NC_FLOAT:
case NC_DOUBLE: {
- // Copied from float case
+ // Read float as double
std::vector<double> tmpdoubledata(sz);
// In the case of ucd mesh, and on multiple proc,
@@ -846,7 +798,7 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
size_t ic = 0;
for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
pair_iter != localGidVerts.pair_end();
- pair_iter++, ic++) {
+ ++pair_iter, ic++) {
EntityHandle starth = pair_iter->first;
EntityHandle endh = pair_iter->second; // Inclusive
vdatas[i].readStarts[2] = (NCDF_SIZE) (starth - 1);
@@ -872,52 +824,6 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
ERRORS(success, "Failed to read double data.");
break;
}
- case NC_FLOAT: {
- std::vector<float> tmpfloatdata(sz);
-
- // In the case of ucd mesh, and on multiple proc,
- // we need to read as many times as subranges we have in the
- // localGidVerts range;
- // basically, we have to give a different point
- // for data to start, for every subrange :(
- size_t indexInFloatArray = 0;
- size_t ic = 0;
- for (Range::pair_iterator pair_iter = localGidVerts.pair_begin();
- pair_iter != localGidVerts.pair_end();
- pair_iter++, ic++) {
- EntityHandle starth = pair_iter->first;
- EntityHandle endh = pair_iter->second; // Inclusive
- vdatas[i].readStarts[2] = (NCDF_SIZE) (starth - 1);
- vdatas[i].readCounts[2] = (NCDF_SIZE) (endh - starth + 1);
-
- success = NCFUNCAG(_vara_float)(_fileId, vdatas[i].varId,
- &(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
- &(tmpfloatdata[indexInFloatArray]));
- ERRORS(success, "Failed to read float data in loop");
- // We need to increment the index in float array for the
- // next subrange
- indexInFloatArray += (endh - starth + 1) * 1 * vdatas[i].numLev;
- }
- assert(ic == localGidVerts.psize());
-
- if (vdatas[i].numLev != 1)
- // Transpose (lev, ncol) to (ncol, lev)
- success = kji_to_jik_stride(ni, nj, nk, data, &tmpfloatdata[0], localGidVerts);
- else {
- for (std::size_t idx = 0; idx != tmpfloatdata.size(); idx++)
- ((float*) data)[idx] = tmpfloatdata[idx];
- }
- ERRORS(success, "Failed to read float data.");
- break;
- }
- case NC_INT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_SHORT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
default:
success = 1;
}
@@ -927,14 +833,6 @@ ErrorCode NCHelperHOMME::read_ucd_variables_to_nonset(std::vector<ReadNC::VarDat
}
}
- for (unsigned int i = 0; i < vdatas.size(); i++) {
- for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- ErrorCode tmp_rval = convert_variable(vdatas[i], t);
- if (MB_SUCCESS != tmp_rval)
- rval = tmp_rval;
- }
- }
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
diff --git a/src/io/NCHelperMPAS.cpp b/src/io/NCHelperMPAS.cpp
index ace33a2..0e51a89 100644
--- a/src/io/NCHelperMPAS.cpp
+++ b/src/io/NCHelperMPAS.cpp
@@ -705,7 +705,14 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
ERRORR(MB_FAILURE, "not implemented");
break;
}
+ case NC_SHORT:
+ case NC_INT: {
+ ERRORR(MB_FAILURE, "not implemented");
+ break;
+ }
+ case NC_FLOAT:
case NC_DOUBLE: {
+ // Read float as double
std::vector<double> tmpdoubledata(sz);
// In the case of ucd mesh, and on multiple proc,
@@ -713,19 +720,18 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
// localGid range;
// basically, we have to give a different point
// for data to start, for every subrange :(
-
size_t indexInDoubleArray = 0;
size_t ic = 0;
for (Range::pair_iterator pair_iter = pLocalGid->pair_begin();
pair_iter != pLocalGid->pair_end();
- pair_iter++, ic++) {
+ ++pair_iter, ic++) {
EntityHandle starth = pair_iter->first;
- EntityHandle endh = pair_iter->second; // inclusive
+ EntityHandle endh = pair_iter->second; // Inclusive
vdatas[i].readStarts[1] = (NCDF_SIZE) (starth - 1);
vdatas[i].readCounts[1] = (NCDF_SIZE) (endh - starth + 1);
// Do a partial read, in each subrange
- // wait outside this loop
+ // Wait outside this loop
success = NCFUNCREQG(_vara_double)(_fileId, vdatas[i].varId,
&(vdatas[i].readStarts[0]), &(vdatas[i].readCounts[0]),
&(tmpdoubledata[indexInDoubleArray]), &requests[idxReq++]);
@@ -768,18 +774,6 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
break;
}
- case NC_FLOAT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_INT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_SHORT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
default:
success = 1;
}
@@ -789,17 +783,6 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async(std::vector<ReadNC::V
}
}
- for (unsigned int i = 0; i < vdatas.size(); i++) {
- if (noEdges && vdatas[i].entLoc == ReadNC::ENTLOCEDGE)
- continue;
-
- for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- ErrorCode tmp_rval = convert_variable(vdatas[i], t);
- if (MB_SUCCESS != tmp_rval)
- rval = tmp_rval;
- }
- }
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
@@ -856,7 +839,14 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
ERRORR(MB_FAILURE, "not implemented");
break;
}
+ case NC_SHORT:
+ case NC_INT: {
+ ERRORR(MB_FAILURE, "not implemented");
+ break;
+ }
+ case NC_FLOAT:
case NC_DOUBLE: {
+ // Read float as double
std::vector<double> tmpdoubledata(sz);
// In the case of ucd mesh, and on multiple proc,
@@ -868,7 +858,7 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
size_t ic = 0;
for (Range::pair_iterator pair_iter = pLocalGid->pair_begin();
pair_iter != pLocalGid->pair_end();
- pair_iter++, ic++) {
+ ++pair_iter, ic++) {
EntityHandle starth = pair_iter->first;
EntityHandle endh = pair_iter->second; // Inclusive
vdatas[i].readStarts[1] = (NCDF_SIZE) (starth - 1);
@@ -913,18 +903,6 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
break;
}
- case NC_FLOAT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_INT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
- case NC_SHORT: {
- ERRORR(MB_FAILURE, "not implemented");
- break;
- }
default:
success = 1;
}
@@ -934,18 +912,6 @@ ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset(std::vector<ReadNC::VarData
}
}
- for (unsigned int i = 0; i < vdatas.size(); i++) {
- if (noEdges && vdatas[i].entLoc == ReadNC::ENTLOCEDGE)
- continue;
-
- for (unsigned int t = 0; t < tstep_nums.size(); t++) {
- dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- ErrorCode tmp_rval = convert_variable(vdatas[i], t);
- if (MB_SUCCESS != tmp_rval)
- rval = tmp_rval;
- }
- }
-
// Debug output, if requested
if (1 == dbgOut.get_verbosity()) {
dbgOut.printf(1, "Read variables: %s", vdatas.begin()->varName.c_str());
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