3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
23 use vars qw($date $sfi $k $a $r $forecast @allowed @denied $fp $node $from
25 $duplth $dupage $filterdef);
27 $fp = 0; # the DXLog fcb
28 $date = 0; # the unix time of the WWV (notional)
29 $sfi = 0; # the current SFI value
30 $k = 0; # the current K value
31 $a = 0; # the current A value
32 $r = 0; # the current R value
33 $forecast = ""; # the current geomagnetic forecast
34 $node = ""; # originating node
35 $from = ""; # who this came from
36 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
37 @denied = (); # if present ignore any wwv from these callsigns
38 $duplth = 20; # the length of text to use in the deduping
39 $dupage = 12*3600; # the length of time to hold spot dups
41 $dirprefix = "$main::data/wwv";
42 $param = "$dirprefix/param";
45 # tag, sort, field, priv, special parser
52 ['origin_dxcc', 'nc', 6],
53 ['origin_itu', 'ni', 7],
54 ['origin_zone', 'nz', 8],
59 $fp = DXLog::new('wwv', 'dat', 'm');
60 do "$param" if -e "$param";
64 # write the current data away
67 my $fh = new IO::File;
68 open $fh, "> $param" or confess "can't open $param $!";
69 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
70 print $fh "\$date = $date;\n";
71 print $fh "\$sfi = $sfi;\n";
72 print $fh "\$a = $a;\n";
73 print $fh "\$k = $k;\n";
74 print $fh "\$r = $r;\n";
75 print $fh "\$from = '$from';\n";
76 print $fh "\$node = '$node';\n";
77 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
78 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
82 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node^$r");
85 # update WWV info in one go (usually from a PC23)
88 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
90 if ((@allowed && grep {$_ eq $myfrom} @allowed) ||
91 (@denied && !grep {$_ eq $myfrom} @denied) ||
92 (@allowed == 0 && @denied == 0)) {
94 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
95 if ($mydate > $date) {
99 $r = 0 unless abs ($mysfi - $sfi) > 3;
104 $forecast = $myforecast;
114 # add or substract an allowed callsign
119 push @allowed, map {uc $_} @_;
123 @allowed = map {$_ ne uc $c} @allowed;
129 # add or substract a denied callsign
134 push @denied, map {uc $_} @_;
138 @denied = map {$_ ne uc $c} @denied;
144 # accessor routines (when I work how symbolic refs work I might use one of those!)
147 @_ ? $sfi = shift : $sfi ;
152 @_ ? $k = shift : $k ;
157 @_ ? $r = shift : $r ;
162 @_ ? $a = shift : $a ;
167 @_ ? $forecast = shift : $forecast ;
172 # print some items from the log backwards in time
174 # This command outputs a list of n lines starting from line $from to $to
180 my $date = $fp->unixtoj(shift);
191 for (\$c = \$#in; \$c >= 0; \$c--) {
195 next if \$count < \$from;
197 last if \$count >= \$to; # stop after n
202 $fp->close; # close any open files
204 my $fh = $fp->open($date);
205 for ($count = 0; $count < $to; ) {
210 push @in, [ split '\^' ] if length > 2;
212 eval $eval; # do the search on this file
213 return ("Geomag search error", $@) if $@;
214 last if $count >= $to; # stop after n
216 $fh = $fp->openprev(); # get the next file
224 # the standard log printing interpreting routine.
226 # every line that is printed should call this routine to be actually visualised
228 # Don't really know whether this is the correct place to put this stuff, but where
231 # I get a reference to an array of items
237 my $d = cldate($ref[1]);
238 my ($t) = (gmtime($ref[1]))[2];
240 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
244 # read in this month's data
248 my $date = $fp->unixtoj(shift);
249 my $fh = $fp->open($date);
256 push @in, [ split '\^' ] if length > 2;
262 # enter the spot for dup checking and return true if it is already a dup
265 my ($d, $sfi, $k, $a, $text, $call) = @_;
268 return 2 if $d < $main::systime - $dupage;
270 my $dupkey = "W$d|$sfi|$k|$a|$call";
271 return DXDupe::check($dupkey, $main::systime+$dupage);
276 return DXDupe::listdups('W', $dupage, @_);