'.$scrpt_vrsn_dt.PHP_EOL;
#-----------------------------------------------
# functions
#-----------------------------------------------
# set_my_time => format time am / pm
#-----------------------------------------------
function set_my_time($time, $int=false)
{ global $timeFormatShort;
$fr_ampm= array ('_am','_pm',);
$to_ampm= array ('am','pm',);
$time = str_replace($fr_ampm, $to_ampm, strtolower($time) );
if ($int)
{ $return = date($timeFormatShort,(int) $time); }
else { $return = date($timeFormatShort, strtotime ($time)); }
$fr_ampm= array ('am','pm');
$to_ampm= array ('am','pm');
return str_replace($fr_ampm, $to_ampm, strtolower($return) ); }
#-----------------------------------------------
# set_my_time => format time am / pm
#-----------------------------------------------
function set_my_time_lng($time, $int=false)
{ global $timeFormat;
$fr_ampm= array ('am','pm');
$to_ampm= array ('am','pm');
if ($int)
{ $return = date($timeFormat,$time); }
else { $return = date($timeFormat, strtotime ($time)); }
return str_replace($fr_ampm, $to_ampm, strtolower($return) ); }
#-----------------------------------------------
# check_value
# => check if tag exists && contains a value
#-----------------------------------------------
function check_value ($key, $arr = '') # check if tag contains correct value
{ global $weather;
if ($arr == '')
{ if (!array_key_exists ($key,$weather) ) { return false;}
$value = trim($weather[$key]);}
elseif (!is_array ($arr) ) { return false;}
else { if (!array_key_exists ($key,$arr) ) { return false;}
$value = trim($arr[$key]);}
#
if ( (string) $value === 'n/a' ) { return false;}
elseif ( (string) $value === '---' ) { return false;}
elseif ( $value === '' ) { return false;}
elseif ( $value === false ) { return false;}
elseif ( $value === NULL ) { return false;}
return true;}
#-----------------------------------------------
# anyToC => return celcius value from a temp
#-----------------------------------------------
function anyToC($field)
{ global $weather;
if ($weather["temp_units"] == 'C')
{ return (float) $field;} # 2021-12-08
else { return convert_temp ($field,'f','c',1); }}
#-----------------------------------------------
# convert_temp => from C=>F and F=>C
#-----------------------------------------------
function convert_temp ($num,$from,$to,$dec=1)
{ global $stck_lst;
$amount = (float) str_replace(',','.',$num);
$from = strtolower($from);
$to = strtolower($to);
if ($from == $to) { $out = $amount;}
elseif (($from == 'c') && ($to = 'f')) { $out = 32 +(9*$amount/5);}
elseif (($from == 'f') && ($to = 'c')) { $out = 5*($amount -32)/9;}
else { $out = -999;}
$return = round($out,$dec);
# $stck_lst .= basename(__FILE__).' ('.__LINE__.') $num='.$num.' $from='.$from.' $to='.$to.' $return='.$return.PHP_EOL;
return $return;}
#-----------------------------------------------
# feel / heat calculations
#-----------------------------------------------
# heatIndexLow => Calculates "real feel" heat index
# valid only at lower temperatures (up to 79 F)
#-----------------------------------------------
function heatIndexLow($temp, $hum) # !!! Assumes Fahrenheit
{ $t = (float) $temp; # 2021-12-08
$rh = (float) $hum; # 2021-12-08
return 0.5 * ($t + 61.0 + (($t - 68.0) * 1.2) + ($rh * 0.094));}
#-----------------------------------------------
# heatIndexHigh => Calculates "real feel" heat index
# valid only at higher temperatures (beginning around 79-80 F)
# the traditional heat index formula
function heatIndexHigh($temp, $hum) # !!! Assumes Fahrenheit
{ $t = (float) $temp; # 2021-12-08
$rh = (float) $hum; # 2021-12-08
$heatIndex = -42.379 + 2.04901523 * $t + 10.1433127*$rh - .22475441*$t*$rh
- .00683783 *$t * $t - .05481717 * $rh * $rh + .00122874*$t*$t*$rh
+ .00085282 *$t * $rh *$rh - .00000199 *$t *$t *$rh * $rh;
# Adjustment formula, adding or subtracting as much as a couple degrees at extreme ends of temperature/humidity ranges
$a = 0;
if ($rh < 13 && ($t >= 80 && $t <= 112))
{ $a=((13 - $rh ) / 4) * sqrt((17-abs($t - 95))/17);
$a = -$a;};
if ($rh > 85 && ($t >= 80 && $t <= 87))
{ $a=(($rh - 85)/10) * ((87 - $t) / 5);};
$heatIndex += $a;
return $heatIndex;}
#-----------------------------------------------
# heatIndex => Ruthfusz heat index formula
# => http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
#-----------------------------------------------
function heatIndex($temp, $rh)
{ global $weather;
$unit = $weather["temp_units"];
if ($unit == 'C')
{ $t = convert_temp ($temp,'c','f',1); }
else { $t = $temp;}
# First try simple formula, valid when calculated heat index <= 79 degrees F
$heatIndex = heatIndexLow($t, $rh);
# If too warm, do the complicated formula instead
if ($heatIndex >= 79)
{ $heatIndex = heatIndexHigh($t, $rh);}
if ($unit == 'C')
{ $heatIndex = convert_temp ($heatIndex,'f','c',1); }
return round($heatIndex, 1);}
#-----------------------------------------------
# convert_baro Pressure
#-----------------------------------------------
function convert_baro ($num,$from,$to,$dec='')
{ $amount = (float) str_replace(',','.',$num);
$repl = array ('/',' ','hg','mb');
$with = array ('' ,'' ,'','hpa');
$convertArr = array
( "hpa" => array('hpa' => 1 , 'mm' => 0.75006 , 'in' => 0.02953),
"mm" => array('hpa' => 1.3332 , 'mm' => 1 , 'in' => 0.03937 ),
"in" => array('hpa' => 33.864 , 'mm' => 25.4 , 'in' => 1) );
$fromUnit = trim(str_replace ($repl,$with,strtolower($from)));
$toUnit = trim(str_replace ($repl,$with,strtolower($to)));
if (!isset ($convertArr[$fromUnit][$toUnit]) )
{ $out = 1;}
else { $out = $convertArr[$fromUnit][$toUnit];}
if ($dec == '')
{ if ($toUnit == 'hpa')
{ $dec = 1;}
else { $dec = 2;}
} // eo empty decimals
$return = round($out*$amount,$dec); #echo '$num='.$num.' $from='.$from.' $to='.$to.' $dec='.$dec.' $return='.$return.'
'.PHP_EOL;
return $return; } // eof convert_baro
#-----------------------------------------------
# convert_precip Precipitation
#-----------------------------------------------
function convert_precip ($num,$from,$to,$dec='')
{ $amount = (float) str_replace(',','.',$num);
$repl = array ('l/m','/',' ','ch');
$with = array ('mm' ,'' ,'' ,'');
$convertArr = array
( "mm"=> array('mm' => 1 ,'in' => 0.03937007874015748 , 'cm' => 0.1 ),
"in"=> array('mm' => 25.4 ,'in' => 1 , 'cm' => 2.54),
"cm"=> array('mm' => 10 ,'in' => 0.3937007874015748 , 'cm' => 1 ) );
$fromUnit = trim(str_replace ($repl,$with,strtolower($from)));
$toUnit = trim(str_replace ($repl,$with,strtolower($to)));
if (!isset ($convertArr[$fromUnit][$toUnit]) )
{ $out = 1;}
else { $out = $convertArr[$fromUnit][$toUnit];}
if ($dec == '')
{ if ($toUnit == 'in' || $toUnit == 'cm')
{ $dec = 2;}
else { $dec = 1;}
} // eo empty decimals
$return = round($out*$amount,$dec);
return $return;} // eof convert_precip
#-----------------------------------------------
# convert_speed Wind / Gust Speed
#-----------------------------------------------
function convert_speed ($num,$from,$to,$dec='')
{ $amount = (float) str_replace(',','.',$num);
$repl = array ('/',' ','p');
$with = array ('','','');
$convertArr= array
( "kmh"=> array('kmh' => 1 , 'kts' => 0.5399568034557235 , 'ms' => 0.2777777777777778 , 'mh' => 0.621371192237334 ),
"kts"=> array('kmh' => 1.852 , 'kts' => 1 , 'ms' => 0.5144444444444445 , 'mh' => 1.1507794480235425),
"ms" => array('kmh' => 3.6 , 'kts' => 1.9438444924406046 , 'ms' => 1 , 'mh' => 2.236936292054402 ),
"mh" => array('kmh' => 1.609344 , 'kts' => 0.8689762419006479 , 'ms' => 0.44704 , 'mh' => 1 ));
$fromUnit = trim(str_replace ($repl,$with,strtolower($from)));
$toUnit = trim(str_replace ($repl,$with,strtolower($to)));
if (!isset ($convertArr[$fromUnit][$toUnit]) )
{ $out = 1;}
else { $out = $convertArr[$fromUnit][$toUnit];}
if ($dec === '') { $dec = 1;}
$return = round($out*$amount,$dec);
return $return;
} // eof convert_speed
#-----------------------------------------------
# distance distance
#-----------------------------------------------
function distance($lat, $lon, $lati, $longi)
{ $lat1 = deg2rad($lati);
$lat2 = deg2rad($lat);
$long1 = deg2rad($longi);
$long2 = deg2rad($lon);
// Great circle calculation uses the radius of earth, 6371 km
return 6371 * acos(sin($lat1)*sin($lat2) + cos($lat1)*cos($lat2)*cos($long2-$long1));}
#-----------------------------------------------
# windlabel convert degrees to compass name
#-----------------------------------------------
$windlabel_dfld = array ('North','NNE', 'NE', 'ENE', 'East', 'ESE', 'SE', 'SSE', 'South',
'SSW','SW', 'WSW', 'West', 'WNW', 'NW', 'NNW');
$windlabel_shrt = array ('N','NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S',
'SSW','SW', 'WSW', 'W', 'WNW', 'NW', 'NNW');
function windlabel($value, $short = false)
{ global $windlabel_dfld, $windlabel_shrt;
$degr = (int) $value;
$key = (int) fmod((($degr + 11) / 22.5),16); # 2022-03-29
if ($short <> false)
{ return $windlabel_dfld[$key];}
else { return $windlabel_shrt[$key];}
}
#-----------------------------------------------
# lang language translate
#-----------------------------------------------
function lang($text)
{ global $lang, $lang_file , $used_lang; #### 2021-02-11
global $missing;
if (trim($text) == '') { return $text;}
if (isset ($lang[$text]) ) { return $lang[$text];}
$txtsmll= strtolower (str_replace (' ','',$text) );
if (isset ($lang[$txtsmll]) ) { return $lang[$txtsmll];}
# skip for UK / US lang if not test mode $lang_file
if ( $lang_file == 'languages/lang_en.txt') {return $text;} # 2021-12-08
# save missing translation #### 2021-02-28
$arr = debug_backtrace();
$file = $arr[0]['file'];
$arr = explode ('/',$file);
$n = count($arr) - 1;
if ($n < 0) {$n = 0;}
$script = '#'.$arr[$n];
if (substr($used_lang,0,2) == 'en') {$script ='';}
$missing[$text]= ' |'.$text.'|'.$text.'| '.$script.PHP_EOL; #### 2021-02-11
return $text;}
#-----------------------------------------------
#
#-----------------------------------------------
# SVGs used in multiple scripts
#-----------------------------------------------
$lightningsvg="";
$online = '';
$rainsvg= '';
$snowflakesvg= '';