3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw($date $sfi $k $a $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 $forecast = ""; # the current geomagnetic forecast
29 $node = ""; # originating node
30 $from = ""; # who this came from
31 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
32 @denied = (); # if present ignore any wwv from these callsigns
33 my $dirprefix = "$main::data/wwv";
34 my $param = "$dirprefix/param";
38 $fp = DXLog::new('wwv', 'dat', 'm');
39 mkdir $dirprefix, 0777 if !-e $dirprefix; # now unnecessary DXLog will create it
40 do "$param" if -e "$param";
44 # write the current data away
47 my $fh = new IO::File;
48 open $fh, "> $param" or confess "can't open $param $!";
49 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
50 print $fh "\$date = $date;\n";
51 print $fh "\$sfi = $sfi;\n";
52 print $fh "\$a = $a;\n";
53 print $fh "\$k = $k;\n";
54 print $fh "\$from = '$from';\n";
55 print $fh "\$node = '$node';\n";
56 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
57 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
61 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node");
64 # update WWV info in one go (usually from a PC23)
67 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode) = @_;
68 if ((@allowed && grep {$_ eq $from} @allowed) ||
69 (@denied && !grep {$_ eq $from} @denied) ||
70 (@allowed == 0 && @denied == 0)) {
72 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
73 if ($mydate >= $date) {
77 $forecast = $myforecast;
87 # add or substract an allowed callsign
92 push @allowed, map {uc $_} @_;
96 @allowed = map {$_ ne uc $c} @allowed;
102 # add or substract a denied callsign
107 push @denied, map {uc $_} @_;
111 @denied = map {$_ ne uc $c} @denied;
117 # accessor routines (when I work how symbolic refs work I might use one of those!)
120 @_ ? $sfi = shift : $sfi ;
125 @_ ? $k = shift : $k ;
130 @_ ? $a = shift : $a ;
135 @_ ? $forecast = shift : $forecast ;
139 # print some items from the log backwards in time
141 # This command outputs a list of n lines starting from line $from to $to
147 my @date = $fp->unixtoj(shift);
158 for (\$c = \$#in; \$c >= 0; \$c--) {
162 next if \$count < \$from;
164 last if \$count >= \$to; # stop after n
169 $fp->close; # close any open files
171 my $fh = $fp->open(@date);
172 for ($count = 0; $count < $to; ) {
177 push @in, [ split '\^' ] if length > 2;
179 eval $eval; # do the search on this file
180 return ("Geomag search error", $@) if $@;
181 last if $count >= $to; # stop after n
183 $fh = $fp->openprev(); # get the next file
191 # the standard log printing interpreting routine.
193 # every line that is printed should call this routine to be actually visualised
195 # Don't really know whether this is the correct place to put this stuff, but where
198 # I get a reference to an array of items
204 my $d = cldate($ref[1]);
205 my ($t) = (gmtime($ref[1]))[2];
207 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
211 # read in this month's data
215 my @date = $fp->unixtoj(shift);
216 my $fh = $fp->open(@date);
223 push @in, [ split '\^' ] if length > 2;