This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
No problem! :-) Happy netCDF'ing! > Hi Sean, > > Thanks for the response. I guess I thought the netcdf info was begin saved > to ncfile and then it was ok to close it. Thanks again! > > -John > > address@hidden> wrote: > > > Greetings John, > > > > Sorry for the delay. It looks like you are closing the netCDF file before > > you try to read in the variable. If you move > > > > makeLatLonGrid(ncfile); > > > > just beneath the netCDF open command, in the`try` block of main, then it > > works great: > > > > 'public static void main(String[] args){ > > ' String filename = "~/20090513-204500.netcdf.gz"; > > ' NetcdfFile ncfile = null; > > ' try { > > ' ncfile = NetcdfFile.open(filename); > > ' makeLatLonGrid(ncfile); > > ' } catch (IOException ioe) { > > ' log("trying to open " + filename, ioe); > > ' } finally { > > ' if (null != ncfile) try { > > ' ncfile.close(); > > ' } catch (IOException ioe) { > > ' log("trying to close " + filename, ioe); > > ' } > > ' } > > '} > > > > Cheers! > > > > Sean > > > > > Hi Sean, > > > > > > Here is my code. I modified it quite a bit so that it should compile for > > > you. I attached the data file as well, if that helps. It's probably > > > something simple I'm doing/failing to do. Thanks for your help! > > > -John > > > > > > ******************* > > > package edu.ou.asgbook.segmentation; > > > > > > import java.io.*; > > > import ucar.nc2.*; > > > import ucar.ma2.*; > > > > > > public class read_netcdf { > > > private static void log(String msg, IOException ioe){ > > > System.out.println(msg + ioe.getMessage()); > > > } > > > private static void makeLatLonGrid(NetcdfFile netcdf){ > > > Variable var = netcdf.findVariable("goesnp_ctype_emiss11_high"); > > > System.out.println(var.getUnitsString()); > > > Array arr = null; > > > try { > > > arr = var.read(); > > > } catch (IOException e) { > > > log("trying to read the variable. ",e); > > > e.printStackTrace(); > > > } > > > } > > > public static void main(String[] args){ > > > String filename = "~/20090513-204500.netcdf.gz"; > > > NetcdfFile ncfile = null; > > > try { > > > ncfile = NetcdfFile.open(filename); > > > } catch (IOException ioe) { > > > log("trying to open " + filename, ioe); > > > } finally { > > > if (null != ncfile) try { > > > ncfile.close(); > > > } catch (IOException ioe) { > > > log("trying to close " + filename, ioe); > > > } > > > } > > > makeLatLonGrid(ncfile); > > > } > > > } > > > > > > ******************* > > > > > > address@hidden> wrote: > > > > > > > Greetings John, > > > > > > > > Would you mind sending the code you wrote, at least the part where you > > > > begin to open the dataset through the point of error? > > > > > > > > Thanks! > > > > > > > > Sean > > > > > > > > > Hello, > > > > > > > > > > I have the latest version of Java and the NetCDF Java library version > > > > 4.2. > > > > > I'm simply trying to read in a variable from a netcdf file. I can > > make a > > > > > Variable just fine and extract info (e.g. var name, data type), but > > then > > > > > when I try to make an Array out of it with read(), (e.g. arr = > > var.read() > > > > > ), I get the runtime error, "BAD: missing spi:" then the variable > > name. I > > > > > can get attributes just fine, and the shape and type of the data are > > > > what I > > > > > expect. I view the data in ncview, and it looks fine. A co-worker > > loaded > > > > it > > > > > up in McIDAS - V and the log message said: "ucar.nc2.NetcdfFile - > > Using > > > > > IOSP ucar.nc2.iosp.netcdf3.N3raf" if that's pertinent at all. I > > think I'm > > > > > importing all of the proper libraries since I'm not getting a > > compiler > > > > > error, but I'm fairly new to Java, so there could be something I'm > > > > missing. > > > > > Any help is much appreciated! Let me know if you'd like more info. > > > > > > > > > > Thanks, > > > > > John > > > > > > > > > > > > > > > -- > > > > > > > > > > > --------------------------------------------------------------------------------------- > > > > > John Cintineo > > > > > Research Meteorologist > > > > > SSEC/CIMSS > > > > > University of Wisconsin -- Madison > > > > > 1225 W. Dayton St. > > > > > Madison, WI 53706 > > > > > > > > > > (608) 890-0619 > > > > > john.cintineo@ <address@hidden>ssec.wisc.edu > > > > > > > > > > "My opinions are my own and not representative of > > > > > CIMSS, SSEC, NOAA or any affiliates" > > > > > > > > > > > > > > > > > > > > > > Ticket Details > > > > =================== > > > > Ticket ID: UMY-837124 > > > > Department: Support netCDF Java > > > > Priority: High > > > > Status: Open > > > > > > > > > > > > > > > > > -- > > > > > --------------------------------------------------------------------------------------- > > > John Cintineo > > > Research Meteorologist > > > SSEC/CIMSS > > > University of Wisconsin -- Madison > > > 1225 W. Dayton St. > > > Madison, WI 53706 > > > > > > (608) 890-0619 > > > john.cintineo@ <address@hidden>ssec.wisc.edu > > > > > > "My opinions are my own and not representative of > > > CIMSS, SSEC, NOAA or any affiliates" > > > > > > > > > > > > Ticket Details > > =================== > > Ticket ID: UMY-837124 > > Department: Support netCDF Java > > Priority: Emergency > > Status: Open > > > > > > > -- > --------------------------------------------------------------------------------------- > John Cintineo > Research Meteorologist > SSEC/CIMSS > University of Wisconsin -- Madison > 1225 W. Dayton St. > Madison, WI 53706 > > (608) 890-0619 > john.cintineo@ <address@hidden>ssec.wisc.edu > > "My opinions are my own and not representative of > CIMSS, SSEC, NOAA or any affiliates" > > Ticket Details =================== Ticket ID: UMY-837124 Department: Support netCDF Java Priority: Emergency Status: Open