X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FGeomag.pm;h=8b0d2ea7f4cd0933757ed90f6ac68d174ca9bd3b;hb=f3adc82a0299652d929b73c718127fa38571eec5;hp=a63d19b66bbdef6d473e19b0a675eedd802c11a9;hpb=3643ef870e040d437448632209039477eac4e52c;p=spider.git diff --git a/perl/Geomag.pm b/perl/Geomag.pm index a63d19b6..8b0d2ea7 100644 --- a/perl/Geomag.pm +++ b/perl/Geomag.pm @@ -140,15 +140,13 @@ sub forecast # # This command outputs a list of n lines starting from line $from to $to # -sub print +sub search { - my $self = $fp; my $from = shift; my $to = shift; - my @date = $self->unixtoj(shift); + my @date = $fp->unixtoj(shift); my $pattern = shift; my $search; - my @in; my @out; my $eval; my $count; @@ -161,28 +159,28 @@ sub print \$ref = \$in[\$c]; if ($search) { \$count++; - next if \$count < $from; - push \@out, print_item(\$ref); - last LOOP if \$count >= \$to; # stop after n + next if \$count < \$from; + push \@out, \$ref; + last if \$count >= \$to; # stop after n } } ); - $self->close; # close any open files + $fp->close; # close any open files - my $fh = $self->open(@date); -LOOP: - while ($count < $to) { - my @spots = (); + 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 ("Spot search error", $@) if $@; + return ("Geomag search error", $@) if $@; + last if $count >= $to; # stop after n } - $fh = $self->openprev(); # get the next file + $fh = $fp->openprev(); # get the next file last if !$fh; } @@ -209,5 +207,23 @@ sub print_item 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__;