cys@caen.engin.umich.edu (CAO YUSONG ) (06/28/90)
I am writting a Fortran program now. I used to be a C programmer.
In C, one can retrieve information from command line arguments, i.e.
In program:
main(argc, argv)
int argc;
char **argv;
{
...
}
Then, argv[0] will be the command name itself, argv[1] will be the first
argument to the command, etc.
Is this also possible in Fortran?
Thanks.
--Jim
khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) (06/28/90)
In article <1990Jun28.153908.4911@caen.engin.umich.edu> cys@caen.engin.umich.edu (CAO YUSONG ) writes:
I am writting a Fortran program now. I used to be a C programmer.
In C, one can retrieve information from command line arguments, i.e.
.....
It depends on what system you are on. On many systems it is quite
easy. For example, on a Sun see page 309 (f77v1.3) of the fortran ref
guide, or getarg(3f)
NAME
getarg, iargc - get the kth command line argument
SYNOPSIS
subroutine getarg ( k, arg )
character*(*) arg
function iargc ()
DESCRIPTION
The statement call getarg( k , arg ) will get the kth
command-line argument and put it into arg .
The 0th argument is the command name.
The function iargc returns the index of the last command-
line argument,
and therefore the number of arguments after the command
name.
EXAMPLE
demo% cat tesargs.f
character argv*10
integer i, iargc, m
m = iargc()
i = 1
do while ( i .le. m )
call getarg ( i, argv )
write( *, '( i2, 1x, a )' ) i, argv
i = i + 1
end do
stop
end
demo % a.out first second last
1 first
2 second
3 last
demo%
FILES
/usr/lang/SC0.0/libF77.a
SEE ALSO
execve(2), getenv(3F)
--
Keith H. Bierman |*My thoughts are my own. !! kbierman@Eng.Sun.COM
It's Not My Fault | MTS --Only my work belongs to Sun* khb@chiba.Eng.Sun.COM
I Voted for Bill & | Advanced Languages/Floating Point Group (415 336 2648)
Opus<khb@eng.sun.com> "When the going gets Weird .. the Weird turn PRO"
seymour@milton.u.washington.edu (Richard Seymour) (06/29/90)
In article <1990Jun28.153908.4911@caen.engin.umich.edu> cys@caen.engin.umich.edu (CAO YUSONG ) writes: > In C, one can retrieve information from command line arguments, i.e. > main(argv,argv) > Then, argv[0] will be the command name itself, argv[1] will be the first > argument to the command, etc. > > Is this also possible in Fortran? This is implementation-dependent. Someone else posted the Sun answer. TheVAX/VMS Fortran answer is the system library function LIB$GET_FOREIGN(result,prompt,result-length,force-prompt) where "result" is the string typed as the command line LESS the actual command. the rest of the arguments are optional: prompt: a string to prompt the user with if they did NOT provide command-line arguments result-length: the number of characters returned by "result" force-prompt: if lowbit is zero, only show "Prompt:" if there were no command arguments, if one, show Prompt: irregardless the function itself returns a typical VMS success value. good luck --dick
joe@etac632 (Joe Fulson-Woytek) (06/29/90)
In article <1990Jun28.153908.4911@caen.engin.umich.edu> cys@caen.engin.umich.edu (CAO YUSONG ) writes: > > I am writting a Fortran program now. I used to be a C programmer. > In C, one can retrieve information from command line arguments, i.e. > > In program: > > main(argc, argv) > int argc; > char **argv; > { > ... > } > It depends on the compiler/machine. On the Iris workstations there's a subroutine getarg for getting the arguments and a function iargc for getting the number of arguments. There is no standard for doing this, however, so you need to check your Fortran reference manual for the machine you are using. Joe Fulson-Woytek joe@etac632.gsfc.nasa.gov
cys@caen.engin.umich.edu (CAO YUSONG ) (06/30/90)
Thank you all who answered my question. Actually, I am programming on Sun, SGI, and DEV/VAX machines. I got all the information I need.