title: Writing Fortran unformatted files with Python
body: <p>I have some single-precision little-endian unformatted data files written by Fortran77. I am reading these files using Python using the following commands:</p>
  
  <pre><code>import numpy as np
  original_data = np.dtype('float32')
  f = open(file_name,'rb')                                                                                                 
  original_data = np.fromfile(f,dtype='float32',count=-1)                                                                            
  f.close()
  </code></pre>
  
  <p>After some data manipulation in Python, I (am trying to) write them back in the original format using Python using the following commands:</p>
  
  <pre><code>out_file = open(output_file,"wb")                                                                                             
  s = struct.pack('f'*len(manipulated_data), *manipulated_data)                                                                     
  out_file.write(s)
  out_file.close()
  </code></pre>
  
  <p>But it doesn't seem to be working. Any ideas what is the right way of writing the data using Python back in the original fortran unformatted format?</p>
  
  <p>Details of the problem:</p>
  
  <p>I am able to read the final file with manipulated data from Fortran. However, I want to visualize these data using a software (Paraview). For this I convert the unformatted data files in the *h5 format. I am able to convert both the original and manipulated data in h5 format using h5 utilities. But while Paraview is able to read the *h5 files created from original data, Paraview is not able to read the *h5 files created from the manipulated data. I am guessing something is being lost in translation.</p>
  
  <p>This is how I am opening the file written by Python in Fortran (single precision data):</p>
  
  <pre><code>open (in_file_id,FILE=in_file,form='unformatted',access='direct',recl=4*n*n*n)
  </code></pre>
  
  <p>And this is I am writing the original unformatted data by Fortran:</p>
  
  <pre><code>open(out_file_id,FILE=out_file,form="unformatted")
  </code></pre>
  
  <p>Is this information sufficient?</p>