[ncl-talk] Division problem

Dennis Shea shea at ucar.edu
Fri Jan 25 11:50:48 MST 2019


Toni's answer is correct.

You could also searh the NCAR archives for (say) "division by zero"
===
See the "caveat" section of the following:

*http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml>

 y = ispan (-5,5,1)*1.0
 y at _FillValue = -999.0
 print(y)
 z = 1.0/*where*(y.ne.0, y, y at _FillValue)     ; or, equivalently:
*where*(y.eq.0.0,
y at _FillValue, y)
 print(y+"   "+z)

===
(0)     -5   -0.2
(1)     -4   -0.25
(2)     -3   -0.333333
(3)     -2   -0.5
(4)     -1   -1
*(5)     0   -999*
(6)     1   1
(7)     2   0.5
(8)     3   0.333333
(9)     4   0.25
(10)    5   0.2

On Fri, Jan 25, 2019 at 6:47 AM Toni Klemm <toni-klemm at tamu.edu> wrote:

> Hi Jalal,
>
> Are you dividing the average January rainfall by the rainfall of a single
> year to see how it compares? That’s how I understand your code.
>
> Then the problem might be that your individual year has zero rainfall in
> January, thus division by zero. I had a similar problem. Try to check if
> your data (jannontc) is zero, and replace zeros with missing values. That
> way NCL won’t divide. You might get a warning message but it should be
> okay.
>
> For example:
> if (jannontc .eq. 0) then
>   jannontc = prc at _FillValue
> end if
>
> I hope that helps.
>
> Best,
> 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
> Contributor to the Early Career Climate Forum <https://www.eccforum.org/>
> www.toni-klemm.de | @toniklemm <https://twitter.com/ToniKlemm>
>
>
> On Jan 25, 2019, at 7:13 AM, Md. Jalal Uddin <dmjalal90 at gmail.com> wrote:
>
> Hi all,
>
> I can minus and multiply but cannot divide. NCL says, "divide by 0 cannot
> continue". Any suggestions?
>
> ;January
>  f  = addfile("all_jan.nc
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__all-5Fjan.nc&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=2oVRg1Gv-7_n71W5tmt0snEIqLy6wzfrkfrTQ0nH_Vk&s=S9iFutzrm_V25uuLNsGJYLacYQwyt9Ht_JJjd2FoH6I&e=>",
> "r")
>  prc =f->pre(:,{65:110},{0:30})
>  prc_reorder = prc(time|:,latitude|:,longitude|:)
>
> ; January TCs average rainfall
>  ntim = (/12,13,14,15,16,34,35,36,37/)
>  tcjan = prc_reorder(ntim,:,:)
>  tcavgjan = dim_avg_n_Wrap(tcjan,0)
>
> ; January contribution
> totjan = dim_sum_n_Wrap(prc_reorder,0)
> jantc = dim_sum_n_Wrap(tcjan,0)
> jannontc = totjan - jantc
> copy_VarMeta(totjan,jannontc)
>
> jancont = jantc / jannontc    ; problem from there
> copy_VarMeta(jantc,jancont)
>
> --
> *Md. Jalal Uddin*
> MSc in Applied Meteorology (English Language)
> Nanjing University of Information, Science and Technology, China
> B.Sc. in Disaster Management (Hons.)
> Patuakhali Science and Technology University, Bangladesh.
> Cell: +8613260859092, +8801792052662
> Web: www.dmjalal90.weebly.com
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.dmjalal90.weebly.com&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=2oVRg1Gv-7_n71W5tmt0snEIqLy6wzfrkfrTQ0nH_Vk&s=ylrSG_BqgtyXgC0wxp3ioTsRRaPUCvFlmg6emXFy0Jc&e=>
>
> Facebook: jalal.hossen.39
> LinkedIn: https://bd.linkedin.com/in/md-jalal-uddin-80a026b0
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__bd.linkedin.com_in_md-2Djalal-2Duddin-2D80a026b0&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=2oVRg1Gv-7_n71W5tmt0snEIqLy6wzfrkfrTQ0nH_Vk&s=WHwXZpXz_jluQmtoJ5LM5P98Y1sDiO55z36KZmVcxlE&e=>
>
> Twitter: dmjalal90
> Skype: dmjalal90
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> 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/20190125/56a092c8/attachment.html>


More information about the ncl-talk mailing list