Merge branch 'universal-error+warning-formatting' into 'development'

CLI errors with IO_error

See merge request damask/DAMASK!774
This commit is contained in:
Sharan Roongta 2023-07-16 09:17:33 +00:00
commit 5882d4210d
2 changed files with 50 additions and 58 deletions

View File

@ -74,7 +74,7 @@ subroutine CLI_init()
print'(a)', achar(27)//'[31m' print'(a)', achar(27)//'[31m'
print'(1x,a,/)', 'debug version - debug version - debug version - debug version - debug version' print'(1x,a,/)', 'debug version - debug version - debug version - debug version - debug version'
#else #else
print'(a)', achar(27)//'[94m' print'(a)', achar(27)//'[1;94m'
#endif #endif
print'(1x,a)', ' _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/' print'(1x,a)', ' _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/'
print'(1x,a)', ' _/ _/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/ _/' print'(1x,a)', ' _/ _/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/ _/'
@ -158,48 +158,34 @@ 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 (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --geom' if (.not. hasArg) call IO_error(610,ext_msg='--geom')
geomArg = getArg(i+1) geomArg = getArg(i+1)
case ('-l', '--load', '--loadcase') case ('-l', '--load', '--loadcase')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --load' if (.not. hasArg) call IO_error(610,ext_msg='--load')
loadArg = getArg(i+1) loadArg = getArg(i+1)
case ('-m', '--material', '--materialconfig') case ('-m', '--material', '--materialconfig')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --material' if (.not. hasArg) call IO_error(610,ext_msg='--material')
materialArg = getArg(i+1) materialArg = getArg(i+1)
case ('-n', '--numerics', '--numericsconfig') case ('-n', '--numerics', '--numericsconfig')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --numerics' if (.not. hasArg) call IO_error(610,ext_msg='--numerics')
numericsArg = getArg(i+1) numericsArg = getArg(i+1)
case ('-j', '--job', '--jobname') case ('-j', '--job', '--jobname')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --jobname' if (.not. hasArg) call IO_error(610,ext_msg='--jobname')
solverJobname = getArg(i+1) solverJobname = getArg(i+1)
case ('-w', '--wd', '--workingdir', '--workingdirectory') case ('-w', '--wd', '--workingdir', '--workingdirectory')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --workingdirectory' if (.not. hasArg) call IO_error(610,ext_msg='--workingdirectory')
workingDirArg = getArg(i+1) workingDirArg = getArg(i+1)
case ('-r', '--rs', '--restart') case ('-r', '--rs', '--restart')
if (.not. hasArg) print'(/,1x,a)', 'ERROR: missing argument for --restart' if (.not. hasArg) call IO_error(610,ext_msg='--jobname')
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) call IO_error(611,ext_msg=arg)
print'(/,1x,a)', 'ERROR: could not parse restart increment: '//trim(arg)
call quit(1)
end if
end select end select
end do end do
if (.not. allocated(loadArg)) then if (.not. allocated(geomArg)) call IO_error(612,ext_msg='--geom')
print'(/,1x,a)', 'Error: no load case specified (-h for help)' if (.not. allocated(loadArg)) call IO_error(612,ext_msg='--load')
call quit(1) if (.not. allocated(materialArg)) call IO_error(612,ext_msg='--material')
end if
if (.not. allocated(geomArg)) then
print'(/,1x,a)', 'Error: no geometry specified (-h for help)'
call quit(1)
end if
if (.not. allocated(materialArg)) then
print'(/,1x,a)', 'Error: no material configuration specified (-h for help)'
call quit(1)
end if
call setWorkingDirectory(trim(workingDirArg)) call setWorkingDirectory(trim(workingDirArg))
CLI_geomFile = getPathRelCWD(geomArg,'geometry') CLI_geomFile = getPathRelCWD(geomArg,'geometry')
@ -211,8 +197,7 @@ subroutine CLI_init()
if (.not. allocated(solverJobname)) then if (.not. allocated(solverJobname)) then
solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile) solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile)
elseif (scan(solverJobname,'/') > 0) then elseif (scan(solverJobname,'/') > 0) then
print'(/,1x,a)', 'ERROR: JOBNAME must not contain any slashes' call IO_error(630)
call quit(1)
endif endif
commandLine = getArg(-1) commandLine = getArg(-1)
@ -272,9 +257,6 @@ subroutine setWorkingDirectory(workingDirectoryArg)
character(len=*), intent(in) :: workingDirectoryArg !< working directory argument character(len=*), intent(in) :: workingDirectoryArg !< working directory argument
character(len=:), allocatable :: workingDirectory character(len=:), allocatable :: workingDirectory
logical :: error
external :: quit
absolutePath: if (workingDirectoryArg(1:1) == '/') then absolutePath: if (workingDirectoryArg(1:1) == '/') then
workingDirectory = workingDirectoryArg workingDirectory = workingDirectoryArg
@ -284,11 +266,7 @@ subroutine setWorkingDirectory(workingDirectoryArg)
end if absolutePath end if absolutePath
workingDirectory = trim(normpath(workingDirectory)) workingDirectory = trim(normpath(workingDirectory))
error = setCWD(trim(workingDirectory)) if (setCWD(trim(workingDirectory))) call IO_error(640,ext_msg=workingDirectory)
if (error) then
print'(1x,a)', 'ERROR: invalid working directory: '//trim(workingDirectory)
call quit(1)
end if
end subroutine setWorkingDirectory end subroutine setWorkingDirectory
@ -344,7 +322,6 @@ function getPathRelCWD(path,fileType)
character(len=*), intent(in) :: fileType character(len=*), intent(in) :: fileType
logical :: file_exists logical :: file_exists
external :: quit
getPathRelCWD = trim(path) getPathRelCWD = trim(path)
@ -352,10 +329,7 @@ function getPathRelCWD(path,fileType)
getPathRelCWD = trim(relpath(getPathRelCWD,getCWD())) getPathRelCWD = trim(relpath(getPathRelCWD,getCWD()))
inquire(file=getPathRelCWD, exist=file_exists) inquire(file=getPathRelCWD, exist=file_exists)
if (.not. file_exists) then if (.not. file_exists) call IO_error(100,ext_msg=fileType//' "'//trim(getPathRelCWD)//'"')
print'(/,1x,a)', 'ERROR: '//fileType//' file does not exist: '//trim(getPathRelCWD)
call quit(1)
end if
end function getPathRelCWD end function getPathRelCWD
@ -438,4 +412,5 @@ function relpath(path,start)
end function relpath end function relpath
end module CLI end module CLI

View File

@ -555,6 +555,18 @@ subroutine IO_error(error_ID,ext_msg,label1,ID1,label2,ID2)
! user errors ! user errors
case (603) case (603)
msg = 'invalid data for table' msg = 'invalid data for table'
case (610)
msg = 'missing argument for option'
case (611)
msg = 'could not parse restart increment'
case (612)
msg = 'missing option'
case (630)
msg = 'JOBNAME must not contain any slashes'
case (640)
msg = 'invalid working directory'
!------------------------------------------------------------------------------------------------ !------------------------------------------------------------------------------------------------
! errors related to YAML data ! errors related to YAML data
@ -704,38 +716,43 @@ subroutine panel(paneltype,ID,msg,ext_msg,label1,ID1,label2,ID2)
character(len=pSTRLEN) :: formatString character(len=pSTRLEN) :: formatString
integer, parameter :: panelwidth = 69 integer, parameter :: panelwidth = 69
character(len=:), allocatable :: msg_,ID_,msg1,msg2
character(len=*), parameter :: DIVIDER = repeat('─',panelwidth) character(len=*), parameter :: DIVIDER = repeat('─',panelwidth)
if (.not. present(label1) .and. present(ID1)) error stop 'missing label for value 1' if (.not. present(label1) .and. present(ID1)) error stop 'missing label for value 1'
if (.not. present(label2) .and. present(ID2)) error stop 'missing label for value 2' if (.not. present(label2) .and. present(ID2)) error stop 'missing label for value 2'
if ( present(label1) .and. .not. present(ID1)) error stop 'missing value for label 1'
if ( present(label2) .and. .not. present(ID2)) error stop 'missing value for label 2'
ID_ = IO_intAsStr(ID)
if (present(label1)) msg1 = label1
if (present(label2)) msg2 = label2
if (present(ID1)) msg1 = msg1//' '//IO_intAsStr(ID1)
if (present(ID2)) msg2 = msg2//' '//IO_intAsStr(ID2)
if (paneltype == 'error') msg_ = achar(27)//'[31m'//trim(msg)//achar(27)//'[0m'
if (paneltype == 'warning') msg_ = achar(27)//'[33m'//trim(msg)//achar(27)//'[0m'
!$OMP CRITICAL (write2out) !$OMP CRITICAL (write2out)
write(IO_STDERR,'(/,a)') ' ┌'//DIVIDER//'┐' write(IO_STDERR,'(/,a)') ' ┌'//DIVIDER//'┐'
write(formatString,'(a,i2,a)') '(a,24x,a,',max(1,panelwidth-24-len_trim(paneltype)),'x,a)' write(formatString,'(a,i2,a)') '(a,24x,a,1x,i0,',max(1,panelwidth-24-len_trim(paneltype)-1-len_trim(ID_)),'x,a)'
write(IO_STDERR,formatString) ' │',trim(paneltype), '│' write(IO_STDERR,formatString) ' │',trim(paneltype),ID, '│'
write(formatString,'(a,i2,a)') '(a,24x,i3,',max(1,panelwidth-24-3),'x,a)'
write(IO_STDERR,formatString) ' │',ID, '│'
write(IO_STDERR,'(a)') ' ├'//DIVIDER//'┤' write(IO_STDERR,'(a)') ' ├'//DIVIDER//'┤'
write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a4,a',max(1,len_trim(msg)),',',& write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a4,a',max(1,len_trim(msg_)),',',&
max(1,panelwidth+3-len_trim(msg)-4),'x,a)' max(1,panelwidth+3-len_trim(msg)-4),'x,a)'
write(IO_STDERR,formatString) '│ ',trim(msg), '│' write(IO_STDERR,formatString) '│ ',trim(msg_), '│'
if (present(ext_msg)) then if (present(ext_msg)) then
write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a4,a',max(1,len_trim(ext_msg)),',',& write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a4,a',max(1,len_trim(ext_msg)),',',&
max(1,panelwidth+3-len_trim(ext_msg)-4),'x,a)' max(1,panelwidth+3-len_trim(ext_msg)-4),'x,a)'
write(IO_STDERR,formatString) '│ ',trim(ext_msg), '│' write(IO_STDERR,formatString) '│ ',trim(ext_msg), '│'
end if end if
if (present(label1)) then if (present(label1)) then
write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a7,a',max(1,len_trim(label1)),',i9,',& write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a7,a',max(1,len_trim(msg1)),',',&
max(1,panelwidth+3-len_trim(label1)-9-7),'x,a)' max(1,panelwidth+3-len_trim(msg1)-7),'x,a)'
write(IO_STDERR,formatString) '│ at ',trim(label1),ID1, '│' write(IO_STDERR,formatString) '│ at ',trim(msg1), '│'
end if end if
if (present(label2)) then if (present(label2)) then
write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a7,a',max(1,len_trim(label2)),',i9,',& write(formatString,'(a,i3.3,a,i3.3,a)') '(1x,a7,a',max(1,len_trim(msg2)),',',&
max(1,panelwidth+3-len_trim(label2)-9-7),'x,a)' max(1,panelwidth+3-len_trim(msg2)-7),'x,a)'
write(IO_STDERR,formatString) '│ at ',trim(label2),ID2, '│' write(IO_STDERR,formatString) '│ at ',trim(msg2), '│'
end if end if
write(formatString,'(a,i2.2,a)') '(a,',max(1,panelwidth),'x,a)' write(formatString,'(a,i2.2,a)') '(a,',max(1,panelwidth),'x,a)'
write(IO_STDERR,formatString) ' │', '│' write(IO_STDERR,formatString) ' │', '│'