public void testAggCoordVar2(NetcdfFile ncfile) { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.INT; assert time.getDimension(0) == ncfile.findDimension("time"); try { Array data = time.read(); assert (data instanceof ArrayInt); IndexIterator dataI = data.getIndexIterator(); assert dataI.getIntNext() == 0 : dataI.getIntCurrent(); assert dataI.getIntNext() == 1 : dataI.getIntCurrent(); assert dataI.getIntNext() == 2 : dataI.getIntCurrent(); } catch (IOException io) { io.printStackTrace(); assert false; } }
public void testAggCoordVar(NetcdfFile ncfile) { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.INT; assert time.getDimension(0) == ncfile.findDimension("time"); try { Array data = time.read(); assert (data instanceof ArrayInt.D1) : data.getClass().getName(); ArrayInt.D1 dataI = (ArrayInt.D1) data; assert dataI.get(0) == 0; assert dataI.get(1) == 10; assert dataI.get(2) == 99; } catch (IOException io) { io.printStackTrace(); assert false; } }
public void testAggCoordVarScan(NetcdfFile ncfile) throws IOException { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.INT : time.getDataType(); assert time.getDimension(0) == ncfile.findDimension("time"); int count = 0; Array data = time.read(); assert (data instanceof ArrayInt); while (data.hasNext()) { int val = data.nextInt(); assert val == count * 10 : val + "!=" + count * 10; count++; } }
public void testAggCoordVar3(NetcdfFile ncfile) throws IOException { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.DOUBLE : time.getDataType(); assert time.getDimension(0) == ncfile.findDimension("time"); Array data = time.read(); assert (data instanceof ArrayDouble); IndexIterator dataI = data.getIndexIterator(); double val = dataI.getDoubleNext(); assert Misc.closeEnough(val, 0.0) : val; assert Misc.closeEnough(dataI.getDoubleNext(), 10.0) : dataI.getDoubleCurrent(); assert Misc.closeEnough(dataI.getDoubleNext(), 99.0) : dataI.getDoubleCurrent(); }
public void testAggCoordVarNoCoordsDir(NetcdfFile ncfile) throws IOException { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.STRING : time.getDataType(); assert time.getDimension(0) == ncfile.findDimension("time"); Array data = time.read(); assert (data instanceof ArrayObject); IndexIterator dataI = data.getIndexIterator(); String coordName = (String) dataI.getObjectNext(); assert coordName.equals("time0Dir.nc") : coordName; coordName = (String) dataI.getObjectNext(); assert coordName.equals("time1Dir.nc") : coordName; coordName = (String) dataI.getObjectNext(); assert coordName.equals("time2Dir.nc") : coordName; }
private int[] getWeights(Variable v) { int rank = v.getRank(); int[] w = new int[rank]; for (int n = 0; n < rank; n++) { Dimension dim = v.getDimension(n); String dimName = dim.getName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
public void testReadData(NetcdfFile ncfile, String name) throws IOException { Variable v = ncfile.findVariable(name); assert null != v; assert v.getShortName().equals(name); assert v.getRank() == 3; assert v.getSize() == 36 : v.getSize(); assert v.getShape()[0] == 3; assert v.getShape()[1] == 3; assert v.getShape()[2] == 4; assert v.getDataType() == DataType.DOUBLE; assert !v.isCoordinateVariable(); assert v.getDimension(0) == ncfile.findDimension("time"); assert v.getDimension(1) == ncfile.findDimension("lat"); assert v.getDimension(2) == ncfile.findDimension("lon"); Array data = v.read(); assert data.getRank() == 3; assert data.getSize() == 36; assert data.getShape()[0] == 3; assert data.getShape()[1] == 3; assert data.getShape()[2] == 4; assert data.getElementType() == double.class; int[] shape = data.getShape(); Index tIndex = data.getIndex(); for (int i = 0; i < shape[0]; i++) for (int j = 0; j < shape[1]; j++) for (int k = 0; k < shape[2]; k++) { double val = data.getDouble(tIndex.set(i, j, k)); // System.out.println(" "+val); assert TestUtils.close(val, 100 * i + 10 * j + k) : val; } }
public void testCoordVar(NetcdfFile ncfile) { Variable lat = ncfile.findVariable("lat"); assert null != lat; assert lat.getShortName().equals("lat"); assert lat.getRank() == 1; assert lat.getSize() == 3; assert lat.getShape()[0] == 3; assert lat.getDataType() == DataType.FLOAT; assert !lat.isUnlimited(); assert lat.getDimension(0).equals(ncfile.findDimension("lat")); Attribute att = lat.findAttribute("units"); assert null != att; assert !att.isArray(); assert att.isString(); assert att.getDataType() == DataType.STRING; assert att.getStringValue().equals("degrees_north"); assert att.getNumericValue() == null; assert att.getNumericValue(3) == null; try { Array data = lat.read(); assert data.getRank() == 1; assert data.getSize() == 3; assert data.getShape()[0] == 3; assert data.getElementType() == float.class; IndexIterator dataI = data.getIndexIterator(); assert TestUtils.close(dataI.getDoubleNext(), 41.0); assert TestUtils.close(dataI.getDoubleNext(), 40.0); assert TestUtils.close(dataI.getDoubleNext(), 39.0); } catch (IOException io) { } }