Re: Replacement of arguments in program declaration in F90 (from F77) (207 Views)
Reply
Occasional Contributor
Jacob Park
Posts: 5
Registered: ‎09-05-2000
Message 1 of 2 (207 Views)
Accepted Solution

Replacement of arguments in program declaration in F90 (from F77)

First of all, to those folks hard at work answering to sometimes not-so-brilliant questions,Thank you all!

Anyway, this is reposting of my question on the usage of arguments on program declaration line (in F77). I was little surprise that this was possible in fortran at all at first. However, I was even more perplexed to know that this operation is not supported in F90 (which I have now) anymore. As I understand, this operation is replaced with "IGETARG" and "IARGC". For single command line argument, this seem to work fine. However, is there anyway to set these to intrinsic functions for multiple command line arguments?

Again, what I like to do is to use

program MAIN (arg1,arg2,arg3..etc) <--F77

in F90.
Honored Contributor
Alex Glennie
Posts: 4,068
Registered: ‎05-07-2000
Message 2 of 2 (207 Views)

Re: Replacement of arguments in program declaration in F90 (from F77)

Accessing Command-Line Arguments

HP FORTRAN 77 extends the PROGRAM statement to enable access to
command-line arguments. This extension is not available in HP Fortran
90. However, an HP Fortran 90 program can nevertheless access
command-line arguments by calling the IGETARG and IARGC intrinsics.

For example, the following command line invokes the program fprog with
arguments:

fprog arg1 another arg 222

HP-UX captures the entire command line and makes the following strings
available to your program:

arg1 another arg 222

To access these arguments, your program must call the IGETARG and IARGC
intrinsics. IGETARG (available either as a function or as a subroutine)
gets a specific command-line argument. IARGC returns the number of
arguments on the command line.

The following program illustrates how to use both intrinsics:

PROGRAM test_igetarg

PARAMETER (arg_num = 1)

! arg_str is the character array to be written to
! by IGETARG
CHARACTER(LEN=30) :: arg_str
! IGETARG returns number of characters read within
! the specified parameter
! arg_num is the position of the desired argument in the
! the command line (the name by which the program
was invoked is 0)
! arg_str is the character array in which the argument
! will be written
! 30 is the number of characters to write to arg_str
PRINT *, IGETARG(arg_num, arg_str, 30)
PRINT *,arg_str

! IARGC returns the total number of arguments on the
! command line
PRINT *, IARGC()

END

If this program is compiled and invoked by the name a.out in the
following command line:

a.out perambulation of a different sort

it produces the output:

13 perambulation 5

For more information about the IGETARG and IARGC intrinsics, see the HP
Fortran 90 Programmer's Reference, Chapter 11. You can also use the
GETARG intrinsic to return command-line arguments. GETARG is also
available as a libU77 routine; see the HP Fortran 90 Programmer's
Reference, Chapter 12.)

If the above does stil not really answer your question, I'll get Andy Bennett our Program specialist to reply tomorrow pm if he can .... he's out am BST
Email : alex_glennie@hotmail.com
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.