Module assertions USE ISO_FORTRAN_ENV, ONLY: ERROR_UNIT Implicit NONE Integer(IK), SAVE :: num_failed_asserts=0 Integer(IK), SAVE :: num_asserts=0 Contains Subroutine assert(assertion, message, file, line, abortOnFailure) Implicit NONE Logical, Intent(IN) :: assertion Character(LEN=*), Intent(IN) :: message Character(LEN=*), Intent(IN) :: file Integer(IK), Intent(IN) :: line Logical, Intent(IN), OPTIONAL :: abortOnFailure Logical :: abort Character(LEN=132) :: mess1 num_asserts = num_asserts + 1 If (assertion .NEQV. .TRUE.) Then abort = .FALSE. If (PRESENT(abortOnFailure)) abort=abortOnFailure mess1 = REPEAT(' ',132) Write(ERROR_UNIT,*) '' Write(mess1,'(A,A,A,I10,A,A)') ' ASSERTION FAILED at ', file,& '(',line,'): ', TRIM(ADJUSTL(message)) Write(ERROR_UNIT,*) TRIM(mess1) Write(ERROR_UNIT,*) '' num_failed_asserts = num_failed_asserts + 1 If (abort) Then ERROR STOP " Stopping due to failed assertion" EndIf End If End Subroutine assert End Module assertions