[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Latest Decoders package 3.0.7+ (fwd)




===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
address@hidden             WWW: http://www.unidata.ucar.edu/
===============================================================================

---------- Forwarded message ----------
Date: Fri, 4 Feb 2005 15:07:10 -0600
From: Richard Carpenter <address@hidden>
To: Chris Peters <address@hidden>, Robb Kambic <address@hidden>
     address@hidden,
     decoders <address@hidden>
Subject: RE: Latest Decoders package 3.0.7+

The treatment of "00" as true is a feature of Perl. From Programming Perl 
section 1.6.1:


1.      Any string is true except for "" and "0".

2.      Any number is true except for 0.

3.      Any reference is true.

4.      Any undefined value is false.


If a value can reasonably be zero (as with dew point), it should be tested 
using defined, as David suggested.

Richard Carpenter

________________________________

From: address@hidden on behalf of Chris Peters
Sent: Fri 2/4/2005 1:26 PM
To: Robb Kambic
Subject: Re: Latest Decoders package 3.0.7+




Actually this is not as much of a bug as it might first appear, due to perhaps a
quirk of perl.

David when I first read your email, your theory looked correct and it made me
run to check the code (we have ldm running here at TWC and use the metar
decoder.)  However, I was unable to confirm the bug with a suite of tests I
wrote.  The tests take some canned metar examples and run them through the
decoder, checking for known values. A metar rep with 14/00 in the T/Td group
correctly decoded the dewpoint as 0.

It turns out that perl doesn't consider the string "00" to be false.  You can
confirm this by running the following perl code on your system:

#!/usr/bin/perl -w
use strict;

print "OK - 1" if ("00");
print "OK - 2" if ("0");
print "OK - 3" if (0);
print "OK - 4" if (00);


It will only print out the first line (OK -1).   For some reason, probably
involving perl's type system and the way it converts strings to numbers, the
string "00" does NOT evaluate to false.  Fortunately, 99% of the time I believe
a metar reports a dewpoint/temp of zero as "00" or "M00".  So due to
coincidence, this bug probably never reared its' head.

You might argue that to be safe, one should go ahead and use the defined test
anyways, as to not do so is to rely on a coincidence that might change in a
future version of perl.

Chris
=======================================================
Christopher Peters
Senior Wx Systems Developer - The Weather Channel
address@hidden
Phone:  770-226-2039




                      Robb Kambic
                      r.edu>                      cc:       address@hidden, 
decoders
                      Sent by:                     <address@hidden>
                      owner-decoders@unida        Subject:  Re: Latest Decoders 
package 3.0.7+
                      ta.ucar.edu


                      02/04/2005 01:59 PM






On Fri, 4 Feb 2005, David Larson wrote:

> Robb,
>
> There seems to be a problem with the dewpoint processing in the decoders
> package (since the dawn of time, perhaps) ... The metar2nc script leaves
> the TD variable as undefined, and therefore it is processed as "missing"
> when the dewpoint is "00".
>
>         # get temperature and dew point
>         if( s#^(M)?(\d{2})/(M)?(\d{2})?\s+## ) {
>             $T = $2 ;
>             $T *= -1 if( $1 ) ;
>             $TD = $4 if( $4 ) ;
>             $TD *= -1 if( $3 ) ;
>         }
David,

you are correct, TD of value 0 fails to get set with the current code.
your fix seems reasonable, i'll fix it and make another release.

thanks,
robb...


>
> The solution is to change the code to use if( defined($4) ) because
> otherwise a zero value is not considered true and therefore the
> assignment to TD does not occur.
>
> Let me know if you have a better way to handle this.
> Dave
>

===============================================================================
Robb Kambic                                               Unidata Program Center
Software Engineer III                                     Univ. Corp for
Atmospheric Research
address@hidden                            WWW:
http://www.unidata.ucar.edu/
===============================================================================