subroutine clear_block(settings, keyword, error, comm)
!================================================!
! a dummy read routine to remove unused but legitimate input block from input stream
! needed to preserve input file error checking (i.e. input stream should be empty after all
! legitimate keywords/blocks are read)
!================================================!
use w90_error, only: w90_error_type, set_error_input
implicit none
! arguments
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
character(len=*), intent(in) :: keyword
type(settings_type), intent(inout) :: settings
! local variables
integer :: loop, line_e, line_s
logical :: found_e, found_s
character(len=maxlen) :: end_st, start_st
found_s = .false.
found_e = .false.
start_st = 'begin '//trim(keyword)
end_st = 'end '//trim(keyword)
! input lines are lower-cased and left-adjusted; the tag is 'begin'/'end', blank(s), the
! keyword and nothing else, so that e.g. 'kpoints' does not match 'begin explicit_kpoints'
do loop = 1, settings%num_lines
if (settings%in_data(loop) (1:6) /= 'begin ') cycle
if (trim(adjustl(settings%in_data(loop) (7:))) /= trim(keyword)) 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
do loop = 1, settings%num_lines
if (settings%in_data(loop) (1:4) /= 'end ') cycle
if (trim(adjustl(settings%in_data(loop) (5:))) /= trim(keyword)) 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 (found_s .and. (.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 (found_e .and. (.not. found_s)) then
call set_error_input(error, 'Error: Found '//trim(end_st)//' but no '//trim(start_st)//' in input file', comm)
return
end if
if (found_s .and. found_e) then
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
settings%in_data(line_s:line_e) (1:maxlen) = ' ' ! clear the block from the input stream
end if ! found tags
end subroutine clear_block