3 # The geomagnetic information and calculation module
6 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw($date $sfi $k $a $forecast @allowed @denied $fp $node $from);
23 $fp = 0; # the DXLog fcb
24 $date = 0; # the unix time of the WWV (notional)
25 $sfi = 0; # the current SFI value
26 $k = 0; # the current K value
27 $a = 0; # the current A value
28 $forecast = ""; # the current geomagnetic forecast
29 $node = ""; # originating node
30 $from = ""; # who this came from
31 @allowed = (); # if present only these callsigns are regarded as valid WWV updators
32 @denied = (); # if present ignore any wwv from these callsigns
33 my $dirprefix = "$main::data/wwv";
34 my $param = "$dirprefix/param";
38 $fp = DXLog::new('wwv', 'dat', 'm');
39 mkdir $dirprefix, 0777 if !-e $dirprefix; # now unnecessary DXLog will create it
40 do "$param" if -e "$param";
44 # write the current data away
47 my $fh = new FileHandle;
48 open $fh, "> $param" or confess "can't open $param $!";
49 print $fh "# Geomagnetic data parameter file last mod:", scalar gmtime, "\n";
50 print $fh "\$date = $date;\n";
51 print $fh "\$sfi = $sfi;\n";
52 print $fh "\$a = $a;\n";
53 print $fh "\$k = $k;\n";
54 print $fh "\$from = '$from';\n";
55 print $fh "\$node = '$node';\n";
56 print $fh "\@denied = qw(", join(' ', @denied), ");\n" if @denied > 0;
57 print $fh "\@allowed = qw(", join(' ', @allowed), ");\n" if @allowed > 0;
61 $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node");
64 # update WWV info in one go (usually from a PC23)
67 my ($mydate, $mytime, $mysfi, $mya, $myk, $myforecast, $myfrom, $mynode) = @_;
68 if ((@allowed && grep {$_ eq $from} @allowed) ||
69 (@denied && !grep {$_ eq $from} @denied) ||
70 (@allowed == 0 && @denied == 0)) {
72 my $trydate = cltounix($mydate, sprintf("%02d18Z", $mytime));
73 if ($trydate >= $date) {
77 $forecast = $myforecast;
87 # add or substract an allowed callsign
92 push @allowed, map {uc $_} @_;
96 @allowed = map {$_ ne uc $c} @allowed;
102 # add or substract a denied callsign
107 push @denied, map {uc $_} @_;
111 @denied = map {$_ ne uc $c} @denied;
117 # accessor routines (when I work how symbolic refs work I might use one of those!)
120 @_ ? $sfi = shift : $sfi ;
125 @_ ? $k = shift : $k ;
130 @_ ? $a = shift : $a ;
135 @_ ? $forecast = shift : $forecast ;
139 # print some items from the log backwards in time
141 # This command outputs a list of n lines starting from line $from to $to
148 my @date = $self->unixtoj(shift);
160 for (\$c = \$#in; \$c >= 0; \$c--) {
164 next if \$count < $from;
165 push \@out, print_item(\$ref);
166 last LOOP if \$count >= \$to; # stop after n
171 $self->close; # close any open files
173 my $fh = $self->open(@date);
175 while ($count < $to) {
180 push @in, [ split '\^' ] if length > 2;
182 eval $eval; # do the search on this file
183 return ("Spot search error", $@) if $@;
185 $fh = $self->openprev(); # get the next file
193 # the standard log printing interpreting routine.
195 # every line that is printed should call this routine to be actually visualised
197 # Don't really know whether this is the correct place to put this stuff, but where
200 # I get a reference to an array of items
206 my $d = cldate($ref[1]);
207 my ($t) = (gmtime($ref[1]))[2];
209 return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);