Fix core WST file
[jabaws.git] / binaries / src / disembl / Tisean_3.0.1 / source_f / tospec.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   Wiener filter x according to spectrum a
23 c   (routine needed by surrogates.f)
24 C   author Thomas Schreiber (1998)
25 c===========================================================================
26       function tospec(nmax,a,x,ibin)
27       parameter(nx=1000000)
28       dimension x(nmax), a(nmax), w(nx), w1(nx), w2(nx), iw(15)
29       save w2, iw
30
31       if(nmax.gt.nx) stop "tospec: make nx larger."
32       do 10 n=1,nmax
33  10      w(n)=x(n)
34       call rffti1(nmax,w2,iw)  
35       call rfftf1(nmax,x,w1,w2,iw)
36       do 20 n=1,nmax
37  20      x(n)=x(n)/real(nmax)
38       x(1)=x(1)*(a(1)/x(1)**2)
39       do 30 i=2+ibin,(nmax+1)/2-ibin,2*ibin+1
40          p=0
41          do 40 ib=i-ibin,i+ibin
42  40         p=p+x(2*ib-2)**2+x(2*ib-1)**2
43          ab=a(2*i-2)/p
44          do 30 ib=i-ibin,i+ibin
45             x(2*ib-2)=x(2*ib-2)*ab
46  30         x(2*ib-1)=x(2*ib-1)*ab
47       if(mod(nmax,2).eq.0) x(nmax)=x(nmax)*(a(nmax)/x(nmax)**2)
48       call rfftb1(nmax,x,w1,w2,iw)
49       tospec=0
50       do 50 n=1,nmax
51  50      tospec=tospec+(x(n)-w(n))**2
52       tospec=sqrt(tospec/nmax)
53       end