Re: [netcdf-java] Writing data for a single timestep

Hi Christopher:

You are right that writing data a record at a time is the key to efficiently 
writing files with an unlimited dimension. Note that in this case you need:

       Dimension timeDim = outNc.addUnlimitedDimension(this.TIME);

Ive just added an example at:

 
http://www.unidata.ucar.edu/software/netcdf-java/tutorial/NetcdfWriteable.html#RecordAtaTime

Let me know if that helps, and if you have more questions.

John

Christopher Mueller wrote:
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 mailing list
netcdf-java@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/