Hi Jin, first, make sure you have the latest Netcdf-JAVA library and your directory "data" is already created. Then, I think you are trying to set the root group for the file and you don't need to do that. You just need: writer.addGroupAttribute(null, new Attribute("lat", 100)); so, when you want to get the root group of a file you can either look for a null group: Group root1 = file.findGroup(null); or an empty String: Group root1 = file.findGroup(""); And for getting the global attributes you can also use: file.getGlobalAttributes(); If this is the case your code could be: NetcdfFileWriter writer = NetcdfFileWriter.createNew(Version.netcdf4, "data/foo.nc"); writer.addGroupAttribute(null, new Attribute("lat", 100)); writer.create(); writer.flush(); writer.close(); NetcdfFile file = NetcdfFile.open("data/foo.nc"); List<Attribute> attr = file.getGlobalAttributes(); However, if you want to add a group to the root group, I'd suggest not calling it "root" (it's pretty confusing) and then your code could be something like this: NetcdfFileWriter writer = NetcdfFileWriter.createNew(Version.netcdf4, "data/foo.nc"); Group root = writer.addGroup(null, ""); //Gets the root group Group newGroup = writer.addGroup(root, "new_group");//Adds a new group to the root group writer.addGroupAttribute(newGroup, new Attribute("lat", 100)); writer.create(); writer.flush(); writer.close(); NetcdfFile file = NetcdfFile.open("data/foo.nc"); newGroup = file.findGroup("new_group"); List<Attribute> attr = newGroup.getAttributes(); Cheers! Marcos Hermida. Ticket Details =================== Ticket ID: SXF-400193 Department: Support netCDF Java Priority: Normal Status: Open
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.