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.
Greetings Owen! If you check out the current packages contained in the netcdf-java library (http://www.unidata.ucar.edu/software/netcdf-java/v4.2/javadoc/index.html), you will see that none of the packages your example tries to import exist. As the comments at the beginning of the file indicate, CreateNetcdf.java is using the v1 interface - you are using the v4 library. So, to test your package, try the following example: http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_wr.java If you keep the .java file and the .jar file in the same directory, you may compile it using: javac -classpath netcdfAll-4.2.jar Simple_xy_wr.java Then, to run the file, execute: java -cp netcdfAll-4.2.jar:. Simple_xy_wr Notice that I've added '.' (i.e. the current directory) to the classpath. For an example of using netcdf-Java to read a netcdf file, check out: http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_rd.java This example will read the file that Simple_xy_wr creates. Cheers! Sean PS: sorry for the duplicate email - please reply to this one and ignore the previous one :-) > Greetings Owen! > > If you check out the current packages contained in the netcdf-java library > (http://www.unidata.ucar.edu/software/netcdf-java/v4.2/javadoc/index.html), > you will see that none of the packages your example tries to import exist. As > the comments at the beginning of the file indicate, CreateNetcdf.java is > using the v1 interface - you are using the v4 library. > > So, to test your package, try the following example: > > http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_wr.java > > If you keep the .java file and the .jar file in the same directory, you may > compile it using: > > javac -classpath netcdfAll-4.2.jar Simple_xy_wr.java > > Then, to run the file, execute: > > java -cp netcdfAll-4.2.jar:. Simple_xy_wr > > Notice that I've added '.' (i.e. the current directory) to the classpath. > > For an example of using netcdf-Java to read a netcdf file, check out: > > http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_rd.java > > This example will read the file that Simple_xy_wr creates. > > Cheers! > > Sean > > > Hi, > > > > > > > > I'm trying to write some java/html to display some statistics on a > > webpage. The statistics are stored in a NetCDF(v3) file and I've no > > experience of writing or reading NetCDF files with Java. Google and > > intranet searches on this have bought up several Unidata and user > > tutorials but even having read these I still can't work out how to > > compile the example with javac. The java script itself looks > > straightforward enough so I'm sure once I can' compile the simple write > > and read examples I can work from these develop my own code, it's just > > compiling and running the examples in the first place. > > > > > > > > I've spoken to the java developers within my organisation who have been > > helpful on Java in general but have little experience using NetCDF files > > in Java. Personally I've tried downloading the netcdf-2.2.20.jar, > > netcdf-4.2.jar, netcdfAll-4.2.jar (which I think is unnecessary for my > > needs). Using a unix system these and the example are all stored in my > > home directory and I've tried compiling using > > > > > > > > javac -classpath netcdf-2.2.20.jar CreateNetcdf.java > > > > javac -classpath netcdf-4.2.jar CreateNetcdf.java > > > > javac -classpath netcdfAll-4.2.jar CreateNetcdf.java > > > > > > > > All of which fail to find the ucar.Multiarray and ucar.netcdf packages > > in the CreateNetcdf.java example. I've also tried compiling this in > > Eclipse with the external jars I named added but this still will not > > work. I could very well be missing something obvious as I'm relatively > > new to java scripting, but after a fairly exhaustive google search of > > all related websites I'm still unable to compile or run the example. > > Any help with this would be much appreciated. > > > > > > > > > > > > Thanks, > > > > Owen > > > > > > > > > > > > Owen Cox Scientist - Active Sensing > > Met Office Joint Centre for Mesoscale Meteorology (JCMM) > > Meteorology Building University of Reading > > PO Box 243 Earley Gate Reading Berks RG6 6BB United Kingdom > > Tel: +44 (0)118 378 7830 Fax: +44 (0)118 378 8791 > > Email: address@hidden Website: www.metoffice.gov.uk > > > > See our guide to climate change at > > http://www.metoffice.gov.uk/climatechange/guide/ > > > > ________________________________ > > > > > > > > Hi Owen, > > > > > > > > You basically need to tell the Java compiler the location of the JAR > > file containing the NetCDF code. This is achieved by including the > > -classpath argument in your invocation of javac. For example: > > > > > > > > javac -classpath /path/to/your/code:/path/to/netcdfcode/netcdf.jar > > YourCode.java > > > > > > > > where /path/to/your/code is the directory containing your Java code, and > > /path/to/netcdfcode/netcdf.jar is the location of the JAR file whose > > code you are using in your source file. This example is for a > > Unix/Linue environment - syntax is slightly different if you use > > Microsoft Windows. > > > > > > > > If you google for something like "adding jar files classpath javac" you > > will find hundreds of examples. You're not the first person to ask this > > question! > > > > > > > > Like Colin, I have never dealt with NetCDF so can't advise on this > > aspect. However I'm happy to advise on any Java-specific problems you > > may encounter. > > > > > > > > Compiling Java programs can be a complex process, something that a good > > IDE will handle for you. Therefore I strongly advise that you obtain > > and familiarise yourself with an IDE (such as Eclipse) before embarking > > on Java development. > > > > > > > > I hope this reply is of some use. > > > > > > > > Regards, > > > > Niall. > > > > Niall Hosiene Senior IT Practitioner > > Met Office FitzRoy Road Exeter Devon EX1 3PB United Kingdom > > Tel: +44 (0)1392 884145 Fax: +44 (0)1392 885681 Mobile: +44 (0)7707 > > 141741 > > Email: address@hidden > > <mailto:address@hidden> Website: > > http://www.metoffice.gov.uk <http://www.metoffice.gov.uk/> > > > > See our guide to climate change at > > http://www.metoffice.gov.uk/climate-change > > > > > > > > ________________________________ > > > > From: Smith, Colin A > > Sent: 15 July 2011 10:08 > > To: Cox, Owen; Hosiene, Niall > > Subject: RE: NetCDF-Java in the office > > > > owen > > > > > > > > I have not dealt with NetCDF so I cannot help you on that. > > > > > > > > hopefully niall can help you with adding your jar on the command line. > > > > Colin A Smith > > Senior IT Practitioner > > Met Office FitzRoy Road Exeter Devon EX1 3PB U.K. > > Tel: +44 (0)1392 886860 > > Website: www.metoffice.gov.uk > > > > > > > > > > > > ________________________________ > > > > From: Cox, Owen > > Sent: 15 July 2011 09:52 > > To: Smith, Colin A; Hosiene, Niall > > Subject: FW: NetCDF-Java in the office > > > > Hi both, > > > > > > > > I emailed Sheila Needham with a question about how to compile the Java > > NetCDF examples in the office (please see the message below for more > > details) and she suggested that either of you may be able to help. > > Basically I'm trying to display some statistics on a Metnet page, but > > this involves reading some numbers from a simple NetCDF file. I'm only > > just starting to use Java but I'm pretty confident that once I can > > compile the write and read examples from Unidata's website I'll be able > > to develop the script I need from here on. Sheila suggested contacting > > either of you, and also adding the netcdf jar to my class path when I > > try compiling with javac. I'd tried this suggestion at home without > > success, although I've not tried in the office since I wasn't sure where > > the netcdfAll-*.*.jar was stored. > > > > > > > > Any help would be appreciated. > > > > > > > > Thanks, > > > > Owen > > > > > > > > Owen Cox Scientist - Active Sensing > > Met Office Joint Centre for Mesoscale Meteorology (JCMM) > > Meteorology Building University of Reading > > PO Box 243 Earley Gate Reading Berks RG6 6BB United Kingdom > > Tel: +44 (0)118 378 7830 Fax: +44 (0)118 378 8791 > > Email: address@hidden Website: www.metoffice.gov.uk > > > > See our guide to climate change at > > http://www.metoffice.gov.uk/climatechange/guide/ > > > > ________________________________ > > > > From: Needham, Sheila > > Sent: 15 July 2011 09:43 > > To: Cox, Owen > > Subject: RE: NetCDF-Java in the office > > > > > > > > Hi Owen, > > > > > > > > 'Fraid I can't really help you. I haven't done much Java since this and > > what I have done has always been with an IDE so I haven't used javac > > from the command line. Have you put the netcdf jar file in your > > classpath? That's all I can think of. > > > > > > > > Colin Smith or Niall Hosiene are both experienced Java developers who > > might be willing to help you. > > > > > > > > Regards, > > > > Sheila > > > > Sheila Needham Senior Software Developer > > Met Office FitzRoy Road Exeter EX1 3PB United Kingdom > > Tel: +44 (0)1626 363489 > > E-mail: address@hidden Website: > > http://www.metoffice.gov.uk <http://www.metoffice.gov.uk/> > > > > See our guide to climate change at > > http://www.metoffice.gov.uk/climatechange > > > > > > > > > > > > ________________________________ > > > > From: Cox, Owen > > Sent: 15 July 2011 09:17 > > To: Needham, Sheila > > Subject: NetCDF-Java in the office > > > > Hi Sheila, > > > > > > > > I'm trying to write some java/html to display some statistics on a > > Metnet page. Unfortunately the statistics are stored in a NetCDF(v3) > > file and I've no experience of writing or reading NetCDF files with > > Java. A Metnet search on this bought up a document you wrote in 2008, > > "Writing an IO Service Provider for NetCDF-Java Version 3". I followed > > the links in this doc to the Unidata website which had some simple > > examples such as WriteNetcdf.java, but even following your document and > > Unidata's tutorials I can't work out how to compile the example with > > javac. The java script itself looks straightforward enough so I'm sure > > once I can' compile the simple write and read examples I can work from > > these develop my own code, it's just compiling and running the examples > > in the first place. > > > > > > > > Would this be something you know how to do, or might be able to advise > > me whom in the office to contact on this? Apologies if you're not > > working in this field anymore (always a danger when MetNet searches are > > involved) but I was concerned a Remedy request wouldn't find it's way to > > the correct group so thought I'd try contacting you directly first. > > > > > > > > Thanks, > > > > Owen > > > > > > > > Owen Cox Scientist - Active Sensing > > Met Office Joint Centre for Mesoscale Meteorology (JCMM) > > Meteorology Building University of Reading > > PO Box 243 Earley Gate Reading Berks RG6 6BB United Kingdom > > Tel: +44 (0)118 378 7830 Fax: +44 (0)118 378 8791 > > Email: address@hidden Website: www.metoffice.gov.uk > > > > See our guide to climate change at > > http://www.metoffice.gov.uk/climatechange/guide/ > > > > > > > > > > > > > > > > > > > Ticket Details =================== Ticket ID: ALR-856518 Department: Support netCDF Java Priority: High Status: Open