Re: metar decoding
| From: | Steve M | Date: | Sun, 11 May 2003 09:17:43 +0000 |
| Subject: | Re: metar decoding | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147225@lists.php.net to get a copy of this message | ||
That's in the right general direction, but it's not quite that simple as the
length of the line and the number of elements varies. In the example Bryan
gave:
KSFF 091753Z 06008G18KT 10SM SCT090 SCT200 16/01 A3000 RMK AO2 SLP158
There are two layers of scattered cloud at 9000ft and 20,000ft, but there
could easily be five layers, or three or none. Regex would be the best way
to go, but that gives me a headache too, so I'd personally use a simpler
method, perhaps matching against arrays containing the abbreviations for
various sections of the code - eg, $cloud[..] might contain 'SKC', 'FEW',
'SCT', 'BKN', or 'OVC'. To give you an idea of the problem, here are
some
other samples to play with...
EGJA 110610Z 110716 13006KT 9999 FEW006 BKN020 TEMPO 0716 5000 RA BKN010
PROB30 TEMPO 0715 1500 RADZ BKN002
LFOC 110800Z 110918 VRB03KT CAVOK BECMG 0911 24008KT SCT025 PROB30 TEMPO
1518 9000 -SHRA
LFOF 110800Z 110918 22008KT 9999 FEW020 BKN043 BKN100
LFOT 110500Z 111206 22005KT 9999 SCT030 BKN120 TEMPO1215 -SHRA BECMG 1821
28006KT 9999 BKN043 BKN50 BECMG 2124 28006KT CAVOK BECMG 0306 28005KT 6000
NSC
Actually, now that I look at those lines that I so quickly cut'n'pasted, I
realise they're TAFs, not METARs, but same goes. In fact, one routine could
easily decode both times, recognising the difference mainly from the format
of the time/validity code groups.
It would be best to explode the whole thing into one array so that it could
be run through a foreach for the pattern matching.
There is a slight difference in format between the US METAR Bryan quoted and
those used in Europe and most of the rest of the world. With European
METARs, the first date/time group is included on the same line as the rest
of the METAR and in the same format, eg:
110800 LFOF 110800Z VRB02KT CAVOK 11/09 Q1021
But the UK puts this date/time group AFTER the station identifier! (Glad I'm
not trying this...)
I know Bryan has already found a solution, but sometimes it's fun to chew
these things over...
> list($date, $weather, $junk) = explode("\n", $data);
> list($date, $time) = explode(" ", $date);
> echo "Date: $date Time: $time<BR>\n";
> //I am reasonably certain some of my variable names are
> //inappropriate :-)
> list($code, $timestamp, $zone, $sm, $sct1, $sct2, $fraction, $hardware,
> $remark, $camping, $slipknots) = explode(" ", $weather);
> $day = substr($timestamp, 0, 2);
> $time = substr($timestamp, 2, 4);
> $sctpart1 = substr($sct1, 0, 3);
> $sctpart2 = substr($sct1, 3, 3);
> echo "Date: $day Time: $time SCT1 $sctpart1 $sctpart2<BR>\n";
>
> I'll leave the rest as an exercise :-)