+use vars qw($fp $statp $maxspots $defaultspots $maxdays $dirprefix $duplth $dupage $filterdef $totalspots $hfspots $vhfspots $maxcalllth);
+
+$fp = undef;
+$statp = undef;
+$maxspots = 100; # maximum spots to return
+$defaultspots = 10; # normal number of spots to return
+$maxdays = 100; # normal maximum no of days to go back
+$dirprefix = "spots";
+$duplth = 20; # the length of text to use in the deduping
+$dupage = 1*3600; # the length of time to hold spot dups
+$maxcalllth = 12; # the max length of call to take into account for dupes
+$filterdef = bless ([
+ # tag, sort, field, priv, special parser
+ ['freq', 'r', 0, 0, \&decodefreq],
+ ['on', 'r', 0, 0, \&decodefreq],
+ ['call', 'c', 1],
+ ['info', 't', 3],
+ ['by', 'c', 4],
+ ['call_dxcc', 'nc', 5],
+ ['by_dxcc', 'nc', 6],
+ ['origin', 'c', 7, 9],
+ ['call_itu', 'ni', 8],
+ ['call_zone', 'nz', 9],
+ ['by_itu', 'ni', 10],
+ ['by_zone', 'nz', 11],
+ ['call_state', 'ns', 12],
+ ['by_state', 'ns', 13],
+ ['channel', 'c', 14],
+
+ ], 'Filter::Cmd');
+$totalspots = $hfspots = $vhfspots = 0;
+
+# create a Spot Object
+sub new
+{
+ my $class = shift;
+ my $self = [ @_ ];
+ return bless $self, $class;
+}
+
+sub decodefreq
+{
+ my $dxchan = shift;
+ my $l = shift;
+ my @f = split /,/, $l;
+ my @out;
+ my $f;
+
+ foreach $f (@f) {
+ my ($a, $b);
+ if (m{^\d+/\d+$}) {
+ push @out, $f;
+ } elsif (($a, $b) = $f =~ m{^(\w+)(?:/(\w+))?$}) {
+ $b = lc $b if $b;
+ my @fr = Bands::get_freq(lc $a, $b);
+ if (@fr) {
+ while (@fr) {
+ $a = shift @fr;
+ $b = shift @fr;
+ push @out, "$a/$b"; # add them as ranges
+ }
+ } else {
+ return ('dfreq', $dxchan->msg('dfreq1', $f));
+ }
+ } else {
+ return ('dfreq', $dxchan->msg('e20', $f));
+ }
+ }
+ return (0, join(',', @out));
+}
+
+sub init
+{
+ mkdir "$dirprefix", 0777 if !-e "$dirprefix";
+ $fp = DXLog::new($dirprefix, "dat", 'd');
+ $statp = DXLog::new($dirprefix, "dys", 'd');
+}
+
+sub prefix
+{
+ return $fp->{prefix};
+}
+
+# fix up the full spot data from the basic spot data
+sub prepare