2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2008, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
44 #include "gromacs/fft/fft.h"
45 #include "gromacs/utility/smalloc.h"
48 #define SWAP(a, b) tempr = (a); (a) = (b); (b) = tempr
50 void four1(real data[], int nn, int isign)
52 int n, mmax, m, j, istep, i;
53 double wtemp, wr, wpr, wpi, wi, theta;
58 for (i = 1; i < n; i += 2)
62 SWAP(data[j], data[i]);
63 SWAP(data[j+1], data[i+1]);
66 while (m >= 2 && j > m)
77 theta = 6.28318530717959/(isign*mmax);
78 wtemp = sin(0.5*theta);
79 wpr = -2.0*wtemp*wtemp;
83 for (m = 1; m < mmax; m += 2)
85 for (i = m; i <= n; i += istep)
88 tempr = wr*data[j]-wi*data[j+1];
89 tempi = wr*data[j+1]+wi*data[j];
90 data[j] = data[i]-tempr;
91 data[j+1] = data[i+1]-tempi;
95 wr = (wtemp = wr)*wpr-wi*wpi+wr;
96 wi = wi*wpr+wtemp*wpi+wi;
104 static void realft(real data[], int n, int isign)
106 int i, i1, i2, i3, i4, n2p3;
107 real c1 = 0.5, c2, h1r, h1i, h2r, h2i;
108 double wr, wi, wpr, wpi, wtemp, theta;
110 theta = 3.141592653589793/(double) n;
121 wtemp = sin(0.5*theta);
122 wpr = -2.0*wtemp*wtemp;
127 for (i = 2; i <= n/2; i++)
129 i4 = 1+(i3 = n2p3-(i2 = 1+(i1 = i+i-1)));
130 h1r = c1*(data[i1]+data[i3]);
131 h1i = c1*(data[i2]-data[i4]);
132 h2r = -c2*(data[i2]+data[i4]);
133 h2i = c2*(data[i1]-data[i3]);
134 data[i1] = h1r+wr*h2r-wi*h2i;
135 data[i2] = h1i+wr*h2i+wi*h2r;
136 data[i3] = h1r-wr*h2r+wi*h2i;
137 data[i4] = -h1i+wr*h2i+wi*h2r;
138 wr = (wtemp = wr)*wpr-wi*wpi+wr;
139 wi = wi*wpr+wtemp*wpi+wi;
143 data[1] = (h1r = data[1])+data[2];
144 data[2] = h1r-data[2];
148 data[1] = c1*((h1r = data[1])+data[2]);
149 data[2] = c1*(h1r-data[2]);
154 static void twofft(real data1[], real data2[], real fft1[], real fft2[], int n)
157 real rep, rem, aip, aim;
159 nn3 = 1+(nn2 = 2+n+n);
160 for (j = 1, jj = 2; j <= n; j++, jj += 2)
162 fft1[jj-1] = data1[j];
167 fft1[2] = fft2[2] = 0.0;
168 for (j = 3; j <= n+1; j += 2)
170 rep = 0.5*(fft1[j]+fft1[nn2-j]);
171 rem = 0.5*(fft1[j]-fft1[nn2-j]);
172 aip = 0.5*(fft1[j+1]+fft1[nn3-j]);
173 aim = 0.5*(fft1[j+1]-fft1[nn3-j]);
185 void correl(real data1[], real data2[], int n, real ans[])
191 twofft(data1, data2, fft, ans, n);
193 for (i = 2; i <= n+2; i += 2)
196 ans[i-1] = (fft[i-1]*dum+fft[i]*ans[i])/no2;
197 ans[i] = (fft[i]*dum-fft[i-1]*ans[i])/no2;
200 realft(ans, no2, -1);