specified(3m_cli2)
πΈ specified(3m_cli2) β the vibe check for your command line πΈ
okay bestie, welcome to the specified(3f) page from the M_CLI2 module β it lives under [ARGUMENTS:M_CLI2] and its license is PD (that's Public Domain, iconic behavior honestly).
β¨ NAME β¨
specified(3f) β [ARGUMENTS:M_CLI2] β it returns true if a keyword was actually present on the command line. (LICENSE:PD) π«Ά
π SYNOPSIS π
elemental impure function specified(name)
character(len=*),intent(in) :: name
logical :: specified
like. it's giving "ask and you shall receive a logical." periodt. π
π¦ DESCRIPTION π¦
So specified(3f) hands you back .true. if the keyword you asked about was present on the command line. That's it. That's the whole job. no cap. β¨
Now here's the tea: M_CLI2 intentionally does not have validators β the only exceptions being SPECIFIED(3f) and, obvi, a check whether the input actually conforms to the type when you request a value (that's via get_args(3f) or the lil convenience functions like inum(3f)). π
Why tho? Because Fortran already has powerful validation capabilities and honestly it ate. The logical expressions ANY(3f) and ALL(3f) are standard Fortran features, and they lowkey let you do all the common validations for command line arguments without having to learn any additional syntax or methods. no extra homework. we love that for us. π
π OPTIONS π
NAMEβ the name of the commandline argument you wanna query the presence of. Long names should always be used. iykyk, do not be out here using the short one, bestie. π
β RETURNS β
SPECIFIEDβ returns.TRUE.if the specifiedNAMEwas present on the command line when the program was invoked. boom. done. π
π₯ EXAMPLE π₯
Sample program, look at her:
program demo_specified
use, intrinsic :: iso_fortran_env, only : &
& stderr=>ERROR_UNIT, stdin=>INPUT_UNIT, stdout=>OUTPUT_UNIT
use M_CLI2, only : set_args, igets, rgets, specified, sget, lget
implicit none
! Define args
integer,allocatable :: ints(:)
real,allocatable :: floats(:)
logical :: flag
character(len=:),allocatable :: color
character(len=:),allocatable :: list(:)
integer :: i
call set_args('&
& --color:c "red" &
& --flag:f F &
& --ints:i 1,10,11 &
& --floats:T 12.3, 4.56 &
& ')
ints=igets('ints')
floats=rgets('floats')
flag=lget('flag')
color=sget('color')
write(*,*)'color=',color
write(*,*)'flag=',flag
write(*,*)'ints=',ints
write(*,*)'floats=',floats
write(*,*)'was -flag specified?',specified('flag')
! elemental
write(*,*)specified(['floats','ints '])
! If you want to know if groups of parameters were specified use
! ANY(3f) and ALL(3f)
write(*,*)'ANY:',any(specified(['floats','ints ']))
write(*,*)'ALL:',all(specified(['floats','ints ']))
! For mutually exclusive
if (all(specified(['floats','ints '])))then
write(*,*)'You specified both names --ints and --floats'
endif
! For required parameter
if (.not.any(specified(['floats','ints '])))then
write(*,*)'You must specify --ints or --floats'
endif
! check if all values are in range from 10 to 30 and even
write(*,*)'are all numbers good?',all([ints >= 10,ints <= 30,(ints/2)*2 == ints])
! perhaps you want to check one value at a time
do i=1,size(ints)
write(*,*)ints(i),[ints(i) >= 10,ints(i) <= 30,(ints(i)/2)*2 == ints(i)]
if(all([ints(i) >= 10,ints(i) <= 30,(ints(i)/2)*2 == ints(i)]) )then
write(*,*)ints(i),'is an even number from 10 to 30 inclusive'
else
write(*,*)ints(i),'is not an even number from 10 to 30 inclusive'
endif
enddo
list = [character(len=10) :: 'red','white','blue']
if( any(color == list) )then
write(*,*)color,'matches a value in the list'
else
write(*,*)color,'not in the list'
endif
if(size(ints).eq.3)then
write(*,*)'ints(:) has expected number of values'
else
write(*,*)'ints(:) does not have expected number of values'
endif
end program demo_specified
Default output β she's serving exactly this, no edits:
> color=red
> flag= F
> ints= 1 10 11
> floats= 12.3000002 4.55999994
> was -flag specified? F
> F F
> ANY: F
> ALL: F
> You must specify --ints or --floats
> 1 F T F
> 1 is not an even number from 10 to 30 inclusive
> 10 T T T
> 10 is an even number from 10 to 30 inclusive
> 11 T T F
> 11 is not an even number from 10 to 30 inclusive
> red matches a value in the list
> ints(:) has expected number of values
π AUTHOR π
John S. Urban, 2019. the literal main character. π
π· LICENSE π·
Public Domain β free as a butterfly, go wild bestie π¦
and that's the whole page, bestie!! this lil doc came from specified(3m_cli2), dated February 10, 2023. go forth and check your command lines. mwah π
πβ¨
π¦ where this page comes from
- ubuntu resolute: libfortran-cli2-dev 3.2.0-6 Β· UNLICENSE
- ubuntu stonking: libfortran-cli2-dev 3.2.0-13 Β· UNLICENSE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms