title: Reading Real data into Complex variables in Fortran using binary read and write
body: <p>I have a code where I have to do a great deal of file I/O and as such would like a pretty efficient way of dealing with the following problem. For the sake of convenience, my code always write to restart files only the real part, coded as follows:</p>
  
  <pre><code>OPEN(UNIT = 2, FILE = filename, STATUS = 'UNKNOWN', form = 'unformatted')
      write(2) CFL
      write(2) W
  CLOSE(2)
  </code></pre>
  
  <p>When I run my code in the real analysis mode, reading these files is trivial:</p>
  
  <pre><code>OPEN(UNIT = 2, FILE = filename, STATUS = 'OLD', form = 'unformatted')
      read(2) CFL
      read(2) W
  CLOSE(2)
  </code></pre>
  
  <p>But when I run in complex I have to do this somewhat clumsy hack:</p>
  
  <pre><code>open(UNIT = funit, FILE = filename, STATUS = 'old', form='unformatted')
  #ifdef COMPLEX_ON
          read(funit) CFL
          read(funit) W_t
          CFL_in = CFL
          W = W_t
  #else                                                                                                                                                                   
          read(funit) CFL_in
          read(funit) W
  #endif
  close(funit)
  </code></pre>
  
  <p>This means that now I need two copies of the data, and if I use implied do-loops like I did previously, I can do this hack one entry at a time and the copy to the W array, but this is a slower way of handling the I/O. Is there a way to tell fortran I want to read real binary data into a complex variable array?</p>
  
  <p>Thanks.</p>