public void finish() throws IOException { writeDataFinish(); ncfile.close(); }
public void testWriteStandardVar() throws Exception { NetcdfFileWriteable ncfile = new NetcdfFileWriteable(filename, false); // define dimensions Dimension latDim = ncfile.addDimension("lat", 2); Dimension lonDim = ncfile.addDimension("lon", 3); ArrayList dims = new ArrayList(); dims.add(latDim); dims.add(lonDim); // case 1 ncfile.addVariable("t1", DataType.DOUBLE, dims); ncfile.addVariableAttribute("t1", CDM.SCALE_FACTOR, new Double(2.0)); ncfile.addVariableAttribute("t1", "add_offset", new Double(77.0)); // case 2 ncfile.addVariable("t2", DataType.BYTE, dims); ncfile.addVariableAttribute("t2", CDM.SCALE_FACTOR, new Short((short) 2)); ncfile.addVariableAttribute("t2", "add_offset", new Short((short) 77)); // case 3 ncfile.addVariable("t3", DataType.BYTE, dims); ncfile.addVariableAttribute("t3", "_FillValue", new Byte((byte) 255)); // case 4 ncfile.addVariable("t4", DataType.SHORT, dims); ncfile.addVariableAttribute("t4", CDM.MISSING_VALUE, new Short((short) -9999)); // case 5 ncfile.addVariable("t5", DataType.SHORT, dims); ncfile.addVariableAttribute("t5", CDM.MISSING_VALUE, new Short((short) -9999)); ncfile.addVariableAttribute("t5", CDM.SCALE_FACTOR, new Short((short) 2)); ncfile.addVariableAttribute("t5", "add_offset", new Short((short) 77)); // case 1 ncfile.addVariable("m1", DataType.DOUBLE, dims); ncfile.addVariableAttribute("m1", CDM.MISSING_VALUE, -999.99); // create the file ncfile.create(); // write t1 ArrayDouble A = new ArrayDouble.D2(latDim.getLength(), lonDim.getLength()); int i, j; Index ima = A.getIndex(); // write for (i = 0; i < latDim.getLength(); i++) for (j = 0; j < lonDim.getLength(); j++) A.setDouble(ima.set(i, j), (double) (i * 10.0 + j)); int[] origin = new int[2]; ncfile.write("t1", origin, A); // write t2 ArrayByte Ab = new ArrayByte.D2(latDim.getLength(), lonDim.getLength()); ima = Ab.getIndex(); for (i = 0; i < latDim.getLength(); i++) for (j = 0; j < lonDim.getLength(); j++) Ab.setByte(ima.set(i, j), (byte) (i * 10 + j)); ncfile.write("t2", origin, Ab); // write t3 ncfile.write("t3", origin, Ab); // write t4 Array As = new ArrayShort.D2(latDim.getLength(), lonDim.getLength()); ima = As.getIndex(); for (i = 0; i < latDim.getLength(); i++) for (j = 0; j < lonDim.getLength(); j++) As.setShort(ima.set(i, j), (short) (i * 10 + j)); ncfile.write("t4", origin, As); As.setShort(ima.set(0, 0), (short) -9999); ncfile.write("t5", origin, As); // write m1 ArrayDouble.D2 Ad = new ArrayDouble.D2(latDim.getLength(), lonDim.getLength()); for (i = 0; i < latDim.getLength(); i++) for (j = 0; j < lonDim.getLength(); j++) Ad.setDouble(ima.set(i, j), (double) (i * 10.0 + j)); Ad.set(1, 1, -999.99); ncfile.write("m1", new int[2], Ad); // all done ncfile.close(); System.out.println("**************TestStandardVar Write done"); }