#!/usr/local/bin/perl use POSIX; print "Content-type: text/html\n\n"; print ""; print " ASOS Station Observations and Zone Forecast "; print ""; print ''; # print ""; print "

\n"; print ' '; print "To display the latest Metar observations and the zone forecast,
"; print "enter the station identifier (ICAO abbrevbiation) below
"; print "
"; $ENV{'PATH'} = '/usr/local/weather/bin/solaris/weather'; print '
'; print '
'; read (STDIN, $user_input, $ENV{'CONTENT_LENGTH'}); $sID = substr($user_input,5,4); print "

\n"; print ""; @mdecode = `/usr/local/weather/bin/solaris/weather -c metardecode $sID l `; @zone = `/usr/local/weather/bin/solaris/weather -c zones $sID l `; $num_obs = @mdecode; $zone_length = @zone; $stat = substr($mdecode[3],0,4); $time = substr($mdecode[3],5,4); $tempc = substr($mdecode[3],27,3); $tempdpc = substr($mdecode[3],31,3); $len = length($sID); if ($len == 0) { print "\n\n"; exit; } if ($len != 0 && $time == 0 && $tempc == 0 && tempdpc == 0) { print "

\n"; print "Station identifier $sID is not a valid station"; print "

\n"; print "\n\n"; exit; } print "

"; if ($len != 0 && $num_obs != 0) { print "For station $sID, the following Metar observation(s) are given:

"; } if ($len != 0 && $num_obs == 0) { print "

\n"; print "
No Metar observations for $sID are available at this time

"; print "

\n"; } for ( $count = 3; $count <= $num_obs - 1; $count++ ) { $wspd = substr($mdecode[$count],39,3); $stat = substr($mdecode[$count],0,4); $time = substr($mdecode[$count],5,4); $alt = substr($mdecode[$count],21,5); $tempc = substr($mdecode[$count],27,3); $tempdpc = substr($mdecode[$count],31,3); $wdir = substr($mdecode[$count],35,3); $sky1 = substr($mdecode[$count],64,3); $sky2 = substr($mdecode[$count],71,3); $sky3 = substr($mdecode[$count],78,3); $tempf = $tempc * 1.8 + 32.5; $tempdpf = $tempdpc * 1.8 + 32.5; $pres = $alt * 33.86; @wnd = (NNE,"NE",ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,N); $wind_inc = 11.25; $wind_count = 0; if ($wdir >=0 && $wdir <= 360) { if (($wdir >=0.0 && $wdir <= 11.25) || ($wdir > 348.75 && $wdir <= 360.0)) { $wind_dir = $wnd[15]; } else { wind: { if ($wdir > $wind_inc && $wdir <= $wind_inc + 22.5) { $wind_dir = $wnd[$wind_count]; } else { $wind_inc = $wind_inc + 22.5; $wind_count++; goto wind; } } } } @sky_ID = (OVC,BKN,SCT,FEW,CLR); if ($sky1 eq $sky_ID[0] || $sky2 eq $sky_ID[0] || $sky3 eq $sky_ID[0]) { $sky_dis = "cloudy"; } elsif ($sky1 eq $sky_ID[1] || $sky2 eq $sky_ID[1] || $sky3 eq $sky_ID[1]) { $sky_dis = "mostly cloudy"; } elsif ($sky1 eq $sky_ID[2] || $sky2 eq $sky_ID[2] || $sky3 eq $sky_ID[2]) { $sky_dis = "partly cloudy"; } elsif ($sky1 eq $sky_ID[3] || $sky2 eq $sky_ID[3] || $sky3 eq $sky_ID[3]) { $sky_dis = "mostly clear"; } elsif ($sky1 eq $sky_ID[4] || $sky2 eq $sky_ID[4] || $sky3 eq $sky_ID[4]) { $sky_dis = "clear"; } else { $sky_dis = "not reported"; } print "Time of observation: $time GMT:
"; if ($tempc == -99.0 || $tempc <= -90.0) { print "Temperature not reported
"; } else { print "Temperature is: $tempf ºF
"; } if ($tempdpc == -99.0 || $tempdpc <= -90.0) { print "Dewpoint is not reported
"; } else { print "Dewpoint is: $tempdpf ºF
"; } print "Pressure is: ".sprintf("%.1f",$pres)." mb
"; if ($wspd <= 5 && $wspd >= 0) { print "Winds are calm"; } elsif ($wspd > 5 && ($wdir > 360 || $wdir < 0)) { print "Winds are $wspd
"; print "Wind direction not reported
"; } elsif ($wspd <= 0 && ($wdir > 360 || $wdir < 0)) { print "Wind speed/direction is not reported"; } else { print "Winds are $wspd kt from the $wind_dir ($wdirº)"; } print "
"; if ($sky_dis =~ /not reported/) { print "Skies are $sky_dis"; } else { print "Skies are $sky_dis"; } print "

"; } %words = ( "TODAY" => "TODAY", "TONIGHT" => "TONIGHT", "THIS AFTERNOON" => "THIS AFTERNOON", "THIS EVENING" => "THIS EVENING", "MONDAY" => "MONDAY", "TUESDAY" => "TUESDAY", "WEDNESDAY" => "WEDNESDAY", "THURSDAY" => "THURSDAY", "FRIDAY" => "FRIDAY", "SATURDAY" => "SATURDAY", "SUNDAY" => "SUNDAY", "THUNDERSTORMS" => "THUNDERSTORMS", "RAIN" => "RAIN", "SHOWERS" => "SHOWERS", "WINDY" => "WINDY", "BREEZY" => "BREEZY", "GUSTY" => "GUSTY", "GUSTS" => "GUSTS", "SNOW" => "SNOW", "FOG" => "FOG", "CLOUDY" => "CLOUDY", "CLEAR" => "CLEAR", "SUNNY" => "SUNNY", "SEABREEZE" => "SEABREEZE", "LANDBREEZE" => "LANDBREEZE", "ADVISORY" => "ADVISORY" ); print "

"; if ($len != 0 && $zone_length == 0) { print "

\n"; print "The zone forecast is not available

"; print "

\n"; } system "/usr/local/weather/bin/solaris/weather -c zones $sID l > /home/cmwalsh/zone.forecast"; open(IN,"/home/cmwalsh/zone.forecast"); while () { foreach $key (keys %words) { s/$key/$words{$key}/gi; } print; print "
"; } print "
"; print "\n\n"; close (IN); exit;