1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
<html>
<head>
<title> </title>
<style>
px {font-family: "Lucida Console", Monaco, monospace }
p { font-size:100%; line-height:1.1em; }
body {xfont-style: sans-serif}
body {
color:#333; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:1em; line-height:1.3em; }
a:visited { color:#666; }
h1,h2,h3,h4,h5,h6 { color:#333; font-family:georgia, verdana, sans-serif; }
h1 { font-size:150%; page-break-before:auto;background-color: #aaaaff}
h2 { font-size:143%;color:teal; }
h3 { font-size:134%;color:blue; }
h4 { font-size:120%;color:gray; }
img { max-width: 55em}
p{ padding: 0;margin:0; }
p{ padding-right:1.4em; }
p{ padding-bottom:0.1em; }
p{ padding-top:1em; }
p{ whitespace: pre-wrap; }
h5,h6 { font-size:100% }
a.nav,a:link.nav, a:visited.nav { background-color:#FFF; color:#000; }
XXtable { border:double #000; border-collapse:collapse; }
XXtable { border-collapse:collapse; }
XXtd { border:thin solid #888; }
XXtd { border:none; }
li { margin-bottom:0.5em; }
blockquote { display:block; font-size:100%; line-height:1.1em; margin:0 0 0.5em; padding:0 2.5em; }
pre { background-color:#DDD; font-size:100%; overflow:auto; padding:1em; }
a,li span { color:#000; }
a:hover, a.nav:hover, a:hover math { background-color:#000; color:#FFF; }
#Container { margin:0 10px; text-align:center; background-color: #BBB}
#Content { border-top:none; margin:auto; padding:0.3em; text-align:left; width:100%; max-width:55em; background:#FFF}
span.webName { font-size:.5em; }
textarea#content { font-size: 1em; line-height: 1.125; }
h1#pageName { line-height:1em; margin:0.2em 0 0.2em 0; padding:0; }
.property { color:#666; font-size:100%; }
a.existingWikiWord[title]{ //border: 1px dashed #BBB; }
.byline { color:#666; font-size:1.0em; font-style:italic; margin-bottom:1em; padding-top:1px; }
</style>
</head>
<BODY bgcolor=#F0F0F0 text=#000000 link=#0000ff vlink=#C000C0 alink=#ff0000><A NAME=top></A>
<!--
<h5><a href="https://github.com/urbanjost/M_CLI2">[UP]</a></h5>
<button type="button" onclick="javascript:history.back()">Back</button>
-->
<div id="Container">
<div id="Content">
<CENTER>
<H1><HR><I>Manual Reference Pages - </I><NOBR>specified (3m_cli2)</NOBR><HR></H1>
</CENTER>
<A name=0>
<H3>NAME</H3>
</A>
<BLOCKQUOTE>
specified(3f) - [ARGUMENTS:M_CLI2] return true if keyword was present
on command line
(LICENSE:PD)
<P>
</BLOCKQUOTE>
<A name=contents></A><H3>CONTENTS</H3></A>
<BLOCKQUOTE>
<A HREF=#1>Synopsis</A><BR>
<A HREF=#2>Description</A><BR>
<A HREF=#3>Options</A><BR>
<A HREF=#4>Returns</A><BR>
<A HREF=#5>Example</A><BR>
<A HREF=#6>Author</A><BR>
<A HREF=#7>License</A><BR>
</BLOCKQUOTE>
<A name=8>
<H3>SYNOPSIS</H3>
</A>
<BLOCKQUOTE>
elemental impure function specified(name)
<P>
<PRE>
character(len=*),intent(in) :: name
logical :: specified
<P>
</PRE>
</BLOCKQUOTE>
<A name=2>
<H3>DESCRIPTION</H3>
</A>
<BLOCKQUOTE>
<P>
specified(3f) returns .true. if the specified keyword was present on
the command line.
<P>
M_CLI2 intentionally does not have validators except for SPECIFIED(3f)
and of course a check whether the input conforms to the type when
requesting a value (with get_args(3f) or the convenience functions
like inum(3f)).
<P>
Fortran already has powerful validation capabilities. Logical
expressions ANY(3f) and ALL(3f) are standard Fortran features which
easily allow performing the common validations for command line
arguments without having to learn any additional syntax or methods.
</BLOCKQUOTE>
<A name=3>
<H3>OPTIONS</H3>
</A>
<BLOCKQUOTE>
<P>
<TABLE cellpadding=3>
<TR valign=top><TD width=6% nowrap>
<B>NAME</B> </TD><TD valign=bottom>
name of commandline argument to query the presence of. Long
names should always be used.
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<A name=4>
<H3>RETURNS</H3>
</A>
<BLOCKQUOTE>
<TABLE cellpadding=3>
<TR valign=top><TD colspan=2>
<B>SPECIFIED</B> </TD></TR><TR valign=top><TD width=6%> </TD><TD>
returns .TRUE. if specified NAME was present on the command
line when the program was invoked.
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<A name=5>
<H3>EXAMPLE</H3>
</A>
<BLOCKQUOTE>
Sample program:
<P>
<PRE>
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
<P>
! Define args
integer,allocatable :: ints(:)
real,allocatable :: floats(:)
logical :: flag
character(len=:),allocatable :: color
character(len=:),allocatable :: list(:)
integer :: i
<P>
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’)
<P>
write(*,*)’color=’,color
write(*,*)’flag=’,flag
write(*,*)’ints=’,ints
write(*,*)’floats=’,floats
<P>
write(*,*)’was -flag specified?’,specified(’flag’)
<P>
! elemental
write(*,*)specified([’floats’,’ints ’])
<P>
! 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 ’]))
<P>
! For mutually exclusive
if (all(specified([’floats’,’ints ’])))then
write(*,*)’You specified both names --ints and --floats’
endif
<P>
! For required parameter
if (.not.any(specified([’floats’,’ints ’])))then
write(*,*)’You must specify --ints or --floats’
endif
<P>
! 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])
<P>
! 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
<P>
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
<P>
if(size(ints).eq.3)then
write(*,*)’ints(:) has expected number of values’
else
write(*,*)’ints(:) does not have expected number of values’
endif
<P>
end program demo_specified
<P>
</PRE>
Default output
<P>
<PRE>
> 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
<P>
</PRE>
</BLOCKQUOTE>
<A name=6>
<H3>AUTHOR</H3>
</A>
<BLOCKQUOTE>
John S. Urban, 2019
</BLOCKQUOTE>
<A name=7>
<H3>LICENSE</H3>
</A>
<BLOCKQUOTE>
Public Domain
</BLOCKQUOTE>
<P><HR>
<TABLE width=100%><TR> <TD width=33%><I>Nemo Release 3.1</I></TD> <TD width=33% align=center>specified (3m_cli2)</TD> <TD align=right width=33%><I>February 10, 2023</I></TD> </TR></TABLE><FONT SIZE=-1>Generated by <A HREF="http://www.squarebox.co.uk/download/manServer.shtml">manServer 1.08</A> from ecdc2e3c-a2c8-48f2-ad7e-3ec7b09bdfdb using man macros.</FONT>
<br><br><center><img src="images/specified.gif"></center>
</div>
</div>
</body>
</HTML>
|