]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. index:: GETARG, command-line arguments, arguments, to program | |
7 | ||
8 | .. _getarg: | |
9 | ||
10 | GETARG --- Get command line arguments | |
11 | ************************************* | |
12 | ||
13 | .. function:: GETARG(POS, VALUE) | |
14 | ||
15 | Retrieve the :samp:`{POS}` -th argument that was passed on the | |
16 | command line when the containing program was invoked. | |
17 | ||
18 | :param POS: | |
19 | Shall be of type ``INTEGER`` and not wider than | |
20 | the default integer kind; :samp:`{POS}` \geq 0 | |
21 | ||
22 | :param VALUE: | |
23 | Shall be of type ``CHARACTER`` and of default | |
24 | kind. | |
25 | ||
26 | :return: | |
27 | After ``GETARG`` returns, the :samp:`{VALUE}` argument holds the | |
28 | :samp:`{POS}` th command line argument. If :samp:`{VALUE}` cannot hold the | |
29 | argument, it is truncated to fit the length of :samp:`{VALUE}`. If there are | |
30 | less than :samp:`{POS}` arguments specified at the command line, :samp:`{VALUE}` | |
31 | will be filled with blanks. If :samp:`{POS}` = 0, :samp:`{VALUE}` is set | |
32 | to the name of the program (on systems that support this feature). | |
33 | ||
34 | Standard: | |
35 | GNU extension | |
36 | ||
37 | Class: | |
38 | Subroutine | |
39 | ||
40 | Syntax: | |
41 | .. code-block:: fortran | |
42 | ||
43 | CALL GETARG(POS, VALUE) | |
44 | ||
45 | Example: | |
46 | .. code-block:: fortran | |
47 | ||
48 | PROGRAM test_getarg | |
49 | INTEGER :: i | |
50 | CHARACTER(len=32) :: arg | |
51 | ||
52 | DO i = 1, iargc() | |
53 | CALL getarg(i, arg) | |
54 | WRITE (*,*) arg | |
55 | END DO | |
56 | END PROGRAM | |
57 | ||
58 | See also: | |
59 | GNU Fortran 77 compatibility function: | |
60 | :ref:`IARGC` | |
61 | Fortran 2003 functions and subroutines: | |
62 | :ref:`GET_COMMAND`, | |
63 | :ref:`GET_COMMAND_ARGUMENT`, | |
3ed1b4ce | 64 | :ref:`COMMAND_ARGUMENT_COUNT` |