Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv29231 Modified Files: metar_parser.php Log Message: Rearranging comments and rounding numbers max. up to 5-6 digits. Index: metar_parser.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/metar_parser.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- metar_parser.php 2001/07/05 16:05:11 1.8 +++ metar_parser.php 2001/07/09 20:31:43 1.9 @@ -22,20 +22,24 @@ /** * The decoded METAR is stored here. * - * $decoded_metar is an array of arrays. Each sub-array corresponds to a group of related weather-info. We have cloud-groups, visibility-groups and so on. + * $decoded_metar is an array of arrays. Each sub-array corresponds + * to a group of related weather-info. We have cloud-groups, + * visibility-groups and so on. * * @var array */ var $decoded_metar; /** - * This constructor does nothing besides passing the input down the hierarchy. + * This constructor does nothing besides passing the input down the + * hierarchy. * * @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); } @@ -44,26 +48,28 @@ * * Given a numerical temperature $temp in Celsius, coded to tenth of * degree, store in $temp_c, convert to Fahrenheit and store in - * $temp_f + * $temp_f. * - * @param string The temperature to convert, coded to tenth of degree, like 1015 - * @param integer The temperature measured in degrees Celsius - * @param integer The temperature measured in degrees Fahrenheit + * @param string Temperature to convert, coded to tenth of + * degree, like 1015 + * @param integer Temperature measured in degrees Celsius + * @param integer Temperature measured in degrees Fahrenheit * @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); } @@ -73,11 +79,16 @@ * * $value is converted and stored based on $windunit. * - * @param float The value one seeks to convert. - * @param string The unit of $value. - * @param float &$knots After $value has been converted into knots, it will be stored in this variable. - * @param float &$meterspersec After $value has been converted into meters per second, it will be stored in this variable. - * @param float &$milesperhour After $value has been converted into miles per hour, it will be stored in this variable. + * @param float The value one seeks to convert. + * @param string The unit of $value. + * @param float &$knots After $value has been converted into knots, + * it will be stored in this variable. + * @param float &$meterspersec After $value has been converted into + * meters per second, it will be stored + * in this variable. + * @param float &$milesperhour After $value has been converted into + * miles per hour, it will be stored + * in this variable. * @access private */ function store_speed($value, $windunit, &$knots, &$meterspersec, &$milesperhour) { @@ -89,25 +100,25 @@ } 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: */ - $meterspersec = number_format($value * 0.51444, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place: */ - $milesperhour = number_format($value * 1.1507695060844667, 1); + /* 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); } 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: */ - $knots = number_format($value / 0.51444, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place: */ - $milesperhour = number_format($value / 0.51444 * 1.1507695060844667, 1); + /* 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 */ + $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.51444, 1); - /* The windspeed measured in miles per hour, rounded to one decimal place: */ - $milesperhour = number_format($knots * 1.1507695060844667, 1); + $knots = number_format($value * 1000 / 3600 / 0.5144, 1); + /* The windspeed measured in miles per hour, rounded to one decimal place */ + $milesperhour = number_format($knots * 1.1508, 1); } } @@ -115,14 +126,17 @@ /** * Decodes a raw METAR. * - * This function loops over the various parts of the raw METAR, and stores the different bits in $decoded_metar. It uses get_metar() to retrieve the METAR, so it is not necessary to connect to the database before you call this function. + * This function loops over the various parts of the raw METAR, and + * stores the different bits in $decoded_metar. It uses get_metar() to + * retrieve the METAR, so it is not necessary to connect to the database + * before you call this function. * - * @return array The decoded METAR. + * @return array The decoded METAR. * @see $decoded_metar * @access public */ function decode_metar() { - /* initialization */ + /* initialization */ $cloud_groups = 0; $weather_groups = 0; $visibility_groups = 0; @@ -140,50 +154,57 @@ $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 beeing 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]; $this->store_speed($regs[2], @@ -194,8 +215,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'], @@ -203,49 +226,66 @@ $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 in meters (4 digits only) + */ + $visibility_groups++; if ($regs[1] == '0000') { - /* Special low value */ + + /* 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; + + $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; } 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_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; } 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_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); } if (!empty($regs[2])) { $decoded_metar['visibility_group' . $visibility_groups]['dir'] = $regs[2]; } } elseif (ereg('^[0-9]$', $part)) { - /* - * Temp Visibility Group, single digit followed by space - */ + + /* + * 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 Group + */ + $visibility_groups++; if ($regs[4] == '/') { $vis_miles = $regs[2] + $regs[3]/$regs[5]; @@ -253,30 +293,48 @@ $vis_miles = $regs[1]; } if ($regs[0][0] == 'M') { - /* Prefix - less than */ - $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = -1; /* Less than */ - } - /* 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.609344, 1); - /* The visibility measured in meters: */ - $decoded_metar['visibility_group' . $visibility_groups]['meter'] = round($vis_miles * 1609.344); + + /* Prefix - less than */ + + $decoded_metar['visibility_group' . $visibility_groups]['prefix'] = -1; /* +Less than */ + + } + + /* 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. */ - $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'; + + /* 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-group */ + $runway_groups++; $decoded_metar['runway_group' . $runway_groups]['nr'] = $regs[1]; if (!empty($regs[2])) { @@ -284,45 +342,61 @@ } 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_group' . $runway_groups]['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_group' . $runway_groups]['max_tendency'] = $regs[8]; } if ($regs[3] == 'M') { - /* Less than. */ - $decoded_metar['runway_group' . $runway_groups]['min_prefix'] = -1; + + /* Less than. */ + + $decoded_metar['runway_group' . $runway_groups]['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.28084); + $decoded_metar['runway_group' . $runway_groups]['min_meter'] = $regs[4] * 1; + $decoded_metar['runway_group' . $runway_groups]['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_group' . $runway_groups]['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.28084); + $decoded_metar['runway_group' . $runway_groups]['max_meter'] = $regs[7] * 1; + $decoded_metar['runway_group' . $runway_groups]['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_group' . $runway_groups]['tendency'] = $regs[5]; } if ($regs[3] == 'M') { - /* Less than. */ - $decoded_metar['runway_group' . $runway_groups]['prefix'] = -1; + + /* Less than. */ + + $decoded_metar['runway_group' . $runway_groups]['prefix'] = -1; } elseif ($regs[3] == 'P') { - /* Greater than. */ - $decoded_metar['runway_group' . $runway_groups]['prefix'] = 1; + + /* Greater than. */ + + $decoded_metar['runway_group' . $runway_groups]['prefix'] = 1; } - $decoded_metar['runway_group' . $runway_groups]['meter'] = $regs[4] * 1; - $decoded_metar['runway_group' . $runway_groups]['ft'] = round($regs[4] * 3.28084); + $decoded_metar['runway_group' . $runway_groups]['meter'] = $regs[4] * 1; + $decoded_metar['runway_group' . $runway_groups]['ft'] = round($regs[4] * +3.2808); } } elseif (ereg('^(VC)?' . /* Proximity */ '(-|\+)?' . /* Intensity */ @@ -331,87 +405,114 @@ '(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. + */ + + $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]; + } elseif ($part == 'SKC' || $part == 'CLR') { - /* - * Cloudr-group. - * There can be up to three of these groups, so we store them as - * cloud_layer1, cloud_layer2 and cloud_layer3. - */ + + /* + * 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++; - /* Again we have to translate the code-characters to a - meaningful string. */ - $decoded_metar['cloud_group'. $cloud_groups]['condition'] = $part; + + /* Again we have to translate the code-characters to a + * meaningful string. + */ + + $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 three of these groups, so we store them as cloud_group1, - cloud_group2 and cloud_group3. */ + + /* 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]; if (!empty($regs[3])) { $decoded_metar['cloud_group'.$cloud_groups]['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['cloud_group'.$cloud_groups]['ft'] = 100; + $decoded_metar['cloud_group'.$cloud_groups]['meter'] = 30; + $decoded_metar['cloud_group'.$cloud_groups]['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['cloud_group'.$cloud_groups]['ft'] = 'nil'; + $decoded_metar['cloud_group'.$cloud_groups]['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['cloud_group'.$cloud_groups]['ft'] = $regs[2] *100; + $decoded_metar['cloud_group'.$cloud_groups]['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. - */ - $decoded_metar['temperature']['temp_c'] = round(strtr($regs[1], 'M', '-')); - $decoded_metar['temperature']['temp_f'] = round(strtr($regs[1], 'M', '-') * (9/5) + 32); + + /* + * 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.33863881578947); - $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 3.3421052631579e-4, 3, '.', ''); + + /* + * 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 - * This is strange, the specification doesnt 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.7500616827, 1, '.', ''); - $decoded_metar['altimeter']['inhg'] = number_format($regs[1] * 0.0295299875, 2); - $decoded_metar['altimeter']['atm'] = number_format($regs[1] * 9.869232667e-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. - * The temperature and dew-point measured in 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']); @@ -423,24 +524,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']); @@ -448,43 +553,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; @@ -493,40 +603,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.710701 + - 44.4293573 * $decoded_metar['temperature']['dew_c'] + - 1.41696846 * pow($decoded_metar['temperature']['dew_c'], 2) + - 0.0274759545 * pow($decoded_metar['temperature']['dew_c'], 3) + - 2.61145937E-4 * pow($decoded_metar['temperature']['dew_c'], 4) + - 2.85993708E-6 * pow($decoded_metar['temperature']['dew_c'], 5) + 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.710701 + - 44.4293573 * $decoded_metar['temperature']['temp_c'] + - 1.41696846 * pow($decoded_metar['temperature']['temp_c'], 2) + - 0.0274759545 * pow($decoded_metar['temperature']['temp_c'], 3) + - 2.61145937E-4 * pow($decoded_metar['temperature']['temp_c'], 4) + - 2.85993708E-6 * pow($decoded_metar['temperature']['temp_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