]> scm.dxcluster.org Git - dweather.git/commitdiff
saner loop_data opening/closing
authorDirk Koopman <djk@tobit.co.uk>
Sat, 24 Jan 2015 00:14:18 +0000 (00:14 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 24 Jan 2015 00:14:18 +0000 (00:14 +0000)
loop.pl

diff --git a/loop.pl b/loop.pl
index b5e939dd5a3e6cdd5fc1aaafe96cd966f7e03235..4046ca9b95b42dd95f00a8313a4fc588b433563b 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -168,10 +168,6 @@ exit 0;
        
 sub loop
 {
-
-       open $dataf, "+>>", $datafn or die "cannot open $datafn $!";
-       $dataf->autoflush(1);
-       
        read_ld();
        
        dbg "last_min: " . scalar gmtime($ld->{last_min});
@@ -380,6 +376,8 @@ sub process
                if ($dayno > $ld->{last_day}) {
                        $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp;
                        $ld->{last_day} = $dayno;
+                       write_ld();
+                       cycle_loop_data_files();
                }
                $ld->{Temp_Out_Max} = $temp if $temp > $ld->{Temp_Out_Max};
                $ld->{Temp_Out_Min} = $temp if $temp < $ld->{Temp_Out_Min};
@@ -623,7 +621,10 @@ sub calc_rain
 
 sub read_ld
 {
-       return unless $dataf;
+       unless ($dataf) {
+               open $dataf, "+>>", $datafn or die "cannot open $datafn $!";
+               $dataf->autoflush(1);
+       }
 
        seek $dataf, 0, 0;
        my $s = <$dataf>;
@@ -650,7 +651,10 @@ sub read_ld
 
 sub write_ld
 {
-       return unless $dataf;
+       unless ($dataf) {
+               open $dataf, "+>>", $datafn or die "cannot open $datafn $!";
+               $dataf->autoflush(1);
+       }
 
        seek $dataf, 0, 0;
        truncate $dataf, 0;
@@ -662,6 +666,8 @@ sub write_ld
 
 sub cycle_loop_data_files
 {
+       close $dataf if $dataf;
+       
        rename "$datafn.oooo", "$datafn.ooooo";
        rename "$datafn.ooo", "$datafn.oooo";
        rename "$datafn.oo", "$datafn.ooo";