Radar Decoding - Java Solution!
This example reads NEXRAD data with the NetCDF for Java API.
1) Download
NetCDF for Java API from Unidata .
The 'toolsUI.jar'
file has everything you need bundled into a single file and also
provides a NetCDF debugger. This example is using the version 4.0
library, although I think 2.2.22 also has super-res support.
2) Read data into Java objects that represent the sweeps, rays,
etc...
With this approach you don't have to deal with NetCDF
dimensions, attributes and variables. Check out the example code below
- it is written for version 4.0 of the library:
import ucar.nc2.NCdump;
import ucar.nc2.constants.FeatureType;
import ucar.nc2.dt.RadialDatasetSweep;
import ucar.nc2.dt.TypedDatasetFactory;
import ucar.nc2.util.CancelTask;
public class ReadNexradExample {
public static void main(String[] args) {
try {
String fileIn = "KPAH20080330_133313_V03";
// print an 'ncdump' of the file
NCdump.print(fileIn, System.out);
CancelTask emptyCancelTask = new CancelTask() {
public boolean isCancel() {
return false;
}
public void setError(String arg0) {
}
};
// open the file and represent as a
// RadialDatasetSweep object
RadialDatasetSweep rds = (RadialDatasetSweep)
TypedDatasetFactory.open(
FeatureType.RADIAL,
fileIn,
emptyCancelTask,
new StringBuilder()
);
// radar information
String stationID = rds.getRadarID();
String stationName = rds.getRadarName();
boolean isVolume = rds.isVolume();
System.out.println("stationID = "+stationID);
System.out.println("stationName = "+stationName);
System.out.println("isVolume = "+isVolume);
System.out.println("station location = "+
rds.getCommonOrigin());
// Read a radial variable
RadialDatasetSweep.RadialVariable varRef =
(RadialDatasetSweep.RadialVariable)
rds.getDataVariable("Reflectivity");
// Read a single sweep
int sweepNum = 0;
RadialDatasetSweep.Sweep sweep =
varRef.getSweep(sweepNum);
float meanElev = sweep.getMeanElevation();
int nrays = sweep.getRadialNumber();
float beamWidth = sweep.getBeamWidth();
int ngates = sweep.getGateNumber();
float gateSize = sweep.getGateSize();
System.out.println("meanElev = "+meanElev);
System.out.println("nrays = "+nrays);
System.out.println("beamWidth = "+beamWidth);
System.out.println("ngates = "+ngates);
System.out.println("gateSize = "+gateSize);
// Read data variable at radial level -
// this is where actual data is read
// into memory
for (int i = 0; i < nrays; i++) {
float azimuth = sweep.getAzimuth(i);
float elevation = sweep.getElevation(i);
float[] data = sweep.readData(i);
// data.length should equal ngates
}
} catch (Exception e) {
e.printStackTrace();
}
}
}



