sub loop
{
-
- open $dataf, "+>>", $datafn or die "cannot open $datafn $!";
- $dataf->autoflush(1);
-
read_ld();
dbg "last_min: " . scalar gmtime($ld->{last_min});
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};
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>;
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;
sub cycle_loop_data_files
{
+ close $dataf if $dataf;
+
rename "$datafn.oooo", "$datafn.ooooo";
rename "$datafn.ooo", "$datafn.oooo";
rename "$datafn.oo", "$datafn.ooo";