本文整理汇总了Java中ucar.nc2.Variable.read方法的典型用法代码示例。如果您正苦于以下问题:Java Variable.read方法的具体用法?Java Variable.read怎么用?Java Variable.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ucar.nc2.Variable
的用法示例。
在下文中一共展示了Variable.read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readTimes
import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
* Reads the times from the given timeVariable and converts them to MJD
* in the returned array.
*
* @param timeVariable
* @return times array.
* @throws IOException
*/
private static double[] readTimes(Variable timeVariable) throws IOException {
double[] convertedTimes = new double[0];
if ((timeVariable != null) && timeVariable.isCoordinateVariable()) {
//read times.
ucar.ma2.Array timesArray = timeVariable.read();
double[] times = (double[]) timesArray.get1DJavaArray(double.class);
//convert times.
convertedTimes = new double[times.length];
DateUnit dateUnit = getDateUnitFromDimension(timeVariable);
for (int n = 0; n < times.length; n++) {
Date date = dateUnit.makeDate(times[n]);
if (date == null) {
convertedTimes[n] = 0;
continue;
}
long time = date.getTime();
convertedTimes[n] = Time.milliesToMjd(time);
}
}
return convertedTimes;
}
示例2: getGrid
import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
* Reads a section of the data for a variable and return a memory resident Array. The Array has the same
* element type as the Variable, and the requested shape. Note that this does not do rank reduction, so
* the returned Array has the same rank as the Variable. Use Array.reduce() for rank reduction.
* <p>
* <code>assert(origin[ii] + shape[ii]*stride[ii] <= Variable.shape[ii]); </code>
* <p>
*
* @param origin int array specifying for each dimension of the variable the starting index of the
* extraction . If null, assume all zeroes.
* @param shape int array specifying the extents in each dimension. If null, assume getShape(); This
* becomes the shape of the returned Array.
* @param fullName variable, with the specified (full) name. It may possibly be nested in multiple groups
* and/or structures. eg "group/subgroup/name1.name2.name".
*
* @return a ucar.ma2.Array with data for the variable.
*
* @throws NetCdfVariableNotFoundException the net cdf variable not found exception
* @throws NetCdfVariableException the net cdf variable exception
*/
public Array getGrid(String fullName, int[] origin, int[] shape) throws NetCdfVariableException, NetCdfVariableNotFoundException {
if (LOG.isDebugEnabled()) {
LOG.debug("getGrid() - entering");
}
Variable var = null;
Array grid = null;
var = getVariable(fullName);
try {
grid = var.read(origin, shape);
} catch (Exception e) {
LOG.error("getGrid()", e);
throw new NetCdfVariableException(var, "Error in getGrid", e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("getGrid() - exiting");
}
return grid;
}
示例3: read
import ucar.nc2.Variable; //导入方法依赖的package包/类
public static Array read(Variable var, int[] origin, int[] shape, NetCdfWriter netCdfWriter) throws IOException, InvalidRangeException {
long d1 = System.nanoTime();
Array data = var.read(origin, shape);
long d2 = System.nanoTime();
if (netCdfWriter != null) {
netCdfWriter.readingTime += (d2 - d1);
}
return data;
}
示例4: fillDataInOneGulp
import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
* Fills variable data in one gulp. It reads all the variable data in memory and fills in a Array object.
*
* @param varToRead variable to be read.
* @param dataToFill array fto fill in.
* @param originToFill originToFill
* @param fillValue fillValue
* @throws MotuException
*/
protected void fillDataInOneGulp(Variable varToRead, Array dataToFill, int[] originToFill, double fillValue) throws MotuException {
Array dataRead = null;
try {
dataRead = varToRead.read();
} catch (IOException e) {
throw new MotuException(ErrorType.BAD_PARAMETERS, "Error in DatasetGridXYLatLon fillDataInOneGulp", e);
}
switch (dataRead.getRank()) {
case 1:
break;
case 2:
fillData2D(varToRead, dataRead, dataToFill, originToFill, fillValue);
break;
case 3:
break;
case 4:
break;
default:
break;
}
}