#!/usr/local/bin/perl use POSIX; #Sets the path of the program to "/usr/local....." see below $ENV{'PATH'} = '/usr/local/weather/bin/solaris/weather'; #Setting up the website print "Content-type: text/html\n\n"; print ""; print " ASOS Station Observations and Zone Forecast "; print ""; #Creates form for user defined input print '
'; print '
'; #Defines variable (tempID) for user input read (STDIN, $manualpost, $ENV{'CONTENT_LENGTH'}); #This takes the variable tempID which has a value of "name=[user defined station]" #and stores the actual station ID in the variable stationID $stationid = substr($manualpost,5,4); #This takes the variable tempID which has a value of "name=[user defined sataion]" and #splits it into 2 elements seperated by the "=" and stores both elements into the #array userID (denoted by the "@" symbol) # # This is not necessary due to metod used above, but kept for reference # # @userID=split(/=/,$tempID); #Reads in the data from the weather program METARDECODE and stores it into #the array metardecode @lines = `/usr/local/weather/bin/solaris/weather -c metardecode $stationid l `; $lsize = @lines; print "$lsize"; print "\n"; #Need to determine the number of metar reports for the current station, this would be #be the size of the array (metardecode) minus 2, as the first 2 lines are the header # $num_obs = @mdecode; #print "$num_obs"; #Now that the array metardecode has the data, variables are set to hold the #individual data elements, such at temperature and pressure. This "reading of #the variables" is to determine if conditions exist $stat = substr($lines[3],0,4); $time = substr($metardecode[3],5,4); $tempc = substr($metardecode[3],27,3); $tempdpc = substr($metardecode[3],31,3); #Need to determine if obserbvations exist, if not, exit if ($time == 0 && $tempc == 0 && $tempdpc == 0) { print "\n The latest observations are not available for this station \n\n"; exit; } #Need to process all obs, convert variables as follows: #Temp (tempc) and dewpoint temp (tempdpc) needs to be converted to fahrenheit #Wind direction wdir needs to be associated with a cardinal dir (eg SSW) #Sky Conditions need to be converted from OVC to overcast ....etc for ($count = 3; $count <= $num_obs + 2; $count++) { $stat = substr($metardecode[$count],0,4); $time = substr($metardecode[$count],5,4); $alt = substr($metardecode[$count],21,5); $tempc = substr($metardecode[$count],27,3); $tempdpc = substr($metardecode[$count],31,3); $wdir = substr($metardecode[$count],35,3); $wspd = sudstr($metardecode[$count],39,3); $sky1 = substr($metardecode[$count],64,3); $sky2 = substr($metardecode[$count],71,3); $sky3 = substr($metardecode[$count],78,3); #Temperature and dewpoint must be converted from Celsius to Fahrenheit #Altimeter pressure must be converted from inHg to hPa (mb) $tempf = $tempc * 1.8 + 32.5; $tempdpf = $tempdpc * 1.8 + 32.5; $calc_press = $alt * 33.86; #Need to adjust the output format of temp, dewpoint, and pressure such that no #decimals are displayed if ($tempf < 100) { $temp = substr($tempf,0,2); } else { $temp = substr($tempf,0,3); } if ($tempdpf < 100) { $tempdp = substr($tempdpf,0,2); } else { $tempdp = substr($tempdpf,0,3); } if ($calc_pres < 1000) { $pres = substr($calc_pres,0,3); } else { $pres = substr($calc_pres,0,4); } #Wind direction in degrees must be converted to a cardinal direction @wnd = (N,NNE,"NE",ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,N); $wind_inc = 0; $wind_count = 0; if ($wdir >=0 && $wdir <= 360) { wind: { if ($wdir > $wind_inc && $wdir <= $wind_inc + 12.25) { $wind_dir = $wnd[$wind_count]; } else { $wind_inc = $wind_inc + 12.25; $wind_count++; goto wind; } } } else { print "\n*!* Error in wind direction: either < 0 or > 360 *!*\n"; } #Sky Conditions must be converted from 3 letter designation to description: #ex. OVC -> Cloudy @sky_ID = (OVC,BKN,SCT,FEW,CLR, ); @sky_obs = (Cloudy,Mostly Cloudy,Partly Cloudy,Mostly Clear,Clear, ); @sky_met = ($sky1,$sky2,$sky3); $sky_count = 0; sky: { if ($sky_met[1] == $sky_ID[$sky_count] || $sky_mey[2] == $sky_ID[$sky_count] || $sky_met[3] == $sky_ID[$sky_count] ) { $sky_dis = $sky_obs[$sky_count]; } else { $sky_count++; goto sky; } } #Ready to ouput conditions print "\nFor station $stat at $time GMT:"; print "
"; print "Temperature is: $temp [F]"; print "
"; print "Dewpoint is: $tempdp [F]"; print "
"; print "Pressure is: $pres [mb]"; print "
"; #Must determine wind conditions. Either winds are calm: wind speed (wspd) = 0 #or wind speed != 0, then wind speed and direction is given if ($wspd = 0) { print "Winds are calm."; } else { print "Winds are $wspd [kt] from the $wind_dir"; } print "
"; print "Skies are $sky_dis"; print "

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