NLSL
correl.f90
Go to the documentation of this file.
1 c NLS Version 1.3 7/13/93
2 c----------------------------------------------------------------------
3 c =====================
4 c subroutine CORREL
5 c =====================
6 c
7 c Taken from subroutine CORREL in Numerical Recipes, Press et al.
8 c Calculates the correlation function of two input arrays.
9 c
10 c
11 c Inputs:
12 c data Data array
13 c spctr Array that is to be shifted to match data array
14 c npt Number of points in data and spctr
15 c NOTE: For the FFT, this must be a power of two.
16 c This routine does not check for this condition.
17 c ans Contains correlation function (should be dimensioned
18 c as complex*16 or twice the size of data array)
19 c fft Work array dimensioned as complex*16(npt)
20 c
21 c Uses:
22 c twofft (from Numerical Recipes)
23 c four1 (from Numerical Recipes)
24 c realft (from Numerical Recipes)
25 c
26 c----------------------------------------------------------------------
27  subroutine correl(data,spctr,npt,ans,fft)
28  implicit none
29  integer npt
30  double precision data(npt),spctr(npt),ans(2*npt),fft(2*npt)
31 c
32  integer i,ii,ir,no2
33  double precision ansr,halfn,tmp
34 c
35 c ----
36  call twofft(data,spctr,fft,ans,npt)
37  no2=npt/2
38  halfn=float(no2)
39  do i=1,no2+1
40  ii=i+i
41  ir=ii-1
42  ansr=ans(ir)
43  ans(ir)=(fft(ir)*ansr+fft(ii)*ans(ii))/halfn
44  ans(ii)=(fft(ii)*ansr-fft(ir)*ans(ii))/halfn
45  end do
46  ans(2)=ans(npt+1)
47  call realft(ans,no2,-1)
48 c ---
49 c
50 c
51 c Note that correlation function is stored from ans(1) to ans(no2)
52 c for zero and positive correlations, and from ans(npt) down to
53 c ans(no2+1) for negative correlations. Rearrange the ans array
54 c according to increasing correlations.
55 c
56  do i=1,no2
57  tmp=ans(i)
58  ans(i)=ans(no2+i)
59  ans(no2+i)=tmp
60  end do
61  return
62 c
63  end
64 
subroutine realft(data, n, isign)
Definition: ftfuns.f90:48
subroutine twofft(data1, data2, fft1, fft2, n)
Definition: ftfuns.f90:9
subroutine correl(data, spctr, npt, ans, fft)
Definition: correl.f90:28