Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.

Re: [netcdf-java] 4.1.14 bug in ucar.nc2.NetcdfFileWriteable.write(String, int[], Array)

  • To: Christian Ward-Garrison <cwardgar@xxxxxxxx>
  • Subject: Re: [netcdf-java] 4.1.14 bug in ucar.nc2.NetcdfFileWriteable.write(String, int[], Array)
  • From: John Caron <caron@xxxxxxxxxxxxxxxx>
  • Date: Thu, 04 Mar 2010 18:38:12 -0700
release Version 4.1.20100305.0017 should fix this problem


Christian Ward-Garrison wrote:
The test case below should demonstrate the bug pretty well. Note that it did not exist in 4.0.

import java.io.File;
import java.io.IOException;
import ucar.ma2.Array;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
import ucar.nc2.Dimension;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFileWriteable;

public class Foo {
public static void main(String[] args) throws IOException, InvalidRangeException {
        File tempFile = File.createTempFile("foo", "nc");
        tempFile.deleteOnExit();
NetcdfFileWriteable ncWriteable = NetcdfFileWriteable.createNew(tempFile.getAbsolutePath(), false);

        try {
Dimension timeDim = ncWriteable.addUnlimitedDimension("time"); ncWriteable.addVariable("time", DataType.INT, new Dimension[]{timeDim}); ncWriteable.addVariableAttribute("time", "units", "hours since 1990-01-01");
            ncWriteable.create();

            Array timeData = Array.factory(DataType.INT, new int[]{1});
            int[] time_origin = new int[] {0};

            for (int time = 0; time < 10; time++) {
                timeData.setInt(timeData.getIndex(), time * 12);
                time_origin[0] = time;
                ncWriteable.write("time", time_origin, timeData);
            }

// Prints "0 12 24 36 48 60 72 84 96 108", the expected result.
            System.out.println(ncWriteable.readSection("time"));
        } finally {
            ncWriteable.close();
        }

        NetcdfFile ncFile = NetcdfFile.open(tempFile.getAbsolutePath());
        try {
            // Prints "0 0 12 0 24 0 36 0 48 0".
            System.out.println(ncFile.readSection("time"));
        } finally {
            ncFile.close();
        }
    }
}

_______________________________________________
netcdf-java mailing list
netcdf-java@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



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