<div dir="ltr"><div class="gmail_default" style="font-size:small">The logical missing value is one of those things that causes many of us grief.  In some cases I wish we&#39;d never implemented the concept of a _FillValue for a logical type, but I understand why it was done.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The issue becomes, then, how to best interpret logicals and missing values in conditional expressions.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">What you are seeing is simply the result of &quot;lazy evaluation&quot;.  Please see this note in our V5.2.0 release, where we described an important change that was made with regard to this behavior:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style=""><a href="http://www.ncl.ucar.edu/prev_releases.shtml#LazyEvaluationUpdate5.2.0">http://www.ncl.ucar.edu/prev_releases.shtml#LazyEvaluationUpdate5.2.0</a><br><a href="http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#LazyEvaluation">http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#LazyEvaluation</a><br></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">When you have  a &quot;.and.&quot; type of evaluation, and the first part of it evaluates to either &quot;False&quot;, then it doesn&#39;t bother evaluating the rest of your expression. So, if it encounters a False first, then False will be returned. However, in every case, if there&#39;s a missing somewhere in the expression, it&#39;s going to return missing.</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Here are some samples:</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><div class="gmail_default"><font face="monospace, monospace">ncl 0&gt; msg = new(1,logical)   ; create a variable that is missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 1&gt; print(&quot;msg = &quot; + msg)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     msg = Missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 2&gt; print(False.and.msg)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     False</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 3&gt; print(msg.and.False)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     Missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 4&gt; print(True.and.msg)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     Missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 5&gt; print(msg.and.True)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     Missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 6&gt; print(msg.and.msg)</font></div><div class="gmail_default"><font face="monospace, monospace">(0)     Missing</font></div><div class="gmail_default"><font face="monospace, monospace">ncl 7&gt; </font><br></div></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">In order to correctly evaluate expressions that may contain missing values, you should use the &quot;ismissing&quot; function. This way you are always comparing pure Trues and Falses, rather than missing values.</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Depending on how you want the expression to evaluate when missing values are encountered, you would use something like:</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><span style="font-size:12.8px">   a = where((.not.ismissing(x).and.x.lt.2.) .and. (.not.ismissing(y).and.y.lt.2.), a@_FillValue, a)</span><br style="font-size:12.8px"></div><div class="gmail_default" style=""><span style="font-size:12.8px"><br></span></div><div class="gmail_default" style=""><span style="font-size:12.8px">The above is just an example. You need to figure out the proper way to using the &quot;ismissing&quot; logic for your own situation.</span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><br></span></div><div class="gmail_default" style=""><span style="font-size:12.8px">--Mary</span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 1, 2015 at 5:54 PM, Qi Tang <span dir="ltr">&lt;<a href="mailto:tang30@llnl.gov" target="_blank">tang30@llnl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
It seems that in the condtnl_expr, the value of missing .and. false give<br>
the value of the first term:<br>
<br>
missing .and. false -&gt; missing<br>
false .and. missing -&gt; false<br>
<br>
Is this a bug? The results to both expressions above should be missing.<br>
Otherwise, it makes it really easy to make mistakes when using the where<br>
function when there can be missing in the condtnl_expr.<br>
<br>
A short example below demonstrates this problem. I am using v6.2.1 on<br>
Redhat 6.7.<br>
<br>
Qi<br>
<br>
==========<br>
   x = new(5,float,-99.)<br>
   y = new(5,float,-99.)<br>
   x(0) = 1.<br>
   x(2) = 3.<br>
   x(4) = 4.<br>
   y(0) = 1.<br>
   y(1) = 3.2<br>
   print(x)<br>
   print(y)<br>
<br>
   a = x<br>
   b = y<br>
   c = y<br>
<br>
   a = where(x.lt.2. .and. y.lt.2., a@_FillValue, a)<br>
   b = where(x.lt.2. .and. y.lt.2., b@_FillValue, b)<br>
   c = where(y.lt.2. .and. x.lt.2., c@_FillValue, c)<br>
   print(a)<br>
   print(b)<br>
   print(c)<br>
========<br>
<br>
The arrays a, b, c should be identical, but they are not. The output is:<br>
<br>
Variable: x<br>
Type: float<br>
Total Size: 20 bytes<br>
             5 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:    [5]<br>
Coordinates:<br>
Number Of Attributes: 1<br>
   _FillValue :    -99<br>
(0)     1<br>
(1)    -99<br>
(2)     3<br>
(3)    -99<br>
(4)     4<br>
<br>
Variable: y<br>
Type: float<br>
Total Size: 20 bytes<br>
             5 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:    [5]<br>
Coordinates:<br>
Number Of Attributes: 1<br>
   _FillValue :    -99<br>
(0)     1<br>
(1)    3.2<br>
(2)    -99<br>
(3)    -99<br>
(4)    -99<br>
<br>
Variable: a<br>
Type: float<br>
Total Size: 20 bytes<br>
             5 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:    [5]<br>
Coordinates:<br>
Number Of Attributes: 1<br>
   _FillValue :    -99<br>
(0)    -99<br>
(1)    -99<br>
(2)     3<br>
(3)    -99<br>
(4)     4<br>
<br>
Variable: b<br>
Type: float<br>
Total Size: 20 bytes<br>
             5 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:    [5]<br>
Coordinates:<br>
Number Of Attributes: 1<br>
   _FillValue :    -99<br>
(0)    -99<br>
(1)    -99<br>
(2)    -99<br>
(3)    -99<br>
(4)    -99<br>
<br>
Variable: c<br>
Type: float<br>
Total Size: 20 bytes<br>
             5 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:    [5]<br>
Coordinates:<br>
Number Of Attributes: 1<br>
   _FillValue :    -99<br>
(0)    -99<br>
(1)    3.2<br>
(2)    -99<br>
(3)    -99<br>
(4)    -99<br>
<br>
<br>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div><br></div>