[ncl-talk] sub: Closest value function

dale zuri dalezuri at gmail.com
Thu Mar 21 10:49:40 MDT 2019


Hi ncl user,
I have been trying to reproduce the result without using the closest
function. But the result is not the same? Could someone help me?
I would appreciate the help and time.

Thanks

;do kj=0,dimsizes(Allens)-1

;index =
closest_val(Allens(0),sotmod);;;;;;;;;;;;;;;;;;;(value2check,array2check)

;print(index)

;return

;index1(kj)=index

;index_obs(kj)=sotobs(index)

;end do


do kj=0,dimsizes(Allens)-1

index=abs(Allens(kj)-sotmod)

vl=min(index)

 if index(kj) .eq. vl then

    print(kj)

    index_obs(kj)=sotobs

 end if

end do

On Thu, Mar 21, 2019 at 5:15 AM Rashed Mahmood <rashidcomsis at gmail.com>
wrote:

> 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/56b976c3/attachment.html>


More information about the ncl-talk mailing list