Next: , Previous: GERROR, Up: Intrinsic Procedures


6.79 GETARG — Get command line arguments

Description:
Retrieve the Nth argument that was passed on the command line when the containing program was invoked.

This intrinsic routine is provided for backwards compatibility with GNU Fortran 77. In new code, programmers should consider the use of the GET_COMMAND_ARGUMENT intrinsic defined by the Fortran 2003 standard.

Standard:
GNU extension
Class:
Subroutine
Syntax:
CALL GETARG(N, ARG)
Arguments:

N Shall be of type INTEGER(4), N \geq 0
ARG Shall be of type CHARACTER(*).

Return value:
After GETARG returns, the ARG argument holds the Nth command line argument. If ARG can not hold the argument, it is truncated to fit the length of ARG. If there are less than N arguments specified at the command line, ARG will be filled with blanks. If N = 0, ARG is set to the name of the program (on systems that support this feature).
Example:
          PROGRAM test_getarg
            INTEGER :: i
            CHARACTER(len=32) :: arg
          
            DO i = 1, iargc()
              CALL getarg(i, arg)
              WRITE (*,*) arg
            END DO
          END PROGRAM
     

See also:
GNU Fortran 77 compatibility function: IARGC

F2003 functions and subroutines: GET_COMMAND, GET_COMMAND_ARGUMENT, COMMAND_ARGUMENT_COUNT