source: Sophya/trunk/SophyaLib/NTools/fftserver.cc@ 517

Last change on this file since 517 was 515, checked in by ansari, 26 years ago

Portage SGI-CC Reza 26/10/99

File size: 4.5 KB
Line 
1#include "fftserver.h"
2#include <iostream.h>
3
4extern "C" {
5 int rffti_(int *n, float *wsave);
6 int rfftf_(int *n, float *r__, float *wsave);
7 int rfftb_(int *n, float *r__, float *wsave);
8 int dffti_(int *n, double *wsave);
9 int dfftf_(int *n, double *r__, double *wsave);
10 int dfftb_(int *n, double *r__, double *wsave);
11 int cffti_(int *n, float *wsave);
12 int cfftf_(int *n, float *c__, float *wsave);
13 int cfftb_(int *n, float *c__, float *wsave);
14 int cdffti_(int *n, double *wsave);
15 int cdfftf_(int *n, double *c__, double *wsave);
16 int cdfftb_(int *n, double *c__, double *wsave);
17 }
18
19FFTServer::FFTServer()
20{
21sz_rfft = 0;
22ws_rfft = NULL;
23sz_cfft = 0;
24ws_cfft = NULL;
25sz_cdfft = 0;
26ws_cdfft = NULL;
27}
28
29FFTServer::~FFTServer()
30{
31if (ws_rfft) delete[] ws_rfft;
32if (ws_cfft) delete[] ws_cfft;
33if (ws_cdfft) delete[] ws_cdfft;
34}
35
36void FFTServer::checkint_rfft(int l)
37{
38 if (sz_rfft == l) return;
39
40 if (ws_rfft) delete[] ws_rfft;
41 sz_rfft = l;
42 ws_rfft = new float[2*l+15];
43 rffti_(&l, ws_rfft);
44}
45
46void FFTServer::checkint_cfft(int l)
47{
48 if (sz_cfft == l) return;
49
50 if (ws_cfft) delete[] ws_cfft;
51 sz_cfft = l;
52 ws_cfft = new float[4*l+15];
53 cffti_(&l, ws_cfft);
54}
55
56void FFTServer::checkint_dfft(int l)
57{
58 if (sz_dfft == l) return;
59
60 if (ws_dfft) delete[] ws_dfft;
61 sz_dfft = l;
62 ws_dfft = new double[2*l+15];
63 dffti_(&l, ws_dfft);
64}
65
66void FFTServer::checkint_cdfft(int l)
67{
68 if (sz_cdfft == l) return;
69
70 if (ws_cdfft) delete[] ws_cdfft;
71 sz_cdfft = l;
72 ws_cdfft = new double[4*l+15];
73 cdffti_(&l, ws_cdfft);
74}
75
76void FFTServer::fftf(int l, float* inout)
77{
78 checkint_rfft(l);
79 rfftf_(&l, inout, ws_rfft);
80 for (int k= 2;k<=(l+1)/2;k++) inout[2*k-2]=-inout[2*k-2];
81}
82
83void FFTServer::fftf(int l, double* inout)
84{
85 checkint_dfft(l);
86 dfftf_(&l, inout, ws_dfft);
87 for (int k= 2;k<=(l+1)/2;k++) inout[2*k-2]=-inout[2*k-2];
88}
89
90void FFTServer::fftf(int l, complex<float>* inout)
91{
92 checkint_cfft(l);
93 float* foo = new float[2*l];
94 int i;
95 for (i=0;i<l;i++){
96 foo[2*i]=inout[i].real();
97 foo[2*i+1]=inout[i].imag();
98 }
99 cfftf_(&l, foo, ws_cfft);
100 inout[0]=complex<float> (foo[0],foo[1]);
101 for (i=1;i<l;i++) inout[l-i]= complex<float> (foo[2*i], foo[2*i+1]);
102 delete[] foo;
103}
104
105void FFTServer::fftf(int l, complex<double>* inout)
106{
107 checkint_cdfft(l);
108 double* foo=new double[2*l];
109 int i;
110 for (i=0;i<l;i++){
111 foo[2*i]=inout[i].real();
112 foo[2*i+1]=inout[i].imag();
113 }
114 cdfftf_(&l, foo, ws_cdfft);
115 inout[0]=complex<double> (foo[0],foo[1]);
116 for (i=1;i<l;i++) {
117 inout[l-i]= complex<double> (foo[2*i],foo[2*i+1]);
118 }
119 delete[] foo;
120}
121
122void FFTServer::fftb(int l, float* inout)
123{
124 checkint_rfft(l);
125 rfftf_(&l, inout, ws_rfft);
126}
127
128void FFTServer::fftb(int l, double* inout)
129{
130 checkint_dfft(l);
131 dfftf_(&l, inout, ws_dfft);
132}
133
134void FFTServer::fftb(int l, complex<float>* inout)
135{
136 checkint_cfft(l);
137 float* foo = new float[2*l];
138 int i;
139 for (i=0;i<l;i++){
140 foo[2*i]=inout[i].real();
141 foo[2*i+1]=inout[i].imag();
142 }
143 cfftf_(&l, foo, ws_cfft);
144 for (i=0;i<l;i++) inout[i]=complex<float> (foo[2*i],foo[2*i+1]);
145 delete[] foo;
146}
147
148void FFTServer::fftb(int l, complex<double>* inout)
149{
150 checkint_cdfft(l);
151 double* foo = new double[2*l];
152 int i;
153 for (i=0;i<l;i++){
154 foo[2*i]=inout[i].real();
155 foo[2*i+1]=inout[i].imag();
156 }
157 cdfftf_(&l, foo, ws_cdfft);
158 for (i=0;i<l;i++) inout[i]=complex<double> (foo[2*i],foo[2*i+1]);
159 delete[] foo;
160}
161
162void FFTServer::fftf(Vector& in, Vector& out)
163{
164 int l = in.NElts();
165/* ----- Si c'etait un Vector<float> on aurait ecrit comme ca
166 Pour le moment Vector est double, on passe donc par un tableau
167 intermediare
168// La transformee sur le tableau de flaot se fait en place,
169// on utilise donc out comme in-out
170 out = in;
171 fftf_float(l, out.Data() );
172 ------------------------------------------------------------- */
173 float * inout = new float[l];
174 int i;
175 for(i=0; i<l; i++) inout[i] = in(i);
176 fftf(l, inout);
177 out.Realloc(l);
178 for(i=0; i<l; i++) out(i) = inout[i];
179}
180
181void FFTServer::fftb(Vector& in, Vector& out)
182{
183 int l = in.NElts();
184/* ----- Si c'etait un Vector<float> on aurait ecrit comme ca
185 Pour le moment Vector est double, on passe donc par un tableau
186 intermediare
187// La transformee sur le tableau de flaot se fait en place,
188// on utilise donc out comme in-out
189 out = in;
190 fftf_float(l, out.Data() );
191 ------------------------------------------------------------- */
192 float * inout = new float[l];
193 int i;
194 for(i=0; i<l; i++) inout[i] = in(i);
195 fftb(l, inout);
196 out.Realloc(l);
197 for(i=0; i<l; i++) out(i) = inout[i];
198}
199
Note: See TracBrowser for help on using the repository browser.