
On 2002-06-06 12:13 -0600, Bruce Raup wrote:
Hi all,
I've just written a short perl program to convert a list of longitude,latitude to GLIMS glacier IDs, and have included it below.
Okay, next time I'll sit on it for a day. Below is the correct version, that gets the north/south bit right. Bruce -------------------------- cut ------------------------- #!/usr/bin/perl -w # $Id: lonlat2glims_id,v 1.3 2002-06-06 14:28:19-06 braup Exp braup $ # Program to take a list of lon/lat values as input (filename on the # command line or as standard input) and generate GLIMS glacier IDs, # printed to standard output. ($progname = $0) =~ s!^.*/!!; # get basename of program use Getopt::Std; $version = '$Revision: 1.3 $'; ($version) = $version =~ /^\$Revision:\s*(\d+\.\d*)/; $usage = "$progname version $version Usage: $progname -h (prints this help message and exits) OR $progname [-v] [lon_lat_filename] where -v specifies verbose mode If no files are specified on the command line, then standard input is read. This routine assumes all lon/lat values are within normal ranges (for now). The input file is expected to have two columns, in lon lat order. Comments are allowed, and are preceded by a '#' character. "; $opt_h = $opt_v = ''; if (! getopts('hv') ) { die "$usage\n"; } print "$progname version $version\n" if $opt_v; die "$usage\n" if $opt_h; while (<>) { next if /^\s*#/; # skip comments next if /^\s*$/; # skip blank lines s/\s*#.*$//; # strip comments off of data lines ($lon,$lat) = split; $WE = $lon < 0 ? "W" : "E"; $SN = $lat < 0 ? "S" : "N"; $alon = abs($lon); $alat = abs($lat); $id = sprintf( "G_$WE%07.3f$SN%06.3f", $alon, $alat ); $id =~ s/\.//g; print "$lon\t$lat\t$id\n"; } -------------------------- cut -------------------------