CVS: phpweather phpweather.php,1.21,1.22
Brought to you by:
iridium
|
From: Martin G. <gim...@us...> - 2002-03-29 13:51:58
|
Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv13943
Modified Files:
phpweather.php
Log Message:
Cleanups. I'm was looking through the code to document the
$decoded_metar array and found a lot of cruft.
Index: phpweather.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- phpweather.php 27 Mar 2002 20:16:00 -0000 1.21
+++ phpweather.php 29 Mar 2002 13:51:55 -0000 1.22
@@ -161,17 +161,9 @@
*/
function decode_metar() {
/* 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();
@@ -197,11 +189,12 @@
* Type of Report: SPECI
*/
$decoded_metar['type'] = 'SPECI';
- } elseif (ereg('^[A-Z]{4}$', $part) && ! isset($decoded_metar['station'])) {
+ } elseif (ereg('^[A-Z]{4}$', $part) &&
+ empty($decoded_metar['icao'])) {
/*
* Station Identifier
*/
- $decoded_metar['station'] = $part;
+ $decoded_metar['icao'] = $part;
} elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) {
/*
* Date and Time of Report.
@@ -224,7 +217,7 @@
} else {
$month = gmdate('n');
}
- $decoded_metar['time'] = gmmktime($regs[2]+$this->properties['offset'], $regs[3], 0, $month, $regs[1], gmdate('Y'));
+ $decoded_metar['time'] = gmmktime($regs[2] + $this->properties['offset'], $regs[3], 0, $month, $regs[1], gmdate('Y'));
} elseif (ereg('(AUTO|COR|RTD|CC[A-Z]|RR[A-Z])', $part, $regs)) {
/*
@@ -262,190 +255,150 @@
/*
* Variable wind-direction
*/
-
- $decoded_metar['wind']['var_beg'] = $regs[1];
+ $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)
*/
-
- if ($regs[1] == '0000') {
-
+ unset($group);
+
+ if ($regs[1] == '0000') {
/* 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;
+ $group['prefix'] = -1; /* Less than */
+ $group['meter'] = 50;
+ $group['km'] = 0.05;
+ $group['ft'] = 164;
+ $group['miles'] = 0.031;
} elseif ($regs[1] == '9999') {
-
/* 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;
+ $group['prefix'] = 1;
+ $group['meter'] = 10000;
+ $group['km'] = 10;
+ $group['ft'] = 32800;
+ $group['miles'] = 6.2;
} else {
-
/* 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);
+ $group['prefix'] = 0;
+ $group['km'] = number_format($regs[1]/1000, 1);
+ $group['miles'] = number_format($regs[1]/1609.344, 1);
+ $group['meter'] = $regs[1] * 1;
+ $group['ft'] = round($regs[1] * 3.28084);
}
if (!empty($regs[2])) {
- $decoded_metar['visibility'][$visibility_group_nr]['dir'] = $regs[2];
+ $group['dir'] = $regs[2];
}
-
- /* We increment $visibility_group_nr so that it's ready for
- the next group. */
- $visibility_group_nr++;
+ $decoded_metar['visibility'][] = $group;
} 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)) {
-
+ $temp_visibility_miles = $part;
+ } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$',
+ $temp_visibility_miles . ' ' . $part, $regs)) {
/*
* Visibility Group
*/
-
+ unset($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'][$visibility_group_nr]['prefix'] = -1; /* Less than */
-
+ $group['prefix'] = -1;
+ } else {
+ $group['prefix'] = 0;
}
/* The visibility measured in miles */
-
- $decoded_metar['visibility'][$visibility_group_nr]['miles'] = number_format($vis_miles, 1);
+ $group['miles'] = number_format($vis_miles, 1);
/* The visibility measured in feet */
-
- $decoded_metar['visibility'][$visibility_group_nr]['ft'] = round($vis_miles * 5280, 1);
+ $group['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);
+ $group['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++;
+ $group['meter'] = round($vis_miles * 1609.3);
+ $decoded_metar['visibility'][] = $group;
} elseif ($part == 'CAVOK') {
-
- /* CAVOK: Used when the visibility is greater than 10
+ /* CAVOK is 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.
+ * 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';
+ unset($group);
+ $group['prefix'] = 1;
+ $group['km'] = 10;
+ $group['meter'] = 10000;
+ $group['miles'] = 6.2;
+ $group['ft'] = 32800;
+ $decoded_metar['visibility'][] = $group;
+ $decoded_metar['clouds'][]['condition'] = 'CAVOK';
- /* We increment $visibility_group_nr so that it's ready for
- the next group. */
- $visibility_group_nr++;
-
- } elseif (ereg('^R([0-9]{2})([RLC]?)/([MP]?)([0-9]{4})([DNU]?)V?(P?)([0-9]{4})?([DNU]?)$', $part, $regs)) {
-
+ } elseif (ereg('^R([0-9]{2})([RLC]?)/([MP]?)([0-9]{4})' .
+ '([DNU]?)V?(P?)([0-9]{4})?([DNU]?)$', $part, $regs)) {
/* Runway-group */
-
- $decoded_metar['runway'][$runway_group_nr]['nr'] = $regs[1];
+ unset($group);
+ $group['nr'] = $regs[1];
if (!empty($regs[2])) {
- $decoded_metar['runway'][$runway_group_nr]['approach'] = $regs[2];
+ $group['approach'] = $regs[2];
}
if (!empty($regs[7])) {
-
/* We have both min and max visibility since $regs[7] holds
- * the max visibility.
+ * the max visibility.
*/
-
if (!empty($regs[5])) {
/* $regs[5] is tendency for min visibility. */
- $decoded_metar['runway'][$runway_group_nr]['min_tendency'] = $regs[5];
+ $group['min_tendency'] = $regs[5];
}
if (!empty($regs[8])) {
/* $regs[8] is tendency for max visibility. */
- $decoded_metar['runway'][$runway_group_nr]['max_tendency'] = $regs[8];
+ $group['max_tendency'] = $regs[8];
}
if ($regs[3] == 'M') {
-
/* Less than. */
-
- $decoded_metar['runway'][$runway_group_nr]['min_prefix'] = -1;
+ $group['min_prefix'] = -1;
}
- $decoded_metar['runway'][$runway_group_nr]['min_meter'] = $regs[4] * 1;
- $decoded_metar['runway'][$runway_group_nr]['min_ft'] = round($regs[4] * 3.2808);
+ $group['min_meter'] = $regs[4] * 1;
+ $group['min_ft'] = round($regs[4] * 3.2808);
if ($regs[6] == 'P') {
-
/* Greater than. */
-
- $decoded_metar['runway'][$runway_group_nr]['max_prefix'] = 1;
+ $group['max_prefix'] = 1;
}
- $decoded_metar['runway'][$runway_group_nr]['max_meter'] = $regs[7] * 1;
- $decoded_metar['runway'][$runway_group_nr]['max_ft'] = round($regs[7] * 3.2808);
+ $group['max_meter'] = $regs[7] * 1;
+ $group['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'][$runway_group_nr]['tendency'] = $regs[5];
+ $group['tendency'] = $regs[5];
}
if ($regs[3] == 'M') {
-
/* Less than. */
-
- $decoded_metar['runway'][$runway_group_nr]['prefix'] = -1;
+ $group['prefix'] = -1;
} elseif ($regs[3] == 'P') {
-
/* Greater than. */
-
- $decoded_metar['runway'][$runway_group_nr]['prefix'] = 1;
+ $group['prefix'] = 1;
}
- $decoded_metar['runway'][$runway_group_nr]['meter'] = $regs[4] * 1;
- $decoded_metar['runway'][$runway_group_nr]['ft'] = round($regs[4] * 3.2808);
+ $group['meter'] = $regs[4] * 1;
+ $group['ft'] = round($regs[4] * 3.2808);
}
-
- /* We increment $runway_group_nr so that it's ready for the
- next group. */
- $runway_group_nr++;
-
+ $decoded_metar['runway'][] = $group;
+
} elseif (ereg('^(VC)?' . /* Proximity */
'(-|\+)?' . /* Intensity */
'(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
@@ -453,99 +406,67 @@
'(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */
'(PO|SQ|FC|SS)?$', /* Other */
$part, $regs)) {
-
/*
* 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++;
+ $decoded_metar['weather'][] =
+ array('proximity' => $regs[1],
+ 'intensity' => $regs[2],
+ 'descriptor' => $regs[3],
+ 'precipitation' => $regs[4],
+ 'obscuration' => $regs[6],
+ 'other' => $regs[7]);
} elseif ($part == 'SKC' || $part == 'CLR') {
-
/* Cloud-group */
+ $decoded_metar['clouds'][]['condition'] = $part;
-
-
- /* 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++;
-
- } elseif (ereg('^(VV|FEW|SCT|BKN|OVC)([0-9]{3}|///)(CB|TCU)?$', $part, $regs)) {
-
+ } elseif (ereg('^(VV|FEW|SCT|BKN|OVC)([0-9]{3}|///)' .
+ '(CB|TCU)?$', $part, $regs)) {
/* We have found (another) a cloud-layer-group. */
-
- $decoded_metar['clouds'][$cloud_group_nr]['condition'] = $regs[1];
+ unset($group);
+
+ $group['condition'] = $regs[1];
if (!empty($regs[3])) {
- $decoded_metar['clouds'][$cloud_group_nr]['cumulus'] = $regs[3];
+ $group['cumulus'] = $regs[3];
}
if ($regs[2] == '000') {
-
/* '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 */
+ $group['ft'] = 100;
+ $group['meter'] = 30;
+ $group['prefix'] = -1; /* Less than */
} elseif ($regs[2] == '///') {
-
/* '///' means height nil */
-
- $decoded_metar['clouds'][$cloud_group_nr]['ft'] = 'nil';
- $decoded_metar['clouds'][$cloud_group_nr]['meter'] = 'nil';
+ $group['ft'] = 'nil';
+ $group['meter'] = 'nil';
} else {
- $decoded_metar['clouds'][$cloud_group_nr]['ft'] = $regs[2] *100;
- $decoded_metar['clouds'][$cloud_group_nr]['meter'] = round($regs[2] * 30.48);
+ $group['ft'] = $regs[2] *100;
+ $group['meter'] = round($regs[2] * 30.48);
}
-
- /* We increment $cloud_group_nr so that it's ready for the
- next group. */
- $cloud_group_nr++;
+ $decoded_metar['clouds'][] = $group;
} 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);
$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
@@ -553,11 +474,9 @@
*/
/* 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, '.', '');
@@ -566,7 +485,6 @@
/*
* 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']);
@@ -582,7 +500,6 @@
/*
* 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']);
@@ -648,7 +565,6 @@
/*
* Snow depth in inches
*/
-
if ($regs[1] == '0000') {
$decoded_metar['precipitation']['snow_in'] = -1;
$decoded_metar['precipitation']['snow_mm'] = -1;
@@ -662,7 +578,6 @@
* If we couldn't match the group, we assume that it was a
* remark.
*/
-
$decoded_metar['remarks'] .= ' ' . $part;
}
}
@@ -670,7 +585,6 @@
/*
* Relative humidity
*/
-
if (!empty($decoded_metar['temperature']['temp_c']) &&
!empty($decoded_metar['temperature']['dew_c'])) {
@@ -703,7 +617,7 @@
}
/* Finally we store our decoded METAR in $this->decoded_metar so
- * that other methods can use it.
+ * that other methods can use it.
*/
$this->decoded_metar = $decoded_metar;
|