Returns the length of a keyword vector
| 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 |
||
| integer, | intent(out) | :: | length |
length of vector |
||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm |
subroutine w90_readwrite_get_vector_length(settings, keyword, found, length, error, comm) !================================================! ! !! Returns the length of a keyword vector ! !================================================! 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 integer, intent(out) :: length !! length of vector 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, pos character(len=maxlen) :: dummy 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 (allocated(settings%entries(loop)%i1d)) then length = size(settings%entries(loop)%i1d) else if (allocated(settings%entries(loop)%r1d)) then length = size(settings%entries(loop)%r1d) else if (allocated(settings%entries(loop)%r2d)) then length = size(settings%entries(loop)%r2d, 1) else if (allocated(settings%entries(loop)%c2d)) then length = size(settings%entries(loop)%c2d, 1) else call set_error_input(error, 'lib array not i or r, r2d or c2d', comm) end if found = .true. end if end do else if (allocated(settings%in_data)) then kl = len_trim(keyword) found = .false. do loop = 1, settings%num_lines in = index(settings%in_data(loop), trim(keyword)) if (in == 0 .or. in > 1) 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:) dummy = adjustl(dummy) if (dummy(1:1) == '=' .or. dummy(1:1) == ':') then dummy = dummy(2:) dummy = adjustl(dummy) end if end do length = 0 if (found) then if (len_trim(dummy) == 0) then call set_error_input(error, 'Error: keyword '//trim(keyword)//' is blank', comm) return end if length = 1 dummy = adjustl(dummy) do pos = index(dummy, ' ') dummy = dummy(pos + 1:) dummy = adjustl(dummy) if (len_trim(dummy) > 0) then length = length + 1 else exit end if end do end if end if ! in_data end subroutine w90_readwrite_get_vector_length