Not sure if that went through, Ken.
Raintodate.php in text format.
<?php
############################################################################
$start_year = 2020; // set to first year of dailynoaareport files available
$rain_places = 2; // set to how many decimal places for rain
$loc = "./"; // set to path of dailynoaareport files
############################################################################
if (isset($_REQUEST['sce']) && ( strtolower($_REQUEST['sce']) == 'view' or
strtolower($_REQUEST['sce']) == 'show') ) {
//--self downloader --
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
if(!function_exists('getnoaafile')) {
# 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);
}
}
$today = getdate();
$year = $today['year'];
$month = $today['mon'];
$day = $today['mday'];
$alltimeaverage = array($avrainjan,$avrainfeb,$avrainmar,$avrainapr,$avrainmay,$avrainjun,$avrainjul,
$avrainaug,$avrainsep,$avrainoct,$avrainnov,$avraindec);
$avg_ytd_rain = 0;
// Get the total rain averages for the month(s) preceding the current month
for ($i = 0 ; $i < ($month-1) ; $i++)
{
$avg_ytd_rain = $avg_ytd_rain + $alltimeaverage[$i];
}
// Calculate the average rain to date for the current month of previous years
$avg_mtd_rain = get_mtd_rain ($start_year,$day,$month,$year,$loc);
$avg_mtd_rain = number_format((round($avg_mtd_rain,2)),$rain_places);
$avg_ytd_rain = $avg_ytd_rain + $avg_mtd_rain;
$avg_ytd_rain = number_format((round($avg_ytd_rain,2)),$rain_places);
########## Functions ##########################################################
function get_mtd_rain ($start_year,$day,$month,$year,$loc)
{
$years = $year - $start_year;
$months = 0;
for ($i = 0 ; $i < $years ; $i++)
{
$filename = "dailynoaareport" . ( $month) . ($start_year + $i) . ".htm";
if (file_exists($loc . $filename) )
{
$data[0] = getnoaafile($loc . $filename);
$months = $months + 1;
// Now get data from the dailynoaareport for this month from the 1st to today's date'.
for ($d = 0 ; $d < $day ; $d++)
{
$rain = $data[0][$d][8];
if ($rain != "")
{
$month_rain = $month_rain + $rain;
}
}
}
}
if ($months == 0) {
$mtd_rain = 0;
} else {
$mtd_rain = $month_rain / $months;
}
return $mtd_rain;
}
############################################################################
# End of Functions
############################################################################
?>