NAME
M_CLI2(3fm) - [ARGUMENTS::M_CLI2::INTRO] - command line argument
parsing using a prototype command
(LICENSE:PD)
SYNOPSIS
Available procedures and variables:
use M_CLI2, only : set_args, get_args, unnamed, remaining, args
use M_CLI2, only : get_args_fixed_length, get_args_fixed_size
use M_CLI2, only : specified
! convenience functions
use M_CLI2, only : dget, iget, lget, rget, sget, cget
use M_CLI2, only : dgets, igets, lgets, rgets, sgets, cgets
DESCRIPTION
Allow for command line parsing much like standard Unix command line
parsing using a simple prototype.
Typically one call to SET_ARGS(3f) is made to define the command
arguments, set default values and parse the command line. Then a call
is made to the convenience commands based on GET_ARGS(3f) for each
command keyword to obtain the argument values.
The documentation for SET_ARGS(3f) and GET_ARGS(3f) provides further
details.
EXAMPLE
Sample program using type conversion routines
program demo_M_CLI2
use M_CLI2, only : set_args, get_args
use M_CLI2, only : filenames=>unnamed
use M_CLI2, only : get_args_fixed_length, get_args_fixed_size
implicit none
integer :: i
integer,parameter :: dp=kind(0.0d0)
!
! DEFINE ARGS
real :: x, y, z
real(kind=dp),allocatable :: point(:)
logical :: l, lbig
logical,allocatable :: logicals(:)
character(len=:),allocatable :: title ! VARIABLE LENGTH
character(len=40) :: label ! FIXED LENGTH
real :: p(3) ! FIXED SIZE
logical :: logi(3) ! FIXED SIZE
!
! DEFINE AND PARSE (TO SET INITIAL VALUES) COMMAND LINE
! o set a value for all keywords.
! o double-quote strings
! o set all logical values to F or T.
! o value delimiter is comma, colon, or space
call set_args(' &
& -x 1 -y 2 -z 3 &
& -p -1 -2 -3 &
& --point 11.11, 22.22, 33.33e0 &
& --title "my title" -l F -L F &
& --logicals F F F F F &
& -logi F T F &
& --label " " &
! note space between quotes is required
& ')
! ASSIGN VALUES TO ELEMENTS
call get_args('x',x) ! SCALARS
call get_args('y',y)
call get_args('z',z)
call get_args('l',l)
call get_args('L',lbig)
call get_args('title',title) ! ALLOCATABLE STRING
call get_args('point',point) ! ALLOCATABLE ARRAYS
call get_args('logicals',logicals)
!
! for NON-ALLOCATABLE VARIABLES
! for non-allocatable string
call get_args_fixed_length('label',label)
! for non-allocatable arrays
call get_args_fixed_size('p',p)
call get_args_fixed_size('logi',logi)
!
! USE VALUES
write(*,*)'x=',x, 'y=',y, 'z=',z, x+y+z
write(*,*)'p=',p
write(*,*)'point=',point
write(*,*)'title=',title
write(*,*)'label=',label
write(*,*)'l=',l
write(*,*)'L=',lbig
write(*,*)'logicals=',logicals
write(*,*)'logi=',logi
!
! unnamed strings
!
if(size(filenames).gt.0)then
write(*,'(i6.6,3a)')(i,'[',filenames(i),']',i=1,size(filenames))
endif
!
end program demo_M_CLI2
AUTHOR
LICENSE
Variables
Type | Visibility |
Attributes | | Name | | Initial | |
logical, |
public, |
save | :: |
CLI_RESPONSE_FILE | = | .false. | |
character(len=:), |
public, |
allocatable | :: |
args(:) | | | |
logical, |
public, |
save | :: |
debug_m_cli2 | = | .false. | |
character(len=:), |
public, |
allocatable | :: |
remaining | | | |
character(len=:), |
public, |
allocatable | :: |
unnamed(:) | | | |
Interfaces
-
private function cgs(n)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value complex,
allocatable, (:)
-
private function cg()
Arguments
None
Return Value complex,
allocatable, (:)
-
private function dgs(n)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value real(kind=dp),
allocatable, (:)
-
private function dg()
Arguments
None
Return Value real(kind=dp),
allocatable, (:)
-
private subroutine get_anyarray_d(keyword, darray, delimiters)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
keyword | |
real(kind=dp), |
intent(out), |
|
allocatable | :: |
darray(:) | |
character(len=*), |
intent(in), |
optional |
| :: |
delimiters | |
-
private subroutine get_args_fixed_length_a_array(keyword, strings, delimiters)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
keyword | |
character(len=*), |
|
|
allocatable | :: |
strings(:) | |
character(len=*), |
intent(in), |
optional |
| :: |
delimiters | |
-
private function igs(n)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value integer,
allocatable, (:)
-
private function ig()
Arguments
None
Return Value integer,
allocatable, (:)
-
private function lgs(n)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value logical,
allocatable, (:)
-
private function lg()
Arguments
None
Return Value logical,
allocatable, (:)
-
private function rgs(n)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value real,
allocatable, (:)
-
private function rg()
Arguments
None
Return Value real,
allocatable, (:)
-
private function sgs(n, delims)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
character(len=*), |
intent(in), |
optional |
| :: |
delims | |
Return Value character(len=:),
allocatable, (:)
-
private function sg()
Arguments
None
Return Value character(len=:),
allocatable, (:)
Functions
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value complex
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value real(kind=dp)
Sample program:
Read more…
Arguments
None
Return Value character(len=:),
allocatable
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value integer
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value logical
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value real
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
n | |
Return Value character(len=:),
allocatable
public impure elemental function specified(key)
Sample program:
Read more…
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
key | |
Return Value logical
Subroutines
Typical usage:
Read more…
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in), |
optional |
| :: |
header | |
logical, |
intent(in), |
optional |
| :: |
stop | |
public subroutine set_args(prototype, help_text, version_text, string, ierr, errmsg)
Sample program:
Read more…
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
prototype | |
character(len=*), |
intent(in), |
optional |
| :: |
help_text(:) | |
character(len=*), |
intent(in), |
optional |
| :: |
version_text(:) | |
character(len=*), |
intent(in), |
optional |
| :: |
string | |
integer, |
intent(out), |
optional |
| :: |
ierr | |
character(len=:), |
intent(out), |
optional |
allocatable | :: |
errmsg | |