#!/usr/bin/perl -w
#
#  $Id$
#

use Time::Local;

%months = (
	'Jan' => 0,
	'Feb' => 1,
	'Mar' => 2,
	'Apr' => 3,
	'May' => 4,
	'Jun' => 5,
	'Jul' => 6,
	'Aug' => 7,
	'Sep' => 8,
	'Oct' => 9,
	'Nov' => 10,
	'Dec' => 11
);

my $previous;

my $begin;
my $end;

while (<>) {
    chomp();

    if (!defined($previous)) {
	if (!defined($begin)) {
	    $begin = parsedate($_);
	} else {
	    $previous = $_;
	}
    } else {
	parsedata($previous);
	$previous = $_;
    }
}

if (!defined($previous)) {
    die "what!!! too few lines!\n";
}

$end = parsedate($previous);

$period = ($end - $begin) / scalar(@data);

for $a (0 .. $#data) {
    $time = int($begin + ($period * $a));
    print($time, " ", $data[$a], "\n");
}

sub parsedate {
    my $date = shift(@_);

    #                     month   day     hour   min  sec           year
    #                      $1      $2      $3    $4    $5            $6
    if ($date !~ m/^\S+\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+\S+\s+(\d+)$/){
	die "could not parse date \"$date\"\n";
    }

    if (!exists($months{$1})) {
	die "month \"$1\" is not valid in date string \"$date\"\n";
    }

    return Time::Local::timelocal($5, $4, $3, $2, $months{$1}, $6 - 1900);
}

sub parsedata {
    my $data = shift(@_);

    if (m/^\s*([0-9.]+)\s+([0-9.]+)/) {
	push(@data, $_);
#	push(@kb, $1);
#	push(@tps, $1);
    } else {
	return;
    }
}
