get_command_argument
- Date:
02-07-2023
NAME
get_command_argument - Returns the specified command line argument
SYNOPSIS
call get_command_argument(arg_pos[, value, length, istatus])
STANDARDS
Fortran 2008
DESCRIPTION
The get_command_argument intrinsic subroutine returns the specified command line argument. This intrinsic accepts the following arguments:
- arg_pos
Specifies the position of the argument for which you want to retrieve information. Valid values range from 0 through command_argument_count. 0 indicates you want information about the name used on the command line to call the application. A value of 1 indicates you want information about the first argument; a value of 2 indicates you want information about the second argument, and so on.
This procedure returns a nonzero value if the value for arg_pos is not valid.
The arg_pos argument must be a scalar of type default integer.
- value
Returns the value given to argument arg_pos. If the value cannot be ascertained, value is filled with blanks. This argument must be a scalar of type default character.
- length
Returns the length of argument arg_pos. If the length cannot be ascertained, this argument returns 0. This argument must be a scalar of type default integer.
- istatus
Returns the condition of the data returned in the value and length arguments. The following values are returned:
- 0
The value argument returned the entire value of command line argument arg_pos.
- Positive nonzero value
The value argument is filled with blanks and length is zero because command line argument arg_pos could not be ascertained.
- -1
The data returned by the value argument was truncated and length indicates the size of the truncated data.
EXAMPLES
The following example can be inserted into your application to return the number of arguments passed to it, their names, and values:
program getargs
integer icmdargs, length, istatus, argposition
character :: argvalue*80
! Get the number of command line arguments
icmdargs = command_argument_count()
print *,'number of command arguments =',icmdargs
if ( icmdargs .ne. 0) then
do argposition = 1, icmdargs
call get_command_argument(argposition,argvalue,length,istatus)
if (istatus .eq. 0) then
print *,'argument ',argposition,' = ',argvalue
endif
enddo
endif
end program
SEE ALSO
get_command(3i), get_environment_variable(3i), command_argument_count(3i)