当前位置: 首页>>代码示例>>Java>>正文


Java Variable.getShortName方法代码示例

本文整理汇总了Java中ucar.nc2.Variable.getShortName方法的典型用法代码示例。如果您正苦于以下问题:Java Variable.getShortName方法的具体用法?Java Variable.getShortName怎么用?Java Variable.getShortName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ucar.nc2.Variable的用法示例。


在下文中一共展示了Variable.getShortName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: finish

import ucar.nc2.Variable; //导入方法依赖的package包/类
public void finish() {

		// Here the intelligence to go back to the right waterlevel (from the fictive one) is needed, before writing the states
		for (Variable variable : this.netcdfFile.getVariables()){
			String varName = variable.getShortName();
			if (Arrays.asList(fictiveVariables).contains(varName)) {
				ITimeInfo timeInfo = NetcdfUtils.createTimeInfo(variable, this.netcdfFile, this.timeInfoCache);
				int LastTimeIndex = timeInfo.getTimes().length;
				double[] values = getExchangeItemValues(varName);
				// This is the critical method applying the intelligence:
				values = back2RealDomain(values,LastTimeIndex);
				// Might not be the most efficient as we write a second time into the files:
				writeExchangeItemValues(varName, values);
			}
		}
		try {
			netcdfFile.close();
			if (binRestartFile != null) {
				binRestartFile.close();
			}
		} catch (IOException e){
			e.printStackTrace();
		}

	}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:26,代码来源:NetcdfD3dMapDataObject.java

示例2: readData

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Reads and returns the data from the given variable.
 *
 * @param variable
 * @return Object.
 */
public static Object readData(Variable variable) {
	double[] values;
	try {
		values = (double[]) variable.read().get1DJavaArray(double.class);
	} catch (IOException e) {
		throw new RuntimeException("Error while reading data from netcdf variable '" + variable.getShortName()
				+ "'. Message was: " + e.getMessage(), e);
	}

	//apply scale factor and offset and replace missing values with Double.NaN.
	double missingValue = getMissingValueDouble(variable);
	double scaleFactor = getScaleFactorDouble(variable);
	double offSet = getOffSetDouble(variable);
	NetcdfUtils.convertDoubleValuesFromNetcdf(values, missingValue, scaleFactor, offSet);

	return new Array(values, variable.getShape(), false);
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:24,代码来源:NetcdfUtils.java

示例3: createTimeInfo

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Creates and returns an ITimeInfo object for the given variable in the given netcdfFile.
 * If no time info available, then returns null.
 *
 * @param variable
 * @param netcdfFile
 * @param timeInfoCache
 * @return timeInfo or null.
 */
public static IArrayTimeInfo createTimeInfo(Variable variable, NetcdfFile netcdfFile,
		Map<Variable, IArrayTimeInfo> timeInfoCache) {

	Variable timeVariable = findTimeVariableForVariable(variable, netcdfFile);
	if (timeVariable == null) {//if data does not depend on time.
		return null;
	}

	//if data depends on time.
	IArrayTimeInfo timeInfo = timeInfoCache.get(timeVariable);
	if (timeInfo == null) {
		//create timeInfo.
		double[] times;
		try {
			times = readTimes(timeVariable);
		} catch (IOException e) {
			throw new RuntimeException("Error while reading data from netcdf time variable '" + timeVariable.getShortName()
					+ "'. Message was: " + e.getMessage(), e);
		}
		timeInfo = new TimeInfo(times);
		//cache timeInfo.
		timeInfoCache.put(timeVariable, timeInfo);
	}

	return timeInfo;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:36,代码来源:NetcdfUtils.java

示例4: writeSelectedData

import ucar.nc2.Variable; //导入方法依赖的package包/类
public static void writeSelectedData(NetcdfFileWriter netcdfFileWriter, Variable variable, int[] origin, int[] sizeArray, double[] values) {
	//replace NaN values with missing value for variable.
	double missingValue = getMissingValueDouble(variable);
	if (!Double.isNaN(missingValue)) {
		double[] newValues = new double[values.length];
		System.arraycopy(values, 0, newValues, 0, values.length);
		for (int n = 0; n < newValues.length; n++) {
			if (Double.isNaN(newValues[n])) {
				newValues[n] = missingValue;
			}
		}
		values = newValues;
	} else {//if missingValue is Double.NaN, then NaN values in values array are already equal to missingValue.
		//do nothing.
	}

	//prepare array for writing.
	ucar.ma2.Array array = ucar.ma2.Array.factory(DataType.DOUBLE, sizeArray, values);

	//write data.
	try {
		netcdfFileWriter.write(variable, origin, array);
	} catch (IOException | InvalidRangeException e) {
		throw new RuntimeException("Error while writing data to netcdf variable '" + variable.getShortName()
				+ "' in netcdf file " + netcdfFileWriter.getNetcdfFile().getLocation() + ". Message was: " + e.getMessage(), e);
	}
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:28,代码来源:NetcdfUtils.java

示例5: readNetcdfFile

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Read data from netcdf file.
 *
 * @throws IOException
 */
//TODO remove, always read data lazily. AK
private void readNetcdfFile() throws IOException  {
	this.exchangeItems.clear();
	NetcdfFile netcdfFile = this.netcdfFileWriter.getNetcdfFile();

	Results.putMessage(this.getClass().getSimpleName() + ": reading data from file " + this.file.getAbsolutePath());

	//in most netcdfFiles the time and spatial coordinate variables are shared between multiple data variables.
	//Therefore cache timeInfo objects so that time coordinate variables
	//are never read more than once.
	Map<Variable, IArrayTimeInfo> timeInfoCache = new HashMap<Variable, IArrayTimeInfo>();
	for (Variable variable : netcdfFile.getVariables()) {
		//do not create exchangeItems for coordinate variables.
		//the coordinate values will be stored in the metadata objects contained in the exchangeItems.
		if (variable.isCoordinateVariable()) {
			continue;
		}

		if (!variable.getDataType().isNumeric()) {
			continue;
		}

		//create exchangeItem.
		IExchangeItem exchangeItem;
		//Note: never use standard name or long name as exchangeItemId, since these are not always unique within a netcdf file.
		String exchangeItemId = variable.getShortName();
		if (variable.getDimensions().isEmpty()) {//if scalar.
			exchangeItem = new DoubleExchangeItem(exchangeItemId, Role.InOut, variable.readScalarDouble());

		} else {//if array.
			ArrayExchangeItem arrayBasedExchangeItem = new ArrayExchangeItem(exchangeItemId, IPrevExchangeItem.Role.InOut);
			arrayBasedExchangeItem.setQuantityInfo(new QuantityInfo(exchangeItemId, variable.getUnitsString()));
			IArrayTimeInfo newTimeInfo = NetcdfUtils.createTimeInfo(variable, netcdfFile, timeInfoCache);
			//skip variables that do not depend on time.
			if (newTimeInfo == null && !allowTimeIndependentItems) continue;

			arrayBasedExchangeItem.setTimeInfo(newTimeInfo);
			//TODO cache variables with spatial coordinates. AK
			arrayBasedExchangeItem.setGeometryInfo(NetcdfUtils.createGeometryInfo(variable, netcdfFile));
			arrayBasedExchangeItem.setArray((IArray) NetcdfUtils.readData(variable));
			exchangeItem = arrayBasedExchangeItem;
		}

		this.exchangeItems.add(exchangeItem);
	}
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:52,代码来源:NetcdfDataObject.java


注:本文中的ucar.nc2.Variable.getShortName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。