Mac binaries
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_f / spectrum.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   Fourier power spectrum
23 c   author T. Schreiber (1998) and earlier
24 c   modified by H. Kantz 2007
25 c=========================================================================== 
26       parameter(nx=1000000)
27       dimension x(nx)
28       character*72 file, fout
29       data h/1./, dh/0./
30       data iverb/1/
31
32       call whatido("Power spectrum by FFT",iverb)
33       nmaxx=ican("l",nx)
34       nexcl=ican("x",0)
35       jcol=ican("c",0)
36       h=fcan("f",h)
37       dh=fcan("w",dh)
38       isout=igetout(fout,iverb)
39
40       do 10 ifi=1,nstrings()
41          call nthstring(ifi,file)
42          nmax=nmaxx
43          call readfile(nmax,x,nexcl,jcol,file,iverb)
44          if(file.eq."-") file="stdin"
45          if(isout.eq.1) call addsuff(fout,file,"_sp")
46          nmaxp=nless(nmax)
47          if(nmaxp.ne.nmax) 
48      .      write(istderr(),*) "spectrum: using first ", nmaxp
49          if(dh.eq.0.) dh=h/nmaxp
50          ibin=nmaxp*dh/(2*h)
51          if(ibin.gt.0) write(istderr(),*) 
52      .      "spectrum: binning", 2*ibin+1," frequencies"
53          call store_spec(nmaxp,x,0)
54          call outfile(fout,iunit,iverb)
55          write(iunit,*) 0., x(1)
56          do 20 i=2+ibin,nmaxp/2+1-ibin,2*ibin+1
57             p=0
58             do 30 ib=i-ibin,i+ibin
59  30            p=p+x(2*ib-2)
60  20         write(iunit,*) h*(i-1)/real(nmaxp), p
61             if(iunit.eq.istdout()) write(iunit,*)
62             if(iunit.eq.istdout()) write(iunit,*)
63  10         if(iunit.ne.istdout()) close(iunit)
64       end
65
66       subroutine usage()
67 c usage message
68
69       call whatineed(
70      .   "[-f# -w# -o outfile -l# -x# -c# -V# -h] file(s)")
71       call popt("f","sampling rate, e.g. in Hz [default 1.]")
72       call popt("w","frequency resolution, e.g. in Hz, [default 1/N]")
73       call popt("l","number of values to be read [all]")
74       call popt("x","number of values to be skipped [0]")
75       call popt("c","column to be read, [1] or file,#")
76       call pout("file_sp")
77       call pall()
78       stop
79       end