1. Various detail changes to remove some more warning with -w on
[spider.git] / perl / Geomag.pm
index f06cbbc640bd05cfb81b97d650b52f0bc5d0d92c..8b0d2ea7f4cd0933757ed90f6ac68d174ca9bd3b 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 # 
 # The geomagnetic information and calculation module
+# a chanfe
 #
 # Copyright (c) 1998 - Dirk Koopman G1TLH
 #
@@ -57,7 +58,7 @@ sub store
   close $fh;
 
   # log it
-  $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node\n");
+  $fp->writeunix($date, "$from^$date^$sfi^$a^$k^$forecast^$node");
 }
 
 # update WWV info in one go (usually from a PC23)
@@ -134,5 +135,95 @@ sub forecast
   @_ ? $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;
+}
+
+#
+# the standard log printing interpreting routine.
+#
+# every line that is printed should call this routine to be actually visualised
+#
+# Don't really know whether this is the correct place to put this stuff, but where
+# else is correct?
+#
+# I get a reference to an array of items
+#
+sub print_item
+{
+       my $r = shift;
+       my @ref = @$r;
+       my $d = cldate($ref[1]);
+       my ($t) = (gmtime($ref[1]))[2];
+
+       return sprintf("$d   %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
+}
+
+#
+# read in this month's data
+#
+sub readfile
+{
+       my @date = $fp->unixtoj(shift);
+       my $fh = $fp->open(@date); 
+       my @spots = ();
+       my @in;
+       
+       if ($fh) {
+               while (<$fh>) {
+                       chomp;
+                       push @in, [ split '\^' ] if length > 2;
+               }
+       }
+       return @in;
+}
 1;
 __END__;