You are here

function _weather_parse_phenomena in Weather 5

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

Extract the phenomena information

Parameters

string Raw METAR data to parse:

array Parsed METAR data, will be altered:

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

File

./weather_parser.inc, line 213

Code

function _weather_parse_phenomena($metar_raw, &$metar) {
  if (preg_match('/^' . '(-|\\+|VC)?' . '(SH|TS|FZ)?' . 'RA' . '$/', $metar_raw, $matches)) {
    $phen = array();
    switch ($matches[1]) {
      case '-':
        $phen['#light'] = true;
        break;
      case '+':
        $phen['#heavy'] = true;
        break;
      default:
        $phen['#moderate'] = true;
    }
    switch ($matches[2]) {
      case 'SH':
        $phen['#showers'] = true;
        break;
      case 'FZ':
        $phen['#freezing'] = true;
        break;
    }
    $metar['phenomena']['rain'] = $phen;
  }
  else {
    if (preg_match('/^' . '(-|\\+|VC)?' . '(FZ)?' . 'DZ' . '$/', $metar_raw, $matches)) {
      $phen = array();
      switch ($matches[1]) {
        case '-':
          $phen['#light'] = true;
          break;
        case '+':
          $phen['#heavy'] = true;
          break;
        default:
          $phen['#moderate'] = true;
      }
      switch ($matches[2]) {
        case 'FZ':
          $phen['#freezing'] = true;
          break;
      }
      $metar['phenomena']['drizzle'] = $phen;
    }
  }
}