4 # Copyright (c) - 1998 Dirk Koopman G1TLH
22 use vars qw($fp $maxspots $defaultspots $maxdays $dirprefix);
25 $maxspots = 50; # maximum spots to return
26 $defaultspots = 10; # normal number of spots to return
27 $maxdays = 35; # normal maximum no of days to go back
28 $dirprefix = "$main::data/spots";
32 mkdir "$dirprefix", 0777 if !-e "$dirprefix";
40 # add a spot to the data file (call as Spot::add)
43 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
45 # sure that the numeric things are numeric now (saves time later)
46 $spot[0] = 0 + $spot[0];
47 $spot[2] = 0 + $spot[2];
49 # remove ssid if present on spotter
50 $spot[4] =~ s/-\d+$//o;
52 # compare dates to see whether need to open another save file (remember, redefining $fp
53 # automagically closes the output file (if any))
54 my @date = Julian::unixtoj($spot[2]);
55 $fp = Spot->open(@date, ">>") if (!$fp || Julian::cmp(@date, $fp->{year}, $fp->{day}));
60 # add the 'dxcc' country on the end
61 my @dxcc = Prefix::extract($spot[1]);
62 push @spot, (@dxcc > 0 ) ? $dxcc[1]->dxcc() : 0;
64 my $buf = join("\^", @spot);
65 $fh->print($buf, "\n");
70 # search the spot database for records based on the field no and an expression
71 # this returns a set of references to the spots
73 # the expression is a legal perl 'if' statement with the possible fields indicated
78 # $f2 = date in unix format
83 # In addition you can specify a range of days, this means that it will start searching
84 # from <n> days less than today to <m> days less than today
86 # Also you can select a range of entries so normally you would get the 0th (latest) entry
87 # back to the 5th latest, you can specify a range from the <x>th to the <y>the oldest.
89 # This routine is designed to be called as Spot::search(..)
94 my ($expr, $dayfrom, $dayto, $from, $to) = @_;
100 my @today = Julian::unixtoj(time);
105 @fromdate = Julian::sub(@today, $dayfrom);
111 @todate = Julian::sub(@fromdate, $dayto);
113 @todate = Julian::sub(@fromdate, $maxdays);
116 $to = $from + $maxspots if $to - $from > $maxspots || $to - $from <= 0;
122 $expr =~ s/\$f(\d)/\$ref->[$1]/g; # swap the letter n for the correct field name
123 # $expr =~ s/\$f(\d)/\$spots[$1]/g; # swap the letter n for the correct field name
125 dbg("search", "expr='$expr', spotno=$from-$to, day=$dayfrom-$dayto\n");
127 # build up eval to execute
131 # my \@spots = split /\\^/o;
132 # if ($expr) { # note NO \$expr
134 # next if \$count < \$from; # wait until from
135 # push(\@out, \\\@spots);
136 # last LOOP if \$count >= \$to; # stop after to
141 for (\$c = \$#spots; \$c >= 0; \$c--) {
142 \$ref = \$spots[\$c];
145 next if \$count < \$from; # wait until from
147 last LOOP if \$count >= \$to; # stop after to
153 for ($i = 0; $i < $maxdays; ++$i) { # look thru $maxdays worth of files only
154 my @now = Julian::sub(@fromdate, $i); # but you can pick which $maxdays worth
155 last if Julian::cmp(@now, @todate) <= 0;
158 my $fp = Spot->open(@now); # get the next file
162 foreach $in (<$fh>) {
164 push @spots, [ split('\^', $in) ];
166 eval $eval; # do the search on this file
167 return ("Spot search error", $@) if $@;
174 # open a spot file of the Julian day
178 return Julian::open("spot", $dirprefix, @_);
184 # do nothing, unreferencing or overwriting the $self will close it
187 # format a spot for user output in 'broadcast' mode
191 my $t = ztime($dx[2]);
192 return sprintf "DX de %-7.7s: %13.1f %-12.12s %-30s<%s>", $dx[4], $dx[0], $dx[1], $dx[3], $t ;
195 # format a spot for user output in list mode
199 my $t = ztime($dx[2]);
200 my $d = cldate($dx[2]);
201 return sprintf "%9.1f %-12s %s %s %-30s<%s>", $dx[0], $dx[1], $d, $t, $dx[3], $dx[4] ;