GETARG

Run-Time Subroutine: Returns the specified command-line argument (where the command itself is argument number 0).

Module: USE DFLIB

Syntax

CALL GETARG (n, buffer [, status])

n
(Input) INTEGER(2). Position of the command-line argument to retrieve. The command itself is argument number 0.


buffer
(Output) Character*(*). Command-line argument retrieved.


status
(Optional; output) INTEGER(2). If specified, returns the completion status. If there were no errors, status returns the number of characters in the retrieved command-line argument before truncation or blank-padding. (That is, status is the original number of characters in the command-line argument.) Errors return a value of -1. Errors include specifying an argument position less than 0 or greater than the value returned by NARGS.

GETARG can be used with two or three arguments. If you use module DFLIB.F90 in the \DF98\INCLUDE subdirectory (by including the statement USE DFLIB), you can mix calls to GETARG with two or three arguments. If you do not use DFLIB.F90, you can use either two-argument or three-argument calls to GETARG but only one type of call within a subprogram.

GETARG returns command-line arguments as they were entered. There is no case conversion.

If the command-line argument is shorter than buffer, GETARG pads buffer on the right with blanks. If the argument is longer than buffer, GETARG truncates the argument. If there is an error, GETARG fills buffer with blanks.

Assume a command-line invocation of ANOVA -g -c -a, and that buffer is at least five characters long. The following GETARG statements return the corresponding arguments in buffer:

Statement String returned
in buffer
Length returned
in status
CALL GETARG (0, buffer, status)
ANOVA
5
CALL GETARG (1, buffer)
-g
undefined
CALL GETARG (2, buffer, status)
-c
2
CALL GETARG (3, buffer)
-a
undefined
CALL GETARG (4, buffer, status)
all blanks
-1

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: NARGS, IARGC

Example

USE DFLIB
INTEGER(2) result
result = RUNQQ('prog', '-c -r')
END
! PROG.F90
USE DFLIB
INTEGER(2) n1, n2, status
CHARACTER(80) buf
n1 = 1
n2 = 2
CALL GETARG(n1, buf, status)
WRITE(*,*) buf
CALL GETARG(n2, buf )
WRITE (*,*) buf
END