This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
=?Windows-1251?B?0eXw4+Xp?= <address@hidden> writes:Hello, Ed. I try to create Structure object and put in some integer data. But I have an empty Netcdf file as a result. Here is my sample code. Could you tell me where is my mistake: public static void main(String[] args) { try { NetcdfFileWriteable ncFile = new NetcdfFileWriteable("e:\\tmp\\ncstruct.nc", false); ncFile.addRecordStructure(); Structure structure = new Structure(ncFile, null, null, "structure_name"); Dimension dim = Dimension.UNLIMITED; dim.setName("dim1"); Variable var1 = new Variable(ncFile, null, structure, "var1"); ArrayList dimList = new ArrayList(); dimList.add(dim); var1.setDimensions(dimList); var1.setDataType(DataType.INT); ArrayList varList = new ArrayList(); varList.add(var1); structure.addMemberVariable(var1); ncFile.finish(); ncFile.create(); StructureMembers members = structure.makeStructureMembers(); ArrayStructureW asw = new ArrayStructureW(members, new int[]{3}); ArrayStructureW.StructureDataW sdata = asw.new StructureDataW(); ArrayInt.D0 array = new ArrayInt.D0(); array.set(1); array.set(2); array.set(3); sdata.setMemberData("var1", array); asw.setStructureData(sdata, 0); ncFile.flush(); System.out.println(ncFile.toString()); ncFile.close(); } catch (IOException e) { System.out.println(e); } } P.S. I can't find detailed information about how to write netCDF files in Java. Do you have manuals besides JavaUserGuide in PDF and Java NetCDF API? -- Best regards, Sergey mailto:address@hidden
Hi Serg:You cannot (yet) write Structures because netcdf-3 file format does not support them. When we have the Netcdf-Java library working with the new Netcdf-4 file format, you will be able to do this. Sometime later this year I expect.
Sorry the docs are so poor, they will be updated ASAP, but for now the JavaUserGuide is all there is. theres some examples in the appendix.
John.