Thanks, Dennis. This works, but is not the more general fix that I requested.
-Dave
On Tue, Apr 17, 2012 at 2:44 PM, Dennis Shea <shea@ucar.edu> wrote:
>
>
> The original thread
>
> z = x/y
>
> To prevent divsion by 0
>
> x = x/where(y.eq.0, y@_FillValue, y)
>
>
> On 4/17/12 2:33 PM, David Brown wrote:
>>
>> Hi Dave,
>>
>> I see the behavior you describe for arrays. However, contrary to (1)
>> below, I see the same behavior for scalars:
>>
>> ncl 9> z1 = -999.0
>> ncl 10> z1@_FillValue = -999.0
>> ncl 11> print(z1 / 0)
>> fatal:divide: Division by 0, Can't continue
>> fatal:Div: operator failed, can't continue
>> fatal:["Execute.c":7514]:Execute: Error occurred at or near line 11
>>
>> ncl 12> z1 = (z1 / 0)
>> fatal:divide: Division by 0, Can't continue
>> fatal:Div: operator failed, can't continue
>> fatal:["Execute.c":7514]:Execute: Error occurred at or near line 12
>>
>> ncl 13> print(z1)
>>
>> Variable: z1
>> Type: float
>> Total Size: 4 bytes
>> 1 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [1]
>> Coordinates:
>> Number Of Attributes: 1
>> _FillValue : -999
>> (0) -999
>>
>> Of course, since the "operator failed" the value remains the same as
>> before. That is true whether the value is scalar or an array. In the case of
>> an array, it seems that all values remain the same as before the operation,
>> even those that could be operated on without error.
>>
>> If you have a counter-example of scalar division of a missing value by 0
>> working as in (1), please let us know.
>>
>> This is not to say that your proposed behavior does not have a lot of
>> merit. We will consider making this change, considering that the docs say
>> _FillValues should always propagate.
>> -dave
>>
>>
>> On Apr 15, 2012, at 6:14 PM, Dave Allured wrote:
>>
>>> NCL support team,
>>>
>>> There seems to be inconsistent behavior when the numerator is a
>>> missing value in simple division. In the scalar case:
>>>
>>> (1) missing value / 0 gives missing value
>>>
>>> In the array case:
>>>
>>> (2) missing value / 0 gives a fatal error
>>>
>>> My interpretation of the current NCL manual is that (1) is the correct
>>> behavior, and (2) is wrong. Also, (1) is best behavior for clean user
>>> programming. I request that NCL be changed to correctly handle the
>>> array case. Either way, would you please explicitly document the
>>> expected behavior for (missing divided by zero) in the NCL manual?
>>>
>>> There is a general workaround for user programs, by setting zeros in
>>> the denominator array to missing values. This is less desirable in
>>> user cases when missing value information is already contained in the
>>> numerator array.
>>>
>>> I found this behavior consistently through several versions of NCL
>>> 5.2.0 through NCL 6.0.0 on Linux and Mac.
>>>
>>> Following is a short test case which ends in a fatal error. Thank you
>>> for your consideration.
>>>
>>> begin
>>> a = new (3, float)
>>> a(0) = 3.3
>>> a(2) = 5.5
>>> print ("A missing = " + ismissing (a))
>>> print (a)
>>>
>>> ; Note, a(1) should be a missing value.
>>>
>>> b = (/ 4, 0, 4 /)
>>> print (b)
>>>
>>> c = a / b
>>> print (c)
>>> end
>>>
>>> --Dave
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 17 18:00:45 2012
This archive was generated by hypermail 2.1.8 : Fri Apr 20 2012 - 16:21:18 MDT