E
Erica
Hi,
I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.
I compile it as follows:
g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm
The errors I get are:
ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'
Here is my code:
#include <fftw3.h>
#include <math.h>
int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;
/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);
p = fftw_plan_dft_2d(nx, ny, in, out, FFTW_FORWARD,
FFTW_ESTIMATE);
/* Now fill the input array with the input data */
/* We'll simply make a sine wave */
for (i = 0; i < (nx * ny); i++) {
in[0] = sin(i / 10.0 * M_PI); /* Real part */
in[1] = 0.0; /* Imaginary part */
}
/* Actually execute the plan on the input data */
fftw_execute(p);
/* Print out the results */
for (i = 0; i < (nx * ny); i++)
printf("Coefficient %d: %f%+f*i\n", i, out[0], out[1]);
/* Clean up after ourselves */
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
return 0;
}
Eventually I will do something more complex than a sine wave, but you
get the idea.
If anyone knows what the problem is, I would greatly appreciate any
help. This is all that fftw.org has about calling it from C++:
http://fftw.org/faq/section2.html#cplusplus
Thanks in advance!!
--Erica
I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.
I compile it as follows:
g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm
The errors I get are:
ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'
Here is my code:
#include <fftw3.h>
#include <math.h>
int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;
/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);
p = fftw_plan_dft_2d(nx, ny, in, out, FFTW_FORWARD,
FFTW_ESTIMATE);
/* Now fill the input array with the input data */
/* We'll simply make a sine wave */
for (i = 0; i < (nx * ny); i++) {
in[0] = sin(i / 10.0 * M_PI); /* Real part */
in[1] = 0.0; /* Imaginary part */
}
/* Actually execute the plan on the input data */
fftw_execute(p);
/* Print out the results */
for (i = 0; i < (nx * ny); i++)
printf("Coefficient %d: %f%+f*i\n", i, out[0], out[1]);
/* Clean up after ourselves */
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
return 0;
}
Eventually I will do something more complex than a sine wave, but you
get the idea.
If anyone knows what the problem is, I would greatly appreciate any
help. This is all that fftw.org has about calling it from C++:
http://fftw.org/faq/section2.html#cplusplus
Thanks in advance!!
--Erica