Finds the value of the required keyword.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(settings_type), | intent(inout) | :: | settings | |||
| character(len=*), | intent(in) | :: | keyword |
Keyword to examine |
||
| logical, | intent(out) | :: | found |
Is keyword present |
||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm | |||
| character(len=*), | intent(inout), | optional | :: | c_value |
Keyword value |
|
| logical, | intent(inout), | optional | :: | l_value |
Keyword value |
|
| integer, | intent(inout), | optional | :: | i_value |
Keyword value |
|
| real(kind=dp), | intent(inout), | optional | :: | r_value |
Keyword value |
subroutine w90_readwrite_get_keyword(settings, keyword, found, error, comm, c_value, l_value, i_value, r_value) !================================================! ! !! Finds the value of the required keyword. ! !================================================! use w90_error, only: w90_error_type, set_error_input, set_error_fatal implicit none character(*), intent(in) :: keyword !! Keyword to examine logical, intent(out) :: found !! Is keyword present character(*), optional, intent(inout) :: c_value !! Keyword value logical, optional, intent(inout) :: l_value !! Keyword value integer, optional, intent(inout) :: i_value !! Keyword value real(kind=dp), optional, intent(inout) :: r_value !! Keyword value type(w90_error_type), allocatable, intent(out) :: error type(w90_comm_type), intent(in) :: comm type(settings_type), intent(inout) :: settings integer :: kl, in, loop, itmp character(len=maxlen) :: dummy kl = len_trim(keyword) found = .false. if (allocated(settings%entries) .and. allocated(settings%in_data)) then call set_error_fatal(error, 'Error: (library use) options interface and .win parsing clash.'// & ' See library documentation "setting options." (readwrite.F90)', comm) return elseif (allocated(settings%entries)) then do loop = 1, settings%num_entries ! this means the first occurance of the variable in settings is used ! memory beyond num_entries is not initialised if (settings%entries(loop)%keyword == keyword) then if (present(i_value)) then i_value = settings%entries(loop)%idata else if (present(r_value)) then r_value = settings%entries(loop)%rdata else if (present(l_value)) then l_value = settings%entries(loop)%ldata else if (present(c_value)) then c_value = settings%entries(loop)%txtdata else call set_error_fatal(error, 'Error: keyword sought, but no variable provided to assign to. (readwrite.F90)', comm) return end if found = .true. return end if end do else if (allocated(settings%in_data)) then ! by default, scan the input file do loop = 1, settings%num_lines in = index(settings%in_data(loop), trim(keyword)) if (in == 0 .or. in > 1) cycle itmp = in + len(trim(keyword)) if (settings%in_data(loop) (itmp:itmp) /= '=' & .and. settings%in_data(loop) (itmp:itmp) /= ':' & .and. settings%in_data(loop) (itmp:itmp) /= ' ') cycle if (found) then call set_error_input(error, 'Error: Found keyword '//trim(keyword)//' more than once in input file', comm) return end if found = .true. dummy = settings%in_data(loop) (kl + 1:) settings%in_data(loop) (1:maxlen) = ' ' dummy = adjustl(dummy) if (dummy(1:1) == '=' .or. dummy(1:1) == ':') then dummy = dummy(2:) dummy = adjustl(dummy) end if end do if (found) then if (present(c_value)) c_value = dummy if (present(l_value)) then if (index(dummy, 't') > 0) then l_value = .true. elseif (index(dummy, 'f') > 0) then l_value = .false. else call set_error_input(error, 'Error: Problem reading logical keyword '//trim(keyword), comm) return end if end if if (present(i_value)) read (dummy, *, err=220, end=220) i_value if (present(r_value)) read (dummy, *, err=220, end=220) r_value end if else ! error condition end if return 220 call set_error_input(error, 'Error: Problem reading keyword '//trim(keyword), comm) return end subroutine w90_readwrite_get_keyword