4 # Copyright (c) - 1998 Dirk Koopman G1TLH
21 use vars qw($fp $maxspots $defaultspots $maxdays $dirprefix);
24 $maxspots = 50; # maximum spots to return
25 $defaultspots = 10; # normal number of spots to return
26 $maxdays = 35; # normal maximum no of days to go back
27 $dirprefix = "$main::data/spots";
34 # add a spot to the data file (call as Spot::add)
37 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
39 # sure that the numeric things are numeric now (saves time later)
40 $spot[0] = 0 + $spot[0];
41 $spot[2] = 0 + $spot[2];
43 # remove ssid if present on spotter
44 $spot[4] =~ s/-\d+$//o;
46 # compare dates to see whether need to open another save file (remember, redefining $fp
47 # automagically closes the output file (if any))
48 my @date = Julian::unixtoj($spot[2]);
49 $fp = Spot->open(@date, ">>") if (!$fp || Julian::cmp(@date, $fp->{year}, $fp->{day}));
54 # add the 'dxcc' country on the end
55 my @dxcc = Prefix::extract($spot[1]);
56 push @spot, (@dxcc > 0 ) ? $dxcc[1]->dxcc() : 0;
58 $fh->print(join("\^", @spot), "\n");
61 # search the spot database for records based on the field no and an expression
62 # this returns a set of references to the spots
64 # the expression is a legal perl 'if' statement with the possible fields indicated
69 # $f2 = date in unix format
74 # In addition you can specify a range of days, this means that it will start searching
75 # from <n> days less than today to <m> days less than today
77 # Also you can select a range of entries so normally you would get the 0th (latest) entry
78 # back to the 5th latest, you can specify a range from the <x>th to the <y>the oldest.
80 # This routine is designed to be called as Spot::search(..)
85 my ($expr, $dayfrom, $dayto, $from, $to) = @_;
91 my @today = Julian::unixtoj(time);
96 @fromdate = Julian::sub(@today, $dayfrom);
102 @todate = Julian::sub(@fromdate, $dayto);
104 @todate = Julian::sub(@fromdate, $maxdays);
107 $to = $from + $maxspots if $to - $from > $maxspots || $to - $from <= 0;
113 $expr =~ s/\$f(\d)/\$ref->[$1]/g; # swap the letter n for the correct field name
115 dbg("search", "expr='$expr', spotno=$from-$to, day=$dayfrom-$dayto\n");
117 # build up eval to execute
119 for (\$c = \$#spots; \$c >= 0; \$c--) {
120 \$ref = \$spots[\$c];
123 next if \$count < \$from; # wait until from
125 last LOOP if \$count >= \$to; # stop after to
130 for ($i = 0; $i < 60; ++$i) {
131 my @now = Julian::sub(@fromdate, $i);
132 last if Julian::cmp(@now, @todate) <= 0;
135 my $fp = Spot->open(@now); # get the next file
139 foreach $in (<$fh>) {
141 push @spots, [ split('\^', $in) ];
144 eval $eval; # do the search on this file
145 return ("error", $@) if $@;
152 # open a spot file of the Julian day
156 return Julian::open("spot", $dirprefix, @_);
162 # do nothing, unreferencing or overwriting the $self will close it