#!/usr/pkg/bin/perl
use strict;
# input cbr format from standard input
# and display  zone x freq matrix

my %FREQ;
my %CHECK;
my @ZONE = qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
              21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 
              41 42 43 44 45 46 47 48 49 50 
	      101 102 103 104 105 106 107 108 109 110 111 112 113 114 );

while (<>) {
    if (/^QSO:/ ) {
	my ($qso, $freq, $mode, $date, $gmt, $op, $rst, $tw, $call, $recv, $zone)
	    = split;
	$zone =~ s/PLMH//;
	$freq = int($freq/1000);
	if ($freq == 1 ) { $freq = 1.8;}
	if ($freq == 3 ) { $freq = 3.5;}
	$FREQ{$freq}++;
	$CHECK{$freq,$zone}++; } }

printf "%107s \n", '1 ';
printf "%2s ", ' ';
foreach my $high ( 0 .. 5) { printf "%d                   ", $high;}
print "\n";
printf "%4s ", ' ';
foreach my $high ( 0 .. 6)  {
    foreach my $low ( 1 .. 9, 0) { printf "%d ", $low;
			   if ( $high*10 + $low > 63) { last;}
    }
}
print "\n";

my $multi = 0;
foreach my  $freq ( sort { $a <=> $b } keys %FREQ) {
    my $count = 0;
    printf "%4s ", $freq;
    foreach my $zone ( @ZONE) {
	if ($CHECK{$freq,$zone})  { printf("%s ", 'x'); $count++;}
	else                      { printf("%s ", ' ');}
    }
    printf("%2d \n", $count); $multi += $count;
}
print "multi total = ", $multi,"\n";
