Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-pcd!hpfcso!hplabs!hpcc05!hpyhde4!hpycla!hpcuhc!hpcupt3!jbc From: jbc@hpcupt3.cup.hp.com (Jeff Caldwell) Newsgroups: comp.sys.hp Subject: Re: argv, argc into Fortran or C subroutine? Message-ID: <48580027@hpcupt3.cup.hp.com> Date: 6 May 91 18:56:58 GMT References: Organization: Hewlett Packard, Cupertino Lines: 107 >I need to get command line arguments into a Fortran program that has >some C linked in, but no C main(). > >On other systems I have either >1) Used a Fortran library call or >2) Accessed an extern char** symbol from a C routine > >Since the 720 short-term loaner has almost no documentation associated >with it, I don't know how to do either. Could some one let me know? >Thanks. > >Brian Brian, To my knowledge, on the HP 700 series machine, their are a number of ways to get ahold of the command line arguments from Fortran. Below, I will describe two ways that I am familiar with: the PROGRAM statement and use of intrinsics (igetarg and iargc). The PROGRAM statement can be used to access information from the command line as follows: PROGRAM parm(arg1, arg2, arg3) CHARACTER*15 arg1, arg2, arg3 INTEGER atoi ! system conversion routine arg1(15:15) = char(0) ! Put nulls at the end of the strings for "atoi". arg2(15:15) = char(0) arg3(15:15) = char(0) iarg1 = atoi(arg1) ! ATOI can be used if the arguments are numeric. iarg2 = atoi(arg2) ! ATOI will convert ascii strings to integers. iarg3 = atoi(arg3) PRINT *, "INITIAL VALUES:", arg1, arg2, arg3 PRINT *, "NUMERIC EQUIVALENT:", iarg1, iarg2, iarg3 END % f77 program.f % a.out 10 20 30 INITIAL VALUES:10 20 30 NUMERIC EQUIVALENT: 10 20 30 % a.out testing command args INITIAL VALUES:testing command args NUMERIC EQUIVALENT: 0 0 0 % a.out mixed 30.3 args INITIAL VALUES:mixed 30.3 args NUMERIC EQUIVALENT: 0 30 0 Simply using the program statement is fairly easy. However, a more general way to access command-line arguments from series 700 Fortran is to use the igetarg() and iargc() functions. The igetarg() function requires 3 arguments: igetarg(n, str, slen) where: n is an integer specifying which command-line argument is requested. str is a character variable that will contain the requested command- line argument, padded with blanks on the end. slen is an integer specifying the maximum length of str, so that the routine knows how far to pad the string with blanks. note: the number of significant characters in "str" is returned as the value of the function igetarg. -1 is returned if the argument doesn't exist. note: The name of the program being run is the zeroth argument. iargc() return the number of parameters actually present on the command- line. Example: program args character*30 s integer numargs, length numargs = iargc() do 10, i = 0, numargs length = igetarg(i, s, 30) print *, "ARG ", i, " : ", s 10 continue end % f77 program.f % a.out testing 1 2 3 of the program ARG 0 : a.out ARG 1 : testing ARG 2 : 1 ARG 3 : 2 ARG 4 : 3 ARG 5 : of ARG 6 : the ARG 7 : program Good Luck, Jeff Caldwell Disclaimer: All information presented here is not an official statement of H.P. It is provided only for informative purposes and does not constitute a guarantee from HP. Only my opinion is presented here, not HP's ...