1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package au.csiro.netcdf;
18
19 import java.io.IOException;
20
21 import ucar.ma2.DataType;
22 import ucar.nc2.Dimension;
23 import ucar.nc2.NetcdfFileWriteable;
24
25 public class CreateFile
26 {
27
28 private static String dimensionName = "lat";
29 private static int dimensionSize = 20;
30 private static String variableName = "temp";
31 private static DataType variableDataType = DataType.getType("Float");
32
33 public static void main(String[] args) throws IOException
34 {
35 NetcdfFileWriteable ncFile = null;
36
37 String outputFilename = args[0];
38 ncFile = NetcdfFileWriteable.createNew(outputFilename, true);
39 try
40 {
41 Dimension dimension = new Dimension(dimensionName, dimensionSize, true
42 false
43 ncFile.addDimension(null, dimension);
44 ncFile.create();
45 }
46 finally
47 {
48 ncFile.close();
49 }
50
51
52 ncFile = NetcdfFileWriteable.openExisting(outputFilename, true);
53 try
54 {
55 ncFile.setRedefineMode(true);
56 ncFile.addVariable(dimensionName, variableDataType, dimensionName);
57 ncFile.addVariable(variableName, variableDataType, dimensionName);
58
59 ncFile.create();
60 }
61 finally
62 {
63 ncFile.close();
64 }
65 }
66
67 }