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
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. It is an INTENT(IN) argument that must be scalar of type default integer.
VALUE (optional)
is assigned the value of the argument, or a string of blanks if the value is unknown. It is an INTENT(OUT) argument that must be scalar of type default character.
LENGTH (optional)
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. It is an INTENT(OUT) argument that must be scalar of type default integer.
STATUS (optional)
is assigned a status value. It is an INTENT(OUT) argument that must be scalar of type default integer.
It has one of the following values:
  • 1 if the argument retrieval fails
  • -1 if the VALUE argument is present and has a value 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
The following is sample output generated by the above program:
$ a.out aa bb
a.out       (followed by two spaces)
5
0