[ncl-talk] fatal:divide: Division by 0, Can't continue

Dennis Shea shea at ucar.edu
Tue Sep 10 13:23:05 MDT 2019


A preferred approach would be to use the '*where*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml>'
function.There are different ways to implement the [See Description
section). Here is a very explicit approach:

a1= 100*(dim_sum_n(X,0))-(sqrt(dim_sum_n(x,0)))
a1= *where*(a1.eq.0, a1 at _FillValue, a1)                     ; avid division
by 0.0
A1=((dim_sum_n(y,0))*(dim_sum_n(X,0)))-(dim_sum_n(x,0))*(dim_sum_n(x*y,0))/a1
...
B2B1 = B2-B1
B2B1 = *where*(B2B1.eq.0, B2B1 at _FillValue, B2B1)
chpOnset = ((A1-A2)/(B2B1))

On Tue, Sep 10, 2019 at 10:12 AM Toni Klemm via ncl-talk <ncl-talk at ucar.edu>
wrote:

> Hi Atul,
>
> Include an if-loop to only run chpOnset if B2 and B1 are not equal (thus
> no division by zero). If they are equal you could include an else portion
> and declare "chpOnset = 9.96921e+36”, making it a missing value.
>
> Toni
>
>
>
> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
> Department of Ecosystem Science and Management
> College of Agriculture and Life Sciences
> Texas A&M University, College Station, TX
> www.toni-klemm.de | @toniklemm <http://www.twitter.com/toniklemm>
> Editorial Board member, Early Career Climate Forum
> <http://www.eccforum.org>
>
>
>
>
>
>
>
>
> On Sep 10, 2019, at 12:57 AM, Atul Saini via ncl-talk <ncl-talk at ucar.edu>
> wrote:
>
> Hi NCL,
>
> While running the following code-
>
> a=addfile("Data_File.nc","r")
> x=a->tym(0:4,:,:)
> X=sqrt(x)
> y=a->rf(0:4,:,:)
> Y=sqrt(y)
> v=a->tym(5:9,:,:)
> V=sqrt(v)
> w=a->rf(5:9,:,:)
> W=sqrt(w)
>
> A1=((dim_sum_n(y,0))*(dim_sum_n(X,0)))-(dim_sum_n(x,0))*(dim_sum_n(x*y,0))/(100*(dim_sum_n(X,0))-(sqrt(dim_sum_n(x,0))))
>
>
> A2=((dim_sum_n(w,0))*(dim_sum_n(V,0)))-(dim_sum_n(v,0))*(dim_sum_n(v*w,0))/(100*(dim_sum_n(V,0))-(sqrt(dim_sum_n(v,0))))
>
> B1=
> (100*(dim_sum_n(x*y,0)))-(dim_sum_n(y,0))/(100*(dim_sum_n(X,0))-(sqrt(dim_sum_n(x,0))))
>
> B2=
> (100*(dim_sum_n(v*w,0)))-(dim_sum_n(w,0))/(100*(dim_sum_n(V,0))-(sqrt(dim_sum_n(v,0))))
>
> chpOnset = ((A1-A2)/(B2-B1))
> print(chpOnset)
>
> I am receiving the following error-
> fatal:divide: Division by 0, Can't continue
> fatal:Div: operator failed, can't continue
>
> Please help, what should be done here?
>
> Regards,
>
>
>
> <Data_File.nc>_______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=zmhRVp0i4wZ5_1Ujh0fnRXAExHgKLTQu0rZLW7PxKA4&m=i-1nT_UhpTjL9AKGdDm3lDt4Lby1v-EFWn-4jeJ703Y&s=yB0EgGvVdxmWZT-DJgktgjRkcOMSd0xAadSqj-YayB0&e=
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190910/8b2977a1/attachment.html>


More information about the ncl-talk mailing list