[MOAB-dev] commit/MOAB: danwu: Updated NCHelper::read_coordinate() to read float type as double type (automatic numeric conversions performed by netCDF, no need to use a temp vector and std::copy).

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jul 1 11:16:14 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/97d584466845/
Changeset:   97d584466845
Branch:      master
User:        danwu
Date:        2014-07-01 18:15:13
Summary:     Updated NCHelper::read_coordinate() to read float type as double type (automatic numeric conversions performed by netCDF, no need to use a temp vector and std::copy).

Affected #:  1 file

diff --git a/src/io/NCHelper.cpp b/src/io/NCHelper.cpp
index 92cad43..613ce13 100644
--- a/src/io/NCHelper.cpp
+++ b/src/io/NCHelper.cpp
@@ -566,18 +566,15 @@ ErrorCode NCHelper::read_coordinate(const char* var_name, int lmin, int lmax, st
     cvals.resize(tcount);
 
   // 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]);
-    ERRORS(success, "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]);
-    ERRORS(success, "Failed to get coordinate values.");
-    std::copy(tcvals.begin(), tcvals.end(), cvals.begin());
-  }
-  else {
-    ERRORR(MB_FAILURE, "Unexpected coordinate variable data type.");
+  switch ((*vmit).second.varDataType) {
+    case NC_FLOAT:
+    case NC_DOUBLE:
+      // Read float as double
+      success = NCFUNCAG(_vars_double)(_fileId, (*vmit).second.varId, &tstart, &tcount, &dum_stride, &cvals[0]);
+      ERRORS(success, "Failed to get coordinate values.");
+      break;
+    default:
+      ERRORR(MB_FAILURE, "Unexpected variable data type.");
   }
 
   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