#!/usr/pkg/bin/perl
# reading cbr format from standard input and 
#   output band/time frame matrix.
#  starts 21:00 and ends 20:59 ... hardcoded marked as ####
use strict;

sub print_title {
    print "       ";
    foreach my $f ( qw (35 70 140 210 280 500 )) {
	printf ("%4.1f  ", $f/10);  }
    print "\n";
    print "      ";
    foreach my $f ( qw (35 70 140 210 280 500 )) {
	printf (" %4s ", '----' ); }
    print "\n";    
}
my %DATA;
my $min_step = 15; # 5 10 15 20 30 60
while (<>) {
    if ( ! /^QSO/ ) { next;}
    my @item  = split ' ';
    my $freq = $item[1];
    my $time = $item[4];

    my $freq10 = int ($freq/100);
    my $hour   = int ($time/100);
    my $min    = int (($time - $hour*100)/$min_step);
#    print $freq, ' ' , $time, ' ', $freq10, ' ', $hour, ' ' , $min, "\n";
    if ($hour > 20) { $hour -= 24 }   ###
    $DATA{ sprintf("%02d:%02d", $hour,$min) }{$freq10}++;

}

foreach my $h ( -3..19 ) {
    if ( ($h - 3) %6 == 0 ) { print_title();}
    foreach my $m ( 0.. int(60/$min_step) - 1  ) {
	my $ph = $h;	# print hour
	my $pt;		# print time
	if ($ph < 0 ) { $ph += 24 ;}  ###
	if ($m == 0 ) {
	    $pt = sprintf("%02d:%02d", $ph, $m); }
	else {
	    $pt = sprintf("%2s:%02d", ' ', $m * $min_step); }
	my $t  = sprintf("%02d:%02d", $h, $m);
	
	print $pt, ' ';
	foreach my $f ( qw( 35 70 140 210 280 500 ) ) {
	    if ( $DATA{$t}{$f}) {
		printf ("  %3d ", $DATA{$t}{$f}); }
	    else  {
		printf ("  %3s ", ' ');}
	}
	print "\n";
    }
}
print_title();
__END__
CBR format:
QSO: 28054 CW 2009-04-25 2118 JA1XMS        599 12M           JJ1QTH 599 11
