X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FGeomag.pm;h=8b0d2ea7f4cd0933757ed90f6ac68d174ca9bd3b;hb=68a71e7d4cb7bdb19162413094333fb8a0b09bfa;hp=1f77f5671f4114992e32550964fb8c0f6d50870a;hpb=6a0068ec3df1dca0c6ae2714af3c0a4a62998dcf;p=spider.git diff --git a/perl/Geomag.pm b/perl/Geomag.pm index 1f77f567..8b0d2ea7 100644 --- a/perl/Geomag.pm +++ b/perl/Geomag.pm @@ -1,6 +1,7 @@ #!/usr/bin/perl # # The geomagnetic information and calculation module +# a chanfe # # Copyright (c) 1998 - Dirk Koopman G1TLH # @@ -11,17 +12,22 @@ package Geomag; use DXVars; use DXUtil; +use DXLog; +use Julian; use FileHandle; use Carp; use strict; -use vars qw($date $sfi $k $a $forecast @allowed @denied); +use vars qw($date $sfi $k $a $forecast @allowed @denied $fp $node $from); +$fp = 0; # the DXLog fcb $date = 0; # the unix time of the WWV (notional) $sfi = 0; # the current SFI value $k = 0; # the current K value $a = 0; # the current A value $forecast = ""; # the current geomagnetic forecast +$node = ""; # originating node +$from = ""; # who this came from @allowed = (); # if present only these callsigns are regarded as valid WWV updators @denied = (); # if present ignore any wwv from these callsigns my $dirprefix = "$main::data/wwv"; @@ -29,9 +35,10 @@ my $param = "$dirprefix/param"; sub init { - mkdir $dirprefix, 0777 if !-e $dirprefix; - do "$param" if -e "$param"; - confess $@ if $@; + $fp = DXLog::new('wwv', 'dat', 'm'); + mkdir $dirprefix, 0777 if !-e $dirprefix; # now unnecessary DXLog will create it + do "$param" if -e "$param"; + confess $@ if $@; } # write the current data away @@ -44,16 +51,20 @@ sub store print $fh "\$sfi = $sfi;\n"; print $fh "\$a = $a;\n"; print $fh "\$k = $k;\n"; - print $fh "\$forecast = '$forecast';\n"; + print $fh "\$from = '$from';\n"; + print $fh "\$node = '$node';\n"; print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0; print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0; close $fh; + + # log it + $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node"); } # update WWV info in one go (usually from a PC23) sub update { - my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $from, $node) = @_; + my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode) = @_; if ((@allowed && grep {$_ eq $from} @allowed) || (@denied && !grep {$_ eq $from} @denied) || (@allowed == 0 && @denied == 0)) { @@ -64,6 +75,10 @@ sub update $k = 0 + $myk; $a = 0 + $mya; $forecast = $myforecast; + $date = $trydate; + $from = $myfrom; + $node = $mynode; + store(); } } @@ -120,5 +135,95 @@ sub forecast @_ ? $forecast = shift : $forecast ; } +# +# print some items from the log backwards in time +# +# This command outputs a list of n lines starting from line $from to $to +# +sub search +{ + my $from = shift; + my $to = shift; + my @date = $fp->unixtoj(shift); + my $pattern = shift; + my $search; + my @out; + my $eval; + my $count; + + $search = 1; + $eval = qq( + my \$c; + my \$ref; + for (\$c = \$#in; \$c >= 0; \$c--) { + \$ref = \$in[\$c]; + if ($search) { + \$count++; + next if \$count < \$from; + push \@out, \$ref; + last if \$count >= \$to; # stop after n + } + } + ); + + $fp->close; # close any open files + + my $fh = $fp->open(@date); + for ($count = 0; $count < $to; ) { + my @in = (); + if ($fh) { + while (<$fh>) { + chomp; + push @in, [ split '\^' ] if length > 2; + } + eval $eval; # do the search on this file + return ("Geomag search error", $@) if $@; + last if $count >= $to; # stop after n + } + $fh = $fp->openprev(); # get the next file + last if !$fh; + } + + return @out; +} + +# +# the standard log printing interpreting routine. +# +# every line that is printed should call this routine to be actually visualised +# +# Don't really know whether this is the correct place to put this stuff, but where +# else is correct? +# +# I get a reference to an array of items +# +sub print_item +{ + my $r = shift; + my @ref = @$r; + my $d = cldate($ref[1]); + my ($t) = (gmtime($ref[1]))[2]; + + return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]); +} + +# +# read in this month's data +# +sub readfile +{ + my @date = $fp->unixtoj(shift); + my $fh = $fp->open(@date); + my @spots = (); + my @in; + + if ($fh) { + while (<$fh>) { + chomp; + push @in, [ split '\^' ] if length > 2; + } + } + return @in; +} 1; __END__;