3 # The WCY analog of the WWV geomagnetic information and calculation module
5 # Copyright (c) 2000 - Dirk Koopman G1TLH
21 use vars qw($date $sfi $k $expk $a $r $sa $gmf $au @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 $sa = ""; # solar activity
32 $gmf = ""; # Geomag activity
33 $au = 'no'; # aurora warning
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 %dup = (); # the spot duplicates hash
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::data/wcy";
43 $param = "$dirprefix/param";
47 $fp = DXLog::new('wcy', 'dat', 'm');
48 do "$param" if -e "$param";
52 # write the current data away
55 my $fh = new IO::File;
56 open $fh, "> $param" or confess "can't open $param $!";
57 print $fh "# WCY data parameter file last mod:", scalar gmtime, "\n";
58 my $dd = new Data::Dumper([ $date, $sfi, $a, $k, $expk, $r, $sa, $gmf, $au, $from, $node, \@denied, \@allowed ], [qw(date sfi a k expk r sa gmf au from node *denied *allowed)]);
62 $fh->print($dd->Dumpxs);
66 $fp->writeunix($date, "$date^$sfi^$a^$k^$expk^$r^$sa^$gmf^$au^$from^$node");
69 # update WWV info in one go (usually from a PC23)
72 my ($mydate, $mytime, $mysfi, $mya, $myk, $myexpk, $myr, $mysa, $mygmf, $myau, $myfrom, $mynode) = @_;
73 if ((@allowed && grep {$_ eq $from} @allowed) ||
74 (@denied && !grep {$_ eq $from} @denied) ||
75 (@allowed == 0 && @denied == 0)) {
77 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
78 if ($mydate >= $date) {
82 $r = 0 unless abs ($mysfi - $sfi) > 3;
101 # add or substract an allowed callsign
106 push @allowed, map {uc $_} @_;
110 @allowed = map {$_ ne uc $c} @allowed;
116 # add or substract a denied callsign
121 push @denied, map {uc $_} @_;
125 @denied = map {$_ ne uc $c} @denied;
132 # print some items from the log backwards in time
134 # This command outputs a list of n lines starting from line $from to $to
140 my @date = $fp->unixtoj(shift);
151 for (\$c = \$#in; \$c >= 0; \$c--) {
155 next if \$count < \$from;
157 last if \$count >= \$to; # stop after n
162 $fp->close; # close any open files
164 my $fh = $fp->open(@date);
165 for ($count = 0; $count < $to; ) {
170 push @in, [ split '\^' ] if length > 2;
172 eval $eval; # do the search on this file
173 return ("Geomag search error", $@) if $@;
174 last if $count >= $to; # stop after n
176 $fh = $fp->openprev(); # get the next file
184 # the standard log printing interpreting routine.
186 # every line that is printed should call this routine to be actually visualised
188 # Don't really know whether this is the correct place to put this stuff, but where
191 # I get a reference to an array of items
196 my $d = cldate($r->[0]);
197 my $t = (gmtime($r->[0]))[2];
199 return sprintf("$d %02d %5d %3d %3d %3d %3d %-5s %-5s %-3s <%s>",
204 # read in this month's data
208 my @date = $fp->unixtoj(shift);
209 my $fh = $fp->open(@date);
216 push @in, [ split '\^' ] if length > 2;
222 # enter the spot for dup checking and return true if it is already a dup
225 my ($d, $sfi, $a, $k, $r) = @_;
228 return 2 if $d < $main::systime - $dupage;
230 $d /= 60; # to the nearest minute
232 # $text = substr($text, 0, $duplth) if length $text > $duplth;
233 my $dupkey = "$d|$sfi|$k|$a|$r";
234 return 1 if exists $dup{$dupkey};
235 $dup{$dupkey} = $d * 60; # in seconds (to the nearest minute)
239 # called every hour and cleans out the dup cache
242 my $cutoff = $main::systime - $dupage;
243 while (my ($key, $val) = each %dup) {
244 delete $dup{$key} if $val < $cutoff;
251 for (sort { $dup{$a} <=> $dup{$b} } keys %dup) {
253 push @out, "$_ = $val (" . cldatetime($val) . ")";