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.
Hi all, I¹ve successfully created an empty NetcdfFile but I¹m having some difficulty writing data to the file. Just for a bit of context, I¹m trying to write data from a list of particles each of which has an id, lat, lon and concentration to the nc file one timestep at a time. In other words, I have a loop where a new list of particles is generated each cycle. After they are generated, they need to be written to the nc file as a ³new² timestep. Basically, I¹d like to have a method that accepts the list of particles (which contain lat, lon, conc) and a time and simply write a new time record with all of the particles in the list. Is that possible?? I¹m completely lost as to how I can do this efficiently. All of the examples I can find show writing all of the variables for all times at once which doesn¹t help (too much data to hold in memory until the end). Any help is very much appreciated. Thanks, Chris Here¹s my file creation code just in case there¹s something wrong here...: outNc = NetcdfFileWriteable.createNew(fileLoc, true); //make the dimensions Dimension timeDim = outNc.addDimension(this.TIME, timeSteps); Dimension partDim = outNc.addDimension(this.PARTICLE, numParts); ArrayList dims = new ArrayList(); //add coordinate variables outNc.addVariable(this.TIME, DataType.INT, new Dimension[]{timeDim}); outNc.addVariable(this.PARTICLE, DataType.INT, new Dimension[]{partDim}); dims.add(timeDim); dims.add(partDim); //add the variables outNc.addVariable(this.LAT, DataType.DOUBLE, dims); outNc.addVariable(this.LON, DataType.DOUBLE, dims); outNc.addVariable(this.CCONC, DataType.DOUBLE, dims); //add attributes to the variables outNc.addVariableAttribute(this.LAT, "units", "deg North"); outNc.addVariableAttribute(this.LON, "units", "deg East"); outNc.addVariableAttribute(this.CCONC, "units", "moles liter^-1"); try { outNc.create(); } catch (IOException ex) { ex.printStackTrace(); }
netcdf-java
archives: