[netcdf-java] Join two files

I have two Netcdf-4 files. Both are for the same region and same time interval. 
The first contains two variables U and V. The second variables S and T. I need 
to generate third Netcdf-4 file with four variables U, V, S, T. I had an idea 
to make copy of the first file and add additional variables to the copy. What i 
did:

- NetcdfFile fileUV = NetcdfFiles.open(fnameUV); // file with U and V
- NetcdfFile fileST = NetcdfFiles.open(fnameST); // file with S and T
- Nc4Chunking chunker = Nc4ChunkingStrategy.factory(type, deflateLevel, 
shuffle);
- NetcdfFormatWriter.Builder builder =
NetcdfFormatWriter.createNewNetcdf4(NetcdfFileFormat.NETCDF4, outName, chunker);
- NetcdfCopier copier = NetcdfCopier.create(fileUV, builder); // copier UV-file 
-> outfile

- NetcdfFile ncfileOut = copier.write(null); // do copy

- NetcdfFormatWriter writer = builder.build();

- ImmutableList<Variable> vST = fileST.getVariables(); // variables S and T

- for(var v : vST) writer.write(v, null); // add vriables to outfile

String 7 generates the exception java.lang.IllegalStateException: Group was 
already built.

May be it is impossible to use the same builder for copying and adding 
variables? Could anyone help me to solve my task correctly? Thanks in advance

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