public impure elemental function specified(key)
NAME
specified(3f) - [ARGUMENTS:M_CLI2] return true if keyword was present
on command line
(LICENSE:PD)
SYNOPSIS
elemental impure function specified(name)
character(len=*),intent(in) :: name
logical :: specified
DESCRIPTION
specified(3f) returns .true. if the specified keyword was present on
the command line.
OPTIONS
NAME name of commandline argument to query the presence of
RETURNS
SPECIFIED returns .TRUE. if specified NAME was present on the command
line when the program was invoked.
EXAMPLE
Sample program:
program demo_specified
use M_CLI2, only : set_args, get_args, specified
implicit none
! DEFINE ARGS
integer :: flag
integer,allocatable :: ints(:)
real,allocatable :: twonames(:)
! IT IS A BAD IDEA TO NOT HAVE THE SAME DEFAULT VALUE FOR ALIASED
! NAMES BUT CURRENTLY YOU STILL SPECIFY THEM
call set_args('-flag 1 -f 1 -ints 1,2,3 -i 1,2,3 -twonames 11.3 -T 11.3')
! ASSIGN VALUES TO ELEMENTS CONDITIONALLY CALLING WITH SHORT NAME
call get_args('flag',flag)
if(specified('f'))call get_args('f',flag)
call get_args('ints',ints)
if(specified('i'))call get_args('i',ints)
call get_args('twonames',twonames)
if(specified('T'))call get_args('T',twonames)
! IF YOU WANT TO KNOW IF GROUPS OF PARAMETERS WERE SPECIFIED USE
! ANY(3f) and ALL(3f)
write(*,*)specified(['twonames','T '])
write(*,*)'ANY:',any(specified(['twonames','T ']))
write(*,*)'ALL:',all(specified(['twonames','T ']))
! FOR MUTUALLY EXCLUSIVE
if (all(specified(['twonames','T '])))then
write(*,*)'You specified both names -T and -twonames'
endif
! FOR REQUIRED PARAMETER
if (.not.any(specified(['twonames','T '])))then
write(*,*)'You must specify -T or -twonames'
endif
! USE VALUES
write(*,*)'flag=',flag
write(*,*)'ints=',ints
write(*,*)'twonames=',twonames
end program demo_specified
AUTHOR
LICENSE
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
character(len=*), |
intent(in) |
|
| :: |
key | |
Return Value logical
Variables
Type | Visibility |
Attributes | | Name | | Initial | |
integer, |
public |
| :: |
place | | | |
Source Code
elemental impure function specified(key)
character(len=*),intent(in) :: key
logical :: specified
integer :: place
call locate_key(key,place) ! find where string is or should be
if(place.lt.1)then
specified=.false.
else
specified=present_in(place)
endif
end function specified