X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FGeomag.pm;h=a63d19b66bbdef6d473e19b0a675eedd802c11a9;hb=3643ef870e040d437448632209039477eac4e52c;hp=0fc16d06a83f934b913d291b6e8805c62c32e536;hpb=7a64dbf69ead057f2fd3fef1df05e30cef339485;p=spider.git diff --git a/perl/Geomag.pm b/perl/Geomag.pm index 0fc16d06..a63d19b6 100644 --- a/perl/Geomag.pm +++ b/perl/Geomag.pm @@ -135,5 +135,79 @@ 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 print +{ + my $self = $fp; + my $from = shift; + my $to = shift; + my @date = $self->unixtoj(shift); + my $pattern = shift; + my $search; + my @in; + 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, print_item(\$ref); + last LOOP if \$count >= \$to; # stop after n + } + } + ); + + $self->close; # close any open files + + my $fh = $self->open(@date); +LOOP: + while ($count < $to) { + my @spots = (); + if ($fh) { + while (<$fh>) { + chomp; + push @in, [ split '\^' ] if length > 2; + } + eval $eval; # do the search on this file + return ("Spot search error", $@) if $@; + } + $fh = $self->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]); +} + 1; __END__;