3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
23 use vars qw($VERSION $BRANCH);
24 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
25 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
26 $main::build += $VERSION;
27 $main::branch += $BRANCH;
29 use vars qw($date $sfi $k $a $r $forecast @allowed @denied $fp $node $from
31 $duplth $dupage $filterdef);
33 $fp = 0; # the DXLog fcb
34 $date = 0; # the unix time of the WWV (notional)
35 $sfi = 0; # the current SFI value
36 $k = 0; # the current K value
37 $a = 0; # the current A value
38 $r = 0; # the current R value
39 $forecast = ""; # the current geomagnetic forecast
40 $node = ""; # originating node
41 $from = ""; # who this came from
42 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
43 @denied = (); # if present ignore any wwv from these callsigns
44 $duplth = 20; # the length of text to use in the deduping
45 $dupage = 12*3600; # the length of time to hold spot dups
47 $dirprefix = "$main::data/wwv";
48 $param = "$dirprefix/param";
51 # tag, sort, field, priv, special parser
55 ['by_dxcc', 'nc', 10],
57 ['by_zone', 'nz', 12],
58 ['origin_dxcc', 'nc', 13],
59 ['origin_itu', 'ni', 14],
60 ['origin_zone', 'nz', 15],
65 $fp = DXLog::new('wwv', 'dat', 'm');
66 do "$param" if -e "$param";
70 # write the current data away
73 my $fh = new IO::File;
74 open $fh, "> $param" or confess "can't open $param $!";
75 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
76 print $fh "\$date = $date;\n";
77 print $fh "\$sfi = $sfi;\n";
78 print $fh "\$a = $a;\n";
79 print $fh "\$k = $k;\n";
80 print $fh "\$r = $r;\n";
81 print $fh "\$from = '$from';\n";
82 print $fh "\$node = '$node';\n";
83 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
84 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
88 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node^$r");
91 # update WWV info in one go (usually from a PC23)
94 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
96 if ((@allowed && grep {$_ eq $myfrom} @allowed) ||
97 (@denied && !grep {$_ eq $myfrom} @denied) ||
98 (@allowed == 0 && @denied == 0)) {
100 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
101 if ($mydate >= $date) {
105 $r = 0 unless abs ($mysfi - $sfi) > 3;
110 $forecast = $myforecast;
120 # add or substract an allowed callsign
125 push @allowed, map {uc $_} @_;
129 @allowed = map {$_ ne uc $c} @allowed;
135 # add or substract a denied callsign
140 push @denied, map {uc $_} @_;
144 @denied = map {$_ ne uc $c} @denied;
150 # accessor routines (when I work how symbolic refs work I might use one of those!)
153 @_ ? $sfi = shift : $sfi ;
158 @_ ? $k = shift : $k ;
163 @_ ? $r = shift : $r ;
168 @_ ? $a = shift : $a ;
173 @_ ? $forecast = shift : $forecast ;
178 # print some items from the log backwards in time
180 # This command outputs a list of n lines starting from line $from to $to
186 my $date = $fp->unixtoj(shift);
197 for (\$c = \$#in; \$c >= 0; \$c--) {
201 next if \$count < \$from;
203 last if \$count >= \$to; # stop after n
208 $fp->close; # close any open files
210 my $fh = $fp->open($date);
211 for ($count = 0; $count < $to; ) {
216 push @in, [ split '\^' ] if length > 2;
218 eval $eval; # do the search on this file
219 return ("Geomag search error", $@) if $@;
220 last if $count >= $to; # stop after n
222 $fh = $fp->openprev(); # get the next file
230 # the standard log printing interpreting routine.
232 # every line that is printed should call this routine to be actually visualised
234 # Don't really know whether this is the correct place to put this stuff, but where
237 # I get a reference to an array of items
243 my $d = cldate($ref[1]);
244 my ($t) = (gmtime($ref[1]))[2];
246 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
250 # read in this month's data
254 my $date = $fp->unixtoj(shift);
255 my $fh = $fp->open($date);
262 push @in, [ split '\^' ] if length > 2;
268 # enter the spot for dup checking and return true if it is already a dup
271 my ($d, $sfi, $k, $a, $text) = @_;
274 return 2 if $d < $main::systime - $dupage;
276 my $dupkey = "W$d|$sfi|$k|$a";
277 return DXDupe::check($dupkey, $main::systime+$dupage);
282 return DXDupe::listdups('W', $dupage, @_);