if (DEBUG) Debug.output(" northing rolled over 18, adding 200k to " + north100k); }  if ((zone_letter == 'S' && north100k < 3000000) || (zone_letter >= 'T')) { north100k += 2000000; if (DEBUG) Debug.output(" northing rolled over 36, adding 200k to " + north100k); }  if ((zone_letter == 'U' && north100k < 5330000) || (zone_letter >= 'V')) { north100k += 2000000; if (DEBUG) Debug.output(" northing rolled over 54, adding 200k to " + north100k); }  if (zone_letter >= 'X') { north100k += 2000000; if (DEBUG) Debug.output(" northing rolled over 72, adding 200k to " + north100k); if (north100k > 9500000) {  north100k -= 2000000; if (DEBUG) Debug.output(" - rolling back to " + north100k); }
    protected void decode(String mgrsString)         throws NumberFormatException {        if (mgrsString == null || mgrsString.length() == 0) {            throw new NumberFormatException("MGRSPoint coverting from nothing");        }        int length = mgrsString.length();        String hunK = null;        String seasting = null;        String snorthing = null;        StringBuffer sb = new StringBuffer();        char testChar;        int i = 0;        // get Zone number        while (!Character.isLetter(testChar = mgrsString.charAt(i))) {            if (i > 2) {                throw new NumberFormatException("MGRSPoint bad conversion from: " + mgrsString);            }            sb.append(testChar);            i++;        }        zone_number = Integer.parseInt(sb.toString());        if (i == 0 || i+3 > length) {            // A good MGRS string has to be 4-5 digits long, ##AAA/#AAA at least.            throw new NumberFormatException("MGRSPoint bad conversion from: " + mgrsString);        }        zone_letter = mgrsString.charAt(i++);        // Should we check the zone letter here?  Why not.        if (zone_letter <= 'A' ||            zone_letter == 'B' ||            zone_letter == 'Y' ||            zone_letter >= 'Z' ||            zone_letter == 'I' ||            zone_letter == 'O') {            throw new NumberFormatException("MGRSPoint zone letter " +                                             (char)zone_letter + " not handled: " +                                             mgrsString);        }        hunK = mgrsString.substring(i, i+=2);        int set =  get100kSetForZone(zone_number);        float east100k = getEastingFromChar(hunK.charAt(0), set);        float north100k = getNorthingFromChar(hunK.charAt(1), set);        // We have a bug where the northing may be 2000000 too low.  How         // do we know when to roll over?  Every 18 degrees. Q - 3, S -        // 5, U - 5, W - 8        if ((zone_letter == 'Q' && north100k < 1700000) ||            (zone_letter >= 'R')) {            north100k += 2000000;            if (DEBUG) Debug.output(" northing rolled over 18, adding 200k to " + north100k);        }        if ((zone_letter == 'S' && north100k < 3000000) ||            (zone_letter >= 'T')) {            north100k += 2000000;            if (DEBUG) Debug.output(" northing rolled over 36, adding 200k to " + north100k);        }        if ((zone_letter == 'U' && north100k < 5330000) ||            (zone_letter >= 'V')) {            north100k += 2000000;            if (DEBUG) Debug.output(" northing rolled over 54, adding 200k to " + north100k);        }        if (zone_letter >= 'X') {            north100k += 2000000;            if (DEBUG) Debug.output(" northing rolled over 72, adding 200k to " + north100k);                   if (north100k > 9500000) {                // There's a tiny sliver of space that does this...                north100k -= 2000000;                if (DEBUG) Debug.output(" - rolling back to " + north100k);            }        }        // calculate the char index for easting/northing separator        int remainder = length - i;        if (remainder%2 != 0) {            throw new NumberFormatException("MGRSPoint has to have an even number \nof digits after the zone letter and two 100km letters - front \nhalf for easting meters, second half for \nnorthing meters" + mgrsString);        }                    int sep = remainder / 2;        float sepEasting = 0f;        float sepNorthing = 0f;        if (sep > 0) {            if (DEBUG) Debug.output(" calculating e/n from " + mgrs.substring(i));            float accuracyBonus = 100000f/(float)Math.pow(10, sep);            if (DEBUG) Debug.output(" calculated accuracy bonus as  " + accuracyBonus);            String sepEastingString = mgrsString.substring(i, i + sep);            if (DEBUG) Debug.output(" parsed easting as " + sepEastingString);            sepEasting = Float.parseFloat(sepEastingString) * accuracyBonus;            String sepNorthingString = mgrsString.substring(i + sep);            if (DEBUG) Debug.output(" parsed northing as " + sepNorthingString);            sepNorthing = Float.parseFloat(sepNorthingString) * accuracyBonus;        }                easting = sepEasting + east100k;        northing = sepNorthing + north100k;        if (DEBUG) {            Debug.output("Decoded " + mgrsString +                          " as zone number: " + zone_number +                          ", zone letter: " + zone_letter +                          ", easting: " + easting +                         ", northing: " + northing      +                          ", 100k: " + hunK);        }    }