title: How do I read Fortran output into Python?
body: <p>I inherited some code that looks like this:</p>
  
  <pre><code>Python -&gt; File -&gt; Modern Fortran -&gt; File -&gt; Python
  </code></pre>
  
  <p>where each File contains a simple array of reals.</p>
  
  <p>I now need to run this program many times and the I/O is hurting me. I want to omit the files and read the Python output into Fortran and read the Fortran output back into Python. </p>
  
  <p>I can omit the first file by calling the Fortran routine from Python and providing the reals as a series of string arguments. </p>
  
  <pre><code>## This Python script converts a to a string and provides it as 
  ## an argument to the Fortran script test_arg
  
  import subprocess
  
  a = 3.123456789
  status = subprocess.call("./test_arg " + str(a), shell=True)
  </code></pre>
  
  <hr>
  
  <pre><code>!! This Fortran script reads in a string argument provided by the 
  !! above Python script and converts it back to a real.
  
  program test_arg
  
    character(len=32) :: a_arg
    real*8      :: a, b
  
    call get_command_argument(1,a_arg)
    read(a_arg,*), a
    print*,a
  
    b = a*10
  
  end program test_arg
  </code></pre>
  
  <p>What would a working code snippet look like to output the variable 'b' into another Python script without using an intermediate file?</p>
  
  <p>I've read about f2py, but the amount of refactoring involved in turning the inherited Fortan scripts into Python modules is more than what I want to do. </p>