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?
Thanks!
-- john
//add some data (1 days worth)
Variable time = ncfile.findVariable("time");
ArrayInt.D1 timeData = (ArrayInt.D1)time.read();
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)atmp.read();
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);
counter++;
}
}
ncfile.write("atmp", origin, atmpData);