Skip to main content.
^^

TNET Weather Station Notebooks - PHP Weather Functions

A couple functions that I use in my PHP code to convert certain values

windDir

This calculates the wind direction lable based upon a wind direction value of between 0 - 360.
function windDir ($winddir)
// Given the wind direction, return the text label
// for that value.  16 point compass
{
  if (!isset($winddir)) {
    return "---";
  }
$windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
   "SSW","SW", "WSW", "W", "WNN", "NW", "NNW");
$dir = $windlabel[ fmod((($winddir + 11) / 22.5),16) ];
return "$dir";
The idea of adding 11 and using mod 16 was an idea provided by Steve from SoftWX.com

tempToCelsius

function tempToCelsius ($fTemp, $prec=0)
// Given a temperature in degrees Celsius, convert it to 
// Fahrenheit and return the value.  Use an integer for 
// precision ($prec) to round the converted value. 
// Returns FALSE on error.
{
  if (!isset($fTemp)) {
    return false;
  }
  $prec = (integer)$prec;
  $cTemp = (float)(($fTemp - 32) / 1.8 );
  return round($cTemp, $prec);
}

ktsToMsec

function ktsToMsec ($Kts, $prec=0)
// Given wind speed in Kts, convert it to 
// m/sec and return the value.  Use an integer for 
// precision ($prec) to round the converted value. 
// Returns FALSE on error.
{
  if (!isset($Kts)) {
    return false;
  }
  $prec = (integer)$prec;
  $Msec = (float)( $Kts * 0.514444 );
  return round($Msec, $prec);
}

tempToFahrenheit

function tempToFahrenheit ($cTemp, $prec=0)
// Given a temperature in degrees Fahrenheit, convert it 
// to Celsius and return the value.  Use an integer for 
// precision ($prec) to round the converted value.
// Returns FALSE on error.
{
  if (!isset($cTemp)) {
    return false;
  }
  $prec = (integer)$prec;
  $fTemp = (float)(1.8 * $cTemp) + 32;
  return round($fTemp, $prec);
}

cmToInch

function cmToInch ($cm, $prec)
// Given a distance in centimeters, convert it to inches 
// and return the value.  Use an integer for precision ($prec)
// to round the converted value. Returns FALSE on error.
{
  if (!isset($cm)) {
    return false;
  }
  $prec = (integer)$prec;
  $inch = (float)$cm * 0.39;
  return round($inch, $prec);
}

inchToCm

function inchToCm ($inch, $prec)
// Given a distance in inches, convert it to centimeters 
// and return the value.  Use an integer for precision ($prec) 
// to round the converted value. Returns FALSE on error.
{
  if (!isset($inch)) {
    return false;
  }
  $prec = (integer)$prec;
  $cm = (float)$inch * 2.54;
  return round($cm, $prec);
}

  Goto Top Of Page
Web Design by TNET   © 1992-2008 Copyright TNET Services, Inc.
Home | Privacy Statement | Site Map | About Us - TNETWebGen v2.6.1
Some images and designs (SM) TNET Services, Inc.
SWN Member   USA Weather Finder