FORTRAN 90 command line arrgument

  • Fortran
  • Thread starter nikkinath
  • Start date
  • Tags
    Fortran Line
In summary, you would need to create a script to read the two files and store the results in a third file.
  • #1
nikkinath
3
0
Hi All,
I am very new to FORTRAN Programming. The problem is related to commandline argument. i have a executable program which take 3 command line argument as an input. one is text file and two is variable. I want to write a script were i can execute this script and save in different file and should be able to change the arguments. for example;

./exe1 input.txt x x[j] > output.txt

i=j=1 ... 10

Any help or suggestion will be appreciated. Please let me know if any other information is neede.

Thank you
 
Technology news on Phys.org
  • #2
nikkinath said:
Hi All,
I am very new to FORTRAN Programming. The problem is related to commandline argument. i have a executable program which take 3 command line argument as an input. one is text file and two is variable. I want to write a script were i can execute this script and save in different file and should be able to change the arguments. for example;

./exe1 input.txt x x[j] > output.txt

i=j=1 ... 10

Any help or suggestion will be appreciated. Please let me know if any other information is neede.

Thank you


According to this web page, you can use the getarg() subroutine to get the i-th command line argument.

Code:
          PROGRAM test_getarg
            INTEGER :: i
            CHARACTER(len=32) :: arg
          
            DO i = 1, iargc()
              CALL getarg(i, arg)
              WRITE (*,*) arg
            END DO
          END PROGRAM

Your description of what you're trying to do is not very clear, particularly what you need to do with the two variables on the command line. Can be give a clearer description?
 
  • #3
Thank you so much for your help and sorry for confusion.

beside input.txt file i have one more input file which have 10 variable (x1,x2...x10) and i would like to make a script which read nested loop to read and compute x1 and x1 and for next iteration it should consider x1 and x2.. and so on such that this script will give me n*n metrix..

and save this ouput in new output.txt file ..

if still some confusion please let me know...

Thank you for your advise
 
  • #4
nikkinath said:
Thank you so much for your help and sorry for confusion.

beside input.txt file i have one more input file which have 10 variable (x1,x2...x10) and i would like to make a script which read nested loop to read and compute x1 and x1 and for next iteration it should consider x1 and x2.. and so on such that this script will give me n*n metrix..
Why do you need two input files?
The input file almost certainly doesn't contain variables - it contains numbers. Variables are what your program (which is NOT a script) uses to store numbers.

What do you mean "read and compute x1 and x1?"
How will your program "consider" x1 and x2?

I still don't know what you're trying to do.
nikkinath said:
and save this ouput in new output.txt file ..

if still some confusion please let me know...

Thank you for your advise
 
  • #5
sorry for the confusion again as i told you before very new to FORTRAN I need to run this for my research.. so thought ask for help...

I haven't made this ./exe program i am just using it and to execute this ./exe we need 3 arguments one is input.txt file and other two are variables such as X and Y..

but i want to run this ./exe for more than 10 times .. if i want i can do it manually by entering all the values of X and Y one by one... but i want to know if there is any way i can write a program such that itself read another file which contains values of X and Y and execute ./exe

i know how to do this in R or C ... but my less knowledge in Fortran is giving me hard time.

if still not clear than let me put it in this way

do i till 10

do j till 10

./exe input.txt x x[j] >> output.txt !but i want to amend all the output in one file

end do

end do
 
  • #6
Why don't you write the code you want in C, since you're more familiar with that than you are with Fortran?
 
  • #7
If the fortran exe file is already compiled and all you want to do is run it a few times, what you need to do is write a script for the shell you are accustom to run the fortran, in the first place...

so, if you use a terminal with bash, just write a script that takes two arguments (names of the two files, the one input file and the one with the x's)...then, make the loop at the bash level and execute the fortran program from there.
 

Related to FORTRAN 90 command line arrgument

What is FORTRAN 90 command line argument?

FORTRAN 90 command line argument is a feature in the FORTRAN 90 programming language that allows users to pass arguments or values to a program through the command line interface. This allows for more flexibility and customization in program execution.

How do I pass arguments to a FORTRAN 90 program through the command line?

To pass arguments to a FORTRAN 90 program through the command line, you can use the "command_argument_count" function to determine the number of arguments being passed and the "get_command_argument" function to retrieve the arguments by their position. These functions are part of the "command_line" module in FORTRAN 90.

Can I use both string and numeric command line arguments in FORTRAN 90?

Yes, you can use both string and numeric command line arguments in FORTRAN 90. The "get_command_argument" function can retrieve both types of arguments, and then you can use type conversion functions to convert the string arguments to numeric values if needed.

Is there a limit to the number of command line arguments that can be passed in FORTRAN 90?

The maximum number of command line arguments that can be passed in FORTRAN 90 is system-dependent. However, it is typically quite large and should not pose a limitation in most cases.

Can I pass command line arguments to a FORTRAN 90 program when running it from an integrated development environment (IDE)?

Yes, you can still pass command line arguments to a FORTRAN 90 program when running it from an IDE. Most IDEs have an option to specify command line arguments when running a program. Alternatively, you can also use the "get_command_argument" function within your code to retrieve arguments passed through the command line, regardless of how the program is executed.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
17
Views
5K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
679
  • Programming and Computer Science
Replies
12
Views
9K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
2
Replies
65
Views
2K
Back
Top