Fortran How to Read in Execution Flags in Fortran

  • Thread starter Thread starter MRLX69
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
Fortran programs can indeed read command-line arguments during execution, similar to Java. The discussion highlights the use of the `getarg` function in Fortran, which allows users to pass arguments directly when running the program, avoiding the need for interactive prompts. This capability enables more streamlined execution for tasks like matrix factorization. Additionally, the conversation emphasizes Fortran's versatility, noting its historical applications in developing operating systems, compilers, and other software, showcasing its capability to handle complex programming tasks effectively.
MRLX69
Messages
4
Reaction score
0
Hi All,



Just like to know if it's possible for a Fortran program to read in data on execution.

For example, in JAVA, say if I've written a program for matrix factorization, I can type in the command line:
"java mfact q" for QR factorization or "java mfact c" for Cholesky decomposition, where mfact is my compiled JAVA program.

When I run my Fortran program in command line-interface, the best I can do is run the program, then have the program to ask me for a flag, like:

Code:
  PRINT *, 'Please input the type of factorization you require:'
  READ *, factype

So I'd have to run the program, then it asks me what I want to do. But I'd like to supply the argument as I'm executing the program. Is this possible in Fortran?


Thanks

Mike
 
Technology news on Phys.org
It's very easy to pass command-line arguments in C or C++. I believe you can do something similar with getarg. Here's a link to a man page: http://www.oc.nps.edu/~bird/web101/fortran/getarg.html
 
Last edited by a moderator:
Mark44 said:
It's very easy to pass command-line arguments in C or C++. I believe you can do something similar with getarg. Here's a link to a man page: http://www.oc.nps.edu/~bird/web101/fortran/getarg.html

Ah, thanks!

This is what I needed.
 
Last edited by a moderator:
You can do (just about) anything in Fortran that you need to do. Fortran was used to:

1. Write an operating system (Prime mini's had an OS written mainly in Fortran)
2. Write a 80386 DOS extender (DBOS)
3. Write a Fortran compiler
4. Write a LISP compiler (really)
5. Write a terminal emulator
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
4K
Replies
17
Views
6K
Replies
4
Views
2K
Replies
5
Views
5K
Replies
1
Views
4K
Back
Top