w90_readwrite_get_range_vector Subroutine

public subroutine w90_readwrite_get_range_vector(settings, keyword, found, length, lcount, error, comm, i_value)

Uses

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

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

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


Calls

proc~~w90_readwrite_get_range_vector~~CallsGraph proc~w90_readwrite_get_range_vector w90_readwrite_get_range_vector proc~set_error_input set_error_input proc~w90_readwrite_get_range_vector->proc~set_error_input proc~w90_readwrite_get_keyword_vector w90_readwrite_get_keyword_vector proc~w90_readwrite_get_range_vector->proc~w90_readwrite_get_keyword_vector proc~w90_readwrite_get_vector_length w90_readwrite_get_vector_length proc~w90_readwrite_get_range_vector->proc~w90_readwrite_get_vector_length 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 proc~w90_readwrite_get_keyword_vector->proc~set_error_input proc~set_error_fatal set_error_fatal proc~w90_readwrite_get_keyword_vector->proc~set_error_fatal proc~w90_readwrite_get_vector_length->proc~set_error_input proc~w90_readwrite_get_vector_length->proc~set_error_fatal proc~set_error_fatal->proc~comms_sync_error proc~set_error_fatal->proc~set_base_error

Called by

proc~~w90_readwrite_get_range_vector~~CalledByGraph proc~w90_readwrite_get_range_vector w90_readwrite_get_range_vector proc~w90_readwrite_clear_keywords w90_readwrite_clear_keywords proc~w90_readwrite_clear_keywords->proc~w90_readwrite_get_range_vector proc~w90_readwrite_read_distk w90_readwrite_read_distk proc~w90_readwrite_read_distk->proc~w90_readwrite_get_range_vector proc~w90_readwrite_read_exclude_bands w90_readwrite_read_exclude_bands proc~w90_readwrite_read_exclude_bands->proc~w90_readwrite_get_range_vector proc~w90_readwrite_read_kmesh_data w90_readwrite_read_kmesh_data proc~w90_readwrite_read_kmesh_data->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_band_plot w90_wannier90_readwrite_read_band_plot proc~w90_wannier90_readwrite_read_band_plot->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_berry w90_wannier90_readwrite_read_berry proc~w90_wannier90_readwrite_read_berry->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_dos w90_wannier90_readwrite_read_dos proc~w90_wannier90_readwrite_read_dos->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_gyrotropic w90_wannier90_readwrite_read_gyrotropic proc~w90_wannier90_readwrite_read_gyrotropic->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_projections w90_wannier90_readwrite_read_projections proc~w90_wannier90_readwrite_read_projections->proc~w90_readwrite_get_range_vector proc~w90_wannier90_readwrite_read_wann_plot w90_wannier90_readwrite_read_wann_plot proc~w90_wannier90_readwrite_read_wann_plot->proc~w90_readwrite_get_range_vector proc~w90_postw90_readwrite_read w90_postw90_readwrite_read proc~w90_postw90_readwrite_read->proc~w90_readwrite_read_exclude_bands proc~w90_postw90_readwrite_read->proc~w90_readwrite_read_kmesh_data proc~w90_postw90_readwrite_read->proc~w90_wannier90_readwrite_read_berry proc~w90_postw90_readwrite_read->proc~w90_wannier90_readwrite_read_dos proc~w90_postw90_readwrite_read->proc~w90_wannier90_readwrite_read_gyrotropic proc~w90_postw90_readwrite_readall w90_postw90_readwrite_readall proc~w90_postw90_readwrite_readall->proc~w90_wannier90_readwrite_read_berry proc~w90_postw90_readwrite_readall->proc~w90_wannier90_readwrite_read_dos proc~w90_postw90_readwrite_readall->proc~w90_wannier90_readwrite_read_gyrotropic proc~w90_readwrite_clean_infile w90_readwrite_clean_infile proc~w90_readwrite_clean_infile->proc~w90_readwrite_clear_keywords proc~w90_wannier90_readwrite_read w90_wannier90_readwrite_read proc~w90_wannier90_readwrite_read->proc~w90_wannier90_readwrite_read_band_plot proc~w90_wannier90_readwrite_read->proc~w90_wannier90_readwrite_read_wann_plot proc~w90_wannier90_readwrite_read_special w90_wannier90_readwrite_read_special proc~w90_wannier90_readwrite_read_special->proc~w90_readwrite_read_distk proc~w90_wannier90_readwrite_read_special->proc~w90_readwrite_read_exclude_bands proc~w90_wannier90_readwrite_read_special->proc~w90_readwrite_read_kmesh_data 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_readwrite_clean_infile 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_readwrite_clean_infile 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 program~postw90->proc~w90_readwrite_clean_infile 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_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