[MOAB-dev] commit/MOAB: danwu: For set variables and scd mesh non-set variables, NC reader can read float type as double type (it has already done so for ucd mesh non-set variables), or read short type as int type.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Jun 16 13:21:21 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/799a37615795/
Changeset: 799a37615795
Branch: master
User: danwu
Date: 2014-06-16 20:20:38
Summary: For set variables and scd mesh non-set variables, NC reader can read float type as double type (it has already done so for ucd mesh non-set variables), or read short type as int type.
Affected #: 1 file
diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 9e982f3..b2f99b9 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -492,25 +492,17 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
&vdatas[i].readCounts[0], (char*) data);
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);
- 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);
- ERRORS(success, "Failed to read float data.");
- break;
+ case NC_SHORT:
case NC_INT:
success = NCFUNCAG(_vara_int)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
&vdatas[i].readCounts[0], (int*) data);
ERRORS(success, "Failed to read int data.");
break;
- case NC_SHORT:
- success = NCFUNCAG(_vara_short)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
- &vdatas[i].readCounts[0], (short*) data);
- ERRORS(success, "Failed to read short data.");
+ case NC_FLOAT:
+ case NC_DOUBLE:
+ success = NCFUNCAG(_vara_double)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0],
+ &vdatas[i].readCounts[0], (double*) data);
+ ERRORS(success, "Failed to read double data.");
break;
default:
success = 1;
@@ -519,10 +511,6 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
if (success)
ERRORR(MB_FAILURE, "Trouble reading variable.");
- dbgOut.tprintf(2, "Converting variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
- rval = convert_variable(vdatas[i], t);
- ERRORR(rval, "Failed to convert variable.");
-
dbgOut.tprintf(2, "Setting data for variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t]);
rval = mbImpl->tag_set_by_ptr(vdatas[i].varTags[t], &_fileSet, 1, &data, &vdatas[i].sz);
ERRORR(rval, "Failed to set data for variable.");
@@ -533,14 +521,14 @@ ErrorCode NCHelper::read_variables_to_set(std::vector<ReadNC::VarData>& vdatas,
case NC_CHAR:
delete[] (char*) data;
break;
- case NC_DOUBLE:
- case NC_FLOAT:
- delete[] (double*) data;
- break;
- case NC_INT:
case NC_SHORT:
+ case NC_INT:
delete[] (int*) data;
break;
+ case NC_FLOAT:
+ case NC_DOUBLE:
+ delete[] (double*) data;
+ break;
default:
break;
}
@@ -705,14 +693,14 @@ ErrorCode NCHelper::get_tag_to_set(ReadNC::VarData& var_data, int tstep_num, Tag
case NC_CHAR:
rval = mbImpl->tag_get_handle(tag_name.str().c_str(), 0, MB_TYPE_OPAQUE, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
break;
- case NC_DOUBLE:
- case NC_FLOAT:
- rval = mbImpl->tag_get_handle(tag_name.str().c_str(), 0, MB_TYPE_DOUBLE, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
- break;
- case NC_INT:
case NC_SHORT:
+ case NC_INT:
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;
+ case NC_FLOAT:
+ case NC_DOUBLE:
+ rval = mbImpl->tag_get_handle(tag_name.str().c_str(), 0, MB_TYPE_DOUBLE, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
+ break;
default:
std::cerr << "Unrecognized data type for tag " << tag_name << std::endl;
rval = MB_FAILURE;
@@ -743,14 +731,14 @@ ErrorCode NCHelper::get_tag_to_nonset(ReadNC::VarData& var_data, int tstep_num,
case NC_CHAR:
rval = mbImpl->tag_get_handle(tag_name.str().c_str(), num_lev, MB_TYPE_OPAQUE, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
break;
- case NC_DOUBLE:
- case NC_FLOAT:
- rval = mbImpl->tag_get_handle(tag_name.str().c_str(), num_lev, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
- break;
- case NC_INT:
case NC_SHORT:
+ case NC_INT:
rval = mbImpl->tag_get_handle(tag_name.str().c_str(), num_lev, MB_TYPE_INTEGER, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
break;
+ case NC_FLOAT:
+ case NC_DOUBLE:
+ rval = mbImpl->tag_get_handle(tag_name.str().c_str(), num_lev, MB_TYPE_DOUBLE, tagh, MB_TAG_DENSE | MB_TAG_CREAT);
+ break;
default:
std::cerr << "Unrecognized data type for tag " << tag_name.str() << std::endl;
rval = MB_FAILURE;
@@ -781,19 +769,12 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
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);
- 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);
- ERRORS(success, "Failed to read attribute float data.");
- ssAtt << "float;";
+ case NC_SHORT:
+ sz = attIt->second.attLen * sizeof(short);
+ attData = (short *) malloc(sz);
+ success = NCFUNC(get_att_short)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (short*) attData);
+ ERRORS(success, "Failed to read attribute short data.");
+ ssAtt << "short;";
break;
case NC_INT:
sz = attIt->second.attLen * sizeof(int);
@@ -802,12 +783,19 @@ ErrorCode NCHelper::create_attrib_string(const std::map<std::string, ReadNC::Att
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);
- ERRORS(success, "Failed to read attribute short data.");
- ssAtt << "short;";
+ case NC_FLOAT:
+ sz = attIt->second.attLen * sizeof(float);
+ attData = (float *) malloc(sz);
+ success = NCFUNC(get_att_float)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (float*) attData);
+ ERRORS(success, "Failed to read attribute float data.");
+ ssAtt << "float;";
+ break;
+ case NC_DOUBLE:
+ sz = attIt->second.attLen * sizeof(double);
+ attData = (double *) malloc(sz);
+ success = NCFUNC(get_att_double)(_fileId, attIt->second.attVarId, attIt->second.attName.c_str(), (double*) attData);
+ ERRORS(success, "Failed to read attribute double data.");
+ ssAtt << "double;";
break;
default:
success = 1;
@@ -932,14 +920,14 @@ ErrorCode NCHelper::read_variables_to_set_allocate(std::vector<ReadNC::VarData>&
case NC_CHAR:
vdatas[i].varDatas[t] = new char[vdatas[i].sz];
break;
- case NC_DOUBLE:
- case NC_FLOAT:
- vdatas[i].varDatas[t] = new double[vdatas[i].sz];
- break;
- case NC_INT:
case NC_SHORT:
+ case NC_INT:
vdatas[i].varDatas[t] = new int[vdatas[i].sz];
break;
+ case NC_FLOAT:
+ case NC_DOUBLE:
+ vdatas[i].varDatas[t] = new double[vdatas[i].sz];
+ break;
default:
std::cerr << "Unrecognized data type for set variable tag values" << std::endl;
rval = MB_FAILURE;
@@ -1285,34 +1273,7 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset(std::vector<ReadNC::VarData>
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 (vdatas[i].numLev > 1)
- // Transpose (lev, lat, lon) to (lat, lon, lev)
- 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 (vdatas[i].numLev > 1)
- // Transpose (lev, lat, lon) to (lat, lon, lev)
- 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_SHORT:
case NC_INT: {
std::vector<int> tmpintdata(sz);
success = NCFUNCAG(_vara_int)(_fileId, vdatas[i].varId, &vdatas[i].readStarts[0], &vdatas[i].readCounts[0],
@@ -1327,18 +1288,19 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset(std::vector<ReadNC::VarData>
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]);
+ case NC_FLOAT:
+ 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 (vdatas[i].numLev > 1)
// Transpose (lev, lat, lon) to (lat, lon, lev)
- success = kji_to_jik(ni, nj, nk, data, &tmpshortdata[0]);
+ success = kji_to_jik(ni, nj, nk, data, &tmpdoubledata[0]);
else {
- for (std::size_t idx = 0; idx != tmpshortdata.size(); idx++)
- ((short*) data)[idx] = tmpshortdata[idx];
+ for (std::size_t idx = 0; idx != tmpdoubledata.size(); idx++)
+ ((double*) data)[idx] = tmpdoubledata[idx];
}
- ERRORS(success, "Failed to read short data.");
+ ERRORS(success, "Failed to read double data.");
break;
}
default:
@@ -1350,15 +1312,6 @@ ErrorCode ScdNCHelper::read_scd_variables_to_nonset(std::vector<ReadNC::VarData>
}
}
- 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());
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