#!/usr/bin/perl # CREATED: 2004-10-06 # UPDATE: 2006-07-24 #This routine is similar to the NWS one, however, we are getting data from SAWS sources. require 5.002; use CGI; use CGI::Carp qw(fatalsToBrowser); $query= new CGI; $source_dir1 = "/var/www/html/1STWX/Realtime"; print $query->header; print ""; print "REALTIME WEATHER | www.1stweather.com"; print ""; print""; #$icao = $ARGV[0]; command line only $icao = uc $query->param('icao'); $icao=~ tr/A-Z/a-z/; %citycode = ( 'faab','Alexander_Bay', 'faan','Aliwal_North', 'faad','Alldays', 'fabp','Badplaas', 'faby','Beaufort_West', 'fabb','Bela-Bela', 'fabe','Bethlehem', 'fabs','Bhisho', 'fabl','Bloemfontein', 'facv','Calvinia', 'facp','Cape_Point', 'fact','Cape_Town_International_Airport', 'facy','Cape_Town', 'facw','Clanwilliam', 'facr','Cradock', 'fadn','Durban', 'fael','East_London', 'faeo','Ermelo', 'faex','Excelsior', 'fafs','Fauresmith', 'fafb','Ficksburg', 'faff','Fort_Beaufort', 'fagg','George', 'fagc','Giants_Castle', 'fagr','Graaff-Reinet', 'fagb','Grabouw', 'fagh','Grahamstown', 'fagk','Graskop', 'fagd','Groblersdal', 'fahm','Hermanus', 'faix','Ixopo', 'fajs','Johannesburg', 'fajb','Joubertina', 'fakm','Kimberley', 'fakl','Klerksdorp', 'fakk','Kokstad', 'fakp','Komatidraai', 'faks','Kroonstad', 'faku','Kuruman', 'fals','Ladysmith', 'falb','Langebaan', 'faer','Lephalale', 'falv','Levubu', 'fald','Lydenburg', 'famk','Mafikeng', 'famm','Malmesbury', 'famg','Margate', 'famp','Mokopane', 'famr','Mooiriver', 'faut','Mthatha', 'fams','Musina', 'fans','Nelspruit', 'fanc','Newcastle', 'fanq','Ngqura', 'faou','Oudtshoorn', 'fapl','Paarl', 'faph','Phalaborwa', 'fapm','Pietermaritzburg', 'fapr','PietRetief', 'fapb','Polokwane', 'fapa','Port_Alfred', 'fape','Port_Elizabeth', 'fapo','Postmasburg', 'faps','Potchefstroom', 'fapr','Pretoria', 'faqt','Queenstown', 'fard','Riversdale', 'faro','Robertson', 'faru','Rustenburg', 'fasa','Sasolburg', 'fasz','Skukuza', 'fask','Slangkop', 'fasb','Springbok', 'fasd','Standerton', 'faca','Stilbaai', 'fasl','St._Lucia_Estuary', 'fasr','Strand', 'fasu','Sutherland', 'fata','Taung', 'fath','Thabazimbi', 'fato','Thohoyandou', 'fatz','Tzaneen', 'faui','Uitenhage', 'fauu','Ulundi', 'faub','Underberg', 'faup','Upington', 'favg','Vereeniging', 'favd','Vredendal', 'favb','Vryburg', 'favy','Vryheid', 'fawm','Welkom', 'fawi','Witbank', 'fawx','Worcester' ); %cityName = ( 'faab','Alexander Bay', 'faan','Aliwal North', 'faad','Alldays', 'fabp','Badplaas', 'faby','Beaufort West', 'fabb','Bela-Bela', 'fabe','Bethlehem', 'fabs','Bhisho', 'fabl','Bloemfontein', 'facv','Calvinia', 'facp','Cape Point', 'fact','Cape Town (Airport)', 'facy','Cape Town', 'facw','Clanwilliam', 'facr','Cradock', 'fadn','Durban', 'fael','East London', 'faeo','Ermelo', 'faex','Excelsior', 'fafs','Fauresmith', 'fafb','Ficksburg', 'faff','Fort Beaufort', 'fagg','George', 'fagc','Giants Castle', 'fagr','Graaff Reinet', 'fagb','Grabouw', 'fagh','Grahamstown', 'fagk','Graskop', 'fagd','Groblersdal', 'fahm','Hermanus', 'faix','Ixopo', 'fajs','Johannesburg', 'fajb','Joubertina', 'fakm','Kimberley', 'fakl','Klerksdorp', 'fakk','Kokstad', 'fakp','Komatidraai', 'faks','Kroonstad', 'faku','Kuruman', 'fals','Ladysmith', 'falb','Langebaan', 'faer','Lephalale', 'falv','Levubu', 'fald','Lydenburg', 'famk','Mafikeng', 'famm','Malmesbury', 'famg','Margate', 'famp','Mokopane', 'famr','Mooiriver', 'faut','Mthatha', 'fams','Musina', 'fans','Nelspruit', 'fanc','Newcastle', 'fanq','Ngqura', 'faou','Oudtshoorn', 'fapl','Paarl', 'faph','Phalaborwa', 'fapm','Pietermaritzburg', 'fapr','PietRetief', 'fapb','Polokwane', 'fapa','Port Alfred', 'fape','Port Elizabeth', 'fapo','Postmasburg', 'faps','Potchefstroom', 'fapr','Pretoria', 'faqt','Queenstown', 'fard','Riversdale', 'faro','Robertson', 'faru','Rustenburg', 'fasa','Sasolburg', 'fasz','Skukuza', 'fask','Slangkop', 'fasb','Springbok', 'fasd','Standerton', 'faca','Stilbaai', 'fasl','St. Lucia Estuary', 'fasr','Strand', 'fasu','Sutherland', 'fata','Taung', 'fath','Thabazimbi', 'fato','Thohoyandou', 'fatz','Tzaneen', 'faui','Uitenhage', 'fauu','Ulundi', 'faub','Underberg', 'faup','Upington', 'favg','Vereeniging', 'favd','Vredendal', 'favb','Vryburg', 'favy','Vryheid', 'fawm','Welkom', 'fawi','Witbank', 'fawx','Worcester' ); %citydirname = ( 'faab','alexanderbay', 'faan','aliwalnorth', 'faad','alldays', 'fabp','badplaas', 'faby','beaufortwest', 'fabb','belabela', 'fabe','bethlehem', 'fabs','bisho', 'fabl','bloemfontein', 'facv','calvinia', 'facp','capepoint', 'fact','capetown', 'facw','clanwilliam', 'facr','cradock', 'fadn','durban', 'fael','eastlondon', 'faeo','Ermelo', 'faex','excelsior', 'fafs','fauresmith', 'fafb','ficksburg', 'faff','fortbeaufort', 'fagg','george', 'fagc','giantscastle', 'fagr','graaffreinet', 'fagb','grabouw', 'fagh','grahamstown', 'fagk','graskop', 'fagd','groblersdal', 'fahm','hermanus', 'faix','ixopo', 'fajs','johannesburg', 'fajb','joubertina', 'fakm','kimberley', 'fakl','klerksdorp', 'fakk','kokstad', 'fakp','komatidraai', 'faks','kroonstad', 'faku','kuruman', 'fals','ladysmith', 'falb','langebaan', 'faer','lephalale', 'falv','levubu', 'fald','lydenburg', 'famk','mafikeng', 'famm','malmesbury', 'famg','margate', 'famp','mokopane', 'famr','mooiriver', 'faut','mthatha', 'fams','musina', 'fans','nelspruit', 'fanc','newcastle', 'fanq','ngqura', 'faou','oudtshoorn', 'fapl','paarl', 'faph','phalaborwa', 'fapm','pietermaritzburg', 'fapr','pietretief', 'fapb','polokwane', 'fapa','portalfred', 'fape','portelizabeth', 'fapo','postmasburg', 'faps','potchefstroom', 'fapr','pretoria', 'faqt','queenstown', 'fard','riversdale', 'faro','robertson', 'faru','rustenburg', 'fasa','sasolburg', 'fasz','skukuza', 'fask','slangkop', 'fasb','springbok', 'fasd','standerton', 'faca','stilbaai', 'fasl','capestlucia', 'fasr','strand', 'fasu','sutherland', 'fata','taung', 'fath','thabazimbi', 'fato','thohoyandou', 'fatz','tzaneen', 'faui','uitenhage', 'fauu','ulundi', 'faub','underberg', 'faup','upington', 'favg','vereeniging', 'favd','vredendal', 'favb','vryburg', 'favy','vryheid', 'fawm','welkom', 'fawi','witbank', 'fawx','worcester' ); $citydir=$citydirname{$icao}; $cityfile=$citycode{$icao}; $city=$cityName{$icao}; $REALTIME_FILE="$source_dir1/SAWS_$cityfile.realtime"; &extract_REALTIME($REALTIME_FILE,$icao,$city); exit; sub extract_REALTIME{ #print "\n\nFILE = $REALTIME_FILE [$city]\n"; $x=0; open REALTIME_FILE or print "Can't open $REALTIME_FILE datafile : $!\n\n"; while(){ $x++; $realtime_data[$x].=$_; chomp ($realtime_data[$x]); #if(($x > 350)&&($x <450)){ print" realtime_data[$x] = $realtime_data[$x]\n";} } for($xx=0;$xx<=$x;$xx++){ # Strip out ALL HTML tags $realtime_data[$xx]=~ s/<.+?>//g; $realtime_data[$xx]=~ s/°C//g; $realtime_data[$xx]=~ s/\t//gs; #if(($xx > 0)&&($xx <450)){ print" realtime_data[$xx] = $realtime_data[$xx]\n";} } $y = 0; for($y = 0;$y<=$x;$y++){ if($realtime_data[$y]=~ /Reported Weather/){ $rt_time{"$icao"} = $realtime_data[$y+4]; # Time } if($realtime_data[$y]=~ /Humidity:/){ $rt_wind_dir{"$icao"} = $realtime_data[$y+11]; # Wind information $rt_wind_spd{"$icao"} = $realtime_data[$y+11]; # Wind information } if($realtime_data[$y]=~ /Temperature/){ $rt_temp{"$icao"} = $realtime_data[$y+2]; # Current Temperature } if($realtime_data[$y]=~ /Point:/){ $rt_dew{"$icao"} = $realtime_data[$y+1]; # Dewpoint Temperature } if($realtime_data[$y]=~ /Humidity:/){ $rt_hum{"$icao"} = $realtime_data[$y+1]; # Humidity } if($realtime_data[$y]=~ /km\/h/){ $rt_wind{"$icao"} = $realtime_data[$y-1]; # WIND CONDITIONS } if($realtime_data[$y]=~ /Pressure/){ $rt_pressure{"$icao"} = $realtime_data[$y+1]; # QNH } if($realtime_data[$y]=~ /cover:/){ $rt_sky{"$icao"} = $realtime_data[$y+1]; # SKY CONDITIONS } if($realtime_data[$y]=~ / Weather /){ $rt_wx{"$icao"} = $realtime_data[$y+2]; # WEATHER CONDITIONS } if($realtime_data[$y]=~ /Visibility:/){ $rt_viz{"$icao"} = $realtime_data[$y+1]; # VIZ CONDITIONS } } #$rt_time{$icao}=~ s/ //g; #print"\n\nUNPROCESSED:\n\n"; #print"\n\nCITY: [$icao]\n\n"; #print"DATE = $rt_time{$icao}\n"; #print"tempC = $rt_temp{$icao}\n"; #print"dewC = [$rt_dew{$icao}]\n"; #print"humidity = $rt_hum{$icao}\n"; #print"pressure = $rt_pressure{$icao}\n"; #print"wind_dir = $rt_wind_dir{$icao}\n"; #print"wind_kph = $rt_wind_spd{$icao}\n"; #print"skycon = [$rt_sky{$icao}]\n\n"; # TIME $mystring = $rt_time{"$icao"}; @words = ($mystring =~ m/(\w+)/g); #print join(",", @words); $words[1] = sprintf("%02d", $words[1]); $words[4] = sprintf("%02d", $words[4]); $words[5] = sprintf("%02d", $words[5]); $words[2]= substr($words[2],0,3); $SAST = $words[0].", ".$words[1]." ".$words[2]." ".$words[3]." ".$words[4].":".$words[5]." SAST"; $SAST1 =$words[4].$words[5]; # TEMPERATURE @words=(); $mystring = $rt_temp{"$icao"}; @words = ($mystring =~ m/(\d+)/g); $tempC = $words[0]; $tempC=~ s/ //g; $tempF = ($tempC*1.8)+32; # DEWPOINT @words=(); $mystring = $rt_dew{"$icao"}; @words = ($mystring =~ m/(\d+)/g); $dewC = $words[0]; $dewC=~ s/ //g; $dewF = ($dewC*1.8)+32; # HUMIDITY @words=(); $mystring = $rt_hum{"$icao"}; @words = ($mystring =~ m/(\d+)/g); $humidity = $words[0]; $humidity=~ s/ //g; # PRESSURE @words=(); $mystring = $rt_pressure{"$icao"}; @words = ($mystring =~ m/(\d+)/g); $pressure = $words[0]; $pressure =~ s/ //g; # &tendency($SAST1,$pressure); # WINDSPEED & WIND SPEED @words=(); $mystring = $rt_wind{"$icao"}; @words = ($mystring =~ m/(\w+)/g); $wind_dir = $words[0]; @words=(); $mystring = $rt_wind{"$icao"}; @words = ($mystring =~ m/(\d+)/g); $wind_kph = $words[0]; $wind_dir=~ s/ //g; $wind_kph=~ s/ //g; $wind_mph= ($wind_kph/0.62); $windknots = $wind_kph/1.83; if($wind_dir eq ""){ if($wind_kph < 1){ $wind_dir = "Calm"; } if($wind_kph > 0){ $wind_dir = "Variable"; } } # VISIBILITY $rt_viz{"$icao"} =~ tr/A-Z/a-z/; #make lower case $mystring = $rt_viz{"$icao"}; @viz_cond = ($mystring =~ m/(\d+)/g); $viz= $viz_cond[0]; if($viz eq ""){$viz = "N/A";} if($viz eq "10"){$viz = "> 10";} # SKY CONDITIONS $rt_sky{"$icao"} =~ tr/A-Z/a-z/; #make lower case $mystring = $rt_sky{"$icao"}; @sky_cond = ($mystring =~ m/(\w+)/g); $sky= $sky_cond[0]; if($skycon eq ""){ $skycon = "N/A"; } # WEATHER CONDITIONS $rt_wx{"$icao"} =~ tr/A-Z/a-z/; #make lower case $mystring = $rt_wx{"$icao"}; @weather_cond = ($mystring =~ m/(\w+)/g); $weather = $weather_cond[0]; if($weather eq ""){ $weather = "N/A"; } # CHOOSE WEATHER ICONS $weather_flag = 0; $skycon =~ tr/A-Z/a-z/; $weather =~ tr/A-Z/a-z/; if($weather_flag < 1){ if(($skycon eq "n/a") || ($skycon=~/clear/)){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_sunny.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/sun.gif"; $wb = "Sunny"; $wb1 = "Sunny"; $weather_flag++; } } if($weather_flag < 1){ if($skycon=~/mostly cloudy/){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_mcloudy.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/clouds.gif"; $wb= "Mostly
cloudy"; $wb1= "Mostly cloudy"; $weather_flag++; } } if($weather_flag < 1){ if($skycon=~/partly cloudy/){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_pcloudy.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/ptcloudy.gif"; $wb= "Partly
cloudy"; $wb1= "Partly cloudy"; $weather_flag++; } } if($weather_flag < 1){ if($skycon=~/mostly clear/){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_pcloudy.gif"; $wb= "Partly
cloudy"; $wx2go_icon = "http://www.1stweather.com/WX2GO/ptcloudy.gif"; $wb1= "Partly cloudy"; $weather_flag++; } } if($weather_flag < 1){ if(($skycon=~/overcast/)||($skycon=~/cloudy/)){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_cloudy.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/clouds.gif"; $wb= "Overcast"; $wb1= "Overcast"; $weather_flag++; } } if($weather_flag < 1){ if($skycon=~/thunder/){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_thunder.gif"; $wb= "Thunder
clouds observed"; $wx2go_icon = "http://www.1stweather.com/WX2GO/thunder.gif"; $wb1= "Thunder clouds observed"; $weather_flag++; } } if($weather_flag < 1){ if(($weather=~/patches of fog/)||($weather=~/fog/)){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_fog.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/fog.gif"; $wb= "Fog"; $wb1= "Fog"; $weather_flag++; } } if($weather_flag < 1){ if(($weather=~/light rain/)||($weather=~/light/)){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_rain.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Light rain"; $weather_flag++; } } if($weather_flag < 1){ if(($weather=~/drizzle/)||($weather=~/light drizzle/)){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_drizzle.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/sprinkles.gif"; $wb= "Light drizzle"; $weather_flag++; } } if($weather_flag < 1){ if(($weather=~/light rain showers/)||($weather=~/showers/)){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_showers.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/showers.gif"; $wb= "Light Showers"; $wb1= "Light Showers"; $weather_flag++; } } if($weather_flag < 1){ if($weather=~/rain/){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_rain.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Rain"; $wb1= "Rain"; $weather_flag++; } } if((($windknots > 30)&& ($weather=~/rain/))){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_stormy.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Stormy"; $wb1= "Stormy"; $weather_flag++; } if((($windknots_gust > 30)&& ($weather=~/rain/))){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_stormy.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Stormy"; $wb1= "Stormy"; $weather_flag++; } if(($windknots > 20) && ($weather eq "n/a")){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_windy.gif"; $wb= "Windy"; $wb1= "Windy"; $weather_flag++; } # if(($weather eq "n/a")&& ($skycon eq "n/a")){ # $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_sunny.gif"; # $wx2go_icon = "http://www.1stweather.com/WX2GO/sun.gif"; # $weather = "Sunny"; # $wb= "Sunny"; # $wb1= "Sunny"; # } if(($weather eq "n/a")&& ($skycon eq "n/a")){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_nodata.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/nodata.gif"; $weather = "NO SKY DATA"; $wb= "NO SKY DATA"; $wb1= "NO SKY DATA"; $weather_flag++; } if($weather eq "n/a"){ $weather = $skycon; $wb= $skycon; $wb1= $skycon; $weather_flag++; } if(($SAST1 < 0500) || ($SAST1 > 1900)){ if($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_sunny.gif"){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_clear_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/night_clear.gif"; $wb = "Clear"; $weather = "Clear"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_mcloudy.gif"){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_mcloudy_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/clouds_night.gif"; $wb= "Mostly
cloudy"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_pcloudy.gif"){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_pcloudy_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/ptcloudy_night.gif"; $wb= "Partly
cloudy"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_cloudy.gif"){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_cloudy_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/clouds_night.gif"; $wb= "Overcast"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_fog.gif"){ $wx_icon = "http://www.1stweather.com/metrocast/images/1STWX/old/mc_fog_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/fog.gif"; $wb= "Fog"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_drizzle.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_dizzle_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Drizzle"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_rain.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_rain_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Rain"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_showers.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_showers_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/showers_night.gif"; $wb= "Showers"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_stormy.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_stormy_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/rain.gif"; $wb= "Stormy"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_windy.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_windy_night.gif"; $wb= "Windy"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_thunder.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_thunder_night.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/thunder_night.gif"; $wb= "Thunder"; } elsif($wx_icon eq "http://www.1stweather.com/metrocast/images/1STWX/old/mc_nodata.gif"){ $wx_icon ="http://www.1stweather.com/metrocast/images/1STWX/old/mc_nodata.gif"; $wx2go_icon = "http://www.1stweather.com/WX2GO/nodata.gif"; $wb= "NO SKY DATA"; } } # CALCULATE WINDCHILLS AND HEAT INDICES if($tempC < 5) { &windchill($windknots, $wind_kph, $tempC,$tempF); } else{ &heatindex($tempC, $dewC, $tempF, $humidity ); } # CHECKS & FORMATS $wind_kph = sprintf("%2.0f", $wind_kph); $windknots = sprintf("%2.0f", $windknots); $dewF = sprintf("%3.1f", $dewF); $tempF = sprintf("%3.1f", $tempF); $temp = sprintf("%3.1f", $temp); if($dewC eq ""){ $dewC = "N/A"; $dewF = "N/A"; $humidity = "N/A"; $windchillC = "N/A"; $heatindexC = "N/A"; $windchillF = "N/A"; $heatindexF = "N/A"; } else{ $dewC = sprintf("%2.1f", $dewC); $windchillC = sprintf("%2.1f", $windchillC); $heatindexC = sprintf("%2.1f", $heatindexC); } $windmph_gust = $windkph_gust = $windknots_gust = "N/A"; #print"n\nPROCESSED:\n"; #print"CITY: [$city]\n"; #print"TIME: [$SAST]\n"; #print"tempC = $tempC\n"; #print"tempF = $tempF\n"; #print"dewC = $dewC\n"; #print"dewF = $dewF]\n"; #print"hum = $humidity\n"; #print"windchill = $windchillC\n"; #print"heatindex = $heatindexC\n"; #print"pressure = $pressure\n"; #print"wind_dir = $wind_dir\n"; #print"wind_kph = $wind_kph\n"; #print"windkph_gust = ($windkph_gust)\n"; #print"windknots_gust = $windknots_gust\n"; #print"skycon = $skycon\n"; #print"weather = $weather\n"; #print"wx_icon = $wx_icon\n\n"; #print"CODE = $code\n\n"; close(REALTIME_FILE); # WRITE OUT REAL-TIME FILE # print &PrintHeader; $URL = "http://www.1stweather.com/metrocast/".$citydir."/index.shtml"; print < $city,
South Africa
$SAST
$weather
$tempC°C
($tempF°F)
Wind: $wind_dir $wind_kph kph
$wb
Humidity: $humidity %
Pressure: $pressure hPa
Click here for forecast
Brought to you by
www.1stweather.com
ENDOFTEXT print ""; return } sub windchill { if (($wind_kph > 5)&&($tempC <=5)){ #$windchillC = sprintf("%d", 0.045 * (5.27 * sqrt($wind_kph) + 10.45 -( 0.28 * $wind_kph)) * ($tempC - 33) + 33); #$windchillF = sprintf("%d",$windchillC * 1.8 + 32); $windchillF = (35.74 + (0.6215*$tempF) - 35.75*($wind_mph**0.16) + 0.4275*$tempF*($wind_mph**0.16)); $windchillC = ($windchillF - 32)*5/9; $code = 1; } else { $windchillC = sprintf("%02d", $tempC); $windchillF = sprintf("%02d", $tempF); $code=2; } return $windchillC, $windchillF, $code; } sub heatindex { if($tempF >80){ $heatindexF=-42.379 + 2.04901523*$tempF + 10.14333127*$humidity -.22475541*$tempF*$humidity - .00683783*$tempF*$tempF - .05481717*$humidity*$humidity + .00122874*$tempF*$tempF*$humidity + .00085282*$tempF*$humidity*$humidity - .00000199*$tempF*$tempF*$humidity*$humidity; $heatindexF= sprintf("%d,",$heatindexF); $heatindexC= sprintf("%d",5/9 * ($heatindexF -32)); $code = 3; } else{ $heatindexC = $tempC; $heatindexC=sprintf("%02d", $heatindexC); $heatindexF = $tempF; $heatindexF=sprintf("%02d", $heatindexF); $code = 3; } return $heatindexC, $heatindexF; }