Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv24514 Modified Files: metar_parser.php Log Message: Instead of storing the different groups (cloud, weather, wind) like group1, group2 etc, they're now stored as group[0], group[1] etc. This makes it easier to pass them around. Index: metar_parser.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/metar_parser.php,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- metar_parser.php 2001/07/09 20:31:43 1.9 +++ metar_parser.php 2001/07/14 21:47:45 1.10 @@ -18,7 +18,7 @@ * @see $decoded_metar */ class metar_parser extends data_retrieval { - + /** * The decoded METAR is stored here. * @@ -29,7 +29,7 @@ * @var array */ var $decoded_metar; - + /** * This constructor does nothing besides passing the input down the * hierarchy. @@ -37,12 +37,12 @@ * @param array The initial properties of the object. */ function metar_parser($input) { - /* This class doesn't have any defaults, so it just calls the - * parent constructor. - */ + /* This class doesn't have any defaults, so it just calls the + * parent constructor. + */ $this->data_retrieval($input); } - + /** * Helper-function used to store temperatures. * @@ -57,19 +57,19 @@ * @access private */ function store_temp($temp, &$temp_c, &$temp_f) { - /* - * Note: $temp is converted to negative if $temp > 100.0 (See - * Federal Meteorological Handbook for groups T, 1, 2 and 4). - * For example, a temperature of 2.6°C and dew point of -1.5°C - * would be reported in the body of the report as "03/M01" and the - * TsnT'T'T'snT'dT'dT'd group as "T00261015"). - */ + /* + * Note: $temp is converted to negative if $temp > 100.0 (See + * Federal Meteorological Handbook for groups T, 1, 2 and 4). + * For example, a temperature of 2.6°C and dew point of -1.5°C + * would be reported in the body of the report as "03/M01" and the + * TsnT'T'T'snT'dT'dT'd group as "T00261015"). + */ if ($temp[0] == 1) { $temp[0] = '-'; } $temp_c = number_format($temp,1); - /* The temperature in Fahrenheit. */ + /* The temperature in Fahrenheit. */ $temp_f = number_format($temp * (9/5) + 32, 1); } @@ -100,24 +100,24 @@ } if ($windunit == 'KT') { - /* The windspeed measured in knots: */ + /* The windspeed measured in knots: */ $knots = number_format($value); - /* The windspeed measured in meters per second, rounded to one decimal place */ + /* The windspeed measured in meters per second, rounded to one decimal place +*/ $meterspersec = number_format($value * 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ - $milesperhour = number_format($value * 1.1508, 1); + /* The windspeed measured in miles per hour, rounded to one decimal place */ + $milesperhour = number_format($value * 1.1508, 1); } elseif ($windunit == 'MPS') { - /* The windspeed measured in meters per second */ + /* The windspeed measured in meters per second */ $meterspersec = number_format($value); - /* The windspeed measured in knots, rounded to one decimal place */ + /* The windspeed measured in knots, rounded to one decimal place */ $knots = number_format($value / 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ + /* The windspeed measured in miles per hour, rounded to one decimal place */ $milesperhour = number_format($value / 0.5144 * 1.1508, 1); } elseif ($windunit == 'KMH') { - /* The windspeed measured in kilometers per hour */ + /* The windspeed measured in kilometers per hour */ $meterspersec = number_format($value * 1000 / 3600, 1); $knots = number_format($value * 1000 / 3600 / 0.5144, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place */ + /* The windspeed measured in miles per hour, rounded to one decimal place */ $milesperhour = number_format($knots * 1.1508, 1); } } @@ -136,74 +136,78 @@ * @access public */ function decode_metar() { - /* initialization */ - $cloud_groups = 0; - $weather_groups = 0; - $visibility_groups = 0; - $runway_groups = 0; + /* initialization */ + $cloud_group_nr = 0; + $weather_group_nr = 0; + $visibility_group_nr = 0; + $runway_group_nr = 0; $temp_visibility_miles = ''; $decoded_metar['remarks'] = ''; + /* There should always be at least one cloud-group, even if it's + empty. */ + $decoded_metar['clouds'][] = array(); + $decoded_metar['metar'] = $this->get_metar(); $decoded_metar['location'] = $this->get_location(); - + $parts = explode(' ', $this->metar); $num_parts = count($parts); for ($i = 0; $i < $num_parts; $i++) { $part = $parts[$i]; if (ereg('RMK|TEMPO|BECMG|INTER', $part)) { - /* The rest of the METAR is either a remark or temporary - * information. We skip the rest of the METAR. - */ + /* The rest of the METAR is either a remark or temporary + * information. We skip the rest of the METAR. + */ $decoded_metar['remarks'] .= ' ' . $part; break; } elseif ($part == 'METAR') { - /* - * Type of Report: METAR - */ + /* + * Type of Report: METAR + */ $decoded_metar['type'] = 'METAR'; } elseif ($part == 'SPECI') { - /* - * Type of Report: SPECI - */ + /* + * Type of Report: SPECI + */ $decoded_metar['type'] = 'SPECI'; } elseif (ereg('^[A-Z]{4}$', $part) && ! isset($decoded_metar['station'])) { - /* - * Station Identifier - */ + /* + * Station Identifier + */ $decoded_metar['station'] = $part; } elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) { - /* - * Date and Time of Report. - * - * We return a standard Unix UTC/GMT timestamp suitable for - * gmdate(). - * There has been a report about the time being wrong. If you - * experience this, then change the next line. You should - * add/subtract some hours to $regs[2], e.g. if all your times - * are 960 minutes off (16 hours) then add 16 to $regs[2]. - */ + /* + * Date and Time of Report. + * + * We return a standard Unix UTC/GMT timestamp suitable for + * gmdate(). + * There has been a report about the time being wrong. If you + * experience this, then change the next line. You should + * add/subtract some hours to $regs[2], e.g. if all your times + * are 960 minutes off (16 hours) then add 16 to $regs[2]. + */ if ($regs[1] > gmdate('j')) { - /* The day is greather that the current day of month => the - * report is from last month. - */ + /* The day is greather that the current day of month => the + * report is from last month. + */ $month = gmdate('n') - 1; } else { $month = gmdate('n'); } $decoded_metar['time'] = gmmktime($regs[2], $regs[3], 0, $month, $regs[1], gmdate('Y')); } elseif (ereg('(AUTO|COR|RTD|CC[A-Z]|RR[A-Z])', $part, $regs)) { - - /* - * Report Modifier: AUTO, COR, CCx or RRx - */ - + + /* + * Report Modifier: AUTO, COR, CCx or RRx + */ + $decoded_metar['report_mod'] = $regs[1]; } elseif (ereg('([0-9]{3}|VRB)([0-9]{2,3})G?([0-9]{2,3})?(KT|MPS|KMH)', $part, $regs)) { - - /* Wind Group */ + + /* Wind Group */ $decoded_metar['wind']['deg'] = $regs[1]; @@ -215,10 +219,10 @@ ); if (!empty($regs[3])) { - - /* We have a report with information about the gust. - * First we have the gust measured in knots. - */ + + /* We have a report with information about the gust. + * First we have the gust measured in knots. + */ $this->store_speed($regs[3], $regs[4], $decoded_metar['wind']['gust_knots'], @@ -226,178 +230,194 @@ $decoded_metar['wind']['gust_miles_per_hour']); } } elseif (ereg('^([0-9]{3})V([0-9]{3})$', $part, $regs)) { - - /* - * Variable wind-direction - */ + + /* + * Variable wind-direction + */ $decoded_metar['wind']['var_beg'] = $regs[1]; $decoded_metar['wind']['var_end'] = $regs[2]; } elseif(ereg('^([0-9]{4})([NS]?[EW]?)$', $part, $regs)) { - - /* - * Visibility in meters (4 digits only) - */ - - $visibility_groups++; + + /* + * Visibility in meters (4 digits only) + */ + if ($regs[1] == '0000') { - - /* Special low value */ - - $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = -1; /* Less than */ - - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = 50; - $decoded_metar['visibility_group' . $visibility_groups]['km'] = 0.05; - $decoded_metar['visibility_group' . $visibility_groups]['ft'] = 164; - $decoded_metar['visibility_group' . $visibility_groups]['miles'] = 0.031; + + /* Special low value */ + + $decoded_metar['visibility'][$visibility_group_nr]['prefix'] = -1; /* Less +than */ + + $decoded_metar['visibility'][$visibility_group_nr]['meter'] = 50; + $decoded_metar['visibility'][$visibility_group_nr]['km'] = 0.05; + $decoded_metar['visibility'][$visibility_group_nr]['ft'] = 164; + $decoded_metar['visibility'][$visibility_group_nr]['miles'] = 0.031; } elseif ($regs[1] == '9999') { - - /* Special high value */ - - $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = 1; - /* Greater than */ - - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = 10000; - $decoded_metar['visibility_group' . $visibility_groups]['km'] = 10; - $decoded_metar['visibility_group' . $visibility_groups]['ft'] = 32800; - $decoded_metar['visibility_group' . $visibility_groups]['miles'] = 6.2; + + /* Special high value */ + + $decoded_metar['visibility'][$visibility_group_nr]['prefix'] = 1; + /* Greater than */ + + $decoded_metar['visibility'][$visibility_group_nr]['meter'] = 10000; + $decoded_metar['visibility'][$visibility_group_nr]['km'] = 10; + $decoded_metar['visibility'][$visibility_group_nr]['ft'] = 32800; + $decoded_metar['visibility'][$visibility_group_nr]['miles'] = 6.2; } else { - - /* Normal visibility, returned in both small and large units. */ - - $decoded_metar['visibility_group' . $visibility_groups]['km'] = number_format($regs[1]/1000, 1); - $decoded_metar['visibility_group' . $visibility_groups]['miles'] = number_format($regs[1]/1609.344, 1); - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = $regs[1] * 1; - $decoded_metar['visibility_group' . $visibility_groups]['ft'] = round($regs[1] * 3.28084); + + /* Normal visibility, returned in both small and large units. */ + + $decoded_metar['visibility'][$visibility_group_nr]['km'] = +number_format($regs[1]/1000, 1); + $decoded_metar['visibility'][$visibility_group_nr]['miles'] = +number_format($regs[1]/1609.344, 1); + $decoded_metar['visibility'][$visibility_group_nr]['meter'] = $regs[1] * 1; + $decoded_metar['visibility'][$visibility_group_nr]['ft'] = +round($regs[1] * 3.28084); } if (!empty($regs[2])) { - $decoded_metar['visibility_group' . $visibility_groups]['dir'] = $regs[2]; + $decoded_metar['visibility'][$visibility_group_nr]['dir'] = $regs[2]; } - } elseif (ereg('^[0-9]$', $part)) { + + /* We increment $visibility_group_nr so that it's ready for + the next group. */ + $visibility_group_nr++; - /* - * Temp Visibility Group, single digit followed by space. - */ - + } elseif (ereg('^[0-9]$', $part)) { + + /* + * Temp Visibility Group, single digit followed by space. + */ + $temp_visibility_miles = $part; } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$', $temp_visibility_miles . ' ' . $part, $regs)) { - - /* - * Visibility Group - */ - - $visibility_groups++; + + /* + * Visibility Group + */ + if ($regs[4] == '/') { $vis_miles = $regs[2] + $regs[3]/$regs[5]; - } else { - $vis_miles = $regs[1]; - } - if ($regs[0][0] == 'M') { - - /* Prefix - less than */ - - $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = -1; /* Less than */ - - } + } else { + $vis_miles = $regs[1]; + } + if ($regs[0][0] == 'M') { + + /* Prefix - less than */ + + $decoded_metar['visibility'][$visibility_group_nr]['prefix'] = -1; /* Less +than */ + + } + + /* The visibility measured in miles */ + + $decoded_metar['visibility'][$visibility_group_nr]['miles'] = +number_format($vis_miles, 1); + + /* The visibility measured in feet */ + + $decoded_metar['visibility'][$visibility_group_nr]['ft'] = +round($vis_miles * 5280, 1); + + /* The visibility measured in kilometers */ + + $decoded_metar['visibility'][$visibility_group_nr]['km'] = +number_format($vis_miles * 1.6093, 1); + + /* The visibility measured in meters */ + + $decoded_metar['visibility'][$visibility_group_nr]['meter'] = +round($vis_miles * 1609.3); + + /* We increment $visibility_group_nr so that it's ready for + the next group. */ + $visibility_group_nr++; - /* The visibility measured in miles */ - - $decoded_metar['visibility_group' . $visibility_groups]['miles'] = number_format($vis_miles, 1); - - /* The visibility measured in feet */ - - $decoded_metar['visibility_group' . $visibility_groups]['ft'] = round($vis_miles * 5280, 1); - - /* The visibility measured in kilometers */ - - $decoded_metar['visibility_group' . $visibility_groups]['km'] = number_format($vis_miles * 1.6093, 1); - - /* The visibility measured in meters */ - - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = round($vis_miles * 1609.3); } elseif ($part == 'CAVOK') { + + /* CAVOK: Used when the visibility is greater than 10 + * kilometers, the lowest cloud-base is at 5000 feet or more + * and there is no significant weather. + */ + + /* Greater than */ + $decoded_metar['visibility'][$visibility_group_nr]['prefix'] = 1; + + $decoded_metar['visibility'][$visibility_group_nr]['km'] = 10; + $decoded_metar['visibility'][$visibility_group_nr]['meter'] = 10000; + $decoded_metar['visibility'][$visibility_group_nr]['miles'] = 6.2; + $decoded_metar['visibility'][$visibility_group_nr]['ft'] = 32800; + $decoded_metar['cloud_group1']['condition'] = 'CAVOK'; + + /* We increment $visibility_group_nr so that it's ready for + the next group. */ + $visibility_group_nr++; - /* CAVOK: Used when the visibility is greater than 10 - * kilometers, the lowest cloud-base is at 5000 feet or more - * and there is no significant weather. - */ - - $visibility_groups++; - $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = 1; - /* Greater than */ - - $decoded_metar['visibility_group' . $visibility_groups]['km'] = 10; - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = 10000; - $decoded_metar['visibility_group' . $visibility_groups]['miles'] = 6.2; - $decoded_metar['visibility_group' . $visibility_groups]['ft'] = 32800; - $decoded_metar['cloud_group1']['condition'] = 'CAVOK'; } elseif (ereg('^R([0-9]{2})([RLC]?)/([MP]?)([0-9]{4})([DNU]?)V?(P?)([0-9]{4})?([DNU]?)$', $part, $regs)) { - - /* Runway-group */ - - $runway_groups++; - $decoded_metar['runway_group' . $runway_groups]['nr'] = $regs[1]; + + /* Runway-group */ + + $decoded_metar['runway'][$runway_group_nr]['nr'] = $regs[1]; if (!empty($regs[2])) { - $decoded_metar['runway_group' . $runway_groups]['approach'] = $regs[2]; + $decoded_metar['runway'][$runway_group_nr]['approach'] = $regs[2]; } if (!empty($regs[7])) { - - /* We have both min and max visibility since $regs[7] holds - * the max visibility. - */ - - if (!empty($regs[5])) { - /* $regs[5] is tendency for min visibility. */ - $decoded_metar['runway_group' . $runway_groups]['min_tendency'] = $regs[5]; + + /* We have both min and max visibility since $regs[7] holds + * the max visibility. + */ + + if (!empty($regs[5])) { + /* $regs[5] is tendency for min visibility. */ + $decoded_metar['runway'][$runway_group_nr]['min_tendency'] = $regs[5]; } - if (!empty($regs[8])) { - /* $regs[8] is tendency for max visibility. */ - $decoded_metar['runway_group' . $runway_groups]['max_tendency'] = $regs[8]; + if (!empty($regs[8])) { + /* $regs[8] is tendency for max visibility. */ + $decoded_metar['runway'][$runway_group_nr]['max_tendency'] = $regs[8]; } if ($regs[3] == 'M') { - - /* Less than. */ - - $decoded_metar['runway_group' . $runway_groups]['min_prefix'] = -1; + + /* Less than. */ + + $decoded_metar['runway'][$runway_group_nr]['min_prefix'] = -1; } - $decoded_metar['runway_group' . $runway_groups]['min_meter'] = $regs[4] * 1; - $decoded_metar['runway_group' . $runway_groups]['min_ft'] = round($regs[4] * 3.2808); + $decoded_metar['runway'][$runway_group_nr]['min_meter'] = $regs[4] * 1; + $decoded_metar['runway'][$runway_group_nr]['min_ft'] = round($regs[4] * +3.2808); if ($regs[6] == 'P') { - - /* Greater than. */ - - $decoded_metar['runway_group' . $runway_groups]['max_prefix'] = 1; + + /* Greater than. */ + + $decoded_metar['runway'][$runway_group_nr]['max_prefix'] = 1; } - $decoded_metar['runway_group' . $runway_groups]['max_meter'] = $regs[7] * 1; - $decoded_metar['runway_group' . $runway_groups]['max_ft'] = round($regs[7] * 3.2808); + $decoded_metar['runway'][$runway_group_nr]['max_meter'] = $regs[7] * 1; + $decoded_metar['runway'][$runway_group_nr]['max_ft'] = round($regs[7] * +3.2808); } else { - - /* We only have a single visibility. */ - - if (!empty($regs[5])) { - /* $regs[5] holds the tendency for visibility. */ - $decoded_metar['runway_group' . $runway_groups]['tendency'] = $regs[5]; + + /* We only have a single visibility. */ + + if (!empty($regs[5])) { + /* $regs[5] holds the tendency for visibility. */ + $decoded_metar['runway'][$runway_group_nr]['tendency'] = $regs[5]; } if ($regs[3] == 'M') { - - /* Less than. */ - - $decoded_metar['runway_group' . $runway_groups]['prefix'] = -1; + + /* Less than. */ + + $decoded_metar['runway'][$runway_group_nr]['prefix'] = -1; } elseif ($regs[3] == 'P') { - - /* Greater than. */ - - $decoded_metar['runway_group' . $runway_groups]['prefix'] = 1; + + /* Greater than. */ + + $decoded_metar['runway'][$runway_group_nr]['prefix'] = 1; } - $decoded_metar['runway_group' . $runway_groups]['meter'] = $regs[4] * 1; - $decoded_metar['runway_group' . $runway_groups]['ft'] = round($regs[4] * 3.2808); + $decoded_metar['runway'][$runway_group_nr]['meter'] = $regs[4] * 1; + $decoded_metar['runway'][$runway_group_nr]['ft'] = round($regs[4] * +3.2808); } + + /* We increment $runway_group_nr so that it's ready for the + next group. */ + $runway_group_nr++; + } elseif (ereg('^(VC)?' . /* Proximity */ '(-|\+)?' . /* Intensity */ '(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */ @@ -405,114 +425,120 @@ '(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */ '(PO|SQ|FC|SS)?$', /* Other */ $part, $regs)) { - - /* - * Current weather-group. - */ - - $weather_groups++; - $decoded_metar['weather_group'.$weather_groups]['proximity'] = $regs[1]; - $decoded_metar['weather_group'.$weather_groups]['intensity'] = $regs[2]; - $decoded_metar['weather_group'.$weather_groups]['descriptor'] = $regs[3]; - $decoded_metar['weather_group'.$weather_groups]['precipitation'] = $regs[4]; - $decoded_metar['weather_group'.$weather_groups]['obscuration'] = $regs[6]; - $decoded_metar['weather_group'.$weather_groups]['other'] = $regs[7]; - + + /* + * Current weather-group. + */ + + $decoded_metar['weather'][$weather_group_nr]['proximity'] = $regs[1]; + $decoded_metar['weather'][$weather_group_nr]['intensity'] = $regs[2]; + $decoded_metar['weather'][$weather_group_nr]['descriptor'] = $regs[3]; + $decoded_metar['weather'][$weather_group_nr]['precipitation'] = $regs[4]; + $decoded_metar['weather'][$weather_group_nr]['obscuration'] = $regs[6]; + $decoded_metar['weather'][$weather_group_nr]['other'] = $regs[7]; + + + /* We increment $weather_group_nr so that it's ready for the + next group. */ + $weather_group_nr++; + } elseif ($part == 'SKC' || $part == 'CLR') { - /* - * Cloudr-group. - * There can be up to 3 of these groups, so we store them as - * cloud_layer1, cloud_layer2 and cloud_layer3. - */ - - $cloud_groups++; + /* Cloud-group */ - /* Again we have to translate the code-characters to a - * meaningful string. - */ + + + /* Again we have to translate the code-characters to a + * meaningful string. + */ + + $decoded_metar['clouds'][ $cloud_group_nr]['condition'] = $part; + + /* We increment $cloud_group_nr so that it's ready for the + next group. */ + $cloud_group_nr++; - $decoded_metar['cloud_group'. $cloud_groups]['condition'] = $part; } elseif (ereg('^(VV|FEW|SCT|BKN|OVC)([0-9]{3}|///)(CB|TCU)?$', $part, $regs)) { - - /* We have found (another) a cloud-layer-group. There can be up - * to 3 of these groups, so we store them as cloud_group1, - * cloud_group2 and cloud_group3. - */ - - $cloud_groups++; - $decoded_metar['cloud_group'.$cloud_groups]['condition'] = $regs[1]; + + /* We have found (another) a cloud-layer-group. */ + + $decoded_metar['clouds'][$cloud_group_nr]['condition'] = $regs[1]; if (!empty($regs[3])) { - $decoded_metar['cloud_group'.$cloud_groups]['cumulus'] = $regs[3]; + $decoded_metar['clouds'][$cloud_group_nr]['cumulus'] = $regs[3]; } if ($regs[2] == '000') { - - /* '000' is a special height. */ - - $decoded_metar['cloud_group'.$cloud_groups]['ft'] = 100; - $decoded_metar['cloud_group'.$cloud_groups]['meter'] = 30; - $decoded_metar['cloud_group'.$cloud_groups]['prefix'] = -1; /* Less than */ + + /* '000' is a special height. */ + + $decoded_metar['clouds'][$cloud_group_nr]['ft'] = 100; + $decoded_metar['clouds'][$cloud_group_nr]['meter'] = 30; + $decoded_metar['clouds'][$cloud_group_nr]['prefix'] = -1; /* Less than */ } elseif ($regs[2] == '///') { - - /* '///' means height nil */ - - $decoded_metar['cloud_group'.$cloud_groups]['ft'] = 'nil'; - $decoded_metar['cloud_group'.$cloud_groups]['meter'] = 'nil'; + + /* '///' means height nil */ + + $decoded_metar['clouds'][$cloud_group_nr]['ft'] = 'nil'; + $decoded_metar['clouds'][$cloud_group_nr]['meter'] = 'nil'; } else { - $decoded_metar['cloud_group'.$cloud_groups]['ft'] = $regs[2] *100; - $decoded_metar['cloud_group'.$cloud_groups]['meter'] = round($regs[2] * 30.48); + $decoded_metar['clouds'][$cloud_group_nr]['ft'] = $regs[2] *100; + $decoded_metar['clouds'][$cloud_group_nr]['meter'] = round($regs[2] * +30.48); } - } elseif (ereg('^(M?[0-9]{2})/(M?[0-9]{2})?$', $part, $regs)) { - /* - * Temperature/Dew Point Group. - * - * The temperature and dew-point measured in Celsius and Fahrenheit. - */ + /* We increment $cloud_group_nr so that it's ready for the + next group. */ + $cloud_group_nr++; - $decoded_metar['temperature']['temp_c'] = round(strtr($regs[1], 'M', '-')); - $decoded_metar['temperature']['temp_f'] = round(strtr($regs[1], 'M', '-') * (9/5) + 32); + } elseif (ereg('^(M?[0-9]{2})/(M?[0-9]{2})?$', $part, $regs)) { + + /* + * Temperature/Dew Point Group. + * + * The temperature and dew-point measured in Celsius and Fahrenheit. + */ + + $decoded_metar['temperature']['temp_c'] = round(strtr($regs[1], 'M', '-')); + $decoded_metar['temperature']['temp_f'] = round(strtr($regs[1], 'M', '-') * +(9/5) + 32); if (!empty($regs[2])) { - $decoded_metar['temperature']['dew_c'] = round(strtr($regs[2], 'M', '-')); - $decoded_metar['temperature']['dew_f'] = round(strtr($regs[2], 'M', '-') * (9/5) + 32); + $decoded_metar['temperature']['dew_c'] = round(strtr($regs[2], 'M', '-')); + $decoded_metar['temperature']['dew_f'] = round(strtr($regs[2], 'M', '-') * +(9/5) + 32); } } elseif(ereg('A([0-9]{4})', $part, $regs)) { - - /* - * Altimeter. - * The pressure measured in inHg. - */ - - $decoded_metar['altimeter']['inhg'] = number_format($regs[1]/100, 2); - - /* The pressure measured in mmHg, hPa and atm */ - - $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.254, 1, '.', ''); - $decoded_metar['altimeter']['hpa'] = round($regs[1] * 0.33864); + + /* + * Altimeter. + * The pressure measured in inHg. + */ + + $decoded_metar['altimeter']['inhg'] = number_format($regs[1]/100, 2); + + /* The pressure measured in mmHg, hPa and atm */ + + $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.254, 1, '.', +''); + $decoded_metar['altimeter']['hpa'] = round($regs[1] * 0.33864); $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 3.3421e-4, 3, '.', ''); } elseif(ereg('Q([0-9]{4})', $part, $regs)) { - - /* - * Altimeter. - * The specification doesn't say anything about - * the Qxxxx-form, but it's in the METARs. - */ - - /* The pressure measured in hPa */ - - $decoded_metar['altimeter']['hpa'] = round($regs[1]); - - /* The pressure measured in mmHg, inHg and atm */ - - $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.75006, 1, '.', ''); - $decoded_metar['altimeter']['inhg'] = number_format($regs[1] * 0.02953, 2); - $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 9.8692e-4, 3, '.', ''); + + /* + * Altimeter. + * The specification doesn't say anything about + * the Qxxxx-form, but it's in the METARs. + */ + + /* The pressure measured in hPa */ + + $decoded_metar['altimeter']['hpa'] = round($regs[1]); + + /* The pressure measured in mmHg, inHg and atm */ + + $decoded_metar['altimeter']['mmhg'] = number_format($regs[1] * 0.75006, 1, +'.', ''); + $decoded_metar['altimeter']['inhg'] = number_format($regs[1] * 0.02953, 2); + $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 9.8692e-4, 3, +'.', ''); } elseif (ereg('^T([0-9]{4})([0-9]{4})', $part, $regs)) { - - /* - * Temperature/Dew Point Group, coded to tenth of degree Celsius. - */ - + + /* + * Temperature/Dew Point Group, coded to tenth of degree Celsius. + */ + $this->store_temp($regs[1] / 10, $decoded_metar['temperature']['temp_c'], $decoded_metar['temperature']['temp_f']); @@ -524,28 +550,28 @@ $decoded_metar['temperature']['temp_c'], $decoded_metar['temperature']['temp_f']); } elseif (ereg('^1([0-9]{4}$)', $part, $regs)) { - - /* - * 6 hour maximum temperature Celsius, coded to tenth of degree - */ - + + /* + * 6 hour maximum temperature Celsius, coded to tenth of degree + */ + $this->store_temp($regs[1] / 10, $decoded_metar['temp_min_max']['max6h_c'], $decoded_metar['temp_min_max']['max6h_f']); } elseif (ereg('^2([0-9]{4}$)', $part, $regs)) { - - /* - * 6 hour minimum temperature Celsius, coded to tenth of degree - */ + + /* + * 6 hour minimum temperature Celsius, coded to tenth of degree + */ $this->store_temp($regs[1] / 10, $decoded_metar['temp_min_max']['min6h_c'], $decoded_metar['temp_min_max']['min6h_f']); } elseif (ereg('^4([0-9]{4})([0-9]{4})$', $part, $regs)) { - - /* - * 24 hour maximum and minimum temperature Celsius, coded to - * tenth of degree - */ + + /* + * 24 hour maximum and minimum temperature Celsius, coded to + * tenth of degree + */ $this->store_temp($regs[1] / 10, $decoded_metar['temp_min_max']['max24h_c'], $decoded_metar['temp_min_max']['max24h_f']); @@ -553,48 +579,48 @@ $decoded_metar['temp_min_max']['min24h_c'], $decoded_metar['temp_min_max']['min24h_f']); } elseif(ereg('^P([0-9]{4})', $part, $regs)) { - - /* - * Precipitation during last hour in hundredths of an inch - */ + + /* + * Precipitation during last hour in hundredths of an inch + */ if ($regs[1] == '0000') { $decoded_metar['precipitation']['in'] = -1; $decoded_metar['precipitation']['mm'] = -1; } else { - $decoded_metar['precipitation']['in'] = number_format($regs[1]/100, 2); - $decoded_metar['precipitation']['mm'] = number_format($regs[1]*0.254, 2); + $decoded_metar['precipitation']['in'] = number_format($regs[1]/100, 2); + $decoded_metar['precipitation']['mm'] = number_format($regs[1]*0.254, 2); } } elseif(ereg('^6([0-9]{4})', $part, $regs)) { - - /* - * Precipitation during last 3 or 6 hours in hundredths of an - * inch. - */ + + /* + * Precipitation during last 3 or 6 hours in hundredths of an + * inch. + */ if ($regs[1] == '0000') { $decoded_metar['precipitation']['in_6h'] = -1; $decoded_metar['precipitation']['mm_6h'] = -1; } else { - $decoded_metar['precipitation']['in_6h'] = number_format($regs[1]/100, 2); - $decoded_metar['precipitation']['mm_6h'] = number_format($regs[1]*0.254, 2); + $decoded_metar['precipitation']['in_6h'] = number_format($regs[1]/100, 2); + $decoded_metar['precipitation']['mm_6h'] = number_format($regs[1]*0.254, 2); } } elseif(ereg('^7([0-9]{4})', $part, $regs)) { - - /* - * Precipitation during last 24 hours in hundredths of an inch. - */ + + /* + * Precipitation during last 24 hours in hundredths of an inch. + */ if ($regs[1] == '0000') { $decoded_metar['precipitation']['in_24h'] = -1; $decoded_metar['precipitation']['mm_24h'] = -1; } else { - $decoded_metar['precipitation']['in_24h'] = number_format($regs[1]/100, 2, '.', ''); - $decoded_metar['precipitation']['mm_24h'] = number_format($regs[1]*0.254, 2, '.', ''); + $decoded_metar['precipitation']['in_24h'] = number_format($regs[1]/100, 2, +'.', ''); + $decoded_metar['precipitation']['mm_24h'] = number_format($regs[1]*0.254, +2, '.', ''); } } elseif(ereg('^4/([0-9]{3})', $part, $regs)) { - - /* - * Snow depth in inches - */ - + + /* + * Snow depth in inches + */ + if ($regs[1] == '0000') { $decoded_metar['precipitation']['snow_in'] = -1; $decoded_metar['precipitation']['snow_mm'] = -1; @@ -603,46 +629,46 @@ $decoded_metar['precipitation']['snow_mm'] = round($regs[1] * 25.4); } } else { - - /* - * If we couldn't match the group, we assume that it was a - * remark. - */ - + + /* + * If we couldn't match the group, we assume that it was a + * remark. + */ + $decoded_metar['remarks'] .= ' ' . $part; } } - - /* - * Relative humidity - */ - + + /* + * Relative humidity + */ + if (!empty($decoded_metar['temperature']['temp_c']) && !empty($decoded_metar['temperature']['dew_c'])) { $decoded_metar['rel_humidity'] = number_format(100 * - ( - 610.71 + - 44.429 * $decoded_metar['temperature']['dew_c'] + - 1.4169 * pow($decoded_metar['temperature']['dew_c'], 2) + - 0.0274 * pow($decoded_metar['temperature']['dew_c'], 3) + - 2.6114E-4 * pow($decoded_metar['temperature']['dew_c'], 4) + - 2.8599E-6 * pow($decoded_metar['temperature']['dew_c'], 5) - ) - / - ( - 610.71 + - 44.429 * $decoded_metar['temperature']['temp_c'] + - 1.4169 * pow($decoded_metar['temperature']['temp_c'], 2) + - 0.0274 * pow($decoded_metar['temperature']['temp_c'], 3) + - 2.6114E-4 * pow($decoded_metar['temperature']['temp_c'], 4) + - 2.8599E-6 * pow($decoded_metar['temperature']['temp_c'], 5) - ), 1); + ( + 610.71 + + 44.429 * +$decoded_metar['temperature']['dew_c'] + + 1.4169 * +pow($decoded_metar['temperature']['dew_c'], 2) + + 0.0274 * +pow($decoded_metar['temperature']['dew_c'], 3) + + 2.6114E-4 * +pow($decoded_metar['temperature']['dew_c'], 4) + + 2.8599E-6 * +pow($decoded_metar['temperature']['dew_c'], 5) + ) + / + ( + 610.71 + + 44.429 * +$decoded_metar['temperature']['temp_c'] + + 1.4169 * +pow($decoded_metar['temperature']['temp_c'], 2) + + 0.0274 * +pow($decoded_metar['temperature']['temp_c'], 3) + + 2.6114E-4 * +pow($decoded_metar['temperature']['temp_c'], 4) + + 2.8599E-6 * +pow($decoded_metar['temperature']['temp_c'], 5) + ), 1); } - /* Finally we store our decoded METAR in $this->decoded_metar so - * that other methods can use it. - */ - + /* Finally we store our decoded METAR in $this->decoded_metar so + * that other methods can use it. + */ + $this->decoded_metar = $decoded_metar; return $decoded_metar; } _______________________________________________ PHPWeather-checkins mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/phpweather-checkins