3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw($date $sfi $k $a $r $forecast @allowed @denied $fp $node $from);
23 $fp = 0; # the DXLog fcb
24 $date = 0; # the unix time of the WWV (notional)
25 $sfi = 0; # the current SFI value
26 $k = 0; # the current K value
27 $a = 0; # the current A value
28 $r = 0; # the current R value
29 $forecast = ""; # the current geomagnetic forecast
30 $node = ""; # originating node
31 $from = ""; # who this came from
32 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
33 @denied = (); # if present ignore any wwv from these callsigns
34 my $dirprefix = "$main::data/wwv";
35 my $param = "$dirprefix/param";
39 $fp = DXLog::new('wwv', 'dat', 'm');
40 mkdir $dirprefix, 0777 if !-e $dirprefix; # now unnecessary DXLog will create it
41 do "$param" if -e "$param";
45 # write the current data away
48 my $fh = new IO::File;
49 open $fh, "> $param" or confess "can't open $param $!";
50 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
51 print $fh "\$date = $date;\n";
52 print $fh "\$sfi = $sfi;\n";
53 print $fh "\$a = $a;\n";
54 print $fh "\$k = $k;\n";
55 print $fh "\$r = $r;\n";
56 print $fh "\$from = '$from';\n";
57 print $fh "\$node = '$node';\n";
58 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
59 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
63 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node^$r");
66 # update WWV info in one go (usually from a PC23)
69 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
70 if ((@allowed && grep {$_ eq $from} @allowed) ||
71 (@denied && !grep {$_ eq $from} @denied) ||
72 (@allowed == 0 && @denied == 0)) {
74 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
75 if ($mydate >= $date) {
77 $r = 0 + $myr unless !$r && $myk == $k;
80 $forecast = $myforecast;
90 # add or substract an allowed callsign
95 push @allowed, map {uc $_} @_;
99 @allowed = map {$_ ne uc $c} @allowed;
105 # add or substract a denied callsign
110 push @denied, map {uc $_} @_;
114 @denied = map {$_ ne uc $c} @denied;
120 # accessor routines (when I work how symbolic refs work I might use one of those!)
123 @_ ? $sfi = shift : $sfi ;
128 @_ ? $k = shift : $k ;
133 @_ ? $r = shift : $r ;
138 @_ ? $a = shift : $a ;
143 @_ ? $forecast = shift : $forecast ;
148 # print some items from the log backwards in time
150 # This command outputs a list of n lines starting from line $from to $to
156 my @date = $fp->unixtoj(shift);
167 for (\$c = \$#in; \$c >= 0; \$c--) {
171 next if \$count < \$from;
173 last if \$count >= \$to; # stop after n
178 $fp->close; # close any open files
180 my $fh = $fp->open(@date);
181 for ($count = 0; $count < $to; ) {
186 push @in, [ split '\^' ] if length > 2;
188 eval $eval; # do the search on this file
189 return ("Geomag search error", $@) if $@;
190 last if $count >= $to; # stop after n
192 $fh = $fp->openprev(); # get the next file
200 # the standard log printing interpreting routine.
202 # every line that is printed should call this routine to be actually visualised
204 # Don't really know whether this is the correct place to put this stuff, but where
207 # I get a reference to an array of items
213 my $d = cldate($ref[1]);
214 my ($t) = (gmtime($ref[1]))[2];
216 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
220 # read in this month's data
224 my @date = $fp->unixtoj(shift);
225 my $fh = $fp->open(@date);
232 push @in, [ split '\^' ] if length > 2;