From: Dirk Koopman Date: Sat, 24 Jan 2015 00:14:18 +0000 (+0000) Subject: saner loop_data opening/closing X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=104d1371435741ced5e3fe8f78f352865505133c;p=dweather.git saner loop_data opening/closing --- diff --git a/loop.pl b/loop.pl index b5e939d..4046ca9 100755 --- 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";