function _weather_parse_wind in Weather 5
Same name and namespace in other branches
- 5.6 weather_parser.inc \_weather_parse_wind()
 - 6.5 weather_parser.inc \_weather_parse_wind()
 - 7 weather_parser.inc \_weather_parse_wind()
 
Extract the wind information
Parameters
string Raw METAR data to parse:
array Parsed METAR data, will be altered:
1 call to _weather_parse_wind()
- weather_parse_metar in ./
weather_parser.inc  - Parses a raw METAR data string
 
File
- ./
weather_parser.inc, line 141  
Code
function _weather_parse_wind($metar_raw, &$metar) {
  if (preg_match('/^' . '([0-9]{3}|VRB)' . '([0-9]{2,3})' . '(G([0-9]{2,3}))?' . '(KT)' . '$/', $metar_raw, $matches)) {
    $metar['wind']['direction'] = (int) $matches[1];
    $wind_speed = (int) $matches[2];
    $wind_gusts = (int) $matches[4];
    $wind_unit = $matches[5];
    // Do a conversion to other formats
    switch ($wind_unit) {
      case 'KT':
        // Convert to km/h and mph
        // nautical mile = 1852 meters
        // statue mile = 1609.344 meters
        $metar['wind']['speed_kmh'] = round($wind_speed * 1.852, 1);
        $metar['wind']['gusts_kmh'] = round($wind_gusts * 1.852, 1);
        $metar['wind']['speed_mph'] = round($wind_speed * 1.151, 1);
        $metar['wind']['gusts_mph'] = round($wind_gusts * 1.151, 1);
        break;
    }
  }
  else {
    if (preg_match('/^' . '([0-9]{3})' . 'V' . '([0-9]{3})' . '$/', $metar_raw, $matches)) {
      $metar['wind']['variable_start'] = (int) $matches[1];
      $metar['wind']['variable_end'] = (int) $matches[2];
    }
  }
}