In our system, and I suspect elsewhere, sometimes .nc files don't get completely copied from one place to another. Normally, this is caught and dealt with (e.g., by the script doing the copying), but sometimes it isn't (e.g., a computer is restarted while a script is running), leaving a shortened file in place. I wanted to understand how netcdf-java (v4.6.6) reacted to these shorted files. So I made the attached file by copying only the first 1/6th of a valid file. Then I tried to read it with this code NetcdfFile ncFile = NetcdfFile.open("/git/erddapTest/nc/invalidShortened.nc"); try { Variable var = ncFile.findVariable("MWcdom"); //size=[1,1,2321,4001] Array array = var.read(); System.out.println("shape=" + Arrays.toString(array.getShape())); array = var.read("0,0,0:2000:1000,0:4000:1000"); System.out.println("shape=" + Arrays.toString(array.getShape())); //System.out.println(array.toString()); System.out.println("Shouldn't get here!"); ncFile.close(); } catch (Throwable t) { try { ncFile.close(); } catch (Throwable t2) { } System.out.println("caught: " + t.toString()); } Note that Variable.read() documentation says that the method throws an IOException. To my surprise, the above code doesn't throw any exception. netcdf-java says it can read the entire var and read the specified section (which gets values from throughout the variable). Is that what you expected? Am I doing something wrong in my test? Doesn't netcdf-java check the validity of the file? Why don't the read()s cause an IOException? Thank you for looking into this. -- Sincerely, Bob Simons IT Specialist Environmental Research Division NOAA Southwest Fisheries Science Center 99 Pacific St., Suite 255A (New!) Monterey, CA 93940 (New!) Phone: (831)333-9878 (New!) Fax: (831)648-8440 Email: bob.simons@xxxxxxxx The contents of this message are mine personally and do not necessarily reflect any position of the Government or the National Oceanic and Atmospheric Administration. <>< <>< <>< <>< <>< <>< <>< <>< <><
Attachment:
invalidShortened.nc
Description: Cdf file
netcdf-java
archives: