#!/usr/bin/perl
#
# Usage: ./fixtime.pl < met20130503.dat.org > met20130503.dat
#
# Need to do for erie-clv dates: 20130502 thru 20130506
# Valid data starts approx 5/2 2100 GMT
#
# Displays time corrections on STDERR

    use POSIX qw(strftime);
    use Time::Local;

    while ( 1 ) {
        $metline = <STDIN>;
        if ( ! defined( $metline ) ) {
            exit;
        }
        chomp( $metline );

        @metfields = split( /\s+/, $metline );
        if ( scalar @metfields != 13 ) { # check for valid number of fields
            next;
        }

        $year  = $metfields[ 1 ];
        $month = $metfields[ 2 ];
        $day   = $metfields[ 3 ];
        $hour  = $metfields[ 4 ];
        $min   = $metfields[ 5 ];
        $sec   = $metfields[ 6 ];

        print( STDERR "$year/$month/$day $hour:$min:$sec --> " );

        $ctime = timegm( $sec, $min, $hour, $day, $month, $year );

        $ctime += 129524665;

        $timestamp = strftime( "%Y %-m %-d %H %M %S", gmtime( $ctime ) );

        print( STDERR "$timestamp\n" );

        print( $metfields[  0 ], " ", $timestamp, " ",
               $metfields[  7 ], " ", $metfields[  8 ], " ",
               $metfields[  9 ], " ", $metfields[ 10 ], " ",
               $metfields[ 11 ], " ", $metfields[ 12 ], "\n" );
    }
