Hi,
I'm able to parse different data in the same loop...however, now I'd
like to extract data from two files, using two while loops after
opening each .txt file...then do arithmetic with the data I extracted.
The problem is that when I reference a variable in the second while
loop that I initialized in the first while loop, the script doesn't
recognize it. To be more clear, there is a number value for
$SLPdataSFO[6] that I extracted in the first while loop, and I'd like
to subtract that value from $SLPdataSAC[6], which I extracted in the
second while loop. I tried to make it a global variable at the
beginning by using "our @SLPdataSFO = ();" to make it a global
variable, but no luck there. Any ideas? Thanks for your help....the
error I receive is shown after the .txt files, with the script after
that.
I've posted the two .txt files I'm bringing in from the while loops if
it's any help.
Shad



                        Station ID: KSFO Lat:   39.48 Long:
-119.77
1st .txt file) NAM Model Run: 12Z JUN  9,
2007

 Forecast Hours:    0hr    6hr   12hr   18hr   24hr   30hr   36hr
 Sfc Prs(mb):     865.3  864.0  863.9  865.1  864.2  862.8  861.7
 Mean SLP (mb):  1012.0 1008.3 1006.3 1009.8 1010.3 1007.0 1003.9
 2m agl Tmp (F):   52.0   71.0   75.0   63.9   58.9   73.3   73.2
 2m agl Dewpt(F):  39.2   37.7   40.5   39.2   34.4   33.0   43.7
 2m agl RH (%):      61     29     28     39     39     22
33
 10m agl Dir:       275    188    260    265    182    231
252
 10m agl Spd(kt):     1      4     10      6      3     10
16
 6hr Precip (in):  0.00   0.00   0.00   0.00   0.00   0.00
0.00
 AccumPrecip(in):  0.00   0.00   0.00   0.00   0.00   0.00   0.00
 Sfc CAPE (J/kg):   0.0    0.0    3.1    0.0    0.0    0.0   36.7
 Sfc CINH (J/kg):   0.0    0.0   -7.8    0.0    0.0   -0.5
-66.6
 Precip H20 (in):  0.47   0.48   0.55   0.58   0.54   0.57   0.71

                        Station ID: KSAC Lat:   39.48 Long:
-119.77
2nd .txt file) NAM Model Run: 12Z JUN  9,
2007

 Forecast Hours:    0hr    6hr   12hr   18hr   24hr   30hr
36hr
 Sfc Prs(mb):     865.3  864.0  863.9  865.1  864.2  862.8  861.7
 Mean SLP (mb):  1014.0 1009.3 1010.3 1011.8 1012.3 1007.0 1003.9
 2m agl Tmp (F):   52.0   71.0   75.0   63.9   58.9   73.3
73.2
 2m agl Dewpt(F):  39.2   37.7   40.5   39.2   34.4   33.0
43.7
 2m agl RH (%):      61     29     28     39     39     22
33
 10m agl Dir:       275    188    260    265    182    231
252
 10m agl Spd(kt):     1      4     10      6      3     10
16
 6hr Precip (in):  0.00   0.00   0.00   0.00   0.00   0.00   0.00
 AccumPrecip(in):  0.00   0.00   0.00   0.00   0.00   0.00   0.00
 Sfc CAPE (J/kg):   0.0    0.0    3.1    0.0    0.0    0.0   36.7
 Sfc CINH (J/kg):   0.0    0.0   -7.8    0.0    0.0   -0.5  -66.6
 0-3km Hel(J/kg):  72.3   17.1    6.3  -56.0   33.1   31.4
19.2
 Precip H20 (in):  0.47   0.48   0.55   0.58   0.54   0.57   0.7



error: Global symbol "@SLPdataSFO" requires explicit package name at c:
\perl-scripts\BarkerRegParser.cgi line 54.
Execution of c:\perl-scripts\BarkerRegParser.cgi aborted due to
compilation errors.


#!/perl/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
use strict;

print header;
print start_html("Gradients");

open(FH, "C:/perl-scripts/Data/BarkerSFOtest.txt") #open barker SFO
extrapolated NAM data .txt file
or &dienice("couldn't open output file: $!");


print "<h2>PW</h2>";



while (my $line = <FH>)  {  #reads through each line of model data

if ($line =~ m/^ Mean/)  {  #finds line with sealevel pressure
    print "$line<br>";
my $SFOdataSLP = $line;   #places $line into new string called $data
SLP
my @SLPdataSFO = split(/\s+/, $SFOdataSLP);  #splits $data SLP string
into individual elements between whitespace
print "$SLPdataSFO[6]<br>";
print "$SLPdataSFO[4]<br>";
my $SLPchgSFO = $SLPdataSFO[6] -= $SLPdataSFO[4];  #subtracts 12hr SLP
from 0hr SLP
print "$SLPchgSFO<br>";
my $roundf = sprintf("%1.1f", $SLPchgSFO);
print "$roundf<br>";
}

elsif ($line =~ m/^ Precip/) {  #if line isn't Precip Water line, then
will skip to next line
    print "$line<br>";
my $dataPW = $line;
my @PWdata = split(/\s+/, $dataPW);
print "$PWdata[6]<br>";
}




}
close (FH);

open(FH, "C:/perl-scripts/Data/BarkerSACtest.txt") #open barker SFO
extrapolated NAM data .txt file
or &dienice("couldn't open output file: $!");

while (my $line = <FH>)  {  #reads through each line of model data

if ($line =~ m/^ Mean/)  {  #finds line with mean sealevel pressure
    print "$line<br>";
my $SACdataSLP = $line;   #places $line into new string called
$SACdataSLP
my @SLPdataSAC = split(/\s+/, $SACdataSLP);  #splits $SACdataSLP
string into individual elements between whitespace
my $SACSFOgrad12 = $SLPdataSFO[6] -= $SLPdataSAC[6]; #subtracts SFO
from SAC 12-hr fcst sealevel pressure
print "$SACSFOgrad12";
}
}

close (FH);






print end_html;

sub dienice  {
 my($errmsg) = @_;
 print "<h2>Error</h2>\n";
 print "<p>$errmsg</p>\n";
 print end_html;
 exit;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to