NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

[netcdf-java] Creating NetCDF files with GeoGrids

Hello,

I am trying to create a NetCDF file with a GeoGrid.  My data is a
200x200 grid indexed by latitude and longitude.  Each grid point has a
"prediction" value that is a double ranging from 0 to 1.  Can I create
a NetCDF file from this data?  I have tried the code following but ran
into trouble trying add a coordinate system.  Any help in creating a
NetCDF file from this data set would be appreciated.

Thanks,
Anthony


        NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew(
                "mypredfile");
        // add dimensions
        Dimension latDim = ncfile.addDimension("lat", 200);
        Dimension lonDim = ncfile.addDimension("lon", 200);
        ArrayList<Dimension> dims = new ArrayList<Dimension>();
        dims.add(latDim);
        dims.add(lonDim);

        ncfile.addVariable("prediction", DataType.DOUBLE, dims);
        Variable predvar = new Variable(ncfile, ncfile.getRootGroup(),
null, "prediction");
        predvar.setDataType(DataType.DOUBLE);
        predvar.setDimensions(dims);
        VariableDS predVariable = new
VariableDS(ncfile.getRootGroup(), predvar, true);

        // ???????????????????????
        //  predVariable.addCoordinateSystem(new
CoordinateSystem(ncfile, arg1, arg2));
        ncfile.create();

        ArrayDouble preds = new ArrayDouble.D2(latDim.getLength(), lonDim.
                getLength());
        Random rand = new Random();
        for (int i = 0; i < latDim.getLength(); i++) {
            for (int j = 0; j < lonDim.getLength(); j++) {
                preds.setDouble(preds.getIndex().set(i, j), rand.nextDouble());
            }
        }
        ncfile.write("prediction", new int[2], preds);
        ncfile.close();


       /* IS THIS CORRECT?????
        GridDataset gd = new ucar.nc2.dt.grid.GridDataset(NetcdfDataset.
                openDataset("mypred"));
        GeoGrid grid = new GeoGrid(gd, new
VariableDS(ncfile.getRootGroup(), ncfile.getVariables().
                get(0), true), new GridCoordSys(null, null));
                ncfile.create();
        grid.writeFile("mypredwithgrid");
        */


  • 2008 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: