#!/usr/bin/perl -w

use strict;

for my $file (@ARGV) {
    if( !open( IN, "<$file" ) ) {
        print STDERR "Could not open $file for reading: $!\n";
        next;
    }
    local $/= 20;
    my $head= <IN>;
    close IN;
    my ($magic, $ntiles, $minx, $miny, $zoom)= unpack("a4L4", $head);
    print "$file:\n";
    print "Magic mismatch!  ", join(" ", map ord($_), split //, $magic), "\n"
        unless $magic eq "META";
    my $metamul= int(sqrt($ntiles));
    print "Tile count $ntiles is not a square!\n"
        unless $ntiles == $metamul*$metamul;
    print "x:    $minx .. ", $minx+$metamul-1, "\ny:    $miny .. ", $miny+$metamul-1, "\nzoom: $zoom\n";
}

