public OSRef(String ref) throws IllegalArgumentException {
  char char1=ref.charAt(0);
  char char2=ref.charAt(1);
  int east=Integer.parseInt(ref.substring(2,5)) * 100;
  int north=Integer.parseInt(ref.substring(5,8)) * 100;
  if (char1 == 'H') {
    north+=1000000;
  }
 else   if (char1 == 'N') {
    north+=500000;
  }
 else   if (char1 == 'O') {
    north+=500000;
    east+=500000;
  }
 else   if (char1 == 'T') {
    east+=500000;
  }
  int char2ord=char2;
  if (char2ord > 73)   char2ord--;
  double nx=((char2ord - 65) % 5) * 100000;
  double ny=(4 - Math.floor((char2ord - 65) / 5)) * 100000;
  easting=east + nx;
  northing=north + ny;
}

public OSRef ( String ref ) throws IllegalArgumentException { char char1 = ref . charAt ( 0 ) ; char char2 = ref . charAt ( 1 ) ; int east = Integer . parseInt ( ref . substring ( 2 , 5 ) ) * 100 ; int north = Integer . parseInt ( ref . substring ( 5 , 8 ) ) * 100 ; if ( char1 == 'H' ) { north += 1000000 ; } else if ( char1 == 'N' ) { north += 500000 ; } else if ( char1 == 'O' ) { north += 500000 ; east += 500000 ; } else if ( char1 == 'T' ) { east += 500000 ; } int char2ord = char2 ; if ( char2ord > 73 ) char2ord -- ; double nx = ( ( char2ord - 65 ) % 5 ) * 100000 ; double ny = ( 4 - Math . floor ( ( char2ord - 65 ) / 5 ) ) * 100000 ; easting = east + nx ; northing = north + ny ; }
take a string formatted as a six - figure os grid reference ( e . g . " tg514131 " ) and create a new osref object that represents that grid reference . the first character must be h , n , s , o or t . the second character can be any uppercase character from a through z excluding i .
