|
[Sponsors] |
March 14, 2007, 22:18 |
Fortran direct input help
|
#1 |
Guest
Posts: n/a
|
Hi,
This is a fortran code problem but I figure out the many fortran programmers might be able to help. Suppose I have a simple code like this: program test integer :: i print *, "input i" read *, i print *, i end program test Running the code will prompt me to enter "i", which will be printed. Is there a way whereby I can input directly? ie ./a.out 10 and "10" will be printed. I was told by my school's computer staff that this is only possible in C, not fortran. Is that true? Thank you. |
|
March 15, 2007, 01:26 |
Re: Fortran direct input help
|
#2 |
Guest
Posts: n/a
|
program test
integer :: i read *, i print *, i end program test Compile the above file, then run with ./a.out < 10 and "10" will be printed |
|
March 15, 2007, 01:30 |
Re: Fortran direct input help
|
#3 |
Guest
Posts: n/a
|
Hi Joe,
look into the Fortran manual for functions/subroutines for the processing of command line arguments, e.g. function iargc() and subroutine getarg(...). Regards, Markus |
|
March 15, 2007, 01:34 |
oops my bad
|
#4 |
Guest
Posts: n/a
|
on second thought, that will not work! Sorry, my mistake. you would need a file called "10" containing the input, in order for the code to work as I entered it. I guess the code the way you had it is the best that Fortran can do in general. There is no general mechanism in Fortran to parse command line arguments, though it is possible in Linux to enter
echo 10 | a.out to achieve the effect you want |
|
March 15, 2007, 04:20 |
Re: Fortran direct input help
|
#5 |
Guest
Posts: n/a
|
Thanks Ananada & Markus.
I've tried the subroutine getarg. I am able to get a character sting but I need the arguments to be in real nos. How can I do that? Is there something like a character to real no. conversion subroutine? I've searched google but nothing meaningful appear. |
|
March 15, 2007, 04:31 |
Re: Fortran direct input help
|
#6 |
Guest
Posts: n/a
|
Hi Joe,
in Fortran, you can read from a text string like from a file. In order to read the double precision variable number from the character string text, try e.g. character text*(80) double precision number read(text,*) number Regards, Markus |
|
March 15, 2007, 04:32 |
Re: Fortran direct input help
|
#7 |
Guest
Posts: n/a
|
Hi,
Guess I was not looking hard enough. ;-) For Intel compilers, the subroutine to convert character to real is dnum. Thanks |
|
March 15, 2007, 04:33 |
Re: Fortran direct input help
|
#8 |
Guest
Posts: n/a
|
Sorry, forgot the new lines.
character text*(80) double precision number read(text,*) number |
|
March 15, 2007, 09:37 |
Re: Fortran direct input help
|
#9 |
Guest
Posts: n/a
|
Wow, I didn't know this is possible too. It's better than "dnum" cos any compiler can use it.
Thanks again |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fortran Compiler-CFX12.1 | Araz | CFX | 13 | March 27, 2017 06:37 |
subroutine FORTRAN // CFX in Spain | spain | CFX | 0 | May 23, 2006 07:12 |
Intrinsic Procedure 'ISNAN' in GNU FORTRAN 77 | hawk | Main CFD Forum | 1 | April 12, 2005 23:13 |
visual fortran | Monica | Main CFD Forum | 1 | August 28, 2004 21:45 |
Why Favoring Fortran over C/C++? | Zi-Wei Chiou | Main CFD Forum | 35 | September 26, 2001 10:34 |