Skip to content
Permalink
Browse files

make sure that fillvalues keep bit representation when changing

datatype, e.g. float to int
(cherry picked from commit dd7ba15)
  • Loading branch information...
heikoklein authored and alexander-buerger-met-no committed Sep 12, 2016
1 parent bdfb7a0 commit 8021533f06d4a23d01d189835d869889657e98c4
Showing with 13 additions and 11 deletions.
  1. +4 −2 include/fimex/CDMInterpolator.h
  2. +5 −6 src/CDMInterpolator.cc
  3. +4 −3 src/CDMProcessor.cc
@@ -281,14 +281,16 @@ class CDMInterpolator : public MetNoFimex::CDMReader
* @return
*/
extern boost::shared_array<float> data2InterpolationArray(const DataPtr& inData, double badValue);

/**
* convert the data inplace from an interpolation-array (with badValue) to one used within data
* convert the data from an interpolation-array (with NaNs) to one used as DataPtr, e.g. correct datatype and badvalue/fillvalue
* @param newType
* @param iData
* @param size
* @param badValue
* @return
*/
extern DataPtr interpolationArray2Data(boost::shared_array<float> iData, size_t size, double badValue);
extern DataPtr interpolationArray2Data(CDMDataType newType, boost::shared_array<float> iData, size_t size, double badValue);


}
@@ -114,10 +114,9 @@ boost::shared_array<float> data2InterpolationArray(const DataPtr& inData, double
return array;
}

// for performance reasons, the iData-reference will be modified and used within the return data
DataPtr interpolationArray2Data(boost::shared_array<float> iData, size_t size, double badValue) {
mifi_nanf2bad(&iData[0], &iData[size], badValue);
return createData(size, iData);
DataPtr interpolationArray2Data(CDMDataType newType, boost::shared_array<float> iData, size_t size, double badValue) {
DataPtr d = createData(size, iData);
return d->convertDataType(MIFI_UNDEFINED_F, 1., 0., newType, badValue, 1., 0.);
}
/**
*
@@ -213,7 +212,7 @@ DataPtr CDMInterpolator::getDataSlice(const std::string& varName, const SliceBui
}
}
processArray_(p_->postprocesses, iArray.get(), newSize, ci->getOutX(), ci->getOutY());
DataPtr outData = interpolationArray2Data(iArray, newSize, badValue);
DataPtr outData = interpolationArray2Data(variable.getDataType(), iArray, newSize, badValue);
// slice the x and y direction of the data
vector<size_t> maxDims = sb.getMaxDimensionSizes();
vector<size_t> startPos = sb.getDimensionStartPositions();
@@ -277,7 +276,7 @@ DataPtr CDMInterpolator::getDataSlice(const std::string& varName, size_t unLimDi
}
}
processArray_(p_->postprocesses, iArray.get(), newSize, ci->getOutX(), ci->getOutY());
return interpolationArray2Data(iArray, newSize, badValue);
return interpolationArray2Data(variable.getDataType(), iArray, newSize, badValue);
}
}

@@ -626,10 +626,11 @@ DataPtr CDMProcessor::getDataSlice(const std::string& varName, size_t unLimDimPo
throw CDMException("xData != yData in vectorInterpolation");
}
cvr->reprojectValues(xArray, yArray, xData->size());
CDMDataType type = getCDM().getVariable(varName).getDataType();
if (xIsFirst) {
data = interpolationArray2Data(xArray, xData->size(), getCDM().getFillValue(xVar));
data = interpolationArray2Data(type, xArray, xData->size(), getCDM().getFillValue(xVar));
} else {
data = interpolationArray2Data(yArray, yData->size(), getCDM().getFillValue(yVar));
data = interpolationArray2Data(type, yArray, yData->size(), getCDM().getFillValue(yVar));
}
}
if (p_->rotateLatLonDirection.find(varName) != p_->rotateLatLonDirection.end()) {
@@ -647,7 +648,7 @@ DataPtr CDMProcessor::getDataSlice(const std::string& varName, size_t unLimDimPo
transform(&array[0], &array[0]+ data->size(), &array[0], ScaleOffset<float>(scaleFactor, addOffset));
cvr->reprojectDirectionValues(array, data->size());
transform(&array[0], &array[0]+ data->size(), &array[0], UnScaleOffset<float>(scaleFactor, addOffset));
data = interpolationArray2Data(array, data->size(), getCDM().getFillValue(varName));
data = interpolationArray2Data(getCDM().getVariable(varName).getDataType(), array, data->size(), getCDM().getFillValue(varName));
}
return data;
}

0 comments on commit 8021533

Please sign in to comment.
You can’t perform that action at this time.