my_status_string_vec Function

public function my_status_string_vec(key, info) result(val)

This function returns the strings in the first line which starts with the specified key strings in the text returned from print_self_status.

The key strings themselves are excluded from the returned string. If the specified key is not found in the text an empty string will be returned.

info can be used to change the input that should be read, it defaults to '/proc/self/status'.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key(:)
character(len=*), intent(in), optional :: info

Return Value character(len=80), (size(key))


Source Code

  function my_status_string_vec(key, info) result(val)
    ! ---------------------------------------------------------------------------
    character(len=*), intent(in) :: key(:) !< Case sensitive!
    character(len=*), intent(in), optional :: info
    character(len=80) :: val(size(key))
    ! ---------------------------------------------------------------------------
    integer :: scratchUnit
    character(len=80) :: bufline
    integer :: ios
    integer :: n, i
    integer :: keylen(size(key))
    logical :: match
    ! ---------------------------------------------------------------------------

    scratchUnit = newUnit()
    n = size(key)

    val = ''
    keylen = len_trim(key)
    open(unit = scratchUnit, status = 'scratch')

    call print_self_status(scratchUnit, info=info)
    do i=1,n
      rewind(scratchUnit)
      do
        read(scratchUnit, '(a)', iostat=ios) bufline
        if (ios /= 0) EXIT  ! end of file reached or reading error occurred
        match = ( bufline(1:keylen(i)) == trim(key(i)) )
        if (match) then
          val(i) = trim(bufline(keylen(i)+1:))
          EXIT
        end if
      end do
    end do
    close(scratchUnit)
    val = adjustl(val)
  end function my_status_string_vec