tem_r2str_arr Function

private function tem_r2str_arr(val, sep, logger) result(str)

Converts a real "array" to a single string according to the format provided in the logger.

Arguments

Type IntentOptional Attributes Name
real(kind=single_k), intent(in) :: val(:)

array to convert

character(len=*), intent(in) :: sep

seperator between array elements

type(tem_logging_type), intent(in), optional :: logger

logger type which provides output format

Return Value character(len=SolSpecLen)

output string


Source Code

  function tem_r2str_arr( val, sep, logger) result(str)
    ! ---------------------------------------------------------------------------
    !> array to convert
    real(kind=single_k), intent(in) :: val(:)
    !> seperator between array elements
    character(len=*), intent(in)    :: sep
    !> logger type which provides output format
    type(tem_logging_type), optional, intent(in) :: logger
    !> output string
    character(len=SolSpecLen) :: str
    ! ---------------------------------------------------------------------------
    character(len=SolSpecLen)     :: temp_str
    character(len=form_len)       :: form
    integer                       :: iter, idx, offset, off_sep
    integer                       :: instrlen, maxstrlen
    ! ---------------------------------------------------------------------------

    if (present(logger)) then
      form = logger%real_form
    else
      form = primary%real_form
    end if

    maxstrlen = 10
    instrlen = size(val)
    off_sep = len(sep)
    offset = 0

    str = ''
    idx = 1
    ! If the length of input string is within limits
    if( instrlen .le. maxstrlen ) then
      do iter=1, instrlen
        ! Convert the ith element of array into character
        write(temp_str, '(' // trim(form) // ')') val(iter)
        ! Append the above obtained character to string followed by separator
        offset = len_trim(temp_str)
        str(idx:idx+offset-1) = trim(temp_str(1:offset) )
        if( iter .ne. instrlen ) then
          str(idx+offset:idx+offset+off_sep) = sep(1:off_sep)
        end if
        idx = idx + offset + off_sep + 1
      end do
      ! Clip the final string to removed unwanted stuff
      str = str(1:instrlen*(offset+off_sep+1)-off_sep-1)
    ! If not then print 1,2,3,...,last
    else
      do iter=1, 3
        write(temp_str, '(' // trim(form) // ')') val(iter)
        offset = len_trim(temp_str)
        str(idx:idx+offset-1) = trim(temp_str(1:offset) )
        str(idx+offset:idx+offset+off_sep) = sep(1:off_sep)
        idx = idx + offset + off_sep + 1
      end do
      ! Now add ,..., and the last entry of array
      str(idx:idx+2)           = '...'
      str(idx+3:idx+3+off_sep) = sep
      write(temp_str, '(' // trim(form) // ')') val(instrlen)
      offset = len_trim(temp_str)
      str(idx+4+off_sep:idx+4+off_sep+offset) = trim(temp_str(1:offset) )
      ! Clip the final string to removed unwanted stuff
      str = str(1:4*(offset+off_sep)-off_sep+4)
    end if

  end function tem_r2str_arr