private long parsePosition(Tokenizer st, String type) throws IOException { boolean isLatitude = type.equals("latitude"); int deg = 0, min = 0; double sec = 0; long value; String s; deg = st.getUInt16(); if (deg > 180 || (deg > 90 && isLatitude)) throw st.exception("Invalid LOC " + type + " degrees"); s = st.getString(); try { min = Integer.parseInt(s); if (min < 0 || min > 59) throw st.exception("Invalid LOC " + type + " minutes"); s = st.getString(); sec = parseFixedPoint(s); if (sec < 0 || sec >= 60) throw st.exception("Invalid LOC " + type + " seconds"); s = st.getString(); } catch (NumberFormatException e) { } if (s.length() != 1) throw st.exception("Invalid LOC " + type); value = (long) (1000 * (sec + 60L * (min + 60L * deg))); char c = Character.toUpperCase(s.charAt(0)); if ((isLatitude && c == 'S') || (!isLatitude && c == 'W')) value = -value; else if ((isLatitude && c != 'N') || (!isLatitude && c != 'E')) throw st.exception("Invalid LOC " + type); value += (1L << 31); return value; }