package henfredemars;

import java.util.HashMap;

//Locate stations by their id
public class StationLocator {
	
	private HashMap<String,float[]> lookupTable = null;
	
	public StationLocator(String fileName) {
		lookupTable = new HashMap<String,float[]>();
		String[] f = Util.readTextfile(fileName);
		int tableStart = -1;
		for (int i = 0; i<f.length; i++) {
			if (f[i].startsWith("010010")) {
				tableStart = i;
				break;
			}
		}
		if (tableStart==-1) {
			throw new RuntimeException("StationLocator - table not found");
		}
		for (int i = tableStart; !f[i].startsWith("997000"); i++) {
			String latString = f[i].substring(60,64);
			String lonString = f[i].substring(66,71);
			float latitude = Integer.valueOf(latString)/100.0f;
			float longitude = Integer.valueOf(lonString)/100.0f;
			if (f[i].charAt(64)=='S') {
				latitude *= -1;
			}
			if (f[i].charAt(71)=='W') {
				longitude *= -1;
			}
			float[] farray = {latitude,longitude};
			lookupTable.put(f[i].split(" +")[0], farray);
		}
	}
	
	public float[] getLatLon(String stationid) {
		return lookupTable.get(stationid);
	}
	
	public boolean inTargetArea(String stationid) {
		if (!knowsStation(stationid)) return false;
		float[] latlon = getLatLon(stationid);
		boolean latInRange = ((latlon[0] < -73) && (latlon[0] > -135));
		boolean lonInRange = ((latlon[1] < 50) && (latlon[1] > 23));
		return latInRange && lonInRange;
	}
	
	public boolean knowsStation(String stationid) {
		return lookupTable.containsKey(stationid);
	}

}

@@ -627,13 +627,13 @@
 ing(
-60,64
+59,63
 );%0A%09
@@ -673,15 +673,105 @@
 ng(6
-6,71
+5,70
 );%0A
+%09%09%09if (latString.trim().isEmpty()) continue;%0A%09%09%09if (lonString.trim().isEmpty()) continue;%0A
 %09%09%09f
@@ -901,9 +901,9 @@
 At(6
-4
+3
 )=='
@@ -953,17 +953,17 @@
 charAt(7
-1
+0
 )=='W') 
@@ -990,16 +990,94 @@
 1;%0A%09%09%09%7D%0A
+%09%09%09if (f%5Bi%5D.charAt(63)==' ') continue;%0A%09%09%09if (f%5Bi%5D.charAt(70)==' ') continue;%0A
 %09%09%09float

Correct indexing