GET_COMMAND_ARGUMENT(NUMBER, VALUE, LENGTH, STATUS) (Fortran 2003)

Purpose

Returns a command line argument of the command that invoked the program.

Class

Subroutine

Argument type and attributes

NUMBER
An INTENT(IN) INTEGER scalar. It is an integer that identifies the argument number. 0 represents the command name. The numbers from 1 to the argument count represent the command's arguments.
VALUE (optional)
An INTENT(OUT) CHARACTER scalar. It is assigned the value of the argument, or a string of blanks if the value is unknown.
LENGTH (optional)
An INTENT(OUT) INTEGER scalar. It is assigned the significant length of the argument, or 0 if the length of the argument is unknown. This length includes significant trailing blanks. It does not include any truncation or padding that occurs when the argument is assigned to the VALUE argument.
STATUS (optional)
An INTENT(OUT) INTEGER scalar. It is assigned a status value.
It has one of the following values:
  • 1 if the argument retrieval fails
  • -1 if the VALUE argument is present and has a length less than the significant length of the command argument
  • 0 otherwise

Examples

integer num, len, status
character*7 value
num = 0
call GET_COMMAND_ARGUMENT(num, value, len, status)
print*, value
print*, len
print*, status
See the following sample output generated by the above program:
$ a.out aa bb
a.out       (followed by two spaces)
5
0