//
// RadarAdapter.java
//
/*
This sofware is part of the Australian Integrated Forecast System (AIFS)
Copyright (C) 2017 Bureau of Meteorology
*/
package visad.bom;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.swing.JFrame;
import visad.CommonUnit;
import visad.DataReference;
import visad.DataReferenceImpl;
import visad.Display;
import visad.FlatField;
import visad.FunctionType;
import visad.GraphicsModeControl;
import visad.Gridded3DSet;
import visad.Integer2DSet;
import visad.Integer3DSet;
import visad.QuickSort;
import visad.RealTupleType;
import visad.RealType;
import visad.ScalarMap;
import visad.VisADException;
import visad.java3d.DisplayImplJ3D;
/**
* RadarAdapter
*
* @author - James Kelly : J.Kelly@bom.gov.au - Bill Hibbard (mainly, while
* working at BOM August 1999)
*
*
*/
public class RadarAdapter {
public RadarFile rf;
public class PolarData {
public double azimuth;
public double range;
}
public PolarData[] polar;
public int numVectors;
FlatField radar;
/**
* @deprecated
*/
public RadarAdapter(float centlat, float centlon, String radarSource,
boolean d3d)
throws IOException, VisADException {
this(centlat, centlon, 0.0f, radarSource, d3d);
}
public RadarAdapter(float centlat, float centlon, float centalt,
String radarSource, boolean d3d)
throws IOException, VisADException {
try {
rf = new RadarFile(radarSource);
// buildFlatField(rf);
} catch (IOException e) {throw new
VisADException("Problem with Radar file: " + e);
}
System.out.println("Radar Adapter : dtTime = " + rf.dtTime);
int naz = rf.pbdataArray.length;
float[] azs = new float[naz];
int nrad = 0;
//
// create an array "azs" containing all the azimuth values
// example:
// azs[0] = 61 degrees = radlow + 0
// azs[1] = 183 degrees = radlow + 122
// azs[2] = 261 degrees = radlow + 200
// azs[3] = 262 degrees = radlow + 201
// azs[4] = 262 degrees = radlow + 202
//
for (int i=0; i nrad) nrad = n;
azs[i] = (float) rf.pbdataArray[i].azimuth;
// System.out.println("i, azs = " + i + " " + azs[i]);
}
int[] sortToOld = QuickSort.sort(azs);
// radlow : distance from radar of 1st "echo" (radial), in metres eg 4000m
float radlow = rf.startrng;
// radres : distance between subsequent radials eg 500m
float radres = rf.rngres;
float azlow = azs[0];
float azres = rf.azimuthres;
//
//
// azs above is the "old" array
// prepare to create a "new" array containing a continuous set of
// azimuth values between azs[0] and azs[naz-1] degrees
// newnaz is the number of continuous azimuth values
//
int newnaz = 1 + (int) ((azs[naz-1] - azs[0]) / azres);
int[] newToOld = new int[newnaz];
// for (int i=0; i (newnaz-1)) k = newnaz-1;
newToOld[k] = sortToOld[i];
// System.out.print("k, newToOld = " + k + " " + newToOld[k] + " ");
}
// System.out.println(" ");
Radar2DCoordinateSystem rcs2d = null;
Radar3DCoordinateSystem rcs3d = null;
float elevlow = 0.5f; // degrees
float elevres = 0.1f; // degrees
int nelev = 1;
if (d3d) {
//ref = new RealTupleType
// (RealType.Latitude, RealType.Longitude, RealType.Altitude);
rcs3d = new Radar3DCoordinateSystem(centlat, centlon, centalt,
radlow, radres, azlow, azres, elevlow, elevres);
}
else {
//ref = new RealTupleType (RealType.Latitude, RealType.Longitude);
rcs2d = new Radar2DCoordinateSystem(centlat, centlon,
radlow, radres, azlow, azres);
}
RealType azimuth =
RealType.getRealType("azimuth", CommonUnit.degree, null);
RealType range = RealType.getRealType("range", CommonUnit.meter, null);
// WLH 14 Oct 99
// RealType elevation =
// RealType.getRealType("elevation", CommonUnit.meter, null);
RealType elevation =
RealType.getRealType("elevation", CommonUnit.degree, null);
RealTupleType radaz = null;
if (d3d) {
RealType[] domain_components = { range, azimuth, elevation};
radaz = new RealTupleType(domain_components, rcs3d, null);
}
else {
RealType[] domain_components = {range, azimuth};
radaz = new RealTupleType(domain_components, rcs2d, null);
}
RealType reflection = RealType.getRealType("reflection");
FunctionType radar_image = new FunctionType(radaz, reflection);
//
// newnaz = 203 using example above
//
// System.out.println("newnaz = " + newnaz + " nrad = " + nrad);
// float[][] samples = new float[2][nrad * naz];
//
// For convenience, the "values" array has all the
// > 0 data values at the start of the array (indexed by k)
// while null data values are stored together at the end of the array
//
// WLH - 21 Sept 99
int bignaz = newnaz;
if (newnaz == 360) bignaz = 361;
float[][] values = new float[1][nrad * bignaz]; // WLH - 21 Sept 99
int m = 0;
for (int i=0; i= 0) {
// there is data for this azimuth
byte[] bd = rf.pbdataArray[newToOld[i]].bdata;
for (int j=0; j 0) System.out.println("i, j = " + i + " " + j + " values = " + values[0][m] );
m++;
}
}
else { // k < 0
//
// fill the rest of the array with NaNs
//
for (int j=0; j
Ads help maintain this website.