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.
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