Generation of glacier IDs for GLIMS: perl code

Bruce Raup braup at nsidc.org
Thu Jun 6 12:13:40 MDT 2002


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.

The output looks something like this:

-24.37826       71.97984        G_W024378S71980
-24.83097       71.97577        G_W024831S71976

etc.

I am sending this for a couple of reasons:

-  This illustrates the format of the GLIMS glacier IDs.  Note that there
   is a typo in the document at
   http://www.GLIMS.org/plan.html#SECTION00032200000000000000.  It should
   say that there are *three* digits after the implied decimal point, not
   four.

   The reason for three decimal points was to set the spacing of the "snap
   grid" for the IDs at around 100 m.  However, as I think about it,
   perhaps the question of how many decimal points should be left up to
   each RC (up to a limit of 4, probably), so that the grid spacing can be
   tailored to each region.  Comments?

   Also, the format now allows (contrary to plan.html) "W" to be used for
   longitudes in the western hemisphere.  The format description is:

     G_[W|E]dddddd[N|S]ddddd

-  This program serves as a reference implementation of an ID generator.

Here's the code.  Note that all the actual work is being done in the last
10 or so lines of the program.

Cheers,
Bruce

-------------------------- cut -------------------------
#!/usr/bin/perl -w
# $Id: lonlat2glims_id,v 1.2 2002-06-06 11:51:26-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.2 $';
($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
  s/\s*#.*$//;          # strip comments off of data lines
  ($lon,$lat) = split;
  $WE = $lon < 0 ? "W" : "E";
  $SN = $lon < 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 -------------------------

-- 
Bruce Raup
National Snow and Ice Data Center                     Phone:  303-492-8814
University of Colorado, 449 UCB                       Fax:    303-492-2468
Boulder, CO  80309-0449                                    braup at nsidc.org





More information about the GLIMS mailing list