clear_block Subroutine

private subroutine clear_block(settings, keyword, error, comm)

Uses

  • proc~~clear_block~~UsesGraph proc~clear_block clear_block module~w90_error w90_error proc~clear_block->module~w90_error module~w90_comms w90_comms module~w90_error->module~w90_comms module~w90_error_base w90_error_base module~w90_error->module~w90_error_base module~w90_comms->module~w90_error_base module~w90_constants w90_constants module~w90_comms->module~w90_constants

Arguments

Type IntentOptional Attributes Name
type(settings_type), intent(inout) :: settings
character(len=*), intent(in) :: keyword
type(w90_error_type), intent(out), allocatable :: error
type(w90_comm_type), intent(in) :: comm

Calls

proc~~clear_block~~CallsGraph proc~clear_block clear_block proc~set_error_input set_error_input proc~clear_block->proc~set_error_input proc~comms_sync_error comms_sync_error proc~set_error_input->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_input->proc~set_base_error

Called by

proc~~clear_block~~CalledByGraph proc~clear_block clear_block proc~w90_readwrite_clear_keywords w90_readwrite_clear_keywords proc~w90_readwrite_clear_keywords->proc~clear_block proc~w90_readwrite_clean_infile w90_readwrite_clean_infile proc~w90_readwrite_clean_infile->proc~w90_readwrite_clear_keywords proc~input_reader_special input_reader_special proc~input_reader_special->proc~w90_readwrite_clean_infile proc~w90_input_reader~2 w90_input_reader proc~w90_input_reader~2->proc~w90_readwrite_clean_infile program~postw90 postw90 program~postw90->proc~w90_readwrite_clean_infile proc~w90_input_reader w90_input_reader proc~w90_input_reader->proc~w90_input_reader~2 program~wannier wannier program~wannier->proc~input_reader_special program~wannier->proc~w90_input_reader~2

Source Code

  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