You are here

function _weather_parse_pressure in Weather 6.5

Same name and namespace in other branches
  1. 5.6 weather_parser.inc \_weather_parse_pressure()
  2. 5 weather_parser.inc \_weather_parse_pressure()
  3. 7 weather_parser.inc \_weather_parse_pressure()

Extract the pressure information

Parameters

string Raw METAR data to parse:

array Parsed METAR data, will be altered:

1 call to _weather_parse_pressure()
weather_parse_metar in ./weather_parser.inc
Parses a raw METAR data string

File

./weather_parser.inc, line 451

Code

function _weather_parse_pressure($metar_raw, &$metar) {
  if (preg_match('/^' . '(A|Q)([0-9]{4})' . '$/', $metar_raw, $matches)) {
    if ($matches[1] == 'A') {

      // Pressure is given in inch Hg
      $metar['pressure']['inHg'] = $matches[2] / 100;
      $metar['pressure']['mmHg'] = round($metar['pressure']['inHg'] * 25.4, 0);
      $metar['pressure']['hPa'] = round($metar['pressure']['inHg'] * 33.8639, 0);
      $metar['pressure']['kPa'] = round($metar['pressure']['inHg'] * 3.38639, 1);
    }
    else {

      // Pressure is given in HektoPascal, hPa
      $metar['pressure']['hPa'] = (int) $matches[2];
      $metar['pressure']['inHg'] = round($metar['pressure']['hPa'] * 0.02953, 2);
      $metar['pressure']['mmHg'] = round($metar['pressure']['inHg'] * 25.4, 0);
      $metar['pressure']['kPa'] = round($metar['pressure']['inHg'] * 3.38639, 1);
    }
  }
}