[ncl-talk] sub: Closest value function
Rashed Mahmood
rashidcomsis at gmail.com
Thu Mar 21 07:15:43 MDT 2019
the if statement inside the loop should be:
do i=0,3
if (xAbsDif(i).eq.xMinVal) then
print(i)
end if
end do
Cheers
Rashed
On Thu, Mar 21, 2019 at 3:09 AM dale zuri <dalezuri at gmail.com> wrote:
> Hi Ncl user,
>
> I would like to implement the closest value function without using ind
> function. I would appreciate any suggestion.
>
> value2check = 18.382
>
> array2check = (/18.0001 ,18.5888, 18.01, 18.5/)
>
> index = closest_val(value2check,array2check)
>
> print(index)
>
> xAbsDif = abs(value2check-array2check)
>
> xMinVal = min(xAbsDif)
>
> iClose = (ind(xAbsDif.eq.xMinVal))
>
> print(iClose)
>
>
> :::::without using ind;;;;;
>
> do i=0,3
>
> if any(xAbsDif(i)) .eq. any(xMinVal) then
>
> print(i) ;; it's not giving right answer
>
> end if
>
> end do
>
>
> Thanks
> _______________________________________________
> 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/20190321/9b32ff7a/attachment.html>
More information about the ncl-talk
mailing list