}
private static void runTests(String fName, String inType) {
LineNumberReader lnr = null;
PrintStream pos = null;
String record = null;
StringBuffer outStr1 = new StringBuffer();
StringBuffer outStr2 = new StringBuffer();
try {
/*
* File inFile = new File(fName + ".dat"); File outFile = new
* File(fName + ".out"); FileInputStream fis = new
* FileInputStream(inFile); FileOutputStream fos = new
* FileOutputStream(outFile); BufferedInputStream bis = new
* BufferedInputStream(fis);
*/
pos = new PrintStream(new FileOutputStream(new File(fName + ".out")));
lnr = new LineNumberReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(new File(fName)))));
if (inType.equalsIgnoreCase("MGRS")) {
outStr1.append("MGRS to LatLonPoint\n\tMGRS\t\tLatitude Longitude\n");
outStr2.append("MGRS to UTM\n\tMGRS\t\tZone Easting Northing\n");
} else if (inType.equalsIgnoreCase("UTM")) {
outStr1.append("UTM to LatLonPoint\n\tUTM\t\tLatitude Longitude\n");
outStr2.append("UTM to MGRS\n\tUTM\t\tMGRS\n");
} else if (inType.equalsIgnoreCase("LatLon")) {
outStr1.append("LatLonPoint to UTM\nLatitude Longitude\t\tZone Easting Northing \n");
outStr2.append("LatLonPoint to MGRS\nLatitude Longitude\t\tMGRS\n");
}
while ((record = lnr.readLine()) != null) {
if (inType.equalsIgnoreCase("MGRS")) {
try {
MGRSPoint mgrsp = new MGRSPoint(record);
record.trim();
mgrsp.decode(record);
outStr1.append(record + " is " + mgrsp.toLatLonPoint()
+ "\n");
outStr2.append(record + " to UTM: " + mgrsp.zone_number
+ " " + mgrsp.easting + " " + mgrsp.northing
+ "\n");
} catch (NumberFormatException nfe) {
Debug.error(nfe.getMessage());
}
} else if (inType.equalsIgnoreCase("UTM")) {
MGRSPoint mgrsp;
UTMPoint utmp;
float e, n;
int z;
char zl;
String tmp;
record.trim();
tmp = record.substring(0, 2);
z = Integer.parseInt(tmp);
tmp = record.substring(5, 11);
e = Float.parseFloat(tmp);
tmp = record.substring(12, 19);
n = Float.parseFloat(tmp);
zl = record.charAt(3);
utmp = new UTMPoint(n, e, z, zl);
LatLonPoint llp = utmp.toLatLonPoint();
mgrsp = LLtoMGRS(llp);
outStr1.append(record + " is " + llp + " back to "
+ LLtoUTM(llp) + "\n");
outStr2.append(record + " is " + mgrsp + "\n");
} else if (inType.equalsIgnoreCase("LatLon")) {
float lat, lon;
int index;
String tmp;
record.trim();
index = record.indexOf("\040");
if (index < 0) {
index = record.indexOf("\011");
}
tmp = record.substring(0, index);
lat = Float.parseFloat(tmp);
tmp = record.substring(index);
lon = Float.parseFloat(tmp);
LatLonPoint llp = new LatLonPoint(lat, lon);
// UTMPoint utmp = LLtoUTM(llp);
MGRSPoint mgrsp = LLtoMGRS(llp);
outStr1.append(record + " to UTM: " + mgrsp.zone_number
+ " " + mgrsp.easting + " " + mgrsp.northing + "\n");
outStr2.append(record + " -> " + mgrsp.mgrs + "\n");
}
}
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("IO error: " + e.getMessage());
} finally {
if (pos != null) {
pos.print(outStr1.toString());
pos.print("\n");
pos.print(outStr2.toString());
pos.close();
}
// if the file opened okay, make sure we close it
if (lnr != null) {
try {
lnr.close();