[ncl-talk] Taking ratio of precipitation dataset
Rick Brownrigg
brownrig at ucar.edu
Tue Jan 5 16:20:55 MST 2016
Offhand, it seems like you want to use the where() function, rather than an
if/else coupled with any():
http://ncl.ucar.edu/Document/Functions/Built-in/where.shtml
Something like (untested):
output = where((any(b(:,:,:).eq.0)) .or. (any(d(:,:,:).eq.0)), d-b, d/b)
On Tue, Jan 5, 2016 at 4:10 PM, amit timilsina <
timilsinaamit87 at huskers.unl.edu> wrote:
> Respected all,
>
> I would like to take ratio and differences of variable precipitation(pr)
> in such way that if both the values for particular day is positive or
> greater than zero, I want to take ratio. If one of the values, either
> denominator or numerator, is zero, then I would like to take differences.
> Here is my code:
> ncl 0>
> a=addfile("pr_day_MRI-CGCM3_decadal2005_r1i1p1_20060101-20351231.nc","r")
> ncl 1> b=a->pr
> ncl 2> c=addfile("pr_day_MRI-CGCM3_rcp45_r1i1p1_20060101-20351231.nc","r")
> ncl 3> d=a->pr
> ncl 4> if (any(b(:,:,:).eq.0)) .or. (any(d(:,:,:).eq.0)) then
> ncl 5> output = (d-b)
> ncl 6> else
> ncl 7> ouput = d/b
> ncl 8> end if
>
> This output gives me only differences, not a combination of both. Is it
> possible to put any flag to know whether we have considered differences or
> ratio at each grid level? I have attached printVarSummary for further
> information.
>
> Thank you in advance
>
>
>
> Amit Prasad Timilsina
> PhD student
> School of Natural Resources,UNL
>
> _______________________________________________
> 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/20160105/18b40d48/attachment.html
More information about the ncl-talk
mailing list