NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

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

Ok, but the documentation says different? The C-library is needed like you
say (and I have it installed) and used by Java-library via JNI?

https://docs.unidata.ucar.edu/netcdf-java/current/userguide/writing_netcdf.html
https://docs.unidata.ucar.edu/netcdf-java/current/userguide/netcdf4_c_library.html

And I can create new files by using
NetcdfFormatWriter.openExisting("/temp/input.nc").setFormat(NetcdfFileFormat
.NETCDF4); // note that I dont call "setNewFile(false)"
(This will create a file called "input.nc" but much smaller and containing
variables filled with "garbage" data.. but the file is still written and
readable)


Den ons 7 apr. 2021 kl 19:50 skrev John Caron <jcaron1129@xxxxxxxxx>:

> Hi Andreas:
>
> Netcdf-Java does not support writing or modifying netcdf-4 files. You need
> to use the netcdf-4 C library directly. Sorry.
>
> John
>
> On Wed, Apr 7, 2021 at 8:49 AM Andreas Imner <andreas.imner@xxxxxxxxx>
> wrote:
>
>> (... continuing since I clicked "Send" to soon)
>>
>> The NPE occurs because the 'ncfile.getLocation()' returns null
>>
>> My question is, is this supposed to work and am I doing something wrong?
>> Or maybe this is not the way you are supposed to work with NetCDF -files
>> that you want to modify the contents of?
>>
>> Den ons 7 apr. 2021 kl 16:33 skrev Andreas Imner <andreas.imner@xxxxxxxxx
>> >:
>>
>>> 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());
>>>
>>>
>>> _______________________________________________
>> NOTE: All exchanges posted to Unidata maintained email lists are
>> recorded in the Unidata inquiry tracking system and made publicly
>> available through the web.  Users who post to any of the lists we
>> maintain are reminded to remove any personal information that they
>> do not want to be made public.
>>
>>
>> netcdf-java mailing list
>> netcdf-java@xxxxxxxxxxxxxxxx
>> For list information or to unsubscribe, visit:
>> https://www.unidata.ucar.edu/mailing_lists/
>>
>
  • 2021 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: