X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FGeomag.pm;h=8b0d2ea7f4cd0933757ed90f6ac68d174ca9bd3b;hb=f3adc82a0299652d929b73c718127fa38571eec5;hp=0fc16d06a83f934b913d291b6e8805c62c32e536;hpb=7a64dbf69ead057f2fd3fef1df05e30cef339485;p=spider.git diff --git a/perl/Geomag.pm b/perl/Geomag.pm index 0fc16d06..8b0d2ea7 100644 --- a/perl/Geomag.pm +++ b/perl/Geomag.pm @@ -135,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__;