3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw($date $sfi $k $a $r $forecast @allowed @denied $fp $node $from
23 %dup $duplth $dupage);
25 $fp = 0; # the DXLog fcb
26 $date = 0; # the unix time of the WWV (notional)
27 $sfi = 0; # the current SFI value
28 $k = 0; # the current K value
29 $a = 0; # the current A value
30 $r = 0; # the current R value
31 $forecast = ""; # the current geomagnetic forecast
32 $node = ""; # originating node
33 $from = ""; # who this came from
34 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
35 @denied = (); # if present ignore any wwv from these callsigns
36 %dup = (); # the spot duplicates hash
37 $duplth = 20; # the length of text to use in the deduping
38 $dupage = 12*3600; # the length of time to hold spot dups
40 $dirprefix = "$main::data/wwv";
41 $param = "$dirprefix/param";
45 $fp = DXLog::new('wwv', 'dat', 'm');
46 mkdir $dirprefix, 0777 if !-e $dirprefix; # now unnecessary DXLog will create it
47 do "$param" if -e "$param";
51 # write the current data away
54 my $fh = new IO::File;
55 open $fh, "> $param" or confess "can't open $param $!";
56 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
57 print $fh "\$date = $date;\n";
58 print $fh "\$sfi = $sfi;\n";
59 print $fh "\$a = $a;\n";
60 print $fh "\$k = $k;\n";
61 print $fh "\$r = $r;\n";
62 print $fh "\$from = '$from';\n";
63 print $fh "\$node = '$node';\n";
64 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
65 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
69 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node^$r");
72 # update WWV info in one go (usually from a PC23)
75 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode, $myr) = @_;
76 if ((@allowed && grep {$_ eq $from} @allowed) ||
77 (@denied && !grep {$_ eq $from} @denied) ||
78 (@allowed == 0 && @denied == 0)) {
80 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
81 if ($mydate >= $date) {
85 $r = 0 unless abs ($mysfi - $sfi) > 3;
90 $forecast = $myforecast;
100 # add or substract an allowed callsign
105 push @allowed, map {uc $_} @_;
109 @allowed = map {$_ ne uc $c} @allowed;
115 # add or substract a denied callsign
120 push @denied, map {uc $_} @_;
124 @denied = map {$_ ne uc $c} @denied;
130 # accessor routines (when I work how symbolic refs work I might use one of those!)
133 @_ ? $sfi = shift : $sfi ;
138 @_ ? $k = shift : $k ;
143 @_ ? $r = shift : $r ;
148 @_ ? $a = shift : $a ;
153 @_ ? $forecast = shift : $forecast ;
158 # print some items from the log backwards in time
160 # This command outputs a list of n lines starting from line $from to $to
166 my @date = $fp->unixtoj(shift);
177 for (\$c = \$#in; \$c >= 0; \$c--) {
181 next if \$count < \$from;
183 last if \$count >= \$to; # stop after n
188 $fp->close; # close any open files
190 my $fh = $fp->open(@date);
191 for ($count = 0; $count < $to; ) {
196 push @in, [ split '\^' ] if length > 2;
198 eval $eval; # do the search on this file
199 return ("Geomag search error", $@) if $@;
200 last if $count >= $to; # stop after n
202 $fh = $fp->openprev(); # get the next file
210 # the standard log printing interpreting routine.
212 # every line that is printed should call this routine to be actually visualised
214 # Don't really know whether this is the correct place to put this stuff, but where
217 # I get a reference to an array of items
223 my $d = cldate($ref[1]);
224 my ($t) = (gmtime($ref[1]))[2];
226 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
230 # read in this month's data
234 my @date = $fp->unixtoj(shift);
235 my $fh = $fp->open(@date);
242 push @in, [ split '\^' ] if length > 2;
248 # enter the spot for dup checking and return true if it is already a dup
251 my ($d, $sfi, $k, $a, $text) = @_;
254 return 2 if $d < $main::systime - $dupage;
256 $d /= 60; # to the nearest minute
258 $text = substr($text, 0, $duplth) if length $text > $duplth;
259 my $dupkey = "$d|$sfi|$k|$a|$text";
260 return 1 if exists $dup{$dupkey};
261 $dup{$dupkey} = $d * 60; # in seconds (to the nearest minute)
265 # called every hour and cleans out the dup cache
268 my $cutoff = $main::systime - $dupage;
269 while (my ($key, $val) = each %dup) {
270 delete $dup{$key} if $val < $cutoff;
277 for (sort { $dup{$a} <=> $dup{$b} } keys %dup) {
279 push @out, "$_ = $val (" . cldatetime($val) . ")";