Mac binaries
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_f / autocor.f
1 c===========================================================================
2 c
3 c   This file is part of TISEAN
4
5 c   Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6
7 c   TISEAN is free software; you can redistribute it and/or modify
8 c   it under the terms of the GNU General Public License as published by
9 c   the Free Software Foundation; either version 2 of the License, or
10 c   (at your option) any later version.
11 c
12 c   TISEAN is distributed in the hope that it will be useful,
13 c   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 c   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 c   GNU General Public License for more details.
16 c
17 c   You should have received a copy of the GNU General Public License
18 c   along with TISEAN; if not, write to the Free Software
19 c   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 c
21 c===========================================================================
22 c   autocor.f
23 c   autocorrelation function through FFT
24 c   author T. Schreiber (1998), H. Kantz (2007)
25 c===========================================================================
26
27       parameter(nx=1000000)
28       dimension x(2*nx)
29       character*72 file, fout
30       data iverb/1/
31
32       call whatido("autocorrelation function estimated by FFT",iverb)
33       ivar=lopt('v',1)
34       iper=lopt('p',1)
35       iexact=lopt('P',1)
36       if(iexact.ne.0) iper=1
37       nmaxx=ican("l",nx)
38       nexcl=ican("x",0)
39       jcol=ican("c",0)
40       isout=igetout(fout,iverb)
41
42       do 10 ifi=1,nstrings()
43          call nthstring(ifi,file)
44          nmax=nmaxx
45          call readfile(nmax,x,nexcl,jcol,file,iverb)
46          if(file.eq."-") file="stdin"
47          if(ivar.eq.0) call normal(nmax,x,sc,sd)
48          if(iper.eq.0) then
49             nmaxp=nmore(2*nmax)
50             do 20 n=nmax+1,nmaxp
51  20            x(n)=0.
52             call store_spec(nmaxp,x,1)
53             do 30 n=1,nmax
54  30            x(n)=x(n)/real(nmax-n+1)
55          else
56             nmaxp=nmax
57             if(iexact.eq.0) then
58                nmaxp=nless(nmax)
59                if(nmaxp.ne.nmax.and.iv_io(iverb).eq.1)  
60      .            write(istderr(),*) "autocor: using", nmaxp
61             endif
62             call store_spec(nmaxp,x,1)
63             do 50 n=1,nmaxp
64  50            x(n)=x(n)/real(nmaxp)
65          endif
66          if(isout.eq.1) call addsuff(fout,file,"_co")
67          call outfile(fout,iunit,iverb)
68          if(ivar.eq.0) then
69             if(sd.eq.0) stop "autocor: cannot normalise - zero variance"
70             fsc=1./x(1)
71          else
72             fsc=1.
73          endif
74          do 60 n=1,min(nmax,nmaxp)
75  60         write(iunit,*) n-1, fsc*x(n)
76  10      if(iunit.ne.istdout()) close(iunit)
77       end
78
79       subroutine usage()
80 c usage message
81
82       call whatineed(
83      .   "[-v -p -P -o outfile -l# -x# -c# -V# -h] file(s)")
84       call popt("v","give unnormalised autocovariance")
85       call popt("p","assume periodic continuation")
86       call popt("P","assume periodic continuation exactly")
87       call popt("l","number of values to be read [all]")
88       call popt("x","number of values to be skipped [0]")
89       call popt("c","column to be read [1 or file,#]")
90       call pout("file_co")
91       call pall()
92       stop
93       end
94
95
96