| deadpickle 2006-11-03, 6:57 pm |
| I have edited my script and now I have ran into another problem. In the
metar the cloud cover is rocorded as a 3 letter abbr. For this program
I want it to run through the elements untill it hits one of these. But
there is a ladder to how they should be printed. If OVC appears then I
want that to be displayed, If BKN appears and OVC does not but FEW
does, then I want BKN to be printed out. How can I do this? the code
works for OVC but when I remove it , it prints nothing to the file.
METAR code
----------------------------------------------------
KCHS 131656Z 15009KT 10SM -RA FEW027 BKN044 24/20 A2994 RMK AO2 RAB44
SLP137 P0000 T02440200
Program Code
----------------------------------------------------
#loads metar file and sets its elemetns into an array
$file="KAKO.txt";
open (IN, $file) || die("Could Not Open File");
$metar=<IN>;
close(IN);
print("$metar\n");
@metar=split(" ", $metar);
#remove station name and time
shift(@metar);
shift(@metar);
open(OUT, ">metar2.txt") || die("could Not Open File!");
#loop through all elements
foreach (@metar) { #Test for each element in the array
if (substr($_,5,2) eq "KT") { #Test the elements to find the wind
spd and dir
print OUT (substr($_,0,3),"\n"); #wind dir
print OUT (substr($_,3,2),"\n"); #wind spd
};
if (substr($_,0,3) eq "SLP") { #test of SLP
print OUT (substr($_,3,3),"\n"); #SLP
};
if (substr($_,5,1) eq "G") { #test for wind gusts
print OUT (substr($_,0,3),"\n"); #wind dir
print OUT (substr($_,3,2),"\n"); #wind spd
print OUT (substr($_,6,2),"\n"); #wind gust
};
if (substr($_,0,3) eq ("OVC" || "BKN" || "FEW" || "CLR")) { #test
for cloud cover
if (substr($_,0,3) eq "OVC") {
print OUT (substr($_,0,3),"\n");
}
elsif (substr($_,0,3) eq "BKN") {
print OUT (substr($_,0,3),"\n");
}
elsif (substr($_,0,3) eq "FEW") {
print OUT (substr($_,0,3),"\n");
}
else {print OUT (substr($_,0,3),"\n")}
};
};
close (OUT);
|