ks300avg.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/perl
  2. # Compute Daily and monthly avarage temp/hum/wind and cumulative rain values
  3. # from the "standard" KS300 logs.
  4. # Best to concatenate all KS300-logs into one big file (cat out*.log > big.log)
  5. # and then start the program with ks300avg.pl big.log
  6. # Note: the program assumes that there are no "holes" in the logs.
  7. use strict;
  8. use warnings;
  9. if(@ARGV != 1) {
  10. print "Usage: ks300avg.pl KS300-logfile\n";
  11. exit(1);
  12. }
  13. open(FH, $ARGV[0]) || die("$ARGV[0]: $!\n");
  14. my ($mt, $mh, $mw, $md) = (0,0,0,0);
  15. my ($t, $h, $w) = (0,0,0);
  16. my (@ld, $lsec, $lr, $mr, $ldsec);
  17. my ($dt, $dev, $sec, @a);
  18. while(my $l = <FH>) {
  19. next if($l =~ m/avg/);
  20. chomp $l;
  21. @a = split(" ", $l);
  22. $dev = $a[1];
  23. $dt = $a[0];
  24. my @d = split("[_:-]", $a[0]);
  25. $sec = $d[3]*3600+$d[4]*60+$d[5];
  26. if(!$lsec) {
  27. @ld = @d;
  28. $lr = $a[9];
  29. $mr = $a[9];
  30. $lsec = $ldsec = $sec;
  31. next;
  32. }
  33. my $difft = $sec - $lsec;
  34. $difft += 86400 if($d[2] != $ld[2]);
  35. $lsec = $sec;
  36. $t += $difft * $a[3];
  37. $h += $difft * $a[5];
  38. $w += $difft * $a[7];
  39. $l = <FH>;
  40. if($d[2] != $ld[2]) { # Day changed
  41. my $diff = ($sec - $ldsec) + 86400;
  42. $t /= $diff; $h /= $diff; $w /= $diff;
  43. printf("$dt $dev avg_day T: %.1f H: %d W: %0.1f R: %.1f\n",
  44. $t, $h, $w, $a[9]-$lr);
  45. $lr = $a[9];
  46. $md++;
  47. $mt += $t; $mh += $h; $mw += $w;
  48. $t = $h = $w = 0;
  49. $ldsec = $sec;
  50. }
  51. if($d[1] != $ld[1]) { # Month changed
  52. printf("$dt $dev avg_month T: %.1f H: %d W: %0.1f R: %.1f\n",
  53. $mt/$md, $mh/$md, $mw/$md, $a[9]-$mr);
  54. $mr = $a[9];
  55. $mt = $mh = $mw = $md = 0;
  56. }
  57. @ld = @d;
  58. }
  59. printf("$dt $dev avg_day T: %.1f H: %d W: %0.1f R: %.1f\n",
  60. $t/$sec, $h/$sec, $w/$sec, $a[9]-$lr);
  61. printf("$dt $dev avg_month T: %.1f H: %d W: %0.1f R: %.1f\n",
  62. $mt/$md, $mh/$md, $mw/$md, $a[9]-$mr);