Here you can find the source of convertDoubleValuesFromNetcdf(double[] netcdfData, double missingValue, double scaleFactor, double offSet)
Parameter | Description |
---|---|
netcdfData | a parameter |
missingValue | a parameter |
scaleFactor | a parameter |
offSet | a parameter |
private static void convertDoubleValuesFromNetcdf(double[] netcdfData, double missingValue, double scaleFactor, double offSet)
//package com.java2s; /* MOD_V2.0/*from www .ja va 2 s . c o m*/ * Copyright (c) 2012 OpenDA Association * All rights reserved. * * This file is part of OpenDA. * * OpenDA is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * OpenDA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenDA. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts the raw values from a netcdf file to the real values using the given * missingValue, scaleFactor and offset. * * @param netcdfData * @param missingValue * @param scaleFactor * @param offSet */ private static void convertDoubleValuesFromNetcdf(double[] netcdfData, double missingValue, double scaleFactor, double offSet) { //according to the CF-convention: //see http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.6/cf-conventions.html#missing-data //"Applications that process variables that have attributes to indicate both a transformation (via a scale and/or offset) //and missing values should first check that a data value is valid, and then apply the transformation." //see http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.6/cf-conventions.html#packed-data //"After the data values of a variable have been read, they are to be multiplied by the scale_factor, //and have add_offset added to them. If both attributes are present, the data are scaled before the offset is added." //apply scale factor and offset and replace missing values with Double.NaN. if (scaleFactor == 1d && offSet == 0d) { //in this case no need to apply the scaleFactor and offset. if (!Double.isNaN(missingValue)) { for (int i = 0; i < netcdfData.length; i++) { if (Double.compare(netcdfData[i], missingValue) == 0) { netcdfData[i] = Double.NaN; } } } else {//if missingValue is Double.NaN, then missing values in netcdfData array are already equal to Double.NaN. //do nothing. } } else { for (int i = 0; i < netcdfData.length; i++) { if (Double.compare(netcdfData[i], missingValue) == 0) { netcdfData[i] = Double.NaN; } else { netcdfData[i] = netcdfData[i] * scaleFactor + offSet; } } } } }