1
2
3
4
5
6program getopt_example
10
11 implicit none
12 character :: option, optStr*(99)
13
14
16
17
18 getopthelpheader =
'present some possibilities for the libSUFR getopt implementation'
20
21
22
23
24 optstr = 'af:hx'
25
26 do
27
28
29
30
31
32
33
34 option =
getopt(trim(optstr))
35
36
37 select case(option)
38 case('>')
39 if(command_argument_count().eq.0)
call getopt_help(trim(optstr), 1,1)
40 exit
41 case('!')
42 write(*,
'(A)')
'WARNING: unknown option: '//trim(
optarg)//
' Use -h for a list of valid options'
43 case('a')
44 write(*,'(A)') 'Found option: -'//option
45 case('f')
46 write(*,
'(A)')
'Found option: -'//option//
' '//trim(
optarg)
47 case('h')
49 stop
50 case('x')
51 write(*,'(A)') 'Found option: -'//option
52 case('.')
53 write(*,
'(A)')
'Found non-option element: '//trim(
optarg)
54 case default
55 write(*,'(A)') 'Option ignored: -'//option
56 end select
57 end do
58
59end program getopt_example
60
61
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 function getopt(optstr)
Parse a command-line parameter and return short options and their arguments. A warning is printed to ...
subroutine getopt_help(optstr, linebef, lineaft)
Print a help list of all short options and their required arguments.
character, dimension(999) getopthelpsyntax
The syntax line for the message printed by getopt(_long)_help()
Struct to define short and long options for getopt_long()