3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
20 use Time::HiRes qw(gettimeofday tv_interval);
24 use vars qw($date $sfi $k $a $r $forecast @allowed @denied $fp $node $from
26 $duplth $dupage $filterdef);
28 $fp = 0; # the DXLog fcb
29 $date = 0; # the unix time of the WWV (notional)
30 $sfi = 0; # the current SFI value
31 $k = 0; # the current K value
32 $a = 0; # the current A value
33 $r = 0; # the current R value
34 $forecast = ""; # the current geomagnetic forecast
35 $node = ""; # originating node
36 $from = ""; # who this came from
37 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
38 @denied = (); # if present ignore any wwv from these callsigns
39 $duplth = 20; # the length of text to use in the deduping
40 $dupage = 12*3600; # the length of time to hold spot dups
42 $dirprefix = "$main::local_data/wwv";
43 $param = "$dirprefix/param";
50 # tag, sort, field, priv, special parser
57 ['origin_dxcc', 'nc', 6],
58 ['origin_itu', 'ni', 7],
59 ['origin_zone', 'nz', 8],
64 $fp = DXLog::new('wwv', 'dat', 'm');
65 do "$param" if -e "$param";
66 # read in existing data
67 my $t0 = [gettimeofday];
68 @cache = readfile($main::systime);
69 shift @cache while @cache > $maxcache;
70 dbg(sprintf "WWV read in last %d records into cache in %dmS", scalar @cache, _diffms($t0));
74 # write the current data away
77 my $fh = new IO::File;
78 open $fh, "> $param" or confess "can't open $param $!";
79 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
80 print $fh "\$date = $date;\n";
81 print $fh "\$sfi = $sfi;\n";
82 print $fh "\$a = $a;\n";
83 print $fh "\$k = $k;\n";
84 print $fh "\$r = $r;\n";
85 print $fh "\$from = '$from';\n";
86 print $fh "\$node = '$node';\n";
87 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
88 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
92 my $s ="$from^$date^$sfi^$a^$k^$forecast^$node^$r";
93 $fp->writeunix($date, $s);
94 push @cache, [ split /\^/, $s ];
95 shift @cache while @cache > $maxcache;
98 # update WWV info in one go (usually from a PC23)
101 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
102 $myfrom =~ s/-\d+$//;
103 if ((@allowed && grep {$_ eq $myfrom} @allowed) ||
104 (@denied && !grep {$_ eq $myfrom} @denied) ||
105 (@allowed == 0 && @denied == 0)) {
107 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
108 if ($mydate > $date) {
112 $r = 0 unless abs ($mysfi - $sfi) > 3;
117 $forecast = $myforecast;
127 # add or substract an allowed callsign
132 push @allowed, map {uc $_} @_;
136 @allowed = map {$_ ne uc $c} @allowed;
142 # add or substract a denied callsign
147 push @denied, map {uc $_} @_;
151 @denied = map {$_ ne uc $c} @denied;
157 # accessor routines (when I work how symbolic refs work I might use one of those!)
160 @_ ? $sfi = shift : $sfi ;
165 @_ ? $k = shift : $k ;
170 @_ ? $r = shift : $r ;
175 @_ ? $a = shift : $a ;
180 @_ ? $forecast = shift : $forecast ;
185 # print some items from the log backwards in time
187 # This command outputs a list of n lines starting from line $from to $to
194 my $date = $fp->unixtoj($t);
201 if ($t == $main::systime && ($to <= $maxcache)) {
202 dbg("using wwv cache") if isdbg('wwv');
203 @out = reverse @cache;
204 pop @out while @out > $to;
206 dbg("using wwv file(s))") if isdbg('wwv');
211 for (\$c = \$#in; \$c >= 0; \$c--) {
215 next if \$count < \$from;
217 last if \$count >= \$to; # stop after n
222 $fp->close; # close any open files
224 my $fh = $fp->open($date);
225 for ($count = 0; $count < $to; ) {
230 push @in, [ split '\^' ] if length > 2;
232 eval $eval; # do the search on this file
233 return ("Geomag search error", $@) if $@;
234 last if $count >= $to; # stop after n
236 $fh = $fp->openprev(); # get the next file
245 # the standard log printing interpreting routine.
247 # every line that is printed should call this routine to be actually visualised
249 # Don't really know whether this is the correct place to put this stuff, but where
252 # I get a reference to an array of items
258 my $d = cldate($ref[1]);
259 my ($t) = (gmtime($ref[1]))[2];
261 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
265 # read in this month's data
269 my $date = $fp->unixtoj(shift);
270 my $fh = $fp->open($date);
277 push @in, [ split '\^' ] if length > 2;
283 # enter the spot for dup checking and return true if it is already a dup
286 my ($d, $sfi, $k, $a, $text, $call) = @_;
289 return 2 if $d < $main::systime - $dupage;
291 my $dupkey = "W$d|$sfi|$k|$a|$call";
292 return DXDupe::check($dupkey, $main::systime+$dupage);
297 return DXDupe::listdups('W', $dupage, @_);