You are here

function weather_parse_metar in Weather 6.5

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

Parses a raw METAR data string

1 call to weather_parse_metar()
weather_get_metar in ./weather.module
Fetches the latest METAR data from the database or internet

File

./weather_parser.inc, line 28

Code

function weather_parse_metar($metar_raw_string) {

  // Some stations insert a space between the cloud conditions
  // and the altitude, e.g. "FEW 025" instead of "FEW025".
  // Therefore, we scan for such occurences and remove the space.
  $metar_raw_string = preg_replace("/(FEW|SCT|BKN|OVC)\\s+([0-9]{3})/", '$1$2', $metar_raw_string);

  // Setup the metar data array
  $metar = array();
  $metar['#raw'] = $metar_raw_string;

  // Split string for parsing routines
  $raw_items = preg_split('/\\s+/', strtoupper($metar_raw_string));

  // Run the data through the METAR routines
  foreach ($raw_items as $metar_raw) {
    if (_weather_parse_stop($metar_raw, $metar)) {
      break;
    }
    _weather_parse_icao($metar_raw, $metar);
    _weather_parse_timestamp($metar_raw, $metar);
    _weather_parse_reporttype($metar_raw, $metar);
    _weather_parse_wind($metar_raw, $metar);
    _weather_parse_visibility($metar_raw, $metar);
    _weather_parse_condition($metar_raw, $metar);
    _weather_parse_phenomena($metar_raw, $metar);
    _weather_parse_temperature($metar_raw, $metar);
    _weather_parse_pressure($metar_raw, $metar);
  }

  // Calculate sunrise and sunset times
  _weather_calculate_sunrise_sunset($metar);
  return $metar;
}