w90_readwrite_get_block_length Subroutine

public subroutine w90_readwrite_get_block_length(settings, keyword, found, rows, error, comm, lunits)

Uses

  • proc~~w90_readwrite_get_block_length~~UsesGraph proc~w90_readwrite_get_block_length w90_readwrite_get_block_length module~w90_error w90_error proc~w90_readwrite_get_block_length->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

Finds the length of the data block

Arguments

Type IntentOptional 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


Calls

proc~~w90_readwrite_get_block_length~~CallsGraph proc~w90_readwrite_get_block_length w90_readwrite_get_block_length proc~set_error_input set_error_input proc~w90_readwrite_get_block_length->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~~w90_readwrite_get_block_length~~CalledByGraph proc~w90_readwrite_get_block_length w90_readwrite_get_block_length proc~readwrite_get_atoms readwrite_get_atoms proc~readwrite_get_atoms->proc~w90_readwrite_get_block_length proc~w90_readwrite_read_atoms w90_readwrite_read_atoms proc~w90_readwrite_read_atoms->proc~w90_readwrite_get_block_length proc~w90_readwrite_read_atoms->proc~readwrite_get_atoms proc~w90_readwrite_read_explicit_kpath w90_readwrite_read_explicit_kpath proc~w90_readwrite_read_explicit_kpath->proc~w90_readwrite_get_block_length proc~w90_readwrite_read_explicit_kpath_points w90_readwrite_read_explicit_kpath_points proc~w90_readwrite_read_explicit_kpath->proc~w90_readwrite_read_explicit_kpath_points proc~w90_readwrite_read_explicit_kpath_points->proc~w90_readwrite_get_block_length proc~w90_readwrite_read_kpath w90_readwrite_read_kpath proc~w90_readwrite_read_kpath->proc~w90_readwrite_get_block_length proc~w90_wannier90_readwrite_read_constrained_centres w90_wannier90_readwrite_read_constrained_centres proc~w90_wannier90_readwrite_read_constrained_centres->proc~w90_readwrite_get_block_length proc~w90_wannier90_readwrite_read_explicit_kpts w90_wannier90_readwrite_read_explicit_kpts proc~w90_wannier90_readwrite_read_explicit_kpts->proc~w90_readwrite_get_block_length proc~w90_wannier90_readwrite_read_projections w90_wannier90_readwrite_read_projections proc~w90_wannier90_readwrite_read_projections->proc~w90_readwrite_get_block_length proc~w90_postw90_readwrite_read w90_postw90_readwrite_read proc~w90_postw90_readwrite_read->proc~w90_readwrite_read_atoms proc~w90_postw90_readwrite_read->proc~w90_readwrite_read_kpath proc~w90_wannier90_readwrite_read w90_wannier90_readwrite_read proc~w90_wannier90_readwrite_read->proc~w90_readwrite_read_explicit_kpath proc~w90_wannier90_readwrite_read->proc~w90_readwrite_read_kpath proc~w90_wannier90_readwrite_read->proc~w90_wannier90_readwrite_read_constrained_centres proc~w90_wannier90_readwrite_read_special w90_wannier90_readwrite_read_special proc~w90_wannier90_readwrite_read_special->proc~w90_readwrite_read_atoms proc~w90_wannier90_readwrite_read_special->proc~w90_wannier90_readwrite_read_explicit_kpts proc~w90_wannier90_readwrite_read_special->proc~w90_wannier90_readwrite_read_projections proc~input_reader_special input_reader_special proc~input_reader_special->proc~w90_wannier90_readwrite_read_special proc~w90_input_reader~2 w90_input_reader proc~w90_input_reader~2->proc~w90_wannier90_readwrite_read proc~w90_input_setopt w90_input_setopt proc~w90_input_setopt->proc~w90_wannier90_readwrite_read proc~w90_input_setopt->proc~w90_wannier90_readwrite_read_special program~postw90 postw90 program~postw90->proc~w90_postw90_readwrite_read proc~w90_input_reader w90_input_reader proc~w90_input_reader->proc~w90_input_reader~2 proc~w90_input_setopt_f w90_input_setopt_f proc~w90_input_setopt_f->proc~w90_input_setopt program~wannier wannier program~wannier->proc~input_reader_special program~wannier->proc~w90_input_reader~2

Source Code

  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