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.

[netcdf-java] How to modify variable in existing netcdf4 file?

Hi!
A am trying to use the Java NetCDF library to modify the data of a variable
in an existing NetCDF4 file.

I use the 5.4.1 version of the Java library
I have version 4.7.4_2 of the netcdf C-library installed and it works
properly.

The problem I get is that when opening the existing file for writing, a NPE
is thrown.

My code looks something like this...

NetcdfFormatWriter.Builder builder =
NetcdfFormatWriter.openExisting("/temp/input.nc").setFormat(NetcdfFileFormat.NETCDF4).setNewFile(false);
NetcdfFormatWriter writer = builder.build();

But when .build() is called an exception is thrown

Exception in thread "main" java.lang.NullPointerException
        at ucar.nc2.NetcdfFiles.canonicalizeUriString(NetcdfFiles.java:359)
        at ucar.nc2.jni.netcdf.Nc4Iosp._open(Nc4Iosp.java:253)
        at ucar.nc2.jni.netcdf.Nc4Iosp.openForWriting(Nc4Iosp.java:239)
        at ucar.nc2.write.NetcdfFormatWriter.<init>(NetcdfFormatWriter.java:329)
        at ucar.nc2.write.NetcdfFormatWriter.<init>(NetcdfFormatWriter.java:49)
        at 
ucar.nc2.write.NetcdfFormatWriter$Builder.build(NetcdfFormatWriter.java:261)

Looking at the code in the class Nc4Iosp.java

private void _open(RandomAccessFile raf, NetcdfFile ncfile, boolean
readOnly) throws IOException {
    ...
String location = NetcdfFiles.canonicalizeUriString(ncfile.getLocation());
  • 2021 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: