get_args(3m_cli2)
π get_args β the get_args(3f) page, bestie edition π
okay so you're in the 3m_cli2 manual, section 3, and this whole page is about get_args(3f). yes the manual name is get_args(3m_cli2), i know, i know, it's giving "two names for one function" energy but that's just how Fortran rolls. π
β¨ NAME β¨
get_args(3f) β [ARGUMENTS:M_CLI2] it returns your keyword values when you're parsing command line arguments. oh and btw, the license on this one is PD (public domain, slay, it's free).
π¦ SYNOPSIS π¦
so here's the whole squad β get_args(3f) plus its lil convenience besties:
use M_CLI2, only : get_args
! convenience functions
use M_CLI2, only : dget, iget, lget, rget, sget, cget
use M_CLI2, only : dgets, igets, lgets, rgets, sgets, cgets
subroutine get_args(name,value,delimiters)
character(len=*),intent(in) :: name
type(${TYPE}),allocatable,intent(out) :: value(:)
! or
type(${TYPE}),allocatable,intent(out) :: value
character(len=*),intent(in),optional :: delimiters
where ${TYPE} may be from the set
{real,doubleprecision,integer,logical,complex,character(len=:)}
and ${TYPE} can literally be any one of those six β real, doubleprecision, integer, logical, complex, or character(len=:). pick your fighter. π
πΈ DESCRIPTION πΈ
GET_ARGS(3f) hands you back the value of keywords after SET_ARGS(3f) has already done the whole parse-the-command-line thing. so the order is: set it up, then get it out. periodt.
if you're working with fixed-length CHARACTER variables, go look at GET_ARGS_FIXED_LENGTH(3f) instead. and for fixed-size arrays? that's GET_ARGS_FIXED_SIZE(3f), bestie. different page, different vibe. π
as a lil convenience moment, you can pass multiple pairs of keywords and variables in one call β but only if and only if every single value is a scalar and the CHARACTER variables are fixed-length or pre-allocated. that's the rule, no exceptions, i don't make them. π
π OPTIONS π
NAMEβ the name of the commandline argument you want the value of. that's it, that's the whole job.VALUEβ the variable that holds the returned value. the kind of that variable is what tells the routine what type to return, so it's the one doing the deciding here. it can be a scalar or an allocatable array. and heads up: if the type isCHARACTER, the scalar has to have an allocatable length, no cap. π«ΆDELIMITERSβ by default, the delimiters for array values are comma, colon, and whitespace. you can pass a string with an alternate list of delimiter characters if you want to switch it up. your call, main character. β¨
π CONVENIENCE FUNCTIONS π
these are the shortcuts, the little helpers that stand in for calls to get_args(3f) β one for each supported default intrinsic type:
- scalars β
dget(3f),iget(3f),lget(3f),rget(3f),sget(3f),cget(3f) - vectors β
dgets(3f),igets(3f),lgets(3f),rgets(3f),sgets(3f),cgets(3f)
and the letter decoding, because i know you're wondering: D is for DOUBLEPRECISION, I for INTEGER, L for LOGICAL, R for REAL, S for string (CHARACTER), and C for COMPLEX. iykyk. π§
also, if you call these functions with no argument at all, they return the UNNAMED array, converted to the specified type. cute, right?
π₯ EXAMPLE π₯
here's the sample program, straight up:
program demo_get_args
use M_CLI2, only : filenames=>unnamed, set_args, get_args
implicit none
integer :: i
! Define ARGS
real :: x, y, z
real,allocatable :: p(:)
character(len=:),allocatable :: title
logical :: l, lbig
! Define and parse (to set initial values) command line
! o only quote strings and use double-quotes
! o set all logical values to F or T.
call set_args(' &
& -x 1 -y 2 -z 3 &
& -p -1,-2,-3 &
& --title "my title" &
& -l F -L F &
& --label " " &
& ')
! Assign values to elements
! Scalars
call get_args('x',x,'y',y,'z',z,'l',l,'L',lbig)
! Allocatable string
call get_args('title',title)
! Allocatable arrays
call get_args('p',p)
! Use values
write(*,'(1x,g0,"=",g0)')'x',x, 'y',y, 'z',z
write(*,*)'p=',p
write(*,*)'title=',title
write(*,*)'l=',l
write(*,*)'L=',lbig
if(size(filenames) > 0)then
write(*,'(i6.6,3a)')(i,'[',filenames(i),']',i=1,size(filenames))
endif
end program demo_get_args
like, look at it β scalars in one call, allocatable string, allocatable array, all vibing. that's the whole point of the multiple-pairs thing. π
π AUTHOR π
John S. Urban, 2019. legend behavior, honestly. π«‘
π LICENSE π
Public Domain. do whatever, it's yours. π
and that's the whole page, bestie β this came to you from the get_args(3m_cli2) manual, February 10, 2023, and yes the footer says the exact same thing as the title because manpages love symmetry. go parse something iconic. π
β¨
π¦ 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