Contributing a function to calculate running correlation....

From: Sabeerali(sebi) <sabeerl_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 11 2010 - 06:15:26 MST

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
Received on Thu Mar 11 06:18:00 2010

This archive was generated by hypermail 2.1.8 : Fri Mar 12 2010 - 09:11:56 MST