protected String latlong2GEOREF(double latitude,double longitude){
  int i;
  char tmp='A';
  char tmp1='A';
  char tmp2='A';
  int tmpi, tmpi1, tmpi2;
  LatLonPoint llp=new LatLonPoint.Double(latitude,longitude);
  DMSLatLonPoint dmsp=new DMSLatLonPoint(llp);
  char[] GEOSTRING=new char[6];
  if (longitude == 0.0000) {
    tmp='N';
    tmp1='A';
    tmp2='0';
  }
 else   if (longitude == -180.0000) {
    tmp='A';
    tmp1='A';
    tmp2='0';
  }
 else   if (longitude == 180.0000) {
    tmp='Z';
    tmp1='Q';
    tmp2='9';
  }
 else   if (longitude > 0.0000) {
    tmpi=dmsp.lon_degrees / 15;
    tmpi+=78;
    if (tmpi >= 79) {
      tmpi+=1;
    }
    if (tmpi > 90) {
      tmpi=90;
    }
    tmp=(char)tmpi;
    for (i=0; i * 15 < (int)(longitude + 0.9999); i++) {
    }
    tmpi1=15 * i - (int)(longitude);
    if ((tmpi1 >= 3) && (tmpi1 < 8)) {
      tmpi1+=1;
    }
 else     if (tmpi1 >= 8) {
      tmpi1+=2;
    }
    if (tmpi1 != 0) {
      tmpi1=82 - tmpi1;
      tmp1=(char)tmpi1;
    }
 else {
      tmp1='A';
    }
    if (tmp1 == 'R') {
      tmp1='A';
    }
    tmpi2=(int)('0') + (dmsp.lon_minutes / 10);
    tmp2=(char)tmpi2;
  }
 else   if (longitude <= 0.0000) {
    tmpi=(int)(((double)dmsp.lon_degrees) / 15.0 - 0.999);
    tmpi=77 - Math.abs(tmpi);
    if (tmpi >= 73) {
      tmpi+=1;
    }
    if (tmpi > 77) {
      tmpi=77;
    }
    tmp=(char)tmpi;
    for (i=0; i * 15 < (int)(Math.abs((longitude - 0.9999))); i++) {
    }
    tmpi1=i * 15 - (int)(Math.abs((longitude - 0.9999)));
    if ((tmpi1 >= 8) && (tmpi1 < 13)) {
      tmpi1+=1;
    }
 else     if (tmpi1 >= 13) {
      tmpi1+=2;
    }
    if (tmpi1 > 16) {
      tmpi1=16;
    }
    tmpi1+=65;
    tmp1=(char)tmpi1;
    if ((int)(dmsp.lon_minutes / 10) != 0) {
      tmpi2=((int)'0') + (6 - (int)(dmsp.lon_minutes / 10));
      tmp2=(char)tmpi2;
    }
 else {
      tmp2='0';
    }
  }
  GEOSTRING[0]=tmp;
  GEOSTRING[2]=tmp1;
  GEOSTRING[4]=tmp2;
  if (latitude == 0.0000) {
    tmp='G';
    tmp1='A';
    tmp2='0';
  }
 else   if (latitude == 90.0000) {
    tmp='M';
    tmp1='Q';
    tmp2='9';
  }
 else   if (latitude == -90.0000) {
    tmp='A';
    tmp1='A';
    tmp2='0';
  }
 else   if (latitude > 0.0000) {
    tmpi=dmsp.lat_degrees / 15;
    tmpi+=71;
    if (tmpi >= 73) {
      tmpi+=1;
    }
    if (tmpi > 77) {
      tmpi=77;
    }
    tmp=(char)tmpi;
    for (i=0; i * 15 < (int)(latitude + 0.9999); i++) {
    }
    tmpi1=15 * i - (int)(latitude);
    if ((tmpi1 >= 3) && (tmpi1 < 8)) {
      tmpi1+=1;
    }
 else     if (tmpi1 >= 8) {
      tmpi1+=2;
    }
    tmpi1=82 - tmpi1;
    tmp1=(char)tmpi1;
    if (tmp1 == 'R') {
      tmp1='A';
    }
    if ((dmsp.lat_minutes / 10) != 0) {
      tmpi2=((int)'0') + (int)(dmsp.lat_minutes / 10);
      tmp2=(char)tmpi2;
    }
 else {
      tmp2='0';
    }
  }
 else   if (latitude < 0.0000) {
    tmpi=(int)((double)dmsp.lat_degrees / 15.0 - 0.999);
    tmpi=71 - Math.abs(tmpi);
    if (tmpi < 65) {
      tmpi=65;
    }
    for (i=0; i * 15 < (int)(Math.abs((latitude - 0.9999))); i++) {
    }
    tmpi1=i * 15 - (int)(Math.abs((latitude - 0.9999)));
    if ((tmpi1 >= 8) && (tmpi1 < 13)) {
      tmpi1+=1;
    }
 else     if (tmpi1 >= 13) {
      tmpi1+=2;
    }
    if (tmpi1 > 16) {
      tmpi1=16;
    }
    tmpi1=65 + tmpi1;
    tmp1=(char)tmpi1;
    tmpi2=((int)'0') + (6 - (int)(dmsp.lat_minutes / 10));
    tmp2=(char)tmpi2;
  }
  GEOSTRING[1]=tmp;
  GEOSTRING[3]=tmp1;
  GEOSTRING[5]=tmp2;
  String ret=new String(GEOSTRING);
  if (Debug.debugging("maketocdetail")) {
    Debug.output("latlon2GEOREF: lat = " + latitude + ", lon = "+ longitude+ ", GEOREF = "+ ret);
  }
  return ret;
}

protected String latlong2GEOREF ( double latitude , double longitude ) { int i ; char tmp = 'A' ; char tmp1 = 'A' ; char tmp2 = 'A' ; int tmpi , tmpi1 , tmpi2 ; LatLonPoint llp = new LatLonPoint . Double ( latitude , longitude ) ; DMSLatLonPoint dmsp = new DMSLatLonPoint ( llp ) ; char [ ] GEOSTRING = new char [ 6 ] ; if ( longitude == 0.0000 ) { tmp = 'N' ; tmp1 = 'A' ; tmp2 = '0' ; } else if ( longitude == - 180.0000 ) { tmp = 'A' ; tmp1 = 'A' ; tmp2 = '0' ; } else if ( longitude == 180.0000 ) { tmp = 'Z' ; tmp1 = 'Q' ; tmp2 = '9' ; } else if ( longitude > 0.0000 ) { tmpi = dmsp . lon_degrees / 15 ; tmpi += 78 ; if ( tmpi >= 79 ) { tmpi += 1 ; } if ( tmpi > 90 ) { tmpi = 90 ; } tmp = ( char ) tmpi ; for ( i = 0 ; i * 15 < ( int ) ( longitude + 0.9999 ) ; i ++ ) { } tmpi1 = 15 * i - ( int ) ( longitude ) ; if ( ( tmpi1 >= 3 ) && ( tmpi1 < 8 ) ) { tmpi1 += 1 ; } else if ( tmpi1 >= 8 ) { tmpi1 += 2 ; } if ( tmpi1 != 0 ) { tmpi1 = 82 - tmpi1 ; tmp1 = ( char ) tmpi1 ; } else { tmp1 = 'A' ; } if ( tmp1 == 'R' ) { tmp1 = 'A' ; } tmpi2 = ( int ) ( '0' ) + ( dmsp . lon_minutes / 10 ) ; tmp2 = ( char ) tmpi2 ; } else if ( longitude <= 0.0000 ) { tmpi = ( int ) ( ( ( double ) dmsp . lon_degrees ) / 15.0 - 0.999 ) ; tmpi = 77 - Math . abs ( tmpi ) ; if ( tmpi >= 73 ) { tmpi += 1 ; } if ( tmpi > 77 ) { tmpi = 77 ; } tmp = ( char ) tmpi ; for ( i = 0 ; i * 15 < ( int ) ( Math . abs ( ( longitude - 0.9999 ) ) ) ; i ++ ) { } tmpi1 = i * 15 - ( int ) ( Math . abs ( ( longitude - 0.9999 ) ) ) ; if ( ( tmpi1 >= 8 ) && ( tmpi1 < 13 ) ) { tmpi1 += 1 ; } else if ( tmpi1 >= 13 ) { tmpi1 += 2 ; } if ( tmpi1 > 16 ) { tmpi1 = 16 ; } tmpi1 += 65 ; tmp1 = ( char ) tmpi1 ; if ( ( int ) ( dmsp . lon_minutes / 10 ) != 0 ) { tmpi2 = ( ( int ) '0' ) + ( 6 - ( int ) ( dmsp . lon_minutes / 10 ) ) ; tmp2 = ( char ) tmpi2 ; } else { tmp2 = '0' ; } } GEOSTRING [ 0 ] = tmp ; GEOSTRING [ 2 ] = tmp1 ; GEOSTRING [ 4 ] = tmp2 ; if ( latitude == 0.0000 ) { tmp = 'G' ; tmp1 = 'A' ; tmp2 = '0' ; } else if ( latitude == 90.0000 ) { tmp = 'M' ; tmp1 = 'Q' ; tmp2 = '9' ; } else if ( latitude == - 90.0000 ) { tmp = 'A' ; tmp1 = 'A' ; tmp2 = '0' ; } else if ( latitude > 0.0000 ) { tmpi = dmsp . lat_degrees / 15 ; tmpi += 71 ; if ( tmpi >= 73 ) { tmpi += 1 ; } if ( tmpi > 77 ) { tmpi = 77 ; } tmp = ( char ) tmpi ; for ( i = 0 ; i * 15 < ( int ) ( latitude + 0.9999 ) ; i ++ ) { } tmpi1 = 15 * i - ( int ) ( latitude ) ; if ( ( tmpi1 >= 3 ) && ( tmpi1 < 8 ) ) { tmpi1 += 1 ; } else if ( tmpi1 >= 8 ) { tmpi1 += 2 ; } tmpi1 = 82 - tmpi1 ; tmp1 = ( char ) tmpi1 ; if ( tmp1 == 'R' ) { tmp1 = 'A' ; } if ( ( dmsp . lat_minutes / 10 ) != 0 ) { tmpi2 = ( ( int ) '0' ) + ( int ) ( dmsp . lat_minutes / 10 ) ; tmp2 = ( char ) tmpi2 ; } else { tmp2 = '0' ; } } else if ( latitude < 0.0000 ) { tmpi = ( int ) ( ( double ) dmsp . lat_degrees / 15.0 - 0.999 ) ; tmpi = 71 - Math . abs ( tmpi ) ; if ( tmpi < 65 ) { tmpi = 65 ; } for ( i = 0 ; i * 15 < ( int ) ( Math . abs ( ( latitude - 0.9999 ) ) ) ; i ++ ) { } tmpi1 = i * 15 - ( int ) ( Math . abs ( ( latitude - 0.9999 ) ) ) ; if ( ( tmpi1 >= 8 ) && ( tmpi1 < 13 ) ) { tmpi1 += 1 ; } else if ( tmpi1 >= 13 ) { tmpi1 += 2 ; } if ( tmpi1 > 16 ) { tmpi1 = 16 ; } tmpi1 = 65 + tmpi1 ; tmp1 = ( char ) tmpi1 ; tmpi2 = ( ( int ) '0' ) + ( 6 - ( int ) ( dmsp . lat_minutes / 10 ) ) ; tmp2 = ( char ) tmpi2 ; } GEOSTRING [ 1 ] = tmp ; GEOSTRING [ 3 ] = tmp1 ; GEOSTRING [ 5 ] = tmp2 ; String ret = new String ( GEOSTRING ) ; if ( Debug . debugging ( "maketocdetail" ) ) { Debug . output ( "latlon2GEOREF: lat = " + latitude + ", lon = " + longitude + ", GEOREF = " + ret ) ; } return ret ; }
this program attempts to convert latitudes and longitudes given in a decimal format into a georef alphanumeric designation code . the first letter of the code denotes the longitudinal 15 degree grid that contains the area of interest . the second letter denotes the latitudinal 15 degree grid . the third letter denotes the one degree longitudinal grid within the 15 degree longitudinal grid . the fourth letter denotes the one degree latitudinal grid within the 15 degree latitudinal grid . the fifth character is a number denoting the minutes longitudinally to the nearest 10 . the sixth number denotes the minutes latitudinally to the nearest 10 . wouldn ' t it just have been easier to use the decimal latitudes and longitudes ?
