Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

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

Go to solution
Jacob Park
Occasional Contributor

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.
Alex Glennie
Honored Contributor

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

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
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


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