= $mintemp) $posvalue = 1; return $posvalue; } // end function // Get data routine function get_raw( $rawfile ) { if (substr($rawfile,0,7) != "http://") { if (!file_exists($rawfile)) { $string = "Unable to find"; create_image1($string,$rawfile); exit; } } $rawdata = array(); $fd = fopen($rawfile, "r"); if ($fd) { $rawcontents = ''; while (! feof ($fd) ) { $rawcontents .= fread($fd, 8192); } fclose($fd); $delimiter = " "; $rawdata = explode ($delimiter, $rawcontents); } else { $rawdata[0]= -9999; } return $rawdata; } // This function gets the hour needed for Last Whole Hour graphs and requires user to // specify their mode they run WD in. Specified in user config section above function get_date( $rawfile ) { global $hostloc; global $hourmode; $clientraw = get_raw("${hostloc}clientraw.txt"); $rawdata = $clientraw[29]; $rawdata = $rawdata - 1; if ($hourmode == "24") { if ($rawdata == -1) $rawdata = 23; if ($rawdata < 10) $rawdata = "0".$rawdata; } if ($hourmode == "12") { if ($rawdata >= 13) $rawdata = $rawdata - 12; if ($rawdata == -1) $rawdata = 11; if ($rawdata == 0) $rawdata = 12; } return $rawdata; } // Calculate dew point - found at http://pear.php.net/index.php // Modified by jmcmurry for use here with Broadstairs library & configuration file // the default in the clienraw files is Celcius so do this now and convert later to Farenheit if needed function dp($temperature, $humidity) { if ($temperature >= 0) { $a = 7.5; $b = 237.3; } else { $a = 7.6; $b = 240.7; } // First calculate saturation steam pressure for temperature $SSP = 6.1078 * pow(10, ($a * $temperature) / ($b + $temperature)); // Steam pressure $SP = $humidity / 100 * $SSP; $v = log($SP / 6.1078, 10); $dpoint = round($b * $v / ($a - $v), 1); return $dpoint; } function create_image1(&$value,$value1) { //Set the image width and height $width = 400; $height = 100; //Create the image resource $image = ImageCreate($width, $height); //We are making three colors, white, black and gray $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); $grey = ImageColorAllocate($image, 204, 204, 204); //Make the background black ImageFill($image, 0, 0, $grey); //Add randomly generated string in white to the image ImageString($image, 5, 40, 20, $value, $black); ImageString($image, 5, 40, 60, $value1, $black); //Tell the browser what kind of file is come in header("Content-Type: image/jpeg"); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); } ############################# function get_yearly_avg ($values,$day, $month, $year){ $days = array(31,28,31,30,31,30,31,31,30,31,30,31); $days[1] = get_days_in_month(2,($year-($month == 1))); // adjust for leap year if needed // All months were not created equal, so convert to days $total_days = array_sum($days); for ( $i = 0; $i < 12 ; $i ++ ) { $total_degrees = $total_degrees + ($values[$i]*$days[$i]); } return $total_degrees/$total_days; } function get_days_in_month($month, $year) { return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year %400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); } function adjust_current_month ($current_value,$day,$month,$year,$loc) { // The avgtempxxxnow customtag is only a partial month, so use the dailynoaareport files to get a complete month $filename = "dailynoaareport" . ( $month) . ($year - 1) . ".htm"; $filename2 = "dailynoaareport.htm"; $new_value = $current_value; if (file_exists($loc . $filename) ) // If no file found, use the $current_value customtag for the month average { $data[0] = getnoaafile($loc . $filename); // Get mean temps for this month of the previous year from today to end of month $days = get_days_in_month($month,($year-1)); for ($i = $day-1 ; $i < $days ; $i++) { $temp = $data[0][$i][1]; if ($temp != "") { $temps = $temps + $data[0][$i][1]; $count = $count + 1; } } // Now get data from the dailynoaareport for this month from the 1st to yesterday. if ($day > 1) // There is no data in the dailynoaareport file on the first day of the month { if (file_exists($loc . $filename2) ) { $data[1] = getnoaafile($loc . $filename2); for ($i = 0 ; $i < $day ; $i++) { $temp = $data[1][$i][1]; if ($temp != "") { $temps = $temps + $data[1][$i][1]; $count = $count + 1; } } } else // No dailynoaareport file found. So use the $current_value customtag for the beginning portion of the month { $temp = $current_value; $temps = $temps + ($temp * ($day - 1)); $count = $count + $day; } } // Now combine the two sections $new_value = $temps/$count; } return $new_value; } # GETNOAAFILE function # Developed by TNETWeather.com # # Returns an array of the contents of the specified filename # Array contains days from 1 - 31 (or less if the month has less) and # the values: # Day # Mean Temp # High Temp # Time of High Temp # Low Temp # Time of Low Temp # Hot Degree Day # Cold Degree Day # Rain # Avg Wind Speed # High Wind # Time High Wind # Dom Wind Direction ############################################################################ function getnoaafile ($filename) { global $SITE; $rawdata = array(); $fd = @fopen($filename,'r'); $startdt = 0; if ( $fd ) { while ( !feof($fd) ) { // Get one line of data $gotdat = trim ( fgets($fd,8192) ); if ($startdt == 1 ) { if ( strpos ($gotdat, "--------------" ) !== FALSE ){ $startdt = 2; } else { $foundline = preg_split("/[\n\r\t ]+/", $gotdat ); $rawdata[intval ($foundline[0]) -1 ] = $foundline; } } if ($startdt == 0 ) { if ( strpos ($gotdat, "--------------" ) !== FALSE ){ $startdt = 1; } } } // Close the file we are done getting data fclose($fd); } return($rawdata); } ?>