Finds the length of the data block
| 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) | :: | rows |
Number of rows |
||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm | |||
| logical, | intent(out), | optional | :: | lunits |
Have we found a unit specification |
subroutine w90_readwrite_get_block_length(settings, keyword, found, rows, error, comm, lunits) !================================================! ! !! Finds the length of the data block ! !================================================! use w90_error, only: w90_error_type, set_error_input, set_error_fatal implicit none type(w90_error_type), allocatable, intent(out) :: error type(w90_comm_type), intent(in) :: comm character(*), intent(in) :: keyword !! Keyword to examine logical, intent(out) :: found !! Is keyword present integer, intent(out) :: rows !! Number of rows logical, optional, intent(out) :: lunits !! Have we found a unit specification type(settings_type), intent(inout) :: settings integer :: i, in, ins, ine, loop, line_e, line_s logical :: found_e, found_s character(len=maxlen) :: end_st, start_st, dummy character(len=2) :: atsym real(kind=dp) :: atpos(3) found = .false. rows = 0 found_s = .false. found_e = .false. ! get_block_length only is meaningful for human text in input file ! not suitable for data passed via library interface (data in settings%entries) !if (.not. allocated(settings%in_data)) then ! call set_error_fatal(error, 'w90_readwrite_get_block_length called with no input file (seeking '//trim(keyword)//')', comm) ! return !elseif (allocated(settings%entries)) then ! call set_error_fatal(error, 'w90_readwrite_get_block_length called with unspent option arrays', comm) ! return !endif if (allocated(settings%entries)) return ! don't try to do this in library mode (i.e. when not reading win file) start_st = 'begin '//trim(keyword) end_st = 'end '//trim(keyword) do loop = 1, settings%num_lines ins = index(settings%in_data(loop), trim(keyword)) if (ins == 0) cycle in = index(settings%in_data(loop), 'begin') if (in == 0 .or. in > 1) cycle line_s = loop if (found_s) then call set_error_input(error, 'Error: Found '//trim(start_st)//' more than once in input file', comm) return end if found_s = .true. end do if (.not. found_s) then found = .false. return end if do loop = 1, settings%num_lines ine = index(settings%in_data(loop), trim(keyword)) if (ine == 0) cycle in = index(settings%in_data(loop), 'end') if (in == 0 .or. in > 1) cycle line_e = loop if (found_e) then call set_error_input(error, 'Error: Found '//trim(end_st)//' more than once in input file', comm) return end if found_e = .true. end do if (.not. found_e) then call set_error_input(error, 'Error: Found '//trim(start_st)//' but no '//trim(end_st)//' in input file', comm) return end if if (line_e <= line_s) then call set_error_input(error, 'Error: '//trim(end_st)//' comes before '//trim(start_st)//' in input file', comm) return end if rows = line_e - line_s - 1 found = .true. if (present(lunits)) then dummy = settings%in_data(line_s + 1) read (dummy, *, end=555) atsym, (atpos(i), i=1, 3) lunits = .false. end if if (rows <= 0) then !cope with empty blocks found = .false. settings%in_data(line_s:line_e) (1:maxlen) = ' ' end if return 555 lunits = .true. if (rows <= 1) then !cope with empty blocks found = .false. settings%in_data(line_s:line_e) (1:maxlen) = ' ' end if end subroutine w90_readwrite_get_block_length