Re: Extracting the vertical levels from Netcdf

hi Carl:

Use
GridCoordSys gcsys = grid.getCoordinateSystem()();
Coordinateavis1D axis = gcsys.getVerticalAxis()

Generally, the GridCoordSys has lots of good stuff in it.



Carl Drews wrote:
John -

I have developed a way to extract the grib vertical levels from a Netcdf
structure, but it seems rather awkward to me.  Do I really have to get
the vertical levels by "Name" and then convert the strings to floats?

        // load the input file into a NetcdfDataset
        _gridset = ucar.nc2.dataset.grid.GridDataset.open(_gribFilename);
...
        _mdv = createMDV(_gridset);


    public Mdv createMDV(ucar.nc2.dataset.grid.GridDataset gridset)
    {

        // get the vertical levels
        java.util.List grids = gridset.getGrids();
        GeoGrid firstGeoGrid = (GeoGrid)grids.get(0);
        ArrayList vlevels = firstGeoGrid.getLevels();

            Field newField = createMDVField(oneVar, vlevels);
...
     }


    public Field createMDVField(Variable netVar, ArrayList verticalLevels)
{
...
        // create the vertical levels
        fieldHeader.setNz(verticalLevels.size());
        VlevelHdr vlevelHeader = new VlevelHdr();
        int[] vtype = vlevelHeader.getVlevelTypes();
        float[] vparam = vlevelHeader.getVlevelParams();
        for (int zi = 0; zi < fieldHeader.getNz(); zi++) {
            vtype[zi] = levelType;
        }
        for (int zi = 0; zi < fieldHeader.getNz(); zi++) {
            NamedObject oneLevel = (NamedObject)verticalLevels.get(zi);
            float oneLevelValue = new Float(oneLevel.getName());
            vparam[zi] = oneLevelValue;
        }
...
}

Carl


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