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::local_data/wwv";
42 $param = "$dirprefix/param";
49 # tag, sort, field, priv, special parser
56 ['origin_dxcc', 'nc', 6],
57 ['origin_itu', 'ni', 7],
58 ['origin_zone', 'nz', 8],
63 $fp = DXLog::new('wwv', 'dat', 'm');
64 do "$param" if -e "$param";
65 # read in existing data
66 @cache = readfile($main::systime);
67 shift @cache while @cache > $maxcache;
68 dbg(sprintf "WWV read in last %d records into cache", scalar @cache);
72 # write the current data away
75 my $fh = new IO::File;
76 open $fh, "> $param" or confess "can't open $param $!";
77 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
78 print $fh "\$date = $date;\n";
79 print $fh "\$sfi = $sfi;\n";
80 print $fh "\$a = $a;\n";
81 print $fh "\$k = $k;\n";
82 print $fh "\$r = $r;\n";
83 print $fh "\$from = '$from';\n";
84 print $fh "\$node = '$node';\n";
85 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
86 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
90 my $s ="$from^$date^$sfi^$a^$k^$forecast^$node^$r";
91 $fp->writeunix($date, $s);
92 push @cache, [ split /\^/, $s ];
93 shift @cache while @cache > $maxcache;
96 # update WWV info in one go (usually from a PC23)
99 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
100 $myfrom =~ s/-\d+$//;
101 if ((@allowed && grep {$_ eq $myfrom} @allowed) ||
102 (@denied && !grep {$_ eq $myfrom} @denied) ||
103 (@allowed == 0 && @denied == 0)) {
105 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
106 if ($mydate > $date) {
110 $r = 0 unless abs ($mysfi - $sfi) > 3;
115 $forecast = $myforecast;
125 # add or substract an allowed callsign
130 push @allowed, map {uc $_} @_;
134 @allowed = map {$_ ne uc $c} @allowed;
140 # add or substract a denied callsign
145 push @denied, map {uc $_} @_;
149 @denied = map {$_ ne uc $c} @denied;
155 # accessor routines (when I work how symbolic refs work I might use one of those!)
158 @_ ? $sfi = shift : $sfi ;
163 @_ ? $k = shift : $k ;
168 @_ ? $r = shift : $r ;
173 @_ ? $a = shift : $a ;
178 @_ ? $forecast = shift : $forecast ;
183 # print some items from the log backwards in time
185 # This command outputs a list of n lines starting from line $from to $to
192 my $date = $fp->unixtoj($t);
199 if ($t == $main::systime && ($to <= $maxcache)) {
200 dbg("using wwv cache") if isdbg('wwv');
201 @out = reverse @cache;
202 pop @out while @out > $to;
204 dbg("using wwv file(s))") if isdbg('wwv');
209 for (\$c = \$#in; \$c >= 0; \$c--) {
213 next if \$count < \$from;
215 last if \$count >= \$to; # stop after n
220 $fp->close; # close any open files
222 my $fh = $fp->open($date);
223 for ($count = 0; $count < $to; ) {
228 push @in, [ split '\^' ] if length > 2;
230 eval $eval; # do the search on this file
231 return ("Geomag search error", $@) if $@;
232 last if $count >= $to; # stop after n
234 $fh = $fp->openprev(); # get the next file
243 # the standard log printing interpreting routine.
245 # every line that is printed should call this routine to be actually visualised
247 # Don't really know whether this is the correct place to put this stuff, but where
250 # I get a reference to an array of items
256 my $d = cldate($ref[1]);
257 my ($t) = (gmtime($ref[1]))[2];
259 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
263 # read in this month's data
267 my $date = $fp->unixtoj(shift);
268 my $fh = $fp->open($date);
275 push @in, [ split '\^' ] if length > 2;
281 # enter the spot for dup checking and return true if it is already a dup
284 my ($d, $sfi, $k, $a, $text, $call) = @_;
287 return 2 if $d < $main::systime - $dupage;
289 my $dupkey = "W$d|$sfi|$k|$a|$call";
290 return DXDupe::check($dupkey, $main::systime+$dupage);
295 return DXDupe::listdups('W', $dupage, @_);