3 # The WCY analog of the WWV geomagnetic information and calculation module
5 # Copyright (c) 2000 - Dirk Koopman G1TLH
22 use vars qw($VERSION $BRANCH);
23 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
24 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
25 $main::build += $VERSION;
26 $main::branch += $BRANCH;
28 use vars qw($date $sfi $k $expk $a $r $sa $gmf $au @allowed @denied $fp $node $from
30 $duplth $dupage $filterdef);
32 $fp = 0; # the DXLog fcb
33 $date = 0; # the unix time of the WWV (notional)
34 $sfi = 0; # the current SFI value
35 $k = 0; # the current K value
36 $a = 0; # the current A value
37 $r = 0; # the current R value
38 $sa = ""; # solar activity
39 $gmf = ""; # Geomag activity
40 $au = 'no'; # aurora warning
41 $node = ""; # originating node
42 $from = ""; # who this came from
43 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
44 @denied = (); # if present ignore any wwv from these callsigns
45 $duplth = 20; # the length of text to use in the deduping
46 $dupage = 12*3600; # the length of time to hold spot dups
48 $dirprefix = "$main::data/wcy";
49 $param = "$dirprefix/param";
52 # tag, sort, field, priv, special parser
59 ['origin_dxcc', 'c', 17],
60 ['origin_itu', 'c', 18],
61 ['origin_itu', 'c', 19],
67 $fp = DXLog::new('wcy', 'dat', 'm');
68 do "$param" if -e "$param";
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 "# WCY data parameter file last mod:", scalar gmtime, "\n";
78 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)]);
82 $fh->print($dd->Dumpxs);
86 $fp->writeunix($date, "$date^$sfi^$a^$k^$expk^$r^$sa^$gmf^$au^$from^$node");
89 # update WWV info in one go (usually from a PC23)
92 my ($mydate, $mytime, $mysfi, $mya, $myk, $myexpk, $myr, $mysa, $mygmf, $myau, $myfrom, $mynode) = @_;
93 if ((@allowed && grep {$_ eq $from} @allowed) ||
94 (@denied && !grep {$_ eq $from} @denied) ||
95 (@allowed == 0 && @denied == 0)) {
97 # my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
98 if ($mydate >= $date) {
102 $r = 0 unless abs ($mysfi - $sfi) > 3;
121 # add or substract an allowed callsign
126 push @allowed, map {uc $_} @_;
130 @allowed = map {$_ ne uc $c} @allowed;
136 # add or substract a denied callsign
141 push @denied, map {uc $_} @_;
145 @denied = map {$_ ne uc $c} @denied;
152 # print some items from the log backwards in time
154 # This command outputs a list of n lines starting from line $from to $to
160 my $date = $fp->unixtoj(shift);
172 for (\$c = \$#in; \$c >= 0; \$c--) {
176 next if \$count < \$from;
178 last if \$count >= \$to; # stop after n
183 $fp->close; # close any open files
184 my $fh = $fp->open($date);
185 for ($i = $count = 0; $count < $to; $i++ ) {
190 push @in, [ split '\^' ] if length > 2;
192 eval $eval; # do the search on this file
193 return ("Geomag search error", $@) if $@;
194 last if $count >= $to; # stop after n
196 $fh = $fp->openprev(); # get the next file
204 # the standard log printing interpreting routine.
206 # every line that is printed should call this routine to be actually visualised
208 # Don't really know whether this is the correct place to put this stuff, but where
211 # I get a reference to an array of items
216 my $d = cldate($r->[0]);
217 my $t = (gmtime($r->[0]))[2];
219 return sprintf("$d %02d %5d %3d %3d %3d %3d %-5s %-5s %6s <%s>",
224 # read in this month's data
228 my $date = $fp->unixtoj(shift);
229 my $fh = $fp->open($date);
236 push @in, [ split '\^' ] if length > 2;
242 # enter the spot for dup checking and return true if it is already a dup
245 my ($d, $sfi, $a, $k, $r) = @_;
248 return 2 if $d < $main::systime - $dupage;
250 my $dupkey = "C$d|$sfi|$k|$a|$r";
251 return DXDupe::check($dupkey, $main::systime+$dupage);
256 return DXDupe::listdups('C', $dupage, @_);