+ @_ ? $forecast = shift : $forecast ;
+}
+
+#
+# print some items from the log backwards in time
+#
+# This command outputs a list of n lines starting from line $from to $to
+#
+sub search
+{
+ my $from = shift;
+ my $to = shift;
+ my @date = $fp->unixtoj(shift);
+ my $pattern = shift;
+ my $search;
+ my @out;
+ my $eval;
+ my $count;
+
+ $search = 1;
+ $eval = qq(
+ my \$c;
+ my \$ref;
+ for (\$c = \$#in; \$c >= 0; \$c--) {
+ \$ref = \$in[\$c];
+ if ($search) {
+ \$count++;
+ next if \$count < \$from;
+ push \@out, \$ref;
+ last if \$count >= \$to; # stop after n
+ }
+ }
+ );
+
+ $fp->close; # close any open files
+
+ my $fh = $fp->open(@date);
+ for ($count = 0; $count < $to; ) {
+ my @in = ();
+ if ($fh) {
+ while (<$fh>) {
+ chomp;
+ push @in, [ split '\^' ] if length > 2;
+ }
+ eval $eval; # do the search on this file
+ return ("Geomag search error", $@) if $@;
+ last if $count >= $to; # stop after n
+ }
+ $fh = $fp->openprev(); # get the next file
+ last if !$fh;
+ }
+
+ return @out;