Hacking attempt. Denied.\n"; exit(); } if(!isset($WX['stationDate'])) {return;} $WXsoftware = 'WV'; // this has WD $varnames = $WX['WV-varnames']; equivalents if(!isset($WX['tempUnit'])) { die ('Unable to find weather data.'); } $uomtemp = $WX['tempUnit']; $uombaro = $WX['barUnit']; $uomwind = $WX['windUnit']; $uomrain = $WX['rainUnit']; $time = $WX['stationTime']; $date = $WX['stationDate']; $sunrise = $WX['sunriseTime']; $sunset = $WX['sunsetTime']; $moonrise = $WX['moonriseTime']; $moonset = $WX['moonsetTime']; $moonphasename = $WX['moonPhase']; $hoursofpossibledaylight = $WX['dayLength']; $stationaltitude = $WX['stationElevation']; $stationlatitude = $WX['stationLatitude']; $stationlongitude = $WX['stationLongitude']; $Startimedate = $WX['wviewUpTime']; $wdversion = preg_replace('|wview |i','',$WX['wviewVersion']); // calculated value $noaacityname = $WX['stationCity']; $temperature = $WX['outsideTemp']; $tempnodp = round(preg_replace('|,|','.',$WX['outsideTemp']),0); // calculated value $humidity = $WX['outsideHumidity']; $dewpt = $WX['outsideDewPt']; $maxtemp = $WX['hiOutsideTemp']; $maxtempt = $WX['hiOutsideTempTime']; $mintemp = $WX['lowOutsideTemp']; $mintempt = $WX['lowOutsideTempTime']; $heati = $WX['outsideHeatIndex']; $heatinodp = round(preg_replace('|,|','.',$WX['outsideHeatIndex']),0); // calculated value $windch = $WX['windChill']; $windchnodp = round(preg_replace('|,|','.',$WX['windChill']),0); // calculated value $apparenttemp = $WX['apparentTemp']; $humchangelasthour = $WX['hourchangehumid']; $dewchangelasthour = $WX['hourchangedewpt']; $barochangelasthour = $WX['hourchangebarom']; $avgspd = $WX['windSpeed']; $gstspd = $WX['windGustSpeed']; $maxgst = $WX['hiWindSpeed']; $maxgstt = $WX['hiWindSpeedTime']; $dirdeg = $WX['windDirectionDegrees']; $dirlabel = $WX['windDirection']; $bftspeedtext = $WX['windBeaufortScale']; $baro = $WX['barometer']; $trend = $WX['hourchangebarom']; $dayrn = $WX['dailyRain']; $monthrn = $WX['monthlyRain']; $yearrn = $WX['totalRain']; $currentrainratehr = $WX['rainRate']; $maxrainrate = $WX['hiRainRate']; $maxrainratehr = $WX['hiRainRate']; $maxrainratetime = $WX['hiRainRateTime']; $vpstormrainstart = $WX['stormStart']; $vpstormrain = $WX['stormRain']; $VPsolar = $WX['solarRad']; $VPuv = $WX['UV']; $highsolar = $WX['hiRadiation']; $highuv = $WX['hiUV']; $highsolartime = $WX['hiRadiationTime']; $highuvtime = $WX['hiUVTime']; $mrecordwindgust = $WX['hiMonthlyWindSpeed']; $VPet = $WX['ET']; $highbaro = $WX['hiBarometer']; $highbarot = $WX['hiBarometerTime']; $minwindch = $WX['lowWindchill']; $minwindcht = $WX['lowWindchillTime']; $mrecordhighbaro = $WX['hiMonthlyBarometer']; $mrecordhightemp = $WX['hiMonthlyOutsideTemp']; $mrecordlowchill = $WX['lowMonthlyWindchill']; $mrecordlowtemp = $WX['lowMonthlyOutsideTemp']; $mrecordwindspeed = $WX['hiMonthlyWindSpeed']; $windruntodatethismonth = $WX['monthtodatewindrun']; $windruntodatethisyear = $WX['yeartodatewindrun']; $windruntoday = $WX['daywindrun']; $yrecordhighbaro = $WX['hiYearlyBarometer']; $yrecordhightemp = $WX['hiYearlyOutsideTemp']; $yrecordlowchill = $WX['lowYearlyWindchill']; $yrecordlowtemp = $WX['lowYearlyOutsideTemp']; $yrecordwindgust = $WX['hiYearlyWindSpeed']; $cloudheightfeet = $WX['cumulusBase']; $mrecordlowbaro = $WX['lowMonthlyBarometer']; $yrecordlowbaro = $WX['lowYearlyBarometer']; $maxdew = $WX['hiDewpoint']; $maxdewt = $WX['hiDewpointTime']; $mindew = $WX['lowDewpoint']; $mindewt = $WX['lowDewpointTime']; $mrecordhighdew = $WX['hiMonthlyDewpoint']; $mrecordlowdew = $WX['lowMonthlyDewpoint']; $yrecordhighdew = $WX['hiYearlyDewpoint']; $yrecordlowdew = $WX['lowYearlyDewpoint']; $maxheat = $WX['hiHeatindex']; $maxheatt = $WX['hiHeatindexTime']; $mrecordhighheatindex = $WX['hiMonthlyHeatindex']; $yrecordhighheatindex = $WX['hiYearlyHeatindex']; $lowbaro = $WX['lowBarometer']; $lowbarot = $WX['lowBarometerTime']; $monthtodatemaxbaro = $WX['hiMonthlyBarometer']; $monthtodateminbaro = $WX['lowMonthlyBarometer']; $mrecordhighsolar = $WX['hiMonthlyRadiation']; $yrecordhighsolar = $WX['hiYearlyRadiation']; $mrecordhighuv = $WX['hiMonthlyUV']; $yrecordhighuv = $WX['hiYearlyUV']; $highhum = $WX['hiHumidity']; $highhumt = $WX['hiHumTime']; $lowhum = $WX['lowHumidity']; $lowhumt = $WX['lowHumTime']; $mrecordhighhum = $WX['hiMonthlyHumidity']; $mrecordlowhum = $WX['lowMonthlyHumidity']; $yrecordhighhum = $WX['hiYearlyHumidity']; $yrecordlowhum = $WX['lowYearlyHumidity']; $yrecordrainrate = $WX['hiYearlyRainRate']; $mrecordrainrate = $WX['hiMonthlyRainRate']; // end of generation script # WV unique functions included from WV-functions-inc.txt #------------------------------------------------------------------------------------- # function processed WV (wview) variables #------------------------------------------------------------------------------------- global $SITE; $SITE['commaDecimal'] = strpos($temperature,',') !==false?true:false; // using comma for decimal point? include_once("get-metar-conditions-inc.php"); if(isset($SITE['conditionsMETAR'])) { // override with METAR conditions for text and icon if requested. list($Currentsolardescription,$iconnumber,$icongraphic,$icontext,$mtrstuff) = mtr_conditions($SITE['conditionsMETAR'], $time, $sunrise, $sunset,true); if(isset($currentrainratehr) and (!isset($SITE['overrideRain']) or (isset($SITE['overrideRain']) and $SITE['overrideRain'])) ) { list($Currentsolardescription,$iconnumber) = WV_RainRateIcon($Currentsolardescription,$iconnumber,$currentrainratehr,$uomrain,$time,$sunrise,$sunset); } } # generate the separate date/time variables by dissection of input date/time and format list($date_year,$date_month,$date_day,$time_hour,$time_minute,$monthname,$dayname) = WV_setDateTimes($date,$time,true); $beaufortnum = WV_beaufortNumber($avgspd,$uomwind); $bftspeedtext = WV_beaufortText($beaufortnum); list($chandler,$chandlertxt,$chandlerimg) = WV_CBI($temperature,$uomtemp,$humidity); list($feelslike,$heatcolourword) = WV_setFeelslike ($temperature,$windch,$heati,$uomtemp); $pressuretrendname = WV_get_barotrend_text($trend,$uombaro); $noaadata = WV_get_yesterday_data_from_NOAA_rpt(); if($noaadata['success'] == 'yes') { $maxtempyest = $noaadata['maxTemp']; $maxtempyestt = $noaadata['maxTempTime']; $mintempyest = $noaadata['minTemp']; $mintempyestt = $noaadata['minTempTime']; $yesterdayrain = $noaadata['rain']; } #------------------------------------------------------------------------------------- # WV support function - WV_RainRateIcon #------------------------------------------------------------------------------------- function WV_RainRateIcon($inText,$inIcon,$inRate,$inUOM,$time,$sunrise,$sunset,$lastRain='0000-00-00T00:00:00') { global $Debug; /* Rainfall intensity is classified according to the rate of precipitation: Light rain — rate is < 2.5 mm (0.098 in) per hour Moderate rain — rate is between 2.5 mm (0.098 in) - 7.6 mm (0.30 in) or 10 mm (0.39 in) per hour Heavy rain — rate is > 7.6 mm (0.30 in) per hour, or between 10 mm (0.39 in) and 50 mm (2.0 in) per hour Violent rain — rate is > 50 mm (2.0 in) per hour */ $Debug .= "\n"; $newText = ''; // assume no changes $newIcon = $inIcon; $rate = $inRate; if(preg_match('|in|i',$inUOM)) { // convert to mm/hr rate $rate = $inRate * 25.4; } if(substr($lastRain,0,4) <> '0000') { if($rate < 0.001 and time()-strtotime($lastRain) < 30*60) { $newText = 'Moderate Drizzle'; } } if ($rate > 0.0 and $rate < 2.5) { $newText = 'Light Rain'; } if ($rate >=2.5 and $rate < 7.6) { $newText = 'Moderate Rain'; } if ($rate >=7.6 and $rate < 50.0) { $newText = 'Heavy Rain'; } if ($rate >= 50.0) { $newText = 'Violent Rain'; } if($newText <> '' or $rate == 0.0) { if ($newText <> '' and $inText <> '') {$newText .= ', ';} $newText .= preg_replace('/(Light|Moderate|Heavy|Violent|Extreme){0,1}\s*(Rain|Mist|Drizzle), /i','',$inText); $newIcon = mtr_get_iconnumber ($time,$newText,$sunrise,$sunset); } else { $newText = $inText; } $Debug .= "\n"; return(array($newText,$newIcon)); } #------------------------------------------------------------------------------------- # WV support function - WVfixupTime #------------------------------------------------------------------------------------- function WVfixupTime ($intime) { global $Debug; $tfixed = $intime; $t = explode(':',$tfixed); if(!isset($t[1])) { $t = explode('.',$tfixed); } if (preg_match('/p/i',$tfixed)) { $t[0] = $t[0] + 12; } if ($t[0] > 23) {$t[0] = 12; } if (preg_match('/^12.*a/i',$tfixed)) { $t[0] = 0; } if ($t[0] < '10') {$t[0] = sprintf("%02d",$t[0]); } // leading zero on hour. $t2 = join(':',$t); // put time back to gether; $t2 = preg_replace('/[^\d\:]/is','',$t2); // strip out the am/pm if any $Debug .= "\n"; return($t2); } // end WVfixupTime #------------------------------------------------------------------------------------- # WV support function - WV_setDateTimes #------------------------------------------------------------------------------------- function WV_setDateTimes ($indate,$intime,$MDYformat=true) { // returns: $date_year,$date_month,$date_day,$time_hour,$time_minute,$date_month,$monthname,$dayname global $Debug; $Debug .= "\n"; $d = explode('/',$indate); if(!isset($d[2])) {$d = explode("-",$indate);} if(!isset($d[2])) {$d = explode(".",$indate);} if($d[2]<2000) {$d[2]+=2000;} if($MDYformat) { // mm/dd/yyyy $YMD = "$d[2]-$d[0]-$d[1]"; } else { // dd/mm/yyyy $YMD = "$d[2]-$d[1]-$d[0]"; } $t = WVfixupTime($intime); $WVtime = strtotime("$YMD $t:00"); $Debug .= "\n"; $WVtime = date('Y m d H i F l',$WVtime); $Debug .= "\n"; if(isset($_REQUEST['debug'])) {echo $Debug; } return(explode(' ',$WVtime)); // results returned in array for list() assignment } // end WV_setDateTimes #------------------------------------------------------------------------------------- # WV support function - WV_beaufortNumber #------------------------------------------------------------------------------------- function WV_beaufortNumber ($inWind,$usedunit) { global $Debug; $rawwind = $inWind; // first convert all winds to knots if(strpos($inWind,',') !== false) { $rawwind = preg_replace('|,|','.',$inWind); } $WINDkts = 0.0; if (preg_match('/kts|knot/i',$usedunit)) { $WINDkts = $rawwind * 1.0; } elseif (preg_match('/mph/i',$usedunit)) { $WINDkts = $rawwind * 0.8689762; } elseif (preg_match('/mps|m\/s/i',$usedunit)) { $WINDkts = $rawwind * 1.94384449; } elseif (preg_match('/kmh|km\/h/i',$usedunit)) { $WINDkts = $rawwind * 0.539956803; } else { $Debug .= "\n"; $WINDkts = $rawwind * 1.0; } // return a number for the beaufort scale based on wind in knots if ($WINDkts < 1 ) {return(0); } if ($WINDkts < 4 ) {return(1); } if ($WINDkts < 7 ) {return(2); } if ($WINDkts < 11 ) {return(3); } if ($WINDkts < 17 ) {return(4); } if ($WINDkts < 22 ) {return(5); } if ($WINDkts < 28 ) {return(6); } if ($WINDkts < 34 ) {return(7); } if ($WINDkts < 41 ) {return(8); } if ($WINDkts < 48 ) {return(9); } if ($WINDkts < 56 ) {return(10); } if ($WINDkts < 64 ) {return(11); } if ($WINDkts >= 64 ) {return(12); } return("0"); } // end WV_beaufortNumber #------------------------------------------------------------------------------------- # WV support function - WV_beaufortText #------------------------------------------------------------------------------------- function WV_beaufortText ($beaufortnumber) { $B = array( /* Beaufort 0 to 12 in English */ "Calm", "Light air", "Light breeze", "Gentle breeze", "Moderate breeze", "Fresh breeze", "Strong breeze", "Near gale", "Gale", "Strong gale", "Storm", "Violent storm", "Hurricane" ); if(isset($B[$beaufortnumber])) { return $B[$beaufortnumber]; } else { return "Unknown $beaufortnumber Bft"; } } // end WV_beaufortText #------------------------------------------------------------------------------------- # WV support function - WV_setFeelslike #------------------------------------------------------------------------------------- function WV_setFeelslike ($temp,$windchill,$heatindex,$tempUOM) { global $Debug, $SITE; // establish the feelslike temperature and return a word describing how it feels $HeatWords = array( 'Unknown', 'Extreme Heat Danger', 'Heat Danger', 'Extreme Heat Caution', 'Extremely Hot', 'Uncomfortably Hot', 'Hot', 'Warm', 'Comfortable', 'Cool', 'Cold', 'Uncomfortably Cold', 'Very Cold', 'Extreme Cold' ); // first convert all temperatures to Centigrade if need be $TC = $temp; $WC = $windchill; $HC = $heatindex; $using = 'HeatIndex'; if(strpos($TC,',') !== false) { $TC = preg_replace('|,|','.',$TC); $WC = preg_replace('|,|','.',$WC); $HC = preg_replace('|,|','.',$HC); } if (preg_match('|F|i',$tempUOM)) { // convert F to C if need be $TC = sprintf("%01.1f",round(($TC-32.0) / 1.8,1)); $WC = sprintf("%01.1f",round(($WC-32.0) / 1.8,1)); $HC = sprintf("%01.1f",round(($HC-32.0) / 1.8,1)); } // Feelslike if ($TC <= 16.0 ) { $feelslike = $WC; //use WindChill } elseif ($TC >=27.0) { $feelslike = $HC; //use HeatIndex/Humidex/ApparentTemp } else { $feelslike = $TC; // use temperature } if (preg_match('|F|i',$tempUOM)) { // convert C back to F if need be $feelslike = (1.8 * $feelslike) + 32.0; } $feelslike = round($feelslike,0); // determine the 'heat color word' to use $hcWord = $HeatWords[0]; $hcFound = false; if ($TC > 32 and $HC > 29) { if ($HC > 54 and ! $hcFound) { $hcWord = $HeatWords[1]; $hcFound = true;} if ($HC > 45 and ! $hcFound) { $hcWord = $HeatWords[2]; $hcFound = true; } if ($HC > 39 and ! $hcFound) { $hcWord = $HeatWords[4]; $hcFound = true; } if ($HC > 29 and ! $hcFound) { $hcWord = $HeatWords[6]; $hcFound = true; } } elseif ($WC < 16 ) { if ($WC < -18 and ! $hcFound) { $hcWord = $HeatWords[13]; $hcFound = true; } if ($WC < -9 and ! $hcFound) { $hcWord = $HeatWords[12]; $hcFound = true; } if ($WC < -1 and ! $hcFound) { $hcWord = $HeatWords[11]; $hcFound = true; } if ($WC < 8 and ! $hcFound) { $hcWord = $HeatWords[10]; $hcFound = true; } if ($WC < 16 and ! $hcFound) { $hcWord = $HeatWords[9]; $hcFound = true; } } elseif ($WC >= 16 and $TC <= 32) { if ($TC <= 26 and ! $hcFound) { $hcWord = $HeatWords[8]; $hcFound = true; } if ($TC <= 32 and ! $hcFound) { $hcWord = $HeatWords[7]; $hcFound = true; } } if(isset($_REQUEST['debug'])) { echo "\n"; } return(array($feelslike,$hcWord)); } // end of WV_setFeelslike #------------------------------------------------------------------------------------- # WV support function - WV_CBI - Chandler Burning Index #------------------------------------------------------------------------------------- function WV_CBI($inTemp,$inTempUOM,$inHumidity) { // thanks to Chris from sloweather.com for the CBI calculation script // modified by Ken True for template usage preg_match('/([\d\.\,\+\-]+)/',$inTemp,$t); // strip non-numeric from inTemp if any $ctemp = $t[1]; if(strpos($ctemp,',') !== false) { $ctemp = preg_replace('|,|','.',$ctemp); } if(!preg_match('|C|i',$inTempUOM)) { $ctemp = ($ctemp-32.0) / 1.8; // convert from Fahrenheit } preg_match('/([\d\.\,\+\-]+)/',$inHumidity,$t); // strip non-numeric from inHumidity if any $rh = $t[1]; if(strpos($rh,',') !== false) { $rh = preg_replace('|,|','.',$rh); } // Start Index Calcs // Chandler Index $cbi = (((110 - 1.373 * $rh) - 0.54 * (10.20 - $ctemp)) * (124 * pow(10,-0.0142 * $rh) ))/60; // CBI = (((110 - 1.373*RH) - 0.54 * (10.20 - T)) * (124 * 10**(-0.0142*RH)))/60 //Sort out the Chandler Index $cbi = round($cbi,1); if ($cbi > "97.5") { $cbitxt = "EXTREME"; $cbiimg= "fdl_extreme.gif"; } elseif ($cbi >="90") { $cbitxt = "VERY HIGH"; $cbiimg= "fdl_vhigh.gif"; } elseif ($cbi >= "75") { $cbitxt = "HIGH"; $cbiimg= "fdl_high.gif"; } elseif ($cbi >= "50") { $cbitxt = "MODERATE"; $cbiimg= "fdl_moderate.gif"; } else { $cbitxt="LOW"; $cbiimg= "fdl_low.gif"; } $data = array($cbi,$cbitxt,$cbiimg); return $data; } // end WV_CBI #------------------------------------------------------------------------------------- # WV support function - WV_get_barotrend_text #------------------------------------------------------------------------------------- function WV_get_barotrend_text($rawpress,$usedunit='hPa') { global $Debug; // routine from Anole's wxsticker PHP (adapted) // Barometric Trend(3 hour) // Change Rates // Rapidly: =.06" inHg; 1.5 mm Hg; 2 hPa; 2 mb // Slowly: =.02" inHg; 0.5 mm Hg; 0.7 hPa; 0.7 mb // 5 Arrow Positions: // Rising Rapidly // Rising Slowly // Steady // Falling Slowly // Falling Rapidly // Page 52 of the PDF Manual // http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf // first convert to hPa for comparisons if (preg_match('/hPa|mb/i',$usedunit)) { $btrend = sprintf("%02.1f",round($rawpress * 1.0,1)); // leave in hPa } elseif (preg_match('/mm/i',$usedunit)) { $btrend = sprintf("%02.1f",round($rawpress * 1.333224,1)); } else { $btrend = sprintf("%02.1f",round($rawpress / 33.86388158,1)); } // figure out a text value for barometric pressure trend (float)$baromtrend = $btrend; // settype($baromtrend, "float"); switch (TRUE) { case (($baromtrend >= -0.6) and ($baromtrend <= 0.6)): $baromtrendwords = "Steady"; break; case (($baromtrend > 0.6) and ($baromtrend < 2.0)): $baromtrendwords = "Rising Slowly"; break; case ($baromtrend >= 2.0): $baromtrendwords = "Rising Rapidly"; break; case (($baromtrend < -0.6) and ($baromtrend > -2.0)): $baromtrendwords = "Falling Slowly"; break; case ($baromtrend <= -2.0): $baromtrendwords = "Falling Rapidly"; break; } // end switch $Debug .= "\n"; return($baromtrendwords); } #------------------------------------------------------------------------------------- # WV support function - WV_get_yesterday_data_from_NOAA_rpt - yesterday data from NOAA rpt #------------------------------------------------------------------------------------- function WV_get_yesterday_data_from_NOAA_rpt( ) { // get overrides from Settings.php if available global $SITE, $Debug; if (isset($SITE['tz'])) {$ourTZ = $SITE['tz'];} if (isset($SITE['NOAAdir'])) {$NOAAdir = $SITE['NOAAdir'];} if (isset($SITE['NOAACurDir'])) {$NOAACurDir = $SITE['NOAACurDir'];} if (isset($SITE['WXsoftware'])) {$Naming = $SITE['WXsoftware'];} // from the [$SITE['WXsoftware']]-defs.php file // end of overrides from Settings.php // Note: WeatherLink conventions: // NOAAMO.TXT, NOAAYR.TXT for current month and current year // // VWS naming format // noaamo.txt,noaayr.txt for current month and current year // // Cumulus naming format // NOAAMOmmyy.txt for month (e.g. NOAA0811.txt for August, 2011 monthly report) // // wview naming format // NOAA-yyyy-mm.txt for month // $validWX = false; if ($Naming == 'WL') { $ThisMonthFile= $NOAACurDir."NOAAMO.TXT"; // point to your current NOAA monthly file $validWX = true; } if ($Naming == 'VWS') { $ThisMonthFile= $NOAAdir."noaamo.txt"; // point to your current NOAA monthly file $validWX = true; } if ($Naming == 'CU') { $cu_year = ""; // initialise Cumulus year file $cu_month = ""; // initialise Cumulus month file $cu_month_year = ""; $CU_year = array(); // storage to find first/last year reports on file $validWX = true; // have to wait to set ThisYearFile, ThisMonthFile until after the default timezone is set. } if ($Naming == 'WV') { $validWX = true; } if(!$validWX) { return(array()); } if (!isset($PHP_SELF)) {$PHP_SELF = $_SERVER['SCRIPT_NAME']; } # Set timezone in PHP5/PHP4 manner if (!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); # $Status .= "\n"; } else { date_default_timezone_set("$ourTZ"); # $Status .= "\n"; } $now = getdate(); // print "\n"; $now_month = sprintf("%02d",$now['mon']); $now_year = $now['year']; $now_day = sprintf("%02d",$now['mday']); // 1..31 $yday = getdate(time() - 86400); $yday_day = sprintf("%02d",$yday['mday']); $yday_year = $yday['year']; $yday_month = sprintf("%02d",$yday['mon']); if($now_day < $yday_day) { // oops.. last day was last month's file $now_year = $yday_year; $now_month = $yday_month; $now_day = $yday_day; if ($Naming == 'WL') { $ThisMonthFile= $NOAACurDir."NOAAPRMO.TXT"; // point to last month NOAA monthly file } if ($Naming == 'VWS') { $ThisMonthFile= $NOAAdir.$now_year . "_" . "$now_month.txt"; // point to last month NOAA monthly file } } else { $now_day = $yday_day; // use yesterday for data } if ($Naming == 'CU') { // have to set ThisMonthFile now we know the date. $ThisMonthFile= $NOAAdir."NOAAMO${now_month}".substr($now_year,2,2).".txt"; // points to your current NOAA monthly file } if ($Naming == 'WV') { // have to set ThisYearFile, ThisMonthFile now we know the date. $ThisMonthFile= $NOAAdir."NOAA-${now_year}-${now_month}.txt"; // points to your current NOAA monthly file } $ret = array(); $ret['WX'] = $Naming; $ret['file'] = $ThisMonthFile; if(file_exists($ThisMonthFile)) { $ret['exists'] = 'yes'; } else { $ret['exists'] = 'no'; } $ret['usingDate'] = "$now_year-$now_month-$now_day"; $ret['success'] = 'no'; // assume the worst (no data) if($ret['exists'] == 'yes') { // read and parse the file $recs = file($ThisMonthFile); /* WV HEAT COOL AVG MEAN DEG DEG WIND DOM DAY TEMP HIGH TIME LOW TIME DAYS DAYS RAIN SPEED HIGH TIME DIR 15 67.8 72.8 20:55 64.0 23:55 0.0 3.4 0.00 0.0 2.0 20:55 N 16 79.0 102.3 14:45 57.5 05:50 0.0 14.9 0.00 0.5 10.0 14:35 N WL HEAT COOL AVG MEAN DEG DEG WIND DOM DAY TEMP HIGH TIME LOW TIME DAYS DAYS RAIN SPEED HIGH TIME DIR 8 62.4 79.2 4:05p 50.7 5:20a 5.7 3.1 0.00 1.3 14.0 4:10p W 9 63.8 81.1 4:30p 44.5 6:00a 6.3 5.1 0.00 2.0 18.0 4:20p NW 10 72.1 91.4 3:55p 52.6 4:35a 3.3 10.4 0.00 1.2 13.0 11:25a NNW 11 75.1 96.3 2:15p 56.5 6:25a 1.6 11.7 0.00 0.9 16.0 3:15p NNW CU Mean Deg Deg Wind Dom Day Temp High Time Low Time Days Days Rain Speed High Time Dir 8 62.4 79.2 4:00p 50.7 5:19a 5.7 3.1 0.00 1.3 14.0 4:08p NNW 9 63.8 81.1 4:26p 44.5 5:58a 6.3 5.1 0.00 2.0 17.0 3:31p NNW 10 72.0 91.4 3:52p 52.6 4:32a 3.3 10.2 0.00 1.2 13.0 11:23a NNW 11 75.1 96.3 2:11p 56.5 6:24a 1.6 11.7 0.00 0.9 16.0 3:13p N VWS HEAT COOL MEAN DEG DEG WIND SPEED DOM MEAN MEAN DAY TEMP HIGH TIME LOW TIME DAYS DAYS RAIN AVG HI TIME DIR BAROM HUM 8 62.4 79.2 4:00pm 50.7 5:19am 6 3 0.00 1 14 4:18pm WSW 29.97 59 9 50.6 80.9 4:26pm 44.5 5:58am 5 0 0.00 1 11 1:08pm WSW 29.96 70 10 70.2 91.4 3:52pm 44.5 5:58am 5 11 0.00 1 13 11:24am NNW 29.90 40 */ foreach ($recs as $n => $rec) { if(preg_match('/^\s*([\d|-|\.]+)\s+/Uis',$rec)) { $vals = preg_split("/\s+/",trim($rec)); if(count($vals) >= 13 and $vals[0] == $now_day) { $ret['matched'] = trim($rec); $ret['meanTemp'] = $vals[1]; $ret['maxTemp'] = $vals[2]; $ret['maxTempTime'] = $vals[3]; $ret['minTemp'] = $vals[4]; $ret['minTempTime'] = $vals[5]; $ret['heatDegDays'] = $vals[6]; $ret['coolDegDays'] = $vals[7]; $ret['rain'] = $vals[8]; $ret['windAvg'] = $vals[9]; $ret['windMax'] = $vals[10]; $ret['windMaxTime'] = $vals[11]; $ret['windDomDir'] = $vals[12]; $ret['success'] = 'yes'; } } } // end foreach } // end file_exists if(isset($_REQUEST['debug'])) { print "\n"; } return($ret); } #------------------------------------------------------------------------------------- # end of WV support functions #------------------------------------------------------------------------------------- ?>