tem_b2str_arr Function

private function tem_b2str_arr(val, sep) result(str)

Converts an array of booleans to a string.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: val(:)
character(len=*), intent(in) :: sep

Return Value character(len=SolSpecLen)


Source Code

  function tem_b2str_arr( val, sep) result(str)
    ! ---------------------------------------------------------------------------
    !>
    logical, intent(in) :: val(:)
    !>
    character(len=*), intent(in) :: sep
    !>
    character(len=SolSpecLen) :: str
    ! ---------------------------------------------------------------------------
    character(len=SolSpecLen)     :: tmp, temp_str
    integer                       :: iter, idx, offset, off_sep
    ! ---------------------------------------------------------------------------
    off_sep = len(sep)
    idx = 1
    offset = 0

    str = ''
    do iter=1, size(val)
      ! Convert the ith element of array into character
      write(tmp, *) val(iter)
      temp_str = adjustl(tmp)
      ! 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. size(val) ) 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:size(val)*(offset+off_sep)-off_sep-1)

  end function tem_b2str_arr