+#
+# return all the spots from a day's file as an array of references
+# the parameter passed is a julian day
+sub readfile($)
+{
+ my @spots;
+
+ my $fh = $fp->open(shift);
+ if ($fh) {
+ my $in;
+ while (<$fh>) {
+ chomp;
+ push @spots, [ split '\^' ];
+ }
+ }
+ return @spots;
+}
+
+# enter the spot for dup checking and return true if it is already a dup
+sub dup
+{
+ my ($freq, $call, $d, $text) = @_;
+
+ # dump if too old
+ return 2 if $d < $main::systime - $dupage;
+
+ $freq = sprintf "%.1f", $freq; # normalise frequency
+ chomp $text;
+ $text = substr($text, 0, $duplth) if length $text > $duplth;
+ unpad($text);
+ $text =~ s/[\\\%]\d+//g;
+ $text =~ s/[^a-zA-Z0-9]//g;
+ my $dupkey = "X$freq|$call|$d|\L$text";
+ return DXDupe::check($dupkey, $main::systime+$dupage);
+}
+
+sub listdups
+{
+ return DXDupe::listdups('X', $dupage, @_);
+}
+
+sub genstats($)
+{
+ my $date = shift;
+ my $in = $fp->open($date);
+ my $out = $statp->open($date, 'w');
+ my @freq = (
+ [0, Bands::get_freq('160m')],
+ [1, Bands::get_freq('80m')],
+ [2, Bands::get_freq('40m')],
+ [3, Bands::get_freq('30m')],
+ [4, Bands::get_freq('20m')],
+ [5, Bands::get_freq('17m')],
+ [6, Bands::get_freq('15m')],
+ [7, Bands::get_freq('12m')],
+ [8, Bands::get_freq('10m')],
+ [9, Bands::get_freq('6m')],
+ [10, Bands::get_freq('4m')],
+ [11, Bands::get_freq('2m')],
+ [12, Bands::get_freq('70cm')],
+ [13, Bands::get_freq('13cm')],
+ [14, Bands::get_freq('9cm')],
+ [15, Bands::get_freq('6cm')],
+ [16, Bands::get_freq('3cm')],
+ [17, Bands::get_freq('12mm')],
+ [18, Bands::get_freq('6cm')],
+ );
+ my %list;
+ my @tot;
+
+ if ($in && $out) {
+ while (<$in>) {
+ chomp;
+ my ($freq, $by, $dxcc) = (split /\^/)[0,4,6];
+ my $ref = $list{$by} || [0, $dxcc];
+ for (@freq) {
+ if ($freq >= $_->[1] && $freq <= $_->[2]) {
+ $$ref[$_->[0]+2]++;
+ $tot[$_->[0]+2]++;
+ $$ref[0]++;
+ $tot[0]++;
+ $list{$by} = $ref;
+ last;
+ }
+ }
+ }
+
+ my $i;
+ for ($i = 0; $i < @freq+2; $i++) {
+ $tot[$i] ||= 0;
+ }
+ $out->write(join('^', 'TOTALS', @tot) . "\n");
+
+ for (sort {$list{$b}->[0] <=> $list{$a}->[0]} keys %list) {
+ my $ref = $list{$_};
+ my $call = $_;
+ for ($i = 0; $i < @freq+2; ++$i) {
+ $ref->[$i] ||= 0;
+ }
+ $out->write(join('^', $call, @$ref) . "\n");
+ }
+ $out->close;
+ }
+}
+
+# return true if the stat file is newer than than the spot file
+sub checkstats($)
+{
+ my $date = shift;
+ my $in = $fp->mtime($date);
+ my $out = $statp->mtime($date);
+ return defined $out && defined $in && $out >= $in;
+}
+
+# daily processing
+sub daily
+{
+ my $date = Julian::Day->new($main::systime)->sub(1);
+ genstats($date) unless checkstats($date);
+}