#!/usr/bin/perl -T use strict; use warnings; use utf8; use open qw(:std :utf8); use Encode qw(encode decode); use POSIX qw(strftime); # runs thru my gps altitude data files, and spits out daily averages. # meant to be run from a cron job such like: # min hour mday month wday command # 59 23 * * * ~/projects/gps/gen_day_avg @ARGV = map { decode("UTF-8", $_) } @ARGV; my $num = 0; my $asum = 0; my $esum = 0; my $ydate = strftime "%Y", localtime; my $mdate = strftime "%Y%m", localtime; my $ddate = strftime "%Y%m%d", localtime; my $in_dat_f = "/import/home/ghz/projects/gps/data/$ydate/gps_alt.dat.$ddate"; my $out_dat_f = "/import/home/ghz/projects/gps/data/$ydate/gps_alt.day.avg.$mdate"; open(IN, "<", $in_dat_f) or die "omg! can't open input file: $in_dat_f"; unless (open(OUT, ">>", $out_dat_f)) { close(IN); die "omg! can't open output file: $out_dat_f"; } while () { chomp; my ($x, $a, $b, $y, $c, $d, $e, $z, $f) = split; $num++; $asum+=$y; $esum+=$z; } printf OUT "%s\t%.1f m\t%.1f m\n", $ddate, $asum / $num, $esum / $num; close(IN); close(OUT);