Re: [netcdf-java] Problem using Redefine mode in netcdf-java 4.1

Hi John,

Thanks for that - we'll grab the update once it is ready and give a workout. At 
the moment we have used a workaround involving a temporary variable that we 
delete as part of the first add variable operation.

Thanks for the warning about define mode too - we'll keep an eye on that. The 
good news is that so far it seems to be working nicely other than this one 
issue.

Cheers,
James Dempsey
Java Technical Lead | Software Services
Information Management and Technology
CSIRO Australia


-----Original Message-----
From: John Caron [mailto:caron@xxxxxxxxxxxxxxxx] 
Sent: Tuesday, 23 March 2010 10:30 AM
To: Dempsey, James (CSIRO IM&T, Yarralumla)
Cc: netcdf-java@xxxxxxxxxxxxxxxx
Subject: Re: [netcdf-java] Problem using Redefine mode in netcdf-java 4.1

Hi James:

Turns out its a bug when there are no variables in the file. Ill make a fix as 
soon as i can (probably tommorrow or day after).

BTW, im sorry to say going in and out of define mode is not very robust in 
netcdf-java. Id use it as minimally as possible, or at least be sure to test 
things are working correctly. Also its quite inefficient, as it forces a 
complete file rewrite in many cases.

Thanks for reporting the bug.

John

James.Dempsey@xxxxxxxx wrote:
> Hi,
>  
> I am using the current 4.1 netcdf-java library (4.1.20100311.2157 or 
> change 14  I believe) and encountering a problem when trying to use 
> redefine mode. A similar problem also occurs using the latest 4.0 library .
>  
> Our aim is to create some command line tools that allow a netCDF file to 
> be build up. First, define a dimension, then add a variable to it, then 
> populate the variable. However when we close and reopen the file, any 
> attempt to add a variable results in the following stack trace:
> 
> Exception in thread "main" _java.io.IOException_: The parameter is incorrect
> at java.io.RandomAccessFile.setLength(_Native Method_)
> at ucar.unidata.io.RandomAccessFile.close(_RandomAccessFile.java:339_)
> at ucar.nc2.iosp.netcdf3.N3iosp.close(_N3iosp.java:878_)
> at ucar.nc2.NetcdfFileWriteable.close(_NetcdfFileWriteable.java:769_)
> at au.csiro.netcdf.CreateFile.main(_CreateFile.java:45_)
> 
> The following code demonstrates the problem.
>  
> package au.csiro.netcdf;
>  
> import java.io.IOException;
>  
> import ucar.ma2.DataType;
> import ucar.nc2.Dimension;
> import ucar.nc2.NetcdfFileWriteable;
>  
> public class CreateFile {
>  
>     private static String dimensionName = "lat";
>     private static int dimensionSize = 20;
>     private static String variableName = "temp";
>     private static DataType variableDataType = DataType.getType("Float");
>  
>     public static void main(String[] args) throws IOException {
>         String outputFilename = args[0];
>         NetcdfFileWriteable ncFile = 
> NetcdfFileWriteable.createNew(outputFilename, true);
>         try  {
>             Dimension dimension = new Dimension(dimensionName, 
> dimensionSize, true /* isShared */,
>                     false /* isUnlimited */, false /* isVariableLength */);
>             ncFile.addDimension(null, dimension);
>             ncFile.create();
>         } finally {
>             ncFile.close();
>         }
>        
>         ncFile = NetcdfFileWriteable.openExisting(outputFilename, true);
>         try {
>             ncFile.setRedefineMode(true);
>             ncFile.addVariable(variableName, variableDataType, 
> dimensionName);
>             ncFile.setRedefineMode(false);
>         } finally {
>             ncFile.close();
>         }
>     }
>  
> }
>  
> If the ncFile.close() and NetcdfFileWriteable.openExisting calls are 
> commented out the file is successfully created with the variable. Could 
> anyone advise if this is something I am doing wrong or a problem with 
> the library please?
>  
> Cheers,
> James Dempsey
> Java Technical Lead | Software Services
> Information Management and Technology
> CSIRO Australia


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