Re: [netcdf-java] appending data to the unlimited dimension

Hi John:

You dont want to have to read the data in order to write the next time step.

Have a look at this example and let me know if that clarifies things:

John Cartwright wrote:
Hello All,

I have a question very similar to Chris' regarding appending data to a previously created file. I have a simple 3D file w/ longitude,latitude, and time as the dimensions. Time is the unlimited dimension. I'm having a little trouble getting my array indices correct in the program that appends the data. Do the x,y elements of the origins array need to be incremented as well? The code below does not seem to increment the timestep. Can someone help me out w/ what I'm doing wrong?


-- john

      //add some data (1 days worth)
      Variable time = ncfile.findVariable("time");
      ArrayInt.D1 timeData = (ArrayInt.D1);
      timeData.set(timeDim.getLength()-1, daysSinceEpoch);
      ncfile.write("time", timeData);

      Variable atmp = ncfile.findVariable("atmp");
      int[] origin = new int[3];
      origin[0] = ncfile.findDimension("time").getLength() -1;
      ArrayInt.D3 atmpData = (ArrayInt.D3);
      int time_idx = timeDim.getLength()-1;
      //generate a grid of dummy data to append at the new timestep
      int counter = 0;
      for (int lat_idx = 0; lat_idx < latDim.getLength(); lat_idx++) {
         for (int lon_idx = 0; lon_idx < lonDim.getLength(); lon_idx++) {
              atmpData.set(time_idx, lat_idx, lon_idx, counter);
      ncfile.write("atmp", origin, atmpData);

netcdf-java mailing list
For list information or to unsubscribe, visit:

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