#!/usr/bin/perl
#
# when.pl : perl script to look at a data file from the active collimator
#           lab view data acquisition program and determine what the time
#           and date was when the data were taken.
#
# Usage:  when.pl < [original_data_file]
#
# Input:  (stdin) lines that look like the following.
#      3259574663.954000	-1.880864	-1.828715
# Output: (stdout) lines that look like the following.
#

use Time::Local;
use Time::Epoch;

%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);
%days   = ('Sun' => 0, 'Mon' => 1, 'Tue' => 2, 'Wed' => 3,
           'Thu' => 4, 'Fri' => 5, 'Sat' => 6);

while (<>) {
   chop $_;
   my @fields = split(' ',$_);
   next if (@fields < 3);
   my $time = epoch2perl($fields[0],'macos','-0000');
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
   printf("%d:%d:%d %s %s %s\n",$hour,$min,$sec,$mday,$mon,$year);
}

#gawk -F"[\055,\040,:,\011]" '{if (NF==12) {\
#                                 printf("%d   %s %s %s %s %s\n",\
#                                     mktime("2007 04 16 "$4+5" "$5" "$6)\
#                                    -mktime("1970 01 01 00 00 00")\
#                                    +2082841400,$8,$9,$10,$11,$12);\
#                              }\
#                             }'
