<?php
############################################################################
# A Project of TNET Services, Inc.
############################################################################
#
#   Project:    Cumulus Project
#   Package:    Cumulus Weather Banner
#   Module:     banner.php
#   Version:    3.0 - October 19th, 2008
#   Purpose:    Outputs a plain weather graphic based upon
#               the Cumulus realtime.txt file
#   Authors:    Kevin W. Reed <programs@tnet.com>
#               TNET Services, Inc.
#   Copyright:  (c) 1992-2008 Copyright TNET Services, Inc.
#
#   License:
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
#   USA.
#
############################################################################
#   HISTORY
############################################################################
#
#   1.0 Released Oct 4th 2008
#       Initial Release
#
#   1.1 Released Oct 5th 2008
#       Added TTF Support
#       Added Check for Rain and if none output No Rain Today
#
#   1.2 Released Oct 5th 2008
#       Corrected ISO Date format, was missing the 20 to make the year
#       a 4 digit value.  Realtime.txt data has it as a 2 digit year
#       value.
#
#   1.3 Released Oct 6th 2008
#       Added new field $SITE['dateiso']  If yes, the date is formated
#       in ISO format (YYYY-MM-DD), else it will use a worded month
#       Date (Oct 6 2008)
#
#   1.4 Released Oct 8th 2008
#       Increased the default size of the Cumulus Version Date line to
#       make it more readable.
#
#   2.0 Released Oct 9th 2008
#       Reconfigured to use new write functions that provide right, left
#       center to position the text more accurately
#
#   3.0 Released Oct 19th, 2008
#       Reconfigured to use extended realtime.txt format that was
#       Released with Cumulus 1.8.2 Beta.
#
############################################################################
#   This document uses Tab 4 Settings
############################################################################
$DATA   = array();
$SITE   = array();
############################################################################
# CONFIGURATION INFORMATION
############################################################################
$SITE['version']        = "3.0";
$SITE['hloc']           = "./";
$SITE['datafile']       = "realtime.txt";
$SITE['image_width']    = 468;
$SITE['image_height']   = 60;
#---------------------------------------------------------------------------
$SITE['fontdir']        = "fonts/";     # must contain ttf font files!
$SITE['usettf']         = "yes";        # Set to No to use default fonts
#---------------------------------------------------------------------------
$SITE['format']         = "png";        # Options: jpeg  gif  png
$SITE['dateiso']        = "no";
$SITE['sitename']       = "&#346;lesin k. Konina";
#---------------------------------------------------------------------------
// Current field names (matches tag fields) used
$SITE['cvalues'] = array
	(
    "date","time","temp","hum","dew","wspeed","wgust","avgbearing","rrate",
    "rfall","press","wdir","beaufort","windunit","tempunit","pressunit","rainunit",
    "windrun","presstrend","rmonth","ryear","rfallY","intemp","inhum","wchill",
    "temptrendval","tempTH","TtempTH","tempTL","TtempTL",
    "windTM","TwindTM","wgustTM","TwgustTM",
    "pressTH","TpressTH","pressTL","TpressTL",
    "cversion","cbuild",
    "wgust","heatindex","humindex","uv","et","solarrad","avgbearing","rhour",
    "forecastnumber","isdaylight","SensorContactLost","wdir","cloudbasevalue",
    "cloudbaseunit","apptemp","sunshinehours","currentsolarmax","issunny"
	);
############################################################################

############################################################################
# SOURCECODE VIEW
############################################################################
if ( isset($_REQUEST['view']) && $_REQUEST['view'] == 'sce' ) {
    $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;
}
############################################################################
# Reference: Cumulus Format of realtime.txt file
############################################################################
#   Field       Pos     Example     Description
#   date        0       18/10/08    date (always dd/mm/yy)
#   time        1       16:03:45    time (always hh:mm:ss)
#   temp        2       8.4         outside temperature
#   hum         3       84          relative humidity
#   dew         4       5.8         dewpoint
#   wspeed      5       24.2        wind speed (average)
#   wgust       6       33.0        wind speed (gust)
#   avgbearing  7       261         wind bearing
#   rrate       8       0.0         current rain rate
#   rfall       9       1.0         rain today
#   press       10      999.7       barometer
#   wdir        11      W           wind direction
#   beaufort    12      6           wind speed (beaufort)
#   windunit    13      mph         wind units
#   tempunit    14      C           temperature units
#   pressunit   15      mb          pressure units
#   rainunit    16      mm          rain units
#   windrun     17      146.6       wind run (today)
#   pressrend   18      +0.1        pressure trend value
#   rmonth      19      85.2        monthly rain
#   ryear       20      588.4       yearly rain
#   rfallY      21      11.6        yesterday's rainfall
#   intemp      22      20.3        inside temperature
#   inhum       23      57          inside humidity
#   wchll       24      3.6         wind chill
#   temptrendval 25     -0.7        temperature trend value
#   tempTH      26      10.9        today's high temp
#   TtempTH     27      12:00       time of today's high temp (hh:mm)
#   tempTL      28      7.8         today's low temp
#   TtempTL     29      14:41       time of today's low temp (hh:mm)
#   windTM      30      37.4        today's high wind speed (average)
#   TwindTM     31      14:38       time of today's hi wind (avg) (hh:mm)
#   wgustTM     32      44.0        today's high wind gust
#   TwgustTM    33      14:28       time of today's high wind gust (hh:mm)
#   pressTH     34      999.8       today's high pressure
#   TpressTH    35      16:01       time of today's high pressure (hh:mm)
#   pressTL     36      998.4       today's low pressure
#   TpressTL    37      12:06       time of today's low pressure (hh:mm)
#   cversion    38      1.8.2       Cumulus version
#   cbuild      39      459         Cumulus build no
#Karv ### add remaining items
#   wgust				40	36.0 	10-minute high gust
#	heatindex			41	10.3 	heat index
#	humindex			42	10.5 	humidex
#	uv					43	13 		UV Index
#	et					44	0.2 	evapotranspiration today
#	solarrad			45	14 		solar radiation W/m2
#	avgbearing			46	260 	10-minute average wind bearing (degrees)
#	rhour				47	2.3 	rainfall last hour
#	forecastnumber		48	3 		The number of the current forecast as per Strings.ini. If the forecast is not being provided by the station and not being generated by Cumulus a value of 0 (zero) is returned
#	isdaylight			49	1 		Flag to indicate that the location of the station is currently in daylight (1 = yes, 0 = No)
#	SensorContactLost	50	1 		If the station has lost contact with its remote sensors "Fine Offset only", a Flag number is given (1 = Yes, 0 = No)
#	wdir				51	NNW 	Average wind direction
#	cloudbasevalue		52	2040 	Cloud base
#	cloudbaseunit		53	ft 		Cloud base units
#	apptemp				54	12.3 	Apparent Temperature
#	sunshinehours		55	11.1 	Sunshine hours so far today
#	currentsolarmax		56	420.1 	Current theoretical max solar radiation
#	issunny				57	1 		Is it sunny? 1 if the sun is shining, otherwise 0
############################################################################


// Path to our font file
$font1 = $SITE['fontdir'] . "arialbd.ttf";
$font2 = $SITE['fontdir'] . "arial.ttf";
$font3 = $SITE['fontdir'] . "weather.ttf";

// Read data into array
$DATA = get_raw($SITE['hloc'] . $SITE['datafile'],' ');

$months = array ("Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień",
    "Wrzesień","Pazdziernik","Listopad","Grudzień");

if ( $SITE['dateiso'] == "yes" ) {
    // Fix date to use ISO formatted date
    $DATA[0] = "20" . substr($DATA[0],6,2) . '-' . substr($DATA[0],3,2) . '-' .
        substr($DATA[0],0,2);
} else {
    // Fix date to use Month formatted date
    $DATA[0] = $months[intval(substr($DATA[0],3,2)) -1 ] .
        " " . intval(substr($DATA[0],0,2)) . " " .
        "20" . substr($DATA[0],6,2);
}

// Fix time by removing seconds from the field
$DATA[1] = substr($DATA[1],0,5);


// Output the header to let the browser know we are
// sending a graphic file format
header("Content-type: image/" . $SITE['format'] );
$im = @imagecreate($SITE['image_width'], $SITE['image_height'])
    or die("Cannot Initialize new GD image stream");


// Temperature colour mod
$temp_rgb=TEMP_COLOUR(ret_value("temp"));
$tr=$temp_rgb[0];
$tg=$temp_rgb[1];
$tb=$temp_rgb[2];



// Set colors we want to use...
// first background is a white background
$background_color   = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black              = imagecolorallocate($im, 139, 10, 80);
$green              = imagecolorallocate($im, 47, 79, 79);
$blue               = imagecolorallocate($im, 0x00, 0x00, 0xff);
$bluerain           = imagecolorallocate($im, 16, 78, 139);
$midnightblue		= imagecolorallocate($im, 25, 25, 112);
$red                = imagecolorallocate($im, 139, 0, 139);
$seagreen			= imagecolorallocate($im, 139, 10, 80);
$indigo			    = imagecolorallocate($im, 75, 0, 130);
$cegl			    = imagecolorallocate($im, 51, 0, 102);
$pink			    = imagecolorallocate($im, 220, 20, 60);
$bluemin		    = imagecolorallocate($im, 25, 25, 112);
$temp               = imagecolorallocate($im, $tr, $tg, $tb);



##############################
# Icon mod                   #
##############################
# image_paste( 'rain.jpg', 0, 39, 0, 39, 135, 39, 2, 39);
# value showing above as 137 is the Y co-ordinate, 2 is the x
# Y determines how far right from left hand side
# x determines how far down from Top

if(ret_value("rhour") > 0 ) // has been raining and is not currently suny
{
    image_paste( 'rain.jpg', 0, 39, 0, 39, 135, 39, 2, 39); // <-- set X and Y HERE
}

// Make a Border Around the box
ImageRectangle($im, 0, 0, $SITE['image_width'] -1 ,
    $SITE['image_height'] -1, $black);

// Print Station Name
$text = $SITE['sitename'];

if ($SITE['usettf'] == "yes" ) {
    $size = 11;
    imagettftextbox($im, $size, 0, 0, 4, $midnightblue, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $midnightblue, "left", 3);
}

// Print Date (top right corner)
$text = ret_value("date") . ' @ ' . ret_value("time");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 1, $green, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $green, "right", 1);
}


// Print Cumulus version info
$text = "Cumulus v" . ret_value("cversion") . ' #' . ret_value("cbuild");
if ($SITE['usettf'] == "yes" ) {
    $size = 6;
    imagettftextbox($im, $size, 0, 0, 14, $green, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $green, "right", 11);
}

// Print Temp Max
$text = ret_value("tempTH") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 70, 20, $pink, $font3, $text, $SITE['image_width'], "center");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $pink, "right", 11);
}

// Print Temp Min
$text = ret_value("tempTL") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 70, 32, $bluemin, $font3, $text, $SITE['image_width'], "center");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $bluemin, "right", 11);
}

// Print Temp
$text = ret_value("temp") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 23;
    imagettftextbox($im, $size, 0, -15, 20, $temp, $font3, $text, $SITE['image_width'], "center");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $temp, "center", 23);
}

// Print Humitidy and Dewpt Centered
$text = "Wilg: " . ret_value("hum") . "% - " . "Pkt rosy: " . ret_value("dew") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, -12, 41, $indigo, $font2, $text, $SITE['image_width'], "center");
} else {
    $size = 3;
    imageWriteString($im, $size, $text, $indigo, "center", 40);
}

// Print windspeed wind speed 58 horisontal position value
$text = "Wiatr:";
if ($SITE['usettf'] == "yes" ) {
    $size = 9.8;
    imagettftextbox($im, $size, 0, 0, 22, $black, $font3, $text, $SITE['image_width'], "left");
	$text = ret_value("wspeed");
	$size = 10.2; // new wind speed
    imagettftextbox($im, $size, 0, 55, 24, $black, $font3, $text, $SITE['image_width'], "left");
	$text = ret_value("windunit");
    $size = 8; // new wind unit size
    imagettftextbox($im, $size, 0, 91, 24, $black, $font3, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $black, "left", 23);
}

// Print Bearing

$text = " -> " . ret_value("wdir");
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 59, 36, $black, $font3, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $black, "left", 23);
}

// Print Wind gust
$text = "Poryw: " . ret_value("wgust");
if ($SITE['usettf'] == "yes" ) {
    $size = 8.1;
    imagettftextbox($im, $size, 0, 1, 47, $cegl, $font3, $text, $SITE['image_width'], "left");
	$text = ret_value("windunit");
    $size = 6; // new wind unit size
    imagettftextbox($im, $size, 0, 86, 48, $cegl, $font3, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $cegl, "left", 39);
}


// Print Rain
if (ret_value("rfall") == "0.00" ) {
    $text = "Snieg: 15cm";
    $py = 25;
} else {
    $text = "   Opady: " . ret_value("rfall") . ' ' . ret_value("rainunit");
    $py = 25;
}
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 0, $py, $blue, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $blue, "right", 23);
}

// Print Month's Rain
$text = "miesiac: " . ret_value("rmonth") . ' ' ;
if ($SITE['usettf'] == "yes" ) {
    $size = 6;
    imagettftextbox($im, $size, 0, -7, 36, $bluerain, $font3, $text, $SITE['image_width'], "right");
	$text = ret_value("rainunit");
    $size = 4; // new wind unit size
    imagettftextbox($im, $size, 0, 444, 39, $bluerain, $font3, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $blue, "right", 39);
}

// Print Baro
$text = "Cisnienie: " . ret_value("press") . ' ' . ret_value("pressunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8.1;
    imagettftextbox($im, $size, 0, 0, 45, $seagreen, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $seagreen, "right", 39);
}


// Output the image in the format we are
// setup.

if ($SITE['format'] == "png" ) {
    imagepng($im);
}

if ($SITE['format'] == "jpeg" ) {
    imagejpeg($im);
}

if ($SITE['format'] == "gif" ) {
    imagegif($im);
}

// We be done... destroy the image
imagedestroy($im);

exit;

############################################################################
# FUNCTIONS
############################################################################

// Function to read the data file with the
// Delimiter provided

function get_raw( $rawfile , $del ) {
    $rawdata = array();
    $fd = fopen( $rawfile, "r" );
    if ( $fd ) {
        $rawinfo = '';
        while (! feof ( $fd ) ) {
            $rawinfo .= fread( $fd, 8192 );
        }
        fclose($fd);
        $rawdata = explode ( $del, $rawinfo );
    } else {
        $rawdata[0]= -9999;
    }
    return $rawdata;
}


// function outputs a string centered in the image
function center_text ( $image, $size, $string, $y, $color) {
    $px = ((imagesx($image)/2) - ( ImageFontWidth($size) *
    strlen($string) ) / 2);
    imagestring($image, $size, $px, $y,$string, $color);
}


// Function snarfed off of a PHP forum.  User sk89q

function imagettftextbox(&$image, $size, $angle, $left, $top, $color,
    $font, $text, $max_width, $align)
{
        $text_lines = explode("\n", $text); // Supports line breaks!

        $lines = array();
        $line_widths = array();

        $largest_line_height = 0;

        foreach($text_lines as $block)
        {
            $current_line = ''; // Reset current line

            $words = explode(' ', $block); // Split the text array of single words

            $first_word = TRUE;

            $last_width = 0;

            for($i = 0; $i < count($words); $i++)
            {
                $item = $words[$i];
                $dimensions = imagettfbbox($size, $angle, $font,
                    $current_line . ($first_word ? '' : ' ') . $item);
                $line_width = $dimensions[2] - $dimensions[0];
                $line_height = $dimensions[1] - $dimensions[7];

                if($line_height > $largest_line_height)
                    $largest_line_height = $line_height;

                if($line_width > $max_width && !$first_word)
                {
                    $lines[] = $current_line;

                    $line_widths[] = $last_width ? $last_width : $line_width;

                    /*if($i == count($words))
                    {
                        continue;
                    }*/

                    $current_line = $item;
                }
                else
                {
                    $current_line .= ($first_word ? '' : ' ') . $item;
                }

                if($i == count($words) - 1)
                {
                    $lines[] = $current_line;

                    $line_widths[] = $line_width;
                }

                $last_width = $line_width;

                $first_word = FALSE;
            }

            if($current_line)
            {
                $current_line = $item;
            }
        }

        $i = 0;
        foreach($lines as $line)
        {
            if($align == "center")
            {
                $left_offset = ($max_width - $line_widths[$i]) / 2;
            }
            elseif($align == "right")
            {
                $left_offset = ($max_width - $line_widths[$i] - 6);
            }
            if ($align == "left") {
                $left_offset = 5;
            }
            imagettftext($image, $size, $angle, $left + $left_offset,
                $top + $largest_line_height + ($largest_line_height * $i),
                $color, $font, $line);
            $i++;
        }

        return $largest_line_height * count($lines);
}

// Similar function for use with standard GD fonts.

function imageWriteString(&$img, $font, $text, $color, $position_x = 'center', $position_y = 'center') {
    // initialize internal variables
    $x = null;
    $y = null;

    if($font < 0 || $font > 5){ $font = 0; }
    $num = array(array(4.6, 6),
                 array(4.6, 6),
                 array(5.6, 12),
                 array(6.5, 12),
                 array(7.6, 16),
                 array(8.5, 16));

    $width = ceil(strlen($text) * $num[$font][0]);
    $height = $num[$font][1] + 2;

    // handle position x
    if (is_string($position_x)) {
        switch($position_x) {
            case 'left':
                $position_x = 5;
                break;
            case 'right':
                $position_x = -8;
                break;
            default:
            case 'center':
                $x     = (imagesx($img) - $width - 8) / 2;
                break;
        }
    }
    if (!isset($x)) {
        if(is_numeric($position_x)) {
            if ($position_x >= 0) {
                $x = $position_x; // left
            } else {
                $x = imagesx($img) - $width + $position_x - 8; // right
            }
        } else {
            $x     = (imagesx($img) - $width - 8) / 2; // default / error value: center
        }
    }

    // handle position y
    if (is_string($position_y)) {
        switch($position_y) {
            case 'top':
                $position_y = 5;
                break;
            case 'bottom':
                $position_y = -5;
                break;
            default:
            case 'center':
                $y     = (Imagesy($img) - ($num[$font][1] + 2))/2;
                break;
        }
    }
    if (!isset($y)) {
        if (is_numeric($position_y)) {
            if ($position_y >= 0) {
                $y = $position_y; // top
            } else {
                $y = Imagesy($img) - $height + $position_y; // bottom
            }
        } else {
            $y     = (Imagesy($img) - ($num[$font][1] + 2))/2; // default / error value: center
        }
    }
    imagestring($img, $font, $x, $y, $text, $color);
}

function ret_value($lookup) {
    global $SITE, $DATA;

    $rtn = array_search  ( $lookup  , $SITE['cvalues'] );

    if ($rtn !== FALSE) {
        return( $DATA[$rtn] );
    } else {
        return("-");
    }
}

function image_paste( $source, $sourceX, $sourceX_width, $sourceY, $sourceY_height, $putX, $putX_width, $putY, $putY_height){
    global $im;
    if(file_exists($source)){
        $pictype = strtolower(substr(strrchr($source,"."),1));
        if($pictype == 'jpeg') $type = 'jpg';
        switch($pictype){
            case 'bmp': $thisIcon = imagecreatefromwbmp($source); break;
            case 'gif': $thisIcon = imagecreatefromgif($source); break;
            case 'jpg': $thisIcon = imagecreatefromjpeg($source); break;
            case 'png': $thisIcon = imagecreatefrompng($source); break;
            default : $thisIcon = false;
        }
        if($thisIcon){
            $newIcon = imagecreatetruecolor($sourceX_width, $sourceY_height); // create full palette canvass
            imagecopy($newIcon, $thisIcon, 0, 0, 0, 0, $sourceX_width, $sourceY_height); // copy to new canvass
            imagedestroy($thisIcon);
            // copy and resize canvass to banner
            imagecopyresampled($im, $newIcon, $putX, $putY, $sourceX, $sourceY, $putX_width, $putY_height, $sourceX_width, $sourceY_height);
            imagedestroy($newIcon);
        }
    }
} // END function image_paste()



function TEMP_COLOUR($T)
{
	if ($T < -15)
	{
		$rgb = array("153","0","102"); // -16
	}
	elseif ($T < -10 && $T >= -15)
	{
		$rgb = array("50","0","127");
	}
	elseif ($T < -8 && $T >= -10)
	{
		$rgb = array("0","0","51");
	}
	elseif ($T < -6 && $T >= -8)
	{
		$rgb = array("0","0","102");
	}
	elseif ($T < -4 && $T >= -6)
	{
		$rgb = array("0","0","153");
	}
	elseif ($T < -2 && $T >= -4)
	{
		$rgb = array("0","0","24");
	}
	elseif ($T < 0 && $T >= -2)
	{
		$rgb = array("0","0","255");
	}
	elseif ($T >= 0 && $T <= 2)
	{
		$rgb = array("0","64","128"); //   0
	}
	elseif ($T >= 2 && $T <= 4)
	{
		$rgb = array("0","128","128");
	}
	elseif ($T >= 4 && $T <= 6)
	{
		$rgb = array("0","64","64");
	}
	elseif ($T >= 6 && $T <= 8)
	{
		$rgb = array("0","128","64");
	}
	elseif ($T >= 8 && $T <= 10)
	{
		$rgb = array("0","128","128");
	}
	elseif ($T >= 10 && $T <= 12)
	{
		$rgb = array("0","64","0");
	}
	elseif ($T >= 12 && $T <= 14)
	{
		$rgb = array("0","85","0");
	}
	elseif ($T >= 14 && $T <= 16)
	{
		$rgb = array("0","128","0");
	}
	elseif ($T >= 16 && $T <= 18)
	{
		$rgb = array("0","179","0");
	}
	elseif ($T >= 18 && $T <= 20)
	{
		$rgb = array("105","210","0");
	}
	elseif ($T >= 20 && $T <= 22)
	{
		$rgb = array("213","213","0");
	}
	elseif ($T >= 22 && $T <= 24)
	{
		$rgb = array("221","111","0");
	}
	elseif ($T >= 24 && $T <= 26)
	{
		$rgb = array("236","77","0");
	}
	elseif ($T >= 26 && $T <= 28)
	{
		$rgb = array("255","40","40");
	}
	elseif ($T >= 28 && $T <= 30)
	{
		$rgb = array("236","0","0");
	}
	elseif ($T >= 30 && $T <= 32)
	{
		$rgb = array("173","0","0");
	}
	elseif ($T >= 32 && $T <= 34)
	{
		$rgb = array("120","0","0");
	}
	elseif ($T >= 34 && $T <= 36)
	{
		$rgb = array("128","0","64");
	}
	elseif ($T > 36)
	{
		$rgb = array("64","0","64"); // +36
	}
	return $rgb;
} // END Funtion TEMP_COLOUR

############################################################################
# END OF MODULES
############################################################################
?>