Read a range vector eg. 1,2,3,4-10 or 1 3 400:100 if(lcount) we return the number of states in length
| 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 found |
||
| integer, | intent(inout) | :: | length |
Number of states |
||
| logical, | intent(in) | :: | lcount |
If T only count states |
||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm | |||
| integer, | intent(out), | optional | :: | i_value(length) |
States specified in range vector |
subroutine w90_readwrite_get_range_vector(settings, keyword, found, length, lcount, error, comm, i_value) !================================================! !! Read a range vector eg. 1,2,3,4-10 or 1 3 400:100 !! if(lcount) we return the number of states in length !================================================! 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 found integer, intent(inout) :: length !! Number of states logical, intent(in) :: lcount !! If T only count states type(w90_error_type), allocatable, intent(out) :: error type(w90_comm_type), intent(in) :: comm integer, optional, intent(out) :: i_value(length) !! States specified in range vector type(settings_type), intent(inout) :: settings integer :: kl, in, loop, num1, num2, i_punc integer :: counter, i_digit, loop_r, range_size character(len=maxlen) :: dummy character(len=10), parameter :: c_digit = "0123456789" character(len=2), parameter :: c_range = "-:" character(len=3), parameter :: c_sep = " ,;" character(len=5), parameter :: c_punc = " ,;-:" character(len=5) :: c_num1, c_num2 if (lcount .and. present(i_value)) then call set_error_input(error, 'w90_readwrite_get_range_vector: incorrect call', comm) return end if kl = len_trim(keyword) found = .false. if (allocated(settings%entries)) then ! library case do loop = 1, settings%num_entries ! the first occurance of the variable in settings is used if (settings%entries(loop)%keyword == trim(keyword)) then found = .true. if (allocated(settings%entries(loop)%i1d)) then if (lcount) then call w90_readwrite_get_vector_length(settings, keyword, found, length, error, comm) return else call w90_readwrite_get_keyword_vector(settings, keyword, found, length, error, comm, & i_value=i_value) return end if else dummy = settings%entries(loop)%txtdata dummy = adjustl(dummy) end if end if end do else ! usual input (.win) file read 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 (.not. lcount) settings%in_data(loop) (1:maxlen) = ' ' if (dummy(1:1) == '=' .or. dummy(1:1) == ':') then dummy = dummy(2:) dummy = adjustl(dummy) end if end do end if if (.not. found) return counter = 0 if (len_trim(dummy) == 0) then call set_error_input(error, 'Error: keyword '//trim(keyword)//' is blank', comm) return end if dummy = adjustl(dummy) do i_punc = scan(dummy, c_punc) if (i_punc == 0) then call set_error_input(error, 'Error parsing keyword '//trim(keyword), comm) return end if c_num1 = dummy(1:i_punc - 1) read (c_num1, *, err=101, end=101) num1 dummy = adjustl(dummy(i_punc:)) !look for range if (scan(dummy, c_range) == 1) then i_digit = scan(dummy, c_digit) dummy = adjustl(dummy(i_digit:)) i_punc = scan(dummy, c_punc) c_num2 = dummy(1:i_punc - 1) read (c_num2, *, err=101, end=101) num2 dummy = adjustl(dummy(i_punc:)) range_size = abs(num2 - num1) + 1 do loop_r = 1, range_size counter = counter + 1 if (.not. lcount) i_value(counter) = min(num1, num2) + loop_r - 1 end do else counter = counter + 1 if (.not. lcount) i_value(counter) = num1 end if if (scan(dummy, c_sep) == 1) dummy = adjustl(dummy(2:)) if (scan(dummy, c_range) == 1) then call set_error_input(error, 'Error parsing keyword '//trim(keyword)//' incorrect range', comm) return end if if (index(dummy, ' ') == 1) exit end do if (lcount) length = counter if (.not. lcount) then do loop = 1, counter - 1 do loop_r = loop + 1, counter if (i_value(loop) == i_value(loop_r)) then call set_error_input(error, 'Error parsing keyword '//trim(keyword)//' duplicate values', comm) return end if end do end do end if return 101 call set_error_input(error, 'Error parsing keyword '//trim(keyword), comm) return end subroutine w90_readwrite_get_range_vector