diff --git a/src/dftbp/common/assert.F90 b/src/dftbp/common/assert.F90 index d9684ab861..4907157b35 100644 --- a/src/dftbp/common/assert.F90 +++ b/src/dftbp/common/assert.F90 @@ -23,7 +23,7 @@ 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 @@ -31,9 +31,15 @@ subroutine assertError(fileName, lineNr) !> 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 diff --git a/src/dftbp/dftbplus/main.F90 b/src/dftbp/dftbplus/main.F90 index c1eac3155b..a2c7fe3bb3 100644 --- a/src/dftbp/dftbplus/main.F90 +++ b/src/dftbp/dftbplus/main.F90 @@ -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, & diff --git a/src/dftbp/include/common.fypp b/src/dftbp/include/common.fypp index 4a0f497880..1e4f5cfb00 100644 --- a/src/dftbp/include/common.fypp +++ b/src/dftbp/include/common.fypp @@ -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