[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDFJava #VKX-901266]: McIDAS Grids to netCDF



Hi Tom-

> Full Name: Tom Coleman
> Email Address: address@hidden
> Organization: Australian Bureau of Meteorology
> Package Version:
> Operating System:
> Hardware:
> Description of problem: I'm looking for some code in Java which converts 
> McIDAS grids to netCDF files. I know it can be done as I can do it using your 
> ToolsUI application, but as I'm very inexperienced with Java I'm not sure how 
> to do it.

Below is some code that will read a McIDAS grid file and write out a CF 
compliant netCDF file. The program is attached.  It will only work with McIDAS 
grid files where all the grids have the same projection.  I don't have a simple 
solution for multi-projection cases.

Most of the classes are in the ucar.nc2.dt.grid package:
 
          System.out.println("Reading from: " + args[0]);
          GridDataset gridDs = GridDataset.open (args[0]);
          List<GridDatatype> grids = gridDs.getGrids();
          List<String> gridNames = new ArrayList<String>();
          for (GridDatatype grid : grids) {
              gridNames.add(grid.getName());
          }
          System.out.println("Writing to: " + args[1]);
          NetcdfCFWriter ncOut = new NetcdfCFWriter();
          ncOut.makeFile(args[1], gridDs, gridNames, null, null, true, 0, 0, 0);

This can actually be used to write any kind of grid file that the netCDF-Java 
handles (McIDAS, GRIB 1&2, netCDF, GEMPAK) with the same caveat that there can 
be only one projection.

You could subset the grids by choosing specific names (above selects all grids) 
and subset by lat/lon etc.  See the javadoc on 
ucar.nc2.dt.grid.NetcdfFileWriter at:

http://www.unidata.ucar.edu/software/netcdf-java/v4.1/javadocAll/index.html

Don Murray

Ticket Details
===================
Ticket ID: VKX-901266
Department: Support netCDF Java
Priority: Normal
Status: Open

Attachment: McGridToNC.java
Description: Binary data