[netcdf-java] Questions

Hello,

I've been tasked with running some data manipulation across a netcdf file. It's 
supposed to work off an existing file, but create a new one that has the same 
structure (although dimensions will have different lengths) and then change 
some of the cell values by applying a formula.

I'm currently trying to replicate the structure of the existing file in the new 
file. I can copy the global attributes just fine and wanted to re-create the 
variables and dimensions next. To do so, I wrote this code:

                @Override
                public void process(NetcdfFile original, NetcdfFileWriter 
target, Config config) throws IOException
                {
                                for(Attribute att : 
original.getGlobalAttributes())
                                                
target.addGroupAttribute(att.getGroup(), att);

                                for(Variable var : original.getVariables())
                                {
                                                Group group = 
target.addGroup(null, var.getGroup().getShortName());
                                                List<Dimension> dimensions = 
new ArrayList<>();

                                                for(Dimension dim : 
var.getDimensions())
                                                {
                                                                
dimensions.add(new Dimension(dim.getShortName(), dim.getLength(), 
dim.isShared(), dim.isUnlimited(), dim.isVariableLength()));
//                                                            
dimensions.add(new Dimension(dim.getShortName(), dim));
                                                }

                                                target.addVariable(group, 
var.getShortName(), var.getDataType(), dimensions);
                                }
                }

I ran into several issues. The code as it stands throws this exception:

Exception in thread "main" java.lang.IllegalStateException: unknown Dimension 
== time = UNLIMITED;   // (53970 currently)
                at 
ucar.nc2.iosp.netcdf3.N3header.findDimensionIndex(N3header.java:970)
                at ucar.nc2.iosp.netcdf3.N3header.writeVars(N3header.java:910)
                at ucar.nc2.iosp.netcdf3.N3header.writeHeader(N3header.java:666)
                at ucar.nc2.iosp.netcdf3.N3header.create(N3header.java:602)
                at ucar.nc2.iosp.netcdf3.N3iosp.create(N3iosp.java:683)
                at ucar.nc2.NetcdfFileWriter.create(NetcdfFileWriter.java:804)
                at jhi.netcdf.Main.main(Main.java:58)

I can't really find any information online about how to best approach this 
scenario or what exactly the exception means. If anyone can give me any clues 
or has experience with this kind of thing, that'd really be appreciated.
Maybe there is a more convenient way to re-create an existing file structure 
(not the actual data) that I'm not aware of.

Regards,
Sebastian Raubach


The James Hutton Institute is a Scottish charitable company limited by 
guarantee.
Registered in Scotland No. SC374831
Registered Office: The James Hutton Institute, Invergowrie Dundee DD2 5DA.
Charity No. SC041796
  • 2018 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: