When invoking an HP Fortran 90 executable
program, you can include one or more arguments on the command line.
The operating system will make these available to your program.
For example, the following command line invokes the program fprog:
$ fprog
arg1 "another arg" 222 |
and it also passes three character arguments to the program:
An HP Fortran 90 program can access these
arguments for internal use by calling the IGETARG
and IARGC intrinsics;
IGETARG is available either as
a function or a subroutine. The IGETARG
intrinsic gets the specified command-line argument; IARGC
returns the number of arguments on the command line. You can also
use the GETARG
intrinsic to return command-line arguments, as illustrated in the
following example program:
Example 7-1 get_args.f90
PROGRAM get_args INTEGER, 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 PROGRAM get_args |
When compiled and invoked with the following command lines:
$ f90
get_args.f90 $ a.out perambulation
of a different sort |
this program produces the following output:
For more information about the IGETARG
and IARGC intrinsics,
see the HP Fortran 90 Programmer's Reference.
GETARGC is also available as a
libU77 routine;
see the HP Fortran 90 Programmer's Reference.