Fortran; Calling an executable that in turn runs an input file

In summary, the conversation is about automating a process of running an input file through a program called "runner.exe". The user needs to create a program that can call "runner.exe" and all 100 input files in order to avoid doing it manually. The solution is to create a set of files with the names "in001.txt" to "in100.txt" and then write a batch file that calls each input file in order, with the output being written to a single file called "out.txt".
  • #1
Aeroengie
2
0
Hi. I need to write a fortran program that calls an EXE, call it "runner.exe" that in turn runs an input file, call it "run.inp". Thing is, I would normally run "runner.exe" manually, and type in "run.inp" and "runner.exe" gives outputs. But now, I have 100's of input files and I can't affod to do it manually anymore so I need to automate the process, that is, have a program that calls "runner.exe" and "runner.exe" calls all the 100's of input files. How do I do that ?
I have tried [ Call system ('runner.exe') ] and all that does is actually run "runner.exe" but remember, "runner.exe" is in turn waiting for me to type in an input file. So how do I automate the process ?
Note: "runner.exe" was written by someone else and let's assume I don't have the code.
Many thanks.
 
Technology news on Phys.org
  • #2
Create a program to create a set of files named in001.txt, in002.txt, ... in100.txt. In each text file, include the name of the file you want to use for input. Then the program should write a batch file, with the following lines:

runner <in001.txt
runner <in002.txt
...
runner <in100.txt

I'm not sure what you're doing with the output, but if you want it all in a single file:

delete out.txt
runner <in001.txt >>out.txt
runner <in002.txt >>out.txt
...
runner <in100.txt >>out.txt
 
  • #3


I understand the need for automation in order to efficiently process large amounts of data. In order to automate the process of calling "runner.exe" and providing it with multiple input files, you will need to use a scripting language such as Python or Bash. These languages allow you to write a script that can call "runner.exe" and provide it with a list of input files to run.

Here is an example of a Python script that can automate this process:

import os

# Change directory to where "runner.exe" is located
os.chdir("path/to/runner.exe")

# Create a list of input files to run
input_files = ["run1.inp", "run2.inp", "run3.inp", ...]

# Loop through the list of input files and call "runner.exe" for each one
for file in input_files:
os.system("runner.exe " + file)

This script will change the directory to where "runner.exe" is located and then loop through the list of input files, calling "runner.exe" for each one. This will automate the process of running "runner.exe" with multiple input files.

If you do not have access to the code for "runner.exe", you may need to reach out to the person who wrote it to see if they have any suggestions for automating the process. They may have a specific method for providing multiple input files to the program.

I hope this helps and good luck with your automation efforts.
 

What is Fortran?

Fortran is a computer programming language commonly used for scientific and numeric computing. It was first developed in the 1950s and has since undergone several revisions. It is known for its efficiency in handling complex mathematical and scientific calculations.

How do you call an executable in Fortran?

To call an executable in Fortran, you need to use the CALL statement followed by the name of the executable file. For example: CALL myexecutable.exe. This will execute the file and any output will be displayed in the console.

What is an input file in Fortran?

An input file in Fortran is a text file that contains data or instructions that are read and used by a Fortran program. It is typically used to provide input values for the program to process. Input files can be created using any text editor and should follow the proper format for Fortran variables.

How do you run an input file in Fortran?

To run an input file in Fortran, you need to first compile your Fortran program and create an executable file. Then, you can use the CALL statement to call the executable and specify the input file as a command line argument. For example: CALL myprogram.exe inputfile.txt. This will run the program using the data from the input file.

What are the benefits of using an input file in Fortran?

Using an input file in Fortran allows for easier and more organized input data management. It also allows for the same program to be run with different input values, making it more versatile. Additionally, using an input file can help reduce the amount of code needed in the main program, making it more concise and easier to read.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
22
Views
868
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
29
Views
1K
  • Programming and Computer Science
Replies
6
Views
924
Back
Top