How to run command line scripts from within Fortran 90

  • Fortran
  • Thread starter AlphaBetaGamma96
  • Start date
  • Tags
    Fortran Line
In summary, the person is making a program for a three body problem and wants to know how to automatically plot the results to gnuplot. They mention creating a script and using a function like "get_command_argument" but are unsure of the correct function to use in Fortran 90. They are recommended to use the "system" command, although it is not part of the Fortran 90 standard, and to include a shebang in the script for proper execution.
  • #1
AlphaBetaGamma96
3
0
Hey!

I'm currently making a program which is a three body problem. I managed to get working results which I can plot to gnuplot. The question is, how can I write this within the program itself, so it can automatically plot the information to gnuplot if the user wants it to? (I'm being lazy :P)

I know I have to create a script, which I have done, but I don't know the function in Fortran 90 which will allow me to call it and then run it automatically. I believe there is a function along the lines of get_command_argument (I tried this but it isn't a function) or something similar to that.

Thank you for the help!
AlphaBetaGamma96
 
Technology news on Phys.org
  • #4
When you do this on UNIX be sure to include a shebang as the very first line first column of your script. This makes the script run with /bin/whatevershell rather than /bin/sh. Which is the default whenever no shell is specified. Example:
Code:
#!/bin/bash

runs the bash shell to execute the script
 

1. How do I call a command line script from within Fortran 90?

To call a command line script from within Fortran 90, you can use the call system() subroutine. This subroutine allows you to execute operating system commands, including running command line scripts.

2. Can I pass arguments to the command line script from my Fortran 90 code?

Yes, you can pass arguments to the command line script from your Fortran 90 code by including them as part of the command in the call system() subroutine. For example, if your command line script takes in an input file, you can specify the file name as an argument in the call system() subroutine.

3. Is it possible to capture the output of the command line script in my Fortran 90 code?

Yes, it is possible to capture the output of the command line script in your Fortran 90 code by using the execute_command_line() subroutine. This subroutine allows you to capture the standard output of the command line script and store it in a character variable.

4. Can I run multiple command line scripts from within Fortran 90?

Yes, you can run multiple command line scripts from within Fortran 90 by using multiple call system() subroutines. You can also use conditional statements and loops to control the execution of multiple command line scripts based on certain conditions.

5. Are there any limitations to running command line scripts from within Fortran 90?

Yes, there are a few limitations to keep in mind when running command line scripts from within Fortran 90. The call system() subroutine may have limited functionality compared to directly running the script from the command line. Additionally, the compatibility of command line scripts may vary depending on the operating system and compiler used. It is important to test and troubleshoot your code to ensure compatibility and functionality.

Similar threads

  • Programming and Computer Science
Replies
7
Views
498
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
538
  • Programming and Computer Science
Replies
1
Views
560
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
10K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
6
Views
15K
Back
Top