]>
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:: GET_COMMAND_ARGUMENT, command-line arguments, arguments, to program | |
7 | ||
8 | .. _get_command_argument: | |
9 | ||
10 | GET_COMMAND_ARGUMENT --- Get command line arguments | |
11 | *************************************************** | |
12 | ||
13 | .. function:: GET_COMMAND_ARGUMENT(NUMBER , VALUE, LENGTH, STATUS) | |
14 | ||
15 | Retrieve the :samp:`{NUMBER}` -th argument that was passed on the | |
16 | command line when the containing program was invoked. | |
17 | ||
18 | :param NUMBER: | |
19 | Shall be a scalar of type ``INTEGER`` and of | |
20 | default kind, :samp:`{NUMBER}` \geq 0 | |
21 | ||
22 | :param VALUE: | |
23 | (Optional) Shall be a scalar of type ``CHARACTER`` | |
24 | and of default kind. | |
25 | ||
26 | :param LENGTH: | |
27 | (Optional) Shall be a scalar of type ``INTEGER`` | |
28 | and of default kind. | |
29 | ||
30 | :param STATUS: | |
31 | (Optional) Shall be a scalar of type ``INTEGER`` | |
32 | and of default kind. | |
33 | ||
34 | :return: | |
35 | After ``GET_COMMAND_ARGUMENT`` returns, the :samp:`{VALUE}` argument holds the | |
36 | :samp:`{NUMBER}` -th command line argument. If :samp:`{VALUE}` cannot hold the argument, it is | |
37 | truncated to fit the length of :samp:`{VALUE}`. If there are less than :samp:`{NUMBER}` | |
38 | arguments specified at the command line, :samp:`{VALUE}` will be filled with blanks. | |
39 | If :samp:`{NUMBER}` = 0, :samp:`{VALUE}` is set to the name of the program (on | |
40 | systems that support this feature). The :samp:`{LENGTH}` argument contains the | |
41 | length of the :samp:`{NUMBER}` -th command line argument. If the argument retrieval | |
42 | fails, :samp:`{STATUS}` is a positive number; if :samp:`{VALUE}` contains a truncated | |
43 | command line argument, :samp:`{STATUS}` is -1; and otherwise the :samp:`{STATUS}` is | |
44 | zero. | |
45 | ||
46 | Standard: | |
47 | Fortran 2003 and later | |
48 | ||
49 | Class: | |
50 | Subroutine | |
51 | ||
52 | Syntax: | |
53 | .. code-block:: fortran | |
54 | ||
55 | CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS]) | |
56 | ||
57 | Example: | |
58 | .. code-block:: fortran | |
59 | ||
60 | PROGRAM test_get_command_argument | |
61 | INTEGER :: i | |
62 | CHARACTER(len=32) :: arg | |
63 | ||
64 | i = 0 | |
65 | DO | |
66 | CALL get_command_argument(i, arg) | |
67 | IF (LEN_TRIM(arg) == 0) EXIT | |
68 | ||
69 | WRITE (*,*) TRIM(arg) | |
70 | i = i+1 | |
71 | END DO | |
72 | END PROGRAM | |
73 | ||
74 | See also: | |
75 | :ref:`GET_COMMAND`, | |
3ed1b4ce | 76 | :ref:`COMMAND_ARGUMENT_COUNT` |