shorter logic for missing arguments

This commit is contained in:
Philip Eisenlohr 2023-07-11 12:35:23 -04:00
parent 295b5348f3
commit 70817606db
1 changed files with 11 additions and 8 deletions

View File

@ -59,6 +59,8 @@ subroutine CLI_init()
i i
integer, dimension(8) :: & integer, dimension(8) :: &
dateAndTime dateAndTime
logical :: &
hasArg
external :: & external :: &
quit quit
@ -109,6 +111,7 @@ subroutine CLI_init()
print'(1x,a,1x,2(i2.2,a),i2.2)', 'Time:',dateAndTime(5),':',dateAndTime(6),':',dateAndTime(7) print'(1x,a,1x,2(i2.2,a),i2.2)', 'Time:',dateAndTime(5),':',dateAndTime(6),':',dateAndTime(7)
do i = 1, command_argument_count() do i = 1, command_argument_count()
hasArg = i < command_argument_count()
arg = getArg(i) arg = getArg(i)
select case(trim(arg)) ! extract key select case(trim(arg)) ! extract key
case ('-h','--help') case ('-h','--help')
@ -155,25 +158,25 @@ subroutine CLI_init()
print'(1x,a,/)',' Prints this message and exits' print'(1x,a,/)',' Prints this message and exits'
call quit(0) ! normal Termination call quit(0) ! normal Termination
case ('-g', '--geom', '--geometry') case ('-g', '--geom', '--geometry')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --geom' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --geom'
geomArg = getArg(i+1) geomArg = getArg(i+1)
case ('-l', '--load', '--loadcase') case ('-l', '--load', '--loadcase')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --load' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --load'
loadArg = getArg(i+1) loadArg = getArg(i+1)
case ('-m', '--material', '--materialconfig') case ('-m', '--material', '--materialconfig')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --material' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --material'
materialArg = getArg(i+1) materialArg = getArg(i+1)
case ('-n', '--numerics', '--numericsconfig') case ('-n', '--numerics', '--numericsconfig')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --numerics' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --numerics'
numericsArg = getArg(i+1) numericsArg = getArg(i+1)
case ('-j', '--job', '--jobname') case ('-j', '--job', '--jobname')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --jobname' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --jobname'
solverJobname = getArg(i+1) solverJobname = getArg(i+1)
case ('-w', '--wd', '--workingdir', '--workingdirectory') case ('-w', '--wd', '--workingdir', '--workingdirectory')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --workingdirectory' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --workingdirectory'
workingDirArg = getArg(i+1) workingDirArg = getArg(i+1)
case ('-r', '--rs', '--restart') case ('-r', '--rs', '--restart')
if (i+1 > command_argument_count()) print'(/,1x,a)', 'ERROR: Missing argument for --restart' if (.not. hasArg) print'(/,1x,a)', 'ERROR: Missing argument for --restart'
arg = getArg(i+1) arg = getArg(i+1)
read(arg,*,iostat=stat) CLI_restartInc read(arg,*,iostat=stat) CLI_restartInc
if (CLI_restartInc < 0 .or. stat /= 0) then if (CLI_restartInc < 0 .or. stat /= 0) then
@ -340,7 +343,7 @@ function getPathRelCWD(path,fileType)
inquire(file=getPathRelCWD, exist=file_exists) inquire(file=getPathRelCWD, exist=file_exists)
if (.not. file_exists) then if (.not. file_exists) then
print'(1x,a)', 'ERROR: '//fileType//' file does not exist: '//trim(getPathRelCWD) print'(/,1x,a)', 'ERROR: '//fileType//' file does not exist: '//trim(getPathRelCWD)
call quit(1) call quit(1)
end if end if