将 java 数组传递到 netcdf 文件中
我的程序读取 ascii 文件并将数据保存到四维 NetCDF 文件中。这是使用气候数据中心规范创建 netcdf 维度、变量和变量属性的代码:
String filename = filename(date);
NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew((filename + ".nc"), true);
//Define Dimensions
Dimension latDim = ncfile.addDimension("lat", 51);
Dimension longDim = ncfile.addDimension("long", 101);
Dimension satDim = ncfile.addDimension("sat", 33);
Dimension timeDim = ncfile.addDimension("time", 96);
//Define latitude variable and attributes
ncfile.addVariable("lat", DataType.INT, "lat");
ncfile.addVariableAttribute("lat", new Attribute("units", "degrees_north"));
ncfile.addVariableAttribute("lat", new Attribute("long_name", "Latitude"));
Array data = Array.factory( int.class, new int [] {2}, new int[] {10,60});
ncfile.addVariableAttribute("lat", new Attribute("actual_range", data));
//Define longitude variable and attributes
ncfile.addVariable("long", DataType.INT, "long");
ncfile.addVariableAttribute("long", new Attribute("units", "degrees_west"));
ncfile.addVariableAttribute("long", new Attribute("long_name", "Longitude"));
data = Array.factory( int.class, new int [] {2}, new int[] {50,150});
ncfile.addVariableAttribute("long", new Attribute("actual_range", data));
//Define time variable and attributes
ncfile.addVariable("time", DataType.INT, "time");
ncfile.addVariableAttribute("time", new Attribute("units", ("minuets since " + dateTool.string(date) + " 00:00UT")));
ncfile.addVariableAttribute("time", new Attribute("long_name", "Time"));
ncfile.addVariableAttribute("time", new Attribute("delta_t", "00:15:00"));
//Define satellite variable and attributes
ncfile.addVariable("sat", DataType.INT, "sat");
ncfile.addVariableAttribute("sat", new Attribute("units", "NAVSTAR GPS Satellite #"));
ncfile.addVariableAttribute("sat", new Attribute("long_name", "Satellite"));
ncfile.addVariableAttribute("sat", new Attribute("vertical_TEC", "Satellite #0"));
//Define TEC variable and attributes
ArrayList<Dimension> dims = new ArrayList<Dimension>();
dims.add(timeDim);
dims.add(latDim);
dims.add(longDim);
dims.add(satDim);
ncfile.addVariable("TEC", DataType.FLOAT, dims);
ncfile.addVariableAttribute("TEC", new Attribute("precision", 1));
ncfile.addVariableAttribute("TEC", new Attribute("least_significant_digit", 10));
ncfile.addVariableAttribute("TEC", new Attribute("units", "TECU (10^16 electrons/m^2)"));
//Define global attributes
ncfile.addGlobalAttribute("creation_date", dateTool.string(date));
ncfile.setFill(true);
try {
ncfile.create();
} catch (IOException e) {
System.out.println("ERROR creating file "+ncfile.getLocation()+"\n"+e);
}
ncfile.close();
现在我的问题是...如何在名为“TEC”的四维变量中的特定点插入三维数组“?它应该是直截了当的,但我已经浏览了 java netcdf 教程,但我似乎找不到示例。如果有人能指出我正确的方向,那就太好了。谢谢! -Dom
P.S.以下是由此代码创建的模板 .nc 文件: http://dl .dropbox.com/u/8058705/USTEC_netcdf/netcdf/2011_08_31.nc另外...我尝试使用 ncfile.write("var_name",array) 但我认为 netcdf 4 甚至不再使用 write 函数。 writeCDL 函数使用 OutputStreams,所以我会尝试一下。
My program reads ascii files and saves the data into a four dimensional NetCDF file. This is the code that creates the netcdf dimensions, variables, and variable attributes using the Climate Data Center specifications:
String filename = filename(date);
NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew((filename + ".nc"), true);
//Define Dimensions
Dimension latDim = ncfile.addDimension("lat", 51);
Dimension longDim = ncfile.addDimension("long", 101);
Dimension satDim = ncfile.addDimension("sat", 33);
Dimension timeDim = ncfile.addDimension("time", 96);
//Define latitude variable and attributes
ncfile.addVariable("lat", DataType.INT, "lat");
ncfile.addVariableAttribute("lat", new Attribute("units", "degrees_north"));
ncfile.addVariableAttribute("lat", new Attribute("long_name", "Latitude"));
Array data = Array.factory( int.class, new int [] {2}, new int[] {10,60});
ncfile.addVariableAttribute("lat", new Attribute("actual_range", data));
//Define longitude variable and attributes
ncfile.addVariable("long", DataType.INT, "long");
ncfile.addVariableAttribute("long", new Attribute("units", "degrees_west"));
ncfile.addVariableAttribute("long", new Attribute("long_name", "Longitude"));
data = Array.factory( int.class, new int [] {2}, new int[] {50,150});
ncfile.addVariableAttribute("long", new Attribute("actual_range", data));
//Define time variable and attributes
ncfile.addVariable("time", DataType.INT, "time");
ncfile.addVariableAttribute("time", new Attribute("units", ("minuets since " + dateTool.string(date) + " 00:00UT")));
ncfile.addVariableAttribute("time", new Attribute("long_name", "Time"));
ncfile.addVariableAttribute("time", new Attribute("delta_t", "00:15:00"));
//Define satellite variable and attributes
ncfile.addVariable("sat", DataType.INT, "sat");
ncfile.addVariableAttribute("sat", new Attribute("units", "NAVSTAR GPS Satellite #"));
ncfile.addVariableAttribute("sat", new Attribute("long_name", "Satellite"));
ncfile.addVariableAttribute("sat", new Attribute("vertical_TEC", "Satellite #0"));
//Define TEC variable and attributes
ArrayList<Dimension> dims = new ArrayList<Dimension>();
dims.add(timeDim);
dims.add(latDim);
dims.add(longDim);
dims.add(satDim);
ncfile.addVariable("TEC", DataType.FLOAT, dims);
ncfile.addVariableAttribute("TEC", new Attribute("precision", 1));
ncfile.addVariableAttribute("TEC", new Attribute("least_significant_digit", 10));
ncfile.addVariableAttribute("TEC", new Attribute("units", "TECU (10^16 electrons/m^2)"));
//Define global attributes
ncfile.addGlobalAttribute("creation_date", dateTool.string(date));
ncfile.setFill(true);
try {
ncfile.create();
} catch (IOException e) {
System.out.println("ERROR creating file "+ncfile.getLocation()+"\n"+e);
}
ncfile.close();
Now my question is...How do I go about inserting a three dimensional array at specific points in the four dimensional variable named "TEC"? It should be strait forward but I've looked through the java netcdf tutorial and I can't seem to find an example. If someone could point me in the right direction that would be fantastic. Thanks! -Dom
P.S. Here is a template .nc file created by this code: http://dl.dropbox.com/u/8058705/USTEC_netcdf/netcdf/2011_08_31.nc Also...I tried using ncfile.write("var_name",array) but I don't think netcdf 4 even uses the write function anymore. The writeCDL function uses OutputStreams so I'll give that a try.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论