Change Eclipse configuration
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_f / spikespec.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   power spectrum of spike trains
23 c   author T. Schreiber (1999)
24 c===========================================================================
25       parameter(nx=1000000)
26       dimension x(nx), lx(nx), sp(nx)
27       character*72 file, fout
28       data iverb/1/
29
30       call whatido("power spectrum of spike trains",iverb)
31       nmaxx=ican("l",nx)
32       nexcl=ican("x",0)
33       jcol=ican("c",0)
34       fmax=fcan("F",0)
35       nfreq=min(ican("#",0),nx)
36       fres=fcan("w",0)
37       inter=lopt("i",1)
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(inter.eq.0) goto 1
45          do 20 n=2,nmax
46  20         x(n)=x(n)+x(n-1)
47  1       call sort(nmax,x,lx)
48          if(fmax.le.0.) fmax=2*nmax/(x(nmax)-x(1))
49          if(nfreq.le.0) nfreq=fmax*(x(nmax)-x(1))/2
50          write(istderr(),*) "spikespec: total time covered: ", 
51      .      x(nmax)-x(1)
52          write(istderr(),*) "spikespec: computing ", nfreq, 
53      .      " frequencies up to ", fmax
54          do 30 n=1,nfreq
55             f=(n*fmax)/nfreq
56  30         sp(n)=sspect(nmax,x,f)
57          ibin=nfreq*fres/2
58          if(ibin.gt.0) write(istderr(),*) 
59      .      "spikespec: binning", 2*ibin+1," frequencies"
60          if(file.eq."-") file="stdin"
61          if(isout.eq.1) call addsuff(fout,file,"_ss")
62          call outfile(fout,iunit,iverb)
63          do 40 n=1+ibin,nfreq-ibin,2*ibin+1
64             f=(n*fmax)/nfreq
65             p=0
66             do 50 ib=n-ibin,n+ibin
67  50            p=p+sp(ib)
68  40         write(iunit,*) f, p
69             if(iunit.eq.istdout()) write(iunit,*)
70             if(iunit.eq.istdout()) write(iunit,*)
71  10      if(iunit.ne.istdout()) close(iunit)
72       end
73
74       function sspect(nmax,x,f)
75       dimension x(nmax)
76       data pi/3.1415926/
77
78       omega=2*pi*f
79       sr=0
80       si=0
81       do 10 n=1,nmax
82          sr=sr+cos(omega*x(n))
83  10      si=si+sin(omega*x(n))
84       sspect=sr**2+si**2
85       end
86
87       subroutine usage()
88 c usage message
89
90       call whatineed(
91      .   "[-F# -## -w# -i -o outfile -l# -x# -c# -V# -h] file(s)")
92       call popt("F","maximal frequency [2*l / total time]")
93       call popt("#","number of frequencies [F* total time /2]")
94       call popt("w","frequency resolution [0]")
95       call popt("i","input data: intervals rather than times")
96       call popt("l","number of values to be read [all]")
97       call popt("x","number of values to be skipped [0]")
98       call popt("c","column to be read [1 or file,#]")
99       call pout("file_ss")
100       call pall()
101       stop
102       end
103
104
105