4 # Copyright (c) - 1998 Dirk Koopman G1TLH
21 my $maxspots = 50; # maximum spots to return
22 my $defaultspots = 10; # normal number of spots to return
23 my $maxdays = 35; # normal maximum no of days to go back
24 my $prefix = "$main::data/spots";
26 # add a spot to the data file (call as Spot::add)
29 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
31 # sure that the numeric things are numeric now (saves time later)
32 $spot[0] = 0 + $spot[0];
33 $spot[2] = 0 + $spot[2];
35 # compare dates to see whether need to open another save file (remember, redefining $fp
36 # automagically closes the output file (if any))
37 my @date = Julian::unixtoj($spot[2]);
38 $fp = Spot->open(@date, ">>") if (!$fp || Julian::cmp(@date, $fp->{year}, $fp->{day}));
42 $fh->print(join("\^", @spot), "\n");
45 # search the spot database for records based on the field no and an expression
46 # this returns a set of references to the spots
48 # the expression is a legal perl 'if' statement with the possible fields indicated
53 # $f2 = date in unix format
57 # In addition you can specify a range of days, this means that it will start searching
58 # from <n> days less than today to <m> days less than today
60 # Also you can select a range of entries so normally you would get the 0th (latest) entry
61 # back to the 5th latest, you can specify a range from the <x>th to the <y>the oldest.
63 # This routine is designed to be called as Spot::search(..)
68 my ($expr, $dayfrom, $dayto, $from, $to) = @_;
74 my @today = Julian::unixtoj(time);
79 @fromdate = Julian::sub(@today, $dayfrom);
85 @todate = Julian::sub(@fromdate, $dayto);
87 @todate = Julian::sub(@fromdate, $maxdays);
90 $to = $from + $maxspots if $to - $from > $maxspots || $to - $from <= 0;
96 $expr =~ s/\$f(\d)/zzzref->[$1]/g; # swap the letter n for the correct field name
97 $expr =~ s/[\@\$\%\{\}]//g; # remove any other funny characters
98 $expr =~ s/\&\w+\(//g; # remove subroutine calls
99 $expr =~ s/eval//g; # remove eval words
100 $expr =~ s/zzzref/\$ref/g; # put back the $ref
101 $expr =~ s|(/.+/)|$1oi|g; # add oi characters to /ccc/
103 print "expr=($expr), from=$from, to=$to\n";
105 # build up eval to execute
107 for (\$c = \$#spots; \$c >= 0; \$c--) {
108 \$ref = \$spots[\$c];
111 next if \$count < \$from; # wait until from
113 last LOOP if \$count >= \$to; # stop after to
118 for ($i = 0; $i < 60; ++$i) {
119 my @now = Julian::sub(@fromdate, $i);
120 last if Julian::cmp(@now, @todate) <= 0;
123 my $fp = Spot->open(@now); # get the next file
127 foreach $in (<$fh>) {
129 push @spots, [ split('\^', $in) ];
132 eval $eval; # do the search on this file
133 return ("error", $@) if $@;
140 # open a spot file of the Julian day
144 return Julian::open("spot", $prefix, @_);
150 # do nothing, unreferencing or overwriting the $self will close it