>I am trying to find the local maxima of a 1-D time series and looked
>around for available functions within NCL to do this. The closest I came
>to were the functions local_max and local_min are for a 2-D array. It
>would be nice to have a similar function for a 1-D array.
Hi Saji
Attached you will find *untested* NCL functions
that [I hope] will work on 1D arrays.
I did not program for the cyclic case. I must leave.
good luck
D
function local_min_1d(x[*]:numeric, cyclic:logical, del[1]:numeric)
begin
if (del.gt.0.0) then
print("local_min_1d: del must be .le. 0.0")
print("local_min_1d: del ="+del)
exit
end if
nx = dimsizes(x)
imn = new( nx-2, "integer")
i = -1
do n=1,nx-2
if ((x(n-1)-x(n)).le.del .and. (x(n+1)-x(n)).le.del) then
i = i+1
imn(i) = n ; indices of local minima
end if
end do
if (i.gt.-1) then
return(x(imn(0:i))) ; return actual minimum values
else ; must be no local minima
if (typeof(x).eq."float") then
return(-999.)
end if
if (typeof(x).eq."double") then
return(-999.d0)
end if
end if
end
; -------------------------------------------------------
function local_max_1d(x[*]:numeric, cyclic:logical, del[1]:numeric)
; imx = ind((x(1:nx-2)-x(0:nx-3)).gt.del .and. \
; (x(1:nx-2)-x(2:nx-1)).gt.del) + 1
; if (.not.ismissing(imx)) then
; return(x(imx))
; end if
begin
if (del.gt.0.0) then
print("local_max_1d: del must be .ge. 0.0")
print("local_max_1d: del ="+del)
exit
end if
nx = dimsizes(x)
imx = new( nx-2, "integer")
i = -1
do n=1,nx-2
if ((x(n)-x(n-1)).ge.del .and. (x(n)-x(n+1)).ge.del) then
i = i+1
imx (i) = n
end if
end do
if (i.gt.-1) then
return(x(imx))
else
if (typeof(x).eq."float") then
return(-999.)
end if
if (typeof(x).eq."double") then
return(-999.d0)
end if
end if
end
_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2b29 : Mon Sep 26 2005 - 10:27:27 MDT