Skip to content
Stefano Zaghi edited this page May 26, 2015 · 2 revisions

Running the provided test program, Test_Driver -h, a taste of FLAP is served:

usage:  Test_Driver [value] --string value [--integer_ex value] [--integer value] [--real value] [--boolean] [--boolean_val value] [--integer_list value#1 value#2 value#3] [--help] [--version]
Toy program for testing FLAP
Required switches:
   --string value, -s value
          String input
Optional switches:
   value
          1-th argument
          default value 1.0
          Positional real input
   --integer_ex value, -ie value
          default value -1
          mutually exclude "--integer"
          Exclusive integer input
   --integer value, -i value, value in: (1,3,5)
          default value 1
          mutually exclude "--integer_ex"
          Integer input with fixed range
   --real value, -r value
          default value 1.0
          Real input
   --boolean, -b
          default value .false.
          Boolean input
   --boolean_val value, -bv value
          default value .true.
          Valued boolean input
   --integer_list value#1 value#2 value#3, -il value#1 value#2 value#3
          default value 1 8 32
          Integer list input
   --help, -h
          Print this help message
   --version, -v
          Print version

Examples:
   Test_Driver -s 'Hello FLAP'
   Test_Driver -s 'Hello FLAP' -i -2 # printing error...
   Test_Driver -s 'Hello FLAP' -i 3 -ie 1 # printing error...
   Test_Driver -s 'Hello FLAP' -i 3 -r 33.d0
   Test_Driver -s 'Hello FLAP' --integer_list 10 -3 87
   Test_Driver 33.0 -s 'Hello FLAP' -i 5
   Test_Driver --string 'Hello FLAP' --boolean

Not so bad for just a very few statements as the following:

...
! initializing Command Line Interface
call cli%init(progname    = 'Test_Driver',                                                &
              version     = 'v2.1.5',                                                     &
              authors     = 'Stefano Zaghi',                                              &
              license     = 'MIT',                                                        &
              description = 'Toy program for testing FLAP',                               &
              examples    = ["Test_Driver -s 'Hello FLAP'                               ",&
                             "Test_Driver -s 'Hello FLAP' -i -2 # printing error...     ",&
                             "Test_Driver -s 'Hello FLAP' -i 3 -ie 1 # printing error...",&
                             "Test_Driver -s 'Hello FLAP' -i 3 -r 33.d0                 ",&
                             "Test_Driver -s 'Hello FLAP' --integer_list 10 -3 87       ",&
                             "Test_Driver 33.0 -s 'Hello FLAP' -i 5                     ",&
                             "Test_Driver --string 'Hello FLAP' --boolean               "])
! setting Command Line Argumenst
call cli%add(switch='--string',switch_ab='-s',help='String input',required=.true.,act='store',error=error)
call cli%add(switch='--integer_ex',switch_ab='-ie',help='Exclusive integer input',required=.false.,act='store',def='-1',error=error)
call cli%add(switch='--integer',switch_ab='-i',help='Integer input with fixed range',required=.false.,act='store',&
             def='1',choices='1,3,5',exclude='-ie',error=error)
call cli%add(switch='--real',switch_ab='-r',help='Real input',required=.false.,act='store',def='1.0',error=error)
call cli%add(switch='--boolean',switch_ab='-b',help='Boolean input',required=.false.,act='store_true',def='.false.',&
             error=error)
call cli%add(switch='--boolean_val',switch_ab='-bv',help='Valued boolean input',required=.false., act='store',&
             def='.true.',error=error)
call cli%add(switch='--integer_list',switch_ab='-il',help='Integer list input',required=.false.,act='store',&
             nargs='3',def='1 8 32',error=error)
call cli%add(positional=.true.,position=1,help='Positional real input',required=.false.,def='1.0',error=error)
! parsing Command Line Interface
call cli%parse(error=error)
if (error/=0) stop
...

For a practical example of FLAP usage see POG source file at line 85.

Clone this wiki locally