Skip to content

Commit

Permalink
Optional text string for debug macro
Browse files Browse the repository at this point in the history
Can be used to give context for error.

Review suggestion by
Co-authored-by: Bálint Aradi <[email protected]>
  • Loading branch information
bhourahine committed Apr 10, 2024
1 parent 80a8cb6 commit f6304ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/dftbp/common/assert.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ module dftbp_common_assert


!> Prints assertion error and abort program execution.
subroutine assertError(fileName, lineNr)
subroutine assertError(fileName, lineNr, message)

!> Name of the file in which the error occurred.
character(*), intent(in) :: fileName

!> Nr. of the line at which the error occurred.
integer, intent(in) :: lineNr

!> Additional message for error
character(*), intent(in), optional :: message

write(stdout, '(A)') "!!! UNFULLFILLED ASSERTION"
write(stdout, '(A,A)') "!!! FILE: ", fileName
write(stdout, '(A,I0)') "!!! LINE NR.: ", lineNr
if (present(message)) then
write(stdout, '(A,A,A)') '!!! MESSAGE: "', trim(message), '"'
end if
call abortProgram()

end subroutine assertError
Expand Down
2 changes: 1 addition & 1 deletion src/dftbp/dftbplus/main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ subroutine processGeometry(this, env, iGeoStep, iLatGeoStep, tWriteRestart, tSto
call buildS(env, this%ints%overlap, this%skOverCont, this%coord, this%nNeighbourSk,&
& this%neighbourList%iNeighbour, this%species, this%iSparseStart, this%orb)
case(hamiltonianTypes%xtb)
@:ASSERT(allocated(this%tblite))
@:ASSERT(allocated(this%tblite), "Compiled without TBLITE included")
call this%tblite%buildSH0(env, this%species, this%coord, this%nNeighbourSk, &
& this%neighbourList%iNeighbour, this%img2CentCell, this%iSparseStart, &
& this%orb, this%H0, this%ints%overlap, this%ints%dipoleBra, this%ints%dipoleKet, &
Expand Down
7 changes: 6 additions & 1 deletion src/dftbp/include/common.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#! Check a condition if WITH_ASSERT is True and call assertError if condition is False.
#:def ASSERT(cond)
#! If an optional text string is included, print this in addition as an error
#:def ASSERT(cond, msg=None)
#:if WITH_ASSERT
if (.not. (${cond}$)) then
block
use dftbp_common_assert, only : assertError
#:if msg
call assertError("${_FILE_}$", ${_LINE_}$, ${msg}$)
#:else
call assertError("${_FILE_}$", ${_LINE_}$)
#:endif
end block
end if
#:endif
Expand Down

0 comments on commit f6304ef

Please sign in to comment.