next_linebreak Function

private function next_linebreak(message, pos, rowlen) result(ibreak)

Helper routine for print_abort_message()

Arguments

TypeIntentOptionalAttributesName
character(len=*), intent(in) :: message
integer, intent(in) :: pos
integer, intent(in) :: rowlen

Return Value integer


Contents

Source Code


Source Code

   FUNCTION next_linebreak(message, pos, rowlen) RESULT(ibreak)
      !! Helper routine for print_abort_message()
      CHARACTER(LEN=*), INTENT(IN)                       :: message
      INTEGER, INTENT(IN)                                :: pos, rowlen
      INTEGER                                            :: ibreak

      INTEGER                                            :: i, n

      n = LEN_TRIM(message)
      IF (n - pos <= rowlen) THEN
         ibreak = n ! remaining message shorter than line
      ELSE
         i = INDEX(message(pos + 1:pos + 1 + rowlen), " ", BACK=.TRUE.)
         IF (i == 0) THEN
            ibreak = pos + rowlen - 1 ! no space found, break mid-word
         ELSE
            ibreak = pos + i ! break at space closest to rowlen
         END IF
      END IF
   END FUNCTION next_linebreak