Fortran: Execution and Input in one command line

In summary, the individual is asking if there is a way to input numerical data on the same command line as executing a file, similar to how it is done with i/o files. They are specifically curious about using floating point numbers and mention a simple program they have that reads in two numbers and outputs their product. They are new to Fortran and looking for guidance on how to achieve this, with a suggestion to use the GETARG or GET_COMMAND_ARGUMENT routines.
  • #1
Aerandir90
1
0
Hello all,

I wanted to know if there was a way to read in numerical data on the same command line on which you execute a file.

I know you can do that for i/o files like:
test.exe < file1.in > file2.out

But I wanted to know if there's some similar notation that can be used for floating point numbers.

Supposing I have this simple program that reads in 2 numbers and outputs their product.
I want to be able to do something similar to the above example in the command line:

test.exe < 3.2 87.3

Hope what I'm asking is clear enough..
I'm very new to Fortran so I'm not too sure about stuff like this
Thanks!
 
Technology news on Phys.org
  • #2
You can do this using the GETARG intrinsic routine. Here's a link to a page that describes how to use this function - http://gcc.gnu.org/onlinedocs/gfortran/GETARG.html.

The page above also recommends that new code be written using the newer GET_COMMAND_ARGUMENT routine that is defined by the Fortran 2003 standard.
 

1. What is the purpose of executing Fortran programs with input in one command line?

The purpose of executing Fortran programs with input in one command line is to streamline the process of running the program and providing input simultaneously. This can save time and make the execution of the program more efficient.

2. How do I execute a Fortran program with input in one command line?

To execute a Fortran program with input in one command line, you can use the "read" statement in your program to read in the input from the command line. Then, when running the program, you can provide the input after the program name, separated by spaces.

3. Can I provide multiple inputs in one command line when executing a Fortran program?

Yes, you can provide multiple inputs in one command line when executing a Fortran program. You can use the "read" statement multiple times in your program to read in different inputs, and then provide them in the same order when running the program.

4. What happens if I don't provide the correct number of inputs in the command line when executing a Fortran program?

If you don't provide the correct number of inputs in the command line when executing a Fortran program, the program may encounter errors or unexpected behavior. It is important to make sure your program can handle different numbers of inputs and provide appropriate error messages if necessary.

5. Are there any limitations to executing Fortran programs with input in one command line?

There are some limitations to executing Fortran programs with input in one command line. The number of inputs that can be provided may be limited by the length of the command line or the maximum number of characters that can be entered. Additionally, the format of the input may be limited to text or numerical values only.

Similar threads

Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
2
Views
843
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top