18 PROGRAM optionparser_test
29 TYPE(optionparser) :: opt
30 INTEGER :: optind, optstatus
33 CHARACTER(len=80) :: name
36 DOUBLE PRECISION :: dval
37 TYPE(arrayof_integer) :: count_list
38 TYPE(arrayof_real) :: value_list
39 LOGICAL :: force, version
42 CHARACTER(len=1024) :: exp_res
43 TYPE(csv_record) :: csv_reader
44 CHARACTER(len=80) :: ccheck
45 INTEGER :: icheck, ier
47 DOUBLE PRECISION :: dcheck
51 opt = optionparser_new(description_msg= &
52 'Test program for the optionparser class, & 53 &it just tests the arguments.', &
54 usage_msg=
'Usage: optionparser_test [options] expected_result')
58 'short and long character option with default value')
60 'long integer option with default value')
62 'short and long real option with default value')
65 'long real option without default value')
67 'short and long double precision option with default value, & 68 &this should be a positive number')
70 'integer array option, a comma-separated list of values can be provided, & 71 &the default is partially displayed, in this case it is 1,2,3')
73 'real array option, a comma-separated list of values can be provided, & 74 &the default in this case does not exist')
76 'logical option, it cannot have a default value because it is .FALSE. by design')
77 CALL optionparser_add_count(opt,
'v',
'verbose', verbose, help= &
78 'count option without start value, it will be incremented at every appearence & 83 CALL optionparser_add_help(opt,
'h',
'help', help=
'show an help message and exit')
84 CALL optionparser_add(opt,
' ',
'version', version, help=
'show version and exit')
87 CALL optionparser_parse(opt, optind, optstatus)
89 IF (optstatus == optionparser_help)
THEN 91 ELSE IF (optstatus == optionparser_err)
THEN 92 WRITE(*,
'(A)')
'Error in command-line arguments' 96 WRITE(*,
'(A,1X,A)')
'optionparser_test 1.0' 99 IF (iargc() > optind)
THEN 100 WRITE(*,
'(A)')
'Error, zero or one non-option argument required' 114 IF (iargc() < optind)
THEN 118 CALL getarg(optind, exp_res)
119 CALL init(csv_reader, exp_res)
122 IF (ier /= 0 .OR. trim(ccheck) /= trim(name))
THEN 123 WRITE(*,
'(A)')
'Error in command-line argument --name' 128 IF (ier /= 0 .OR. icheck /= nx)
THEN 129 WRITE(*,
'(A)')
'Error in command-line argument --nx' 134 IF (ier /= 0 .OR. rcheck /= xval)
THEN 135 WRITE(*,
'(A)')
'Error in command-line argument --xval' 140 IF (ier /= 0 .OR. rcheck /= yval)
THEN 141 WRITE(*,
'(A)')
'Error in command-line argument --yval' 146 IF (ier /= 0 .OR. dcheck /= dval)
THEN 147 WRITE(*,
'(A)')
'Error in command-line argument --dval' 154 IF (ier /= 0 .OR. icheck /= verbose)
THEN 155 WRITE(*,
'(A)')
'Error in command-line argument --verbose' 163 END PROGRAM optionparser_test
Destructor for the optionparser class.
Constructor for the class csv_record.
Module for parsing command-line optons.
Utilities for managing files.
Methods for successively obtaining the fields of a csv_record object.
This module defines usefull general purpose function and subroutine.
Definitions of constants and functions for working with missing values.
Add a new option of a specific type.