From f6304ef5b69cf052a45314be45bdce97e3fdd8e1 Mon Sep 17 00:00:00 2001 From: Ben Hourahine Date: Tue, 12 Mar 2024 19:35:52 +0000 Subject: [PATCH] Optional text string for debug macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Can be used to give context for error. Review suggestion by Co-authored-by: Bálint Aradi --- src/dftbp/common/assert.F90 | 8 +++++++- src/dftbp/dftbplus/main.F90 | 2 +- src/dftbp/include/common.fypp | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) 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