forked from UNC-CECL/CDM_v3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfftw12d.cc
133 lines (108 loc) · 3.07 KB
/
rfftw12d.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "rfftw12d.h"
/******************************************************************************
Class rfftw2d_array
******************************************************************************/
rfftw1d_array::rfftw1d_array( int size )
{
m_size= size;
m_padsize= 2*(size/2+1);
m_buf= (double*)fftw_malloc(sizeof(double)*m_padsize);
m_cbuf= (fftw_complex*)m_buf;
m_plan_forw= fftw_plan_dft_r2c_1d( m_size, m_buf, m_cbuf, FFTW_MEASURE );
m_plan_back= fftw_plan_dft_c2r_1d( m_size, m_cbuf, m_buf, FFTW_MEASURE );
}
rfftw1d_array::~rfftw1d_array()
{
fftw_destroy_plan( m_plan_forw );
fftw_destroy_plan( m_plan_back );
fftw_free(m_buf);
}
/*! Divides all values by the factor xsize*ysize by which they are too large
after forward+backward transformation by fftw. This is called by
transform_back() automatically. */
void rfftw1d_array::renormalize()
{
int x;
double scale= 1.0/(double)(m_size);
for( x= 0; x< m_size; ++x )
pos(x) *= scale;
}
/******************************************************************************
Class rfftw2d_array
******************************************************************************/
rfftw2d_array::rfftw2d_array( int xsize, int ysize )
{
m_xsize= xsize;
m_ysize= ysize;
m_clineoff= m_ysize/2 + 1;
m_lineoff= 2*m_clineoff;
m_buf= (double*)fftw_malloc(sizeof(double)*m_xsize*m_lineoff);
m_cbuf= (fftw_complex*)m_buf;
m_plan_forw= fftw_plan_dft_r2c_2d( m_xsize, m_ysize, m_buf, m_cbuf,
FFTW_MEASURE );
m_plan_back= fftw_plan_dft_c2r_2d( m_xsize, m_ysize, m_cbuf, m_buf,
FFTW_MEASURE );
}
rfftw2d_array::~rfftw2d_array()
{
fftw_destroy_plan( m_plan_forw );
fftw_destroy_plan( m_plan_back );
fftw_free(m_buf);
}
/*!
Prints out all position-space values. y determines the column, x the row.
*/
void rfftw2d_array::dumppos(void)
{
int x, y;
for( y= 0; y< pos_ysize(); ++y ) {
for( x= 0; x< pos_xsize(); ++x )
printf("%g ", pos(x, y));
printf("\n");
}
}
/*!
Prints out all frequency-space values as (real, imaginary) value pairs.
y determines the column, x the row.
*/
void rfftw2d_array::dumpfreq(void)
{
int x, y;
for( y= 0; y< freq_ysize(); ++y ) {
for( x= 0; x< freq_xsize(); ++x )
printf( "(%g, %g) ", freqre(x, y), freqim(x, y) );
printf("\n");;
}
}
/*!
Divides all values by the factor xsize*ysize by which they are too large
after forward+backward transformation by fftw. This is called by
transform_back() automatically.
*/
void rfftw2d_array::renormalize()
{
int x, y;
double scale= 1.0/(double)(m_xsize*m_ysize);
for( x= 0; x< m_xsize; ++x )
for( y= 0; y< m_lineoff; ++y )
pos(x, y) *= scale;
}
//void rfftw2d_array::foreachpos(
// void (*func)(double *elem, int x, int y) )
//{
// int x, y;
//
// for( x= 0; x< m_xsize; ++x )
// for( y= 0; y< m_ysize; ++y )
// func( &pos(x, y), x, y);
//}
//
//void rfftw2d_array::foreachfreq(
// void (*func)(fftw_complex *elem, int fx, int fy) )
//{
// int x, y;
//
// for( x= 0; x< m_xsize; ++x )
// for( y= 0; y< m_clineoff; ++y )
// func( &freq(x, y), x, y);
//}