Obtain the command line argument at a given index
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | idx |
Index of command line argument, range [0:command_argument_count()] |
||
character(len=:), | intent(out), | allocatable | :: | arg |
Command line argument |
subroutine get_argument(idx, arg) !> Index of command line argument, range [0:command_argument_count()] integer, intent(in) :: idx !> Command line argument character(len=:), allocatable, intent(out) :: arg integer :: length, stat call get_command_argument(idx, length=length, status=stat) if (stat /= 0) then return endif allocate(character(len=length) :: arg, stat=stat) if (stat /= 0) then return endif if (length > 0) then call get_command_argument(idx, arg, status=stat) if (stat /= 0) then deallocate(arg) return end if end if end subroutine get_argument