Re: 20050215:netCDF Java - NetcdfFile open method does not work as suggested

Unidata Support wrote:

------- Forwarded Message

To: support-netcdf-java@xxxxxxxxxxxxxxxx
From: "Alain Boucher" <boucher@xxxxxxxxxxxxxxxxxxxxxxx>
Subject: netCDF Java - NetcdfFile open method does not work as suggested
Organization: UCAR/Unidata
Keywords: 200502151901.j1FJ1u9O023527

Institution: Fisheries and Oceans Canada
Package Version: 2.2 (alpha)
Operating System: WindowsXP
Hardware Information: Intel P4
Inquiry: Hi there,

    I have downloaded the latest release of the Java NetCDF library.  I noticed 
that when using the open(String location) method on a NetcdfFile object, the 
method crashes when the file is empty (size of 0 bytes).

    I am not sure if the problem results from an ill-formed Netcdf structure or 
from the null size of the file, but the result is I get a OutOfMemoryError.

    However, the API suggests that it should throw an IOException() if the 
method fails.

    If I am misinterpreting what the method should do, does that mean I have to 
open a File object (from java.io) to first check if the file is a 0-length file?

    Thanks a lot in advance and congratulations on the great work you did of 
making that Java Netcdf library!  It is actually very helpful to our department!



--
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.

------- End of Forwarded Message
Hi Alan

When i run the NetcdfFile.main()

public static void main( String[] arg) throws Exception {

   try {
     String filename = "C:/data/bad/zero.nc";
     NetcdfFile ncfile = NetcdfFile.open(filename);

     System.out.println();
     System.out.println( ncfile.toString());
ncfile.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }

I get:

java.io.IOException: Cant read C:/data/bad/zero.nc: not a valid NetCDF file.
   at ucar.nc2.NetcdfFile.open(NetcdfFile.java:231)
   at ucar.nc2.NetcdfFile.open(NetcdfFile.java:183)
   at ucar.nc2.NetcdfFile.open(NetcdfFile.java:141)
   at ucar.nc2.NetcdfFile.main(NetcdfFile.java:841)

can you try that and send me your output? thanks