MiscJunk logo My coordinates
Page banner

.img File Information

Introduction

Using SendMap (or similar utility) to upload maps to Garmin GPS mapping units can be an exercise in chance since it's hard to determine which .img file corresponds to what area. The perl script utility below aids the effort by scanning a directory of .img files and displaying the area/description fields associated with each file.

Usage and Output

The perl script (see below) of course requires perl to be installed and is executed from the command prompt (DOS box) as follows:

C:\> ImgInfo.pl c:\progra~1\cotopo

The output resembles the following:

Processing c:\progra~1\cotopo...

88200001.img        CANYON OF LODORE          COLORADO
88200002.img        CRAIG                     COLORADO
88200003.img        WALDEN                    COLORADO
88200004.img        FORT COLLINS              COLORADO
88200005.img        EATON                     COLORADO
88200006.img        STERLING                  COLORADO
88200007.img        JULESBURG                 COLORADO
88200008.img        RANGELY                   COLORADO
88200009.img        MEEKER                    COLORADO
88200010.img        STEAMBOAT SPRINGS         COLORADO
88200011.img        ESTES PARK                COLORADO
88200012.img        GREELEY                   COLORADO
88200013.img        FORT MORGAN               COLORADO
88200014.img        WRAY                      COLORADO
88200015.img        DOUGLAS PASS              COLORADO
.
.
.
88200052.img        ANTONITO                  COLORADO
88200053.img        ALAMOSA                   COLORADO
88200054.img        TRINIDAD                  COLORADO
88200055.img        KIM                       COLORADO
88200056.img        SPRINGFIELD               COLORADO
COTOPO.img          Preview Map

Listed 57 files.

Output to csv File

A few easy changes to the script will allow you to utilize the information from within a spreadsheet. Simply delete the first and last print statements from the script and change the middle print statement to the following:

printf ("%s,%s,%s\n", $filename, $name, $other);

Run the script and redirect the output to a file:

C:\> ImgInfo.pl c:\progra~1\cotopo > maplist.csv

The resulting file is a csv file which will easliy import into your favorite spreadsheet software:

88200001.img,CANYON OF LODORE,COLORADO
88200002.img,CRAIG,COLORADO
88200003.img,WALDEN,COLORADO
88200004.img,FORT COLLINS,COLORADO
88200005.img,EATON,COLORADO
88200006.img,STERLING,COLORADO
88200007.img,JULESBURG,COLORADO
88200008.img,RANGELY,COLORADO
88200009.img,MEEKER,COLORADO
88200010.img,STEAMBOAT SPRINGS,COLORADO

Perl Script

The perl script is listed below and can also be obtained here.

#
# this scripts reads names/information from img files
#
use IO::Seekable;

my $location = $ARGV[0];

if ($location eq "")
{
  $location = ".";
}

opendir(DIR, $location) or die "Cannot open $location: $!";
my @files = readdir(DIR);
closedir(DIR);

print "\nProcessing $location...\n\n";

my $count = 0;

foreach $filename (@files)
{
  if ($filename =~ /\.img/)
  {
    $count++;

    open(FH, $location . "\\" . $filename) or die "Cannot open $filename: $!";
    binmode(FH);

    seek (FH,73,0);
    read (FH,$tmp1, 20);
    seek (FH,101,0);
    read (FH,$tmp2, 20);

    $test = $tmp1 . $tmp2;
    @ch = split(//, $test);
    $tst = ord $ch[0];

    if ($tst < 32 || $tst > 126)
    {
      $test = "";

      foreach $let (@ch)
      {
        $tst = chr(ord $let ^ (hex '0x96'));
        $test .= $tst;
      }
    }
    ($name, $other) = split (/,/, $test);
    printf ("%-17.17s %-22.22s %-22.22s\n", $filename, $name, $other);

    close(FH);
  }
}
print "\nListed $count files.\n";

exit;

Last updated: 26 January 2008