title: FFT of an array of complex numbers
body: <p>Using FFTW, I want to perform the IFFT of an array of complex numbers, reading data from file "numbers.txt" (where they are stored in the format  a+b*I, one complex number per each row). I have tried with the following, but it doesn't work:  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;math.h&gt;
  #include &lt;complex.h&gt;
  #include &lt;fftw3.h&gt;
  
  int main(void)
  {
  fftw_complex *in;
  fftw_complex *out;
  float re,im;
  int size;
  
  printf("Insert size");
  scanf("%d", &amp;size);
  
  FILE *file = fopen("numbers.txt", "r");
  
  int i=0;
  
  while(fscanf(file, "%f+%fi", &amp;re, &amp;im) &gt; 0) {
  in[i]=re+im*I;
  i++;
  }
  fclose(file);
  
   fftw_complex *out_cpx;
  
   fftw_plan ifft;
   out_cpx = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size);
   out = (double *) malloc(size*sizeof(double));
  
   ifft = fftw_plan_dft_c2r_1d(size, out_cpx, out, FFTW_ESTIMATE);   //Setup fftw plan 
  
   fftw_execute(ifft);
  
   printf("Input:    \tOutput:\n");
   for(i=0;i&lt;size;i++)
   {
   printf("%f\t%f\n",(in[i]),out[i]);
   }
  
   fftw_destroy_plan(ifft);
   fftw_free(out_cpx);
   free(out);
  
  
   return 0;
   }
  </code></pre>
  
  <p>Sample input is (one number per each row):</p>
  
  <pre><code>0+0*I
  0.01198+-0.0825632*I
  1.32139e-05+1.94777e-05*I 
  -1.18289e-11+7.30045e-12*I 
  2.71773e-20+0*I 
  -1.18289e-11+-7.30045e-12*I 
  1.32139e-05+-1.94777e-05*I 
  0.01198+0.0825632*I
  </code></pre>
  
  <p>In particular, I have problems in reading the data from the file. Does someone have any suggestion? Thanks in advance</p>
  
  <p>Edit:</p>
  
  <p>After some improvements, I'm now using this modified code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;math.h&gt;
  #include &lt;complex.h&gt;
  #include &lt;fftw3.h&gt;
  
  
   int main(void)
  {
  fftw_complex *in;
  fftw_complex *out;
  double re,im;
  int size;
  int i=0;
  FILE *file;
  fftw_plan ifft;
  
  printf("Insert size");
  if (scanf("%d", &amp;size) != 1 || size &lt; 1)
      return 1;
  
  in = fftw_malloc(sizeof(*in)*size);
  out = fftw_malloc(sizeof(*out)*size);
  
  file = fopen("numbers.txt", "r");
  
  for (i = 0; i &lt; size &amp;&amp; fscanf(file, "%lf+%lf*I\n", &amp;re, &amp;im) == 2; i++)
  {
      in[i]= re+im*I;
  }
  
  fclose(file);
  // Error if i != size?
  
  
  ifft = fftw_plan_dft_1d(size, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
  
  fftw_execute(ifft);
  
  printf("Input:    \tOutput:\n");
  for(i=0; i&lt;size; i++)
  {
  printf("%lf+%lfI\t%lf+%lfI\n", creal(in[i]), cimag(in[i]), creal(out[i]), cimag(out[i]));
  }
  
  fftw_destroy_plan(ifft);
  fftw_free(in);
  fftw_free(out);
  //free(out);
  
  return 0;
  }
  </code></pre>
  
  <p>The problem now is that I always get a real-valued transformed array. How can I fix it?</p>