report_message Subroutine

private subroutine report_message(me, str, ival, rval, fatal)

Report a message from an slsqp_solver class. This uses the iprint variable in the class as the unit number for printing. Note: for fatal errors, if no unit is specified, the error_unit is used.

Type Bound

slsqp_solver

Arguments

Type IntentOptional Attributes Name
class(slsqp_solver), intent(in) :: me
character(len=*), intent(in) :: str

the message to report.

integer, intent(in), optional :: ival

optional integer to print after the message.

real(kind=wp), intent(in), optional :: rval

optional real to print after the message.

logical, intent(in), optional :: fatal

if True, then the program is stopped (default=False).


Called by

proc~~report_message~~CalledByGraph proc~report_message slsqp_module::slsqp_solver%report_message proc~initialize_slsqp slsqp_module::slsqp_solver%initialize_slsqp proc~initialize_slsqp->proc~report_message proc~slsqp_wrapper slsqp_module::slsqp_solver%slsqp_wrapper proc~slsqp_wrapper->proc~report_message

Source Code

    subroutine report_message(me,str,ival,rval,fatal)

    implicit none

    class(slsqp_solver),intent(in) :: me
    character(len=*),intent(in)    :: str    !! the message to report.
    integer,intent(in),optional    :: ival   !! optional integer to print after the message.
    real(wp),intent(in),optional   :: rval   !! optional real to print after the message.
    logical,intent(in),optional    :: fatal  !! if True, then the program is stopped (default=False).

    logical :: stop_program  !! true if the program is to be stopped
    logical :: write_message  !! true if the message is to be printed
    character(len=10) :: istr  !! string version of `ival`
    character(len=30) :: rstr  !! string version of `rval`
    character(len=:),allocatable :: str_to_write  !! the actual message to the printed
    integer :: istat  !! iostat for integer to string conversion

    !fatal error check:
    if (present(fatal)) then
        stop_program = fatal
    else
        stop_program = .false.
    end if

    !note: if stopping program, then the message is always printed:
    write_message = me%iprint/=0 .or. stop_program

    if (write_message) then

        if (present(ival)) then
            write(istr,fmt='(I10)',iostat=istat) ival
            if (istat/=0) istr = '*****'
            str_to_write = str//' '//trim(adjustl(istr))
        elseif (present(rval)) then
            write(istr,fmt='(F30.16)',iostat=istat) rval
            if (istat/=0) rstr = '*****'
            str_to_write = str//' '//trim(adjustl(rstr))
        else
            str_to_write = str
        end if

        if (me%iprint==0) then
            write(error_unit,'(A)') str_to_write  !in this case, use the error unit
        else
            write(me%iprint,'(A)') str_to_write   !user specified unit number
        end if
        deallocate(str_to_write)

        if (stop_program) error stop 'Fatal Error'

    end if

    end subroutine report_message