Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EELS2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Karl-Michael Schindler
EELS2
Commits
3cad2fb7
Commit
3cad2fb7
authored
1 year ago
by
kamischi
Browse files
Options
Downloads
Patches
Plain Diff
add examples
parent
da237d2e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/getopt-libs/Examples/getopt_example.f90
+39
-0
39 additions, 0 deletions
source/getopt-libs/Examples/getopt_example.f90
source/getopt-libs/Examples/getopt_long_example.f90
+58
-0
58 additions, 0 deletions
source/getopt-libs/Examples/getopt_long_example.f90
with
97 additions
and
0 deletions
source/getopt-libs/Examples/getopt_example.f90
0 → 100644
+
39
−
0
View file @
3cad2fb7
!***********************************************************************************************************************************
program
getopt_example
use
sufr_getopt
,
only
:
getopt_t
,
getopt
,
optarg
,
getopt_help
implicit
none
character
::
option
,
optStr
*
(
99
)
! Set the option string for short options. Only specify the character after the dash (e.g. 'a' for -a). Characters followed
! by a colon (:) have a required argument:
optstr
=
'af:hx'
do
! scan all the command-line parameters
! getopt() returns a single character" ">","!",".", or the short-option character (e.g. "a" for -a).
! It also sets this 'global' variable through the SUFR_getopt module:
! - optArg: the argument following the option (if required and present)
option
=
getopt
(
trim
(
optstr
))
! Do different things depending on the option returned:
select
case
(
option
)
case
(
'>'
)
! Last parameter
if
(
command_argument_count
()
.eq.
0
)
call
getopt_help
(
trim
(
optstr
))
! No parameters found - print help
exit
case
(
'!'
)
! Unknown option (starting with "-" or "--")
write
(
*
,
'(A)'
)
'WARNING: unknown option: '
//
trim
(
optarg
)//
' Use -h for a list of valid options'
case
(
'a'
)
write
(
*
,
'(A)'
)
'Found option: -'
//
option
case
(
'f'
)
write
(
*
,
'(A)'
)
'Found option: -'
//
option
//
' '
//
trim
(
optarg
)
case
(
'h'
)
call
getopt_help
(
trim
(
optstr
))
case
(
'.'
)
! Parameter is not an option (i.e., it doesn't start with "-" or "--")
write
(
*
,
'(A)'
)
'Found non-option element: '
//
trim
(
optarg
)
case
default
write
(
*
,
'(A)'
)
'Option ignored: -'
//
option
end
select
end
do
end
program
getopt_example
!***********************************************************************************************************************************
This diff is collapsed.
Click to expand it.
source/getopt-libs/Examples/getopt_long_example.f90
0 → 100644
+
58
−
0
View file @
3cad2fb7
!***********************************************************************************************************************************
program
getopt_long_example
use
sufr_getopt
,
only
:
getopt_t
,
getopt_long
,
longoption
,
optarg
,
getopt_long_help
implicit
none
integer
::
Np
character
::
option
! Set up the longopts struct to define the valid options: short option, long option, argument (0/1), short description:
type
(
getopt_t
)
::
longopts
(
4
)
=
[
&
getopt_t
(
'a'
,
'all'
,
0
,
'Select all'
),
&
getopt_t
(
'f'
,
'file'
,
1
,
'Specify input file'
),
&
getopt_t
(
'h'
,
'help'
,
0
,
'Print help'
),
&
getopt_t
(
''
,
'ignore'
,
0
,
''
)
]
np
=
0
do
! scan all the command-line parameters
! getopt_long() returns a single character" ">","!",".", or the short-option character (e.g. "a" for -a).
! It also sets two 'global' variables through the SUFR_getopt module:
! - longOption: the full option (e.g. "-a" or "--all") including the dashes
! - optArg: the argument following the option (if required and present)
option
=
getopt_long
(
longopts
)
! Do different things depending on the option returned:
select
case
(
option
)
case
(
'>'
)
! Last parameter
if
(
command_argument_count
()
.eq.
0
)
call
getopt_long_help
(
longopts
)
! No parameters found - print help
exit
case
(
'!'
)
! Unknown option (starting with "-" or "--")
write
(
*
,
'(A)'
)
'WARNING: unknown option: '
//
trim
(
optarg
)//
' Use --help for a list of valid options'
case
(
'a'
)
write
(
*
,
'(A)'
)
'Found option: '
//
trim
(
longoption
)
case
(
'f'
)
write
(
*
,
'(A)'
)
'Found option: '
//
trim
(
longoption
)//
' '
//
trim
(
optarg
)
case
(
'h'
)
call
getopt_long_help
(
longopts
)
case
(
'.'
)
! Parameter is not an option (i.e., it doesn't start with "-" or "--")
write
(
*
,
'(A)'
)
'Found parameter: '
//
trim
(
optarg
)
np
=
np
+
1
case
default
select
case
(
longoption
)
case
(
'--ignore'
)
! Note that --ignore was not given a short equivalent
write
(
*
,
'(A)'
)
'Found option: '
//
trim
(
longoption
)
case
default
write
(
*
,
'(A)'
)
'Valid option unhandled: '
//
trim
(
longoption
)
end
select
end
select
end
do
if
(
np
.eq.
0
)
then
write
(
*
,
'(A)'
)
'No parameters found'
else
write
(
*
,
'(I0,A)'
)
np
,
' parameters found'
end
if
end
program
getopt_long_example
!***********************************************************************************************************************************
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment