NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: problems while writing Structure


=?Windows-1251?B?0eXw4+Xp?= <serg@xxxxxxxx> 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:serg@xxxxxxxx


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.


  • 2005 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: