You are here

function _weather_parse_phenomena in Weather 6.5

Same name and namespace in other branches
  1. 5.6 weather_parser.inc \_weather_parse_phenomena()
  2. 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 263

Code

function _weather_parse_phenomena($metar_raw, &$metar) {
  if (preg_match('/^' . '(-|\\+|VC)?' . '(SH|TS|FZ)?' . 'RA' . '$/', $metar_raw, $matches)) {
    $phen = array();
    if (isset($matches[1])) {
      switch ($matches[1]) {
        case '-':
          $phen['#light'] = TRUE;
          break;
        case '+':
          $phen['#heavy'] = TRUE;
          break;
        default:
          $phen['#moderate'] = TRUE;
      }
    }
    if (isset($matches[2])) {
      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();
      if (isset($matches[1])) {
        switch ($matches[1]) {
          case '-':
            $phen['#light'] = TRUE;
            break;
          case '+':
            $phen['#heavy'] = TRUE;
            break;
          default:
            $phen['#moderate'] = TRUE;
        }
      }
      if (isset($matches[2])) {
        switch ($matches[2]) {
          case 'FZ':
            $phen['#freezing'] = TRUE;
            break;
        }
      }
      $metar['phenomena']['drizzle'] = $phen;
    }
    else {
      if (preg_match('/^' . '(-|\\+|VC)?' . '(BL|DR|SH)?' . 'SN' . '$/', $metar_raw, $matches)) {
        $phen = array();
        if (isset($matches[1])) {
          switch ($matches[1]) {
            case '-':
              $phen['#light'] = TRUE;
              break;
            case '+':
              $phen['#heavy'] = TRUE;
              break;
            default:
              $phen['#moderate'] = TRUE;
          }
        }
        if (isset($matches[2])) {
          switch ($matches[2]) {
            case 'BL':
              $phen['#blowing'] = TRUE;
              break;
            case 'DR':
              $phen['#low_drifting'] = TRUE;
              break;
            case 'SH':
              $phen['#showers'] = TRUE;
              break;
          }
        }
        $metar['phenomena']['snow'] = $phen;
      }
      else {
        if (preg_match('/^' . 'BR' . '$/', $metar_raw, $matches)) {
          $metar['phenomena']['#mist'] = TRUE;
        }
        else {
          if (preg_match('/^' . '(VC|MI|PR|BC)?' . 'FG' . '$/', $metar_raw, $matches)) {
            $phen = array();
            if (isset($matches[1])) {
              switch ($matches[1]) {
                case 'MI':
                  $phen['#shallow'] = TRUE;
                  break;
                case 'PR':
                  $phen['#partial'] = TRUE;
                  break;
                case 'BC':
                  $phen['#patches'] = TRUE;
                  break;
              }
            }
            $metar['phenomena']['fog'] = $phen;
          }
          else {
            if (preg_match('/^' . 'FU' . '$/', $metar_raw, $matches)) {
              $metar['phenomena']['#smoke'] = TRUE;
            }
          }
        }
      }
    }
  }
}