use of ucar.nc2.constants.CDM in project ncWMS by Unidata.
the class NcDiag method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: NcDiag <filename>");
System.exit(-1);
}
String filename = args[0];
PrintStream ps = System.out;
printHeader(ps, filename);
// Open the file using the Unidata CDM
NetcdfDataset nc = null;
try {
nc = NetcdfDataset.openDataset(filename);
// TODO: print information about the NetCDF file as a whole
GridDataset gd = CdmUtils.getGridDataset(nc);
// Read all the metadata from the file
Collection<CoverageMetadata> coverages = CdmUtils.readCoverageMetadata(gd);
// Cycle through all the coverages, printing out information from each
for (CoverageMetadata cm : coverages) {
printInfo(ps, nc, cm);
}
} finally {
if (nc != null)
nc.close();
printFooter(ps);
ps.close();
}
}
use of ucar.nc2.constants.CDM in project ncWMS by Unidata.
the class NcImageGen method main.
public static void main(String[] args) throws IOException {
if (args.length != 9) {
System.err.println("Usage: NcImageGen <filename> <output_width> <output_height> <min_lon> <max_lon> <min_lat> <max_lat> <height> <tIndex>");
System.exit(-1);
}
String filename = args[0];
int xsize = Integer.parseInt(args[1]);
int ysize = Integer.parseInt(args[2]);
double lonmin = Double.parseDouble(args[3]);
double lonmax = Double.parseDouble(args[4]);
double latmin = Double.parseDouble(args[5]);
double latmax = Double.parseDouble(args[6]);
double zVal = Double.parseDouble(args[7]);
int tIndex = Integer.parseInt(args[8]);
GeographicBoundingBox bbox = new DefaultGeographicBoundingBox(lonmin, lonmax, latmin, latmax);
// Open the file using the Unidata CDM
NetcdfDataset nc = null;
try {
nc = NetcdfDataset.openDataset(filename);
GridDataset gd = CdmUtils.getGridDataset(nc);
// Read all the metadata from the file
Collection<CoverageMetadata> coverages = CdmUtils.readCoverageMetadata(gd);
// Cycle through all the coverages, printing out information from each
for (CoverageMetadata cm : coverages) {
List<Double> zVals = cm.getElevationValues();
double min_diff = 1000000.0;
int zIndex = 0;
for (int i = 0; i < zVals.size(); i++) {
double z = zVals.get(i);
if (Math.abs(z - zVal) < min_diff) {
min_diff = Math.abs(z - zVal);
zIndex = i;
}
}
if (zVals.isEmpty()) {
System.out.println("Variable: " + cm.getId() + " only has one point in the vertical axis.");
} else {
System.out.println("Variable: " + cm.getId() + " has " + zVals.size() + " elevation data. Nearest elevation to " + zVal + " is " + zVals.get(zIndex) + ".");
}
List<DateTime> tVals = cm.getTimeValues();
if (tVals.isEmpty() || tVals.size() == 1) {
System.out.println("Variable: " + cm.getId() + " only has one point in the time axis.");
tIndex = 0;
} else if (tIndex > tVals.size()) {
System.out.println("Variable: " + cm.getId() + " has " + tVals.size() + " time values. Index " + tIndex + " is too large. Using maximum, which corresponds to " + tVals.get(tVals.size() - 1) + ".");
tIndex = tVals.size() - 1;
} else if (tIndex < 0) {
System.out.println("Variable: " + cm.getId() + " has " + tVals.size() + " time values. Index " + tIndex + " is negative. Using first time value, which corresponds to " + tVals.get(0) + ".");
tIndex = 0;
} else {
System.out.println("Variable: " + cm.getId() + " has " + tVals.size() + " time values. Index " + tIndex + " corresponds to " + tVals.get(tIndex) + ".");
}
List<Float> data = readData(nc, cm, bbox, xsize, ysize, tIndex, zIndex);
BufferedImage image = createImage(data, xsize, ysize);
String imageFilename = cm.getId().toLowerCase() + ".png";
ImageIO.write(image, "png", new File(imageFilename));
}
} finally {
if (nc != null)
nc.close();
}
}
Aggregations