Closed trrisner closed 9 years ago
Thank you for the feedback, I'll have a look at this example to see what can be done.
No problem. I appear to be having the same issue with Wind Direction. It's like the "null" variable isn't getting passed through to the final output. If the ??ChunkDecoder.php defines the variable as null, it throws the error from above.
After a quick analysis it appears that what you're describing is the normal behaviour. If any information in the original METAR is missing, there is nothing we can do but put a null value for the corresponding object field. That's because we want to keep track of the fact that no information was present, which we'll not be able to do with a default value.
What you could do in your case is avoid using any value of the decoded METAR without checking if the corresponding Value object is null. You could do it like this:
use MetarDecoder\Entity\Value;
use MetarDecoder\MetarDecoder;
//decode your metar
$decoder = new MetarDecoder();
$d = $decoder->parse('cwob 171747Z auto 05005kt 01/ A3007')
// check that the value is not null
$dew_point = $d->getDewPointTemperature();
if($dew_point == null){
$dew_point = new Value(999, Value::DEGREE_CELSIUS)
}
// you can now use your $dew_point object safely
$dew_point->getValue();
$dew_point->getUnit();
This concept is not detailed in the documentation, I apologize for that. I should consider making it explicit in the README.
That makes sense, and is close to the fix I found. What would you suggest for a wind that looks like this:
CYZP 201145Z AUTO /////KT 9SM OVC024 16/13 A2987 RMK SLP116 DENSITY ALT 100FT
Please forgive my ignorance. This is the first time I've really dealt with objects to this degree.
In your sample METAR, the automatic observing system (AUTO) was unable to measure the surface wind direction (///) and speed (//). In such case I would suggest that the decoder accepts this METAR and reply NULL for both wind direction and speed. But this only in the non-strict version of the decoder as these ///// are not allowed by ICAO annex 3 for surface wind information.
My ignorance of objects has proven to be the culprit. I was using $dewpoint=$d->getDewPointTemperature()->getValue() == null in my if/then when I should have been using $dewpoint=$d->getDewPointTemperature() == null since getValue() doesn't exist if getDewPointTemerature() ==null
The decoder handles the winds correctly as well, in this case.
Thanks for all the help!
@trrisner you got it about the "null" issue Nevertheless it seems that the parser does not behaves exactlty as Jalan mentionned. The problem is that the ///// section is not recognized at all which causes the rest of the parsing to fail. see http://php-metar-decoder.inouire.net/index.php?metar=CYZP+201145Z+AUTO+%2F%2F%2F%2F%2FKT+9SM+OVC024+16%2F13+A2987+RMK+SLP116+DENSITY+ALT+100FT
I'll close this issue and open another one dedicated to the sruface wind parsing
If any observation is missing Dewpt or temp like this: "cwob 171747Z auto 05005kt 01/ A3007" I get a "PHP Fatal Error: call to member function getValue() on a non-object in..." Error.
Solution I found was to edit the ../arc/ChunckDecoder/TemperatureChunckDecoder.php script and take out any $found==null if/thens or anything that set dewpoint to null. Then, once you run the metar through the decoder in your php script you can set the missing value to whatever you want since it is null by default at the point. In my case, i used the following code in my php script. ... $dewpoint=$d->getDewPointTemperature()->getValue(); If($dewpoint==NULL){$dewpoint = 999;} ...