Searching for all Occurances and Evaling Them

D

deadpickle

What I want to do is search for all matching strings (lets say KBQP
for example) within a file with ext .wmo. Then I want to compare thier
times which is the second string in the file (ends with Z). Next I
want to take the newest one and run it through the rest of the
program. Im not sure how to do this. I hope this makes sense.

CODE
==========================================================
use strict;
use warnings;
$\ = "\n";
open OUT,'>', 'asospf.txt' or die "cannot open 'asospf.txt' $!";
print OUT "Title: Metar Plots";
print OUT "RefreshSeconds: 20\n";
print OUT 'IconFile: 1, 15, 15, 7, 7, "cover.png"'; #file for cover
print OUT 'IconFile: 2, 27, 54, 2, 53, "barb.png"'; #file for wind
barbs
print OUT 'Font: 1, 12, 1, "Times New Roman"',"\n"; #font
close OUT;
open OUT,'>>', 'asospf.txt' or die "cannot open 'asospf.txt' $!";
#open output file/this part needs to be appended to my $year = '07';
my $month = '02';
my $day = '07';
my $hour = '19';
my $min = '00';
my $wmo = "07020719f.wmo";
open WMO, $wmo;
#Check WMO file for station metars aka stations starting with K
while (my $obs = <WMO>) {
if ($obs =~ m/^(K)/) {
my @a = split(" ", $obs);
#Matches the obs with the station data contain within stations.txt
open ID, '<', 'stations' or die "cannot open 'stations' $!";
while ( my $stations = <ID> ) {
next unless $stations =~ /\A.{20}($a[0]|A)\s+(.+)/;
my @id = split (" ",$2);
#Section reserved for comparing the time of the obs with current
time
#wmo variables
my $sday = substr($a[1], 0, 2);
my $shour = substr($a[1], 2, 2);
my $smin = substr($a[1], 4, 2);
my $totalsys = "$hour$min";
my $totalwmo = "$shour$smin";
#check for if days are equal
if ($day >= $sday || $day < $sday) {
#how old is the obs? checks by minusing 40 from the actual time
#compare the WMO time stamp to the system time to make sure it is
in positive realm
if ($totalsys >= $totalwmo) {
#check hour to see if the system time needs editing
#then check to see how old the obs is
if ($hour > $shour) {
my $age = ($totalsys-40)-$totalwmo;
if ($age < 20) {
}
elsif ($age >= 20 && $age < 30) {
my $color = "133 245 252";
print OUT "Color: $color";
}
elsif ($age >=30 && $age < 60) {
my $color = "239 165 52";
print OUT "Color: $color";
}
else {
my $color = "172 49 49";
print OUT "Color: $color";
}
}
elsif ($hour == $shour) {
my $age = $totalsys-$totalwmo;
if ($age < 20) {
my $color = "0 0 0";
print OUT "Color: $color";
}
elsif ($age >= 20 && $age < 30) {
my $color = "133 245 252";
print OUT "Color: $color";
}
elsif ($age >=30 && $age < 60) {
my $color = "239 165 52";
print OUT "Color: $color";
}
else {
my $color = "172 49 49";
print OUT "Color: $color";
}
}
}
elsif ($totalsys <= $totalwmo) {
my $age = ($totalsys+60)-($totalwmo-2300);
if ($age < 20) {
my $color = "0 0 0";
print OUT "Color: $color";
}
elsif ($age >= 20 && $age < 30) {
my $color = "133 245 252";
print OUT "Color: $color";
}
elsif ($age >=30 && $age < 60) {
my $color = "239 165 52";
print OUT "Color: $color";
}
else {
my $color = "172 49 49";
print OUT "Color: $color";
}
}
}
if (length($id[1]) == 5) { #with synop code
chop ($id[3]);
chop ($id[5]);
chomp $obs;
my $p = ".";
my $n = "-";
my $lat = $id[2]+($id[3]*(1/60));
my $rlat = sprintf("%.4f", $lat);
my $long = -($id[4]+($id[5]*(1/60)));
my $rlong = sprintf("%.4f", $long);
my @stid = ( $obs, $rlat, $rlong);
metarcode (@stid);
}
else { #without synop code
chop ($id[2]);
chop ($id[4]);
chomp $obs;
my $lat = $id[1]+($id[2]*(1/60));
my $rlat = sprintf("%.4f", $lat);
my $long = -($id[3]+($id[4]*(1/60)));
my $rlong = sprintf("%.4f", $long);
my @stid = ( $obs, $rlat, $rlong);
metarcode (@stid);
}
}
}
}
close (OUT);

FILE
=========================================================
KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top