Re: Division by zero?

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Mon Feb 18 2013 - 17:32:59 MST

Ed,

The NCL where function does not work the same way as the Fortran where
function. NCL evaluates all three input arguments of the function
independently at all array points, then combines the results. So you
are getting a divide by zero while executing the second argument,
x1/x2, before the "where" function really gets started.

Dennis's code changes all zeros in the denominator to missing values.
This prevents any divide by zeros. This is discussed in the function
documentation, under "Caveat".

--Dave

On Mon, Feb 18, 2013 at 4:42 PM, Yang Yang <yang123yang@yahoo.com> wrote:
> Hi Dennis:
>
> Thanks very much for your help!
> Your suggestion works.
> But what is wrong with ssnow = where(x2.gt.0.01, x1/x2, -999.)? Thanks!
>
> Regards
> Ed
>
>
> ----- Original Message -----
> From: Dennis Shea <shea@ucar.edu>
> To: Yang Yang <yang123yang@yahoo.com>
> Cc: "ncl-talk@ucar.edu" <ncl-talk@ucar.edu>
> Sent: Tuesday, February 19, 2013 11:43 AM
> Subject: Re: Division by zero?
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml
>
> As noted, the 'true_value' and 'false_value' expression get executed.
>
> x1 = sim->snow_liq_gb(:,0,0)
> x2 = sim->snow_mass_gb(:,0,0)
> x2 = where(x2.gt.0.01, x2, x2@_FillValue)
> ssnow = where(x2.gt.0.01, x1/x2, x2@_FillValue)
>
>
>
> On 2/18/13 3:00 PM, Yang Yang wrote:
>> Dear All:
>>
>> I have a NCL script contains the following:
>>
>> sim = addfile("Mt_Cook.day_38102.nc","r")
>> x1 = sim->snow_liq_gb(:,0,0)
>> x2 = sim->snow_mass_gb(:,0,0)
>> ssnow = where(x2.gt.0.01, x1/x2, -999.)
>>
>> When I ran it, I had the following errors:
>> fatal:divide: Division by 0, Can't continue
>> fatal:Div: operator failed, can't continue
>> fatal:Execute: Error occurred at or near line 19 in file snow_sim_mass_1_ratio.ncl
>>
>> Line 19 is: ssnow = where(x2.gt.0.01, x1/x2, -999.)
>>
>> I cannot figure out why "where" cannnot work here? Any help is appreciated. Thanks!
>>
>> Ed
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Feb 18 17:33:10 2013

This archive was generated by hypermail 2.1.8 : Thu Feb 21 2013 - 11:26:43 MST