1

I have a Fortran program and want to execute it in python for multiple files. I have 2000 input files but in my Fortran code I am able to run only one file at a time. How should I call the Fortran program in python?

My Script:

import subprocess
import glob
input = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
output = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
f = open("output", "w")
for i in input:
    subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
f.write(i)

Error:

Traceback (most recent call last):
  File "<pyshell#14>", line 2, in <module>
subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
  File "C:\Users\Vishnu\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
  File "C:\Users\Vishnu\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Jone
  • 421
  • 1
  • 5
  • 9

1 Answers1

0

perhaps calling the fortran program with subprocess a la this thread?

Calling an external command in Python

e.g.

import subprocess
subprocess.call('fortran program.f', '-flags')

also, read the documentation

Community
  • 1
  • 1
aydow
  • 3,673
  • 2
  • 23
  • 40