This is FTR [For-The-Record]
Attached is a minor revision of the original code.
Note: This is *NOT* a supported NCL function.
THX
On 03/11/2010 06:15 AM, Sabeerali(sebi) wrote:
> Here I am contributing a function to calculate running/moving
> correlation..............
>
>
>
> ; Function to calculate running/moving correlation..
>
> undef ("run_cor")
> function run_cor(x:numeric,y:numeric,time:numeric,wSize:integer)
> ;**********************************************************************
> ; x and y: numeric array of 1D [eg: x(time) and y(time)]
> ; x and y should have same size
> ; time: numeric array of 1D that represent time coordinate of x or y
> ; time coordinate must have recognized by ut_calendar
> ; wSize is the scalar integer that specifies window size.[e.g 11 yr, 15
> year, 21 year, etc]
> ;Sample usage: x(time) and y(time).
> ; cor_11=run_cor(x,y,time,11)
> ; cor_15=run_cor(x,y,time,15)
> ; cor_21=run_cor(x,y,time,21)
> ;************************************************************************
> local aa,bb,i,cor,k,N
> begin
>
> N=dimsizes(x)
> cor=new((/(N-(wSize-1))/),float)
> date=new((/(N-(wSize-1))/),integer)
> utc_date=ut_calendar(time,0)
> year = floattointeger(utc_date(:,0))
>
> k=(wSize-1)/2
> do j=0,N-(wSize)
> date(j)=year(k)+j
> end do
>
> do i=0,(N-wSize)
> aa=x(i:i+(wSize-1))
> bb=y(i:i+(wSize-1))
> cor(i)=escorc(aa,bb)
> end do
> cor!0="time"
> cor&time=date
> return(cor)
> end
>
>
> -- Regards
> sabeerali
>
> **********************************
> Sabeerali
> Climate and Global Modeling Division
> Indian Institute of Tropical Meteorology
> Pashan, Pune, 411 008
> ****************************************
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-- ====================================================== Dennis J. Shea tel: 303-497-1361 | P.O. Box 3000 fax: 303-497-1333 | Climate Analysis Section | Climate & Global Dynamics Div. | National Center for Atmospheric Research | Boulder, CO 80307 | USA email: shea 'at' ucar.edu | ======================================================
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2.1.8 : Fri Mar 12 2010 - 09:11:56 MST