I am trying to take the inverse Fourier transform of complex output and print out in a 2D array. I wrote a printf function (that seems part of the error) and tried to take inverse FFT using fttw.3 library which is working. But for some reason, I cannot print it.
The printf function is called: print2DPhysArray in arithmetic functions.
Error message:
1) From the printf function I wrote
1 2 3 4 5
warning: format ‘%le’ expects argument of type ‘double’, but argument 2 has type ‘double*’ [-Wformat=]
printf("%+4.2le ",arr[j + ny*i]); //[j + ny*i] real. from arr[i][j]). from: printf("%+4.2le ",arr[j + ny*i]);
| ~~~~~~^ ~
| | |
| doubledouble*
2) From the cpp file where I am trying to print out results
1 2 3 4 5 6 7 8
error: cannot convert ‘double*’ to ‘double (*)[512]’
885 | print2DPhysArray(potSource_inertia); //try *
| ^~~~~~~~~~~~~~~~~
| |
| double*
In file included from spectralFunctions.cpp:7:
arithmeticFunctions.h:9:30: note: initializing argument 1 of ‘void print2DPhysArray(double (*)[512])’
9 | void print2DPhysArray(double arr[][ny]);
You are printing your array element as if it's a 1d array (with 2d mapping logic).
You are passing your array as if it is a 2d array, but it would appear that potSource_inertia is a 1d array.
I would try making everything consistent:
- Change function to void print2DPhysArray(double arr[]);
- Pass a 1d array to it as you appear to already be doing.
- Keep your printf statement the same.
Btw, if your width is not the same value as your height, make sure your stride is the right length. If the width of the array is "width", then you would access each index as arr[width * i + j]. The height doesn't matter for the indexing.