Re: closest_val problem

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu, 15 Mar 2007 14:00:43 -0600

Will,

I have run into strange behavior from closest_val before. I
recommend using the modified function below, rather than the library
function. The following is much simpler and more robust.

This is straight from the documentation page for closest_val, at the
very bottom of the page.

http://www.ncl.ucar.edu/Document/Functions/Contributed/closest_val.shtml

function closest_val_AnyOrder(xVal[1]:numeric, x:numeric)
local xAbsDif, xMinVal, iClose
begin
   xAbsDif = abs(xVal-x)
   iClose = minind(xAbsDif)
   return(iClose) ; original doc says "first occurence"
end

--Dave A.
CU/CIRES Climate Diagnostics Center (CDC)
NOAA/ESRL/PSD, Climate Analysis Branch (CAB)

Will Hobbs wrote:
> The following script returns a value of 3 for actpk - I was expecting 2.
> I've played around with different values, and it seems only to do this
> when all the values in posspk are less than prevpk. Am I using the
> function incorrectly?
>
> Will
>
>
>
> begin
>
> posspk = (/9, 12, 22/)
> prevpk = 23
>
> actpk = closest_val(prevpk, posspk)
> print(actpk)
> end
>
>
>
>
> ============================
> Room A113
> UCLA Department of Geography
> 1255 Bunche Hall
> Los Angeles CA 90095-1524
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 15 2007 - 14:00:43 MDT

This archive was generated by hypermail 2.2.0 : Fri Mar 16 2007 - 08:51:26 MDT