1
2
3
4
5
6program getopt_long_example
11
12 implicit none
13 integer :: nPosArg
14 character :: option
15 logical, parameter :: getoptDebug = .true.
16
17
18 type(getopt_t) :: longopts(5) = [ &
19 getopt_t(
'a',
'all', 0,
'Select all'), &
20 getopt_t(
'f',
'file', 1,
'Specify input file'), &
22 getopt_t(
'h',
'help', 0,
'Print help'), &
24
25
26
28
29
30 getopthelpheader =
'present some possibilities for the libSUFR getopt implementation'
32
33
34 nposarg = 0
35 do
36
37
38
39
40
41
42
43
45
46
47 select case(option)
48 case('>')
50 exit
51 case('!')
52
54 case('a')
55 if(getoptdebug)
write(*,
'(A)')
'Found option: '//trim(
longoption)
56 case('f')
57 if(getoptdebug)
write(*,
'(A)')
'Found option: '//trim(
longoption)//
' '//trim(
optarg)
58 case('h')
60 stop
61 case('.')
62 nposarg = nposarg + 1
63 if(getoptdebug)
write(*,
'(A,I0,A)')
'Found parameter ',nposarg,
': '//trim(
optarg)
64
65 case default
67 case('--ignore')
68 if(getoptdebug)
write(*,
'(A)')
'Found option: '//trim(
longoption)
69 case default
71 end select
72 end select
73 end do
74
75 if(getoptdebug) then
76 if(nposarg.eq.0) then
77 write(*,'(A)') 'No positional arguments found'
78 else
79 write(*,'(I0,A)') nposarg, ' positional arguments found'
80 end if
81 end if
82
83end program getopt_long_example
84
85
Provides all constants in the library, and routines to define them.
subroutine set_sufr_constants
Define the values of all the constants used in this package.
Procedures for a getopt and getopt_long implementation to parse command-line parameters in Fortran.
character, dimension(999) optarg
The option's argument, if required and present.
character, dimension(999) getopthelpheader
The header line for the message printed by getopt(_long)_help()
character, dimension(longoptlen+2) longoption
The short or long option found, including leading dash(es)
subroutine getopt_long_help(longopts, linebef, lineaft)
Print a help list of all short/long options, their required arguments and their descriptions.
character function getopt_long(longopts)
Parse a command-line parameter and return short and/or long options and their arguments....
character, dimension(999) getopthelpsyntax
The syntax line for the message printed by getopt(_long)_help()
System-related procedures.
subroutine quit_program_error(message, status)
Print an error message to StdErr and stop the execution of the current program.
Struct to define short and long options for getopt_long()