w90_readwrite_in_file Subroutine

public subroutine w90_readwrite_in_file(settings, seedname, error, comm)

Uses

  • proc~~w90_readwrite_in_file~~UsesGraph proc~w90_readwrite_in_file w90_readwrite_in_file module~w90_error w90_error proc~w90_readwrite_in_file->module~w90_error module~w90_utility w90_utility proc~w90_readwrite_in_file->module~w90_utility 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_utility->module~w90_comms module~w90_constants w90_constants module~w90_utility->module~w90_constants module~w90_comms->module~w90_constants module~w90_comms->module~w90_error_base

Load the *.win file into a character array in_file, ignoring comments and blank lines and converting everything to lowercase characters

Arguments

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

Calls

proc~~w90_readwrite_in_file~~CallsGraph proc~w90_readwrite_in_file w90_readwrite_in_file proc~set_error_alloc set_error_alloc proc~w90_readwrite_in_file->proc~set_error_alloc proc~set_error_file set_error_file proc~w90_readwrite_in_file->proc~set_error_file proc~utility_lowercase utility_lowercase proc~w90_readwrite_in_file->proc~utility_lowercase proc~comms_sync_error comms_sync_error proc~set_error_alloc->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_alloc->proc~set_base_error proc~set_error_file->proc~comms_sync_error proc~set_error_file->proc~set_base_error

Called by

proc~~w90_readwrite_in_file~~CalledByGraph proc~w90_readwrite_in_file w90_readwrite_in_file proc~input_reader_special input_reader_special proc~input_reader_special->proc~w90_readwrite_in_file proc~w90_input_reader~2 w90_input_reader proc~w90_input_reader~2->proc~w90_readwrite_in_file program~postw90 postw90 program~postw90->proc~w90_readwrite_in_file 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 w90_readwrite_in_file(settings, seedname, error, comm)
    !================================================!
    !! Load the *.win file into a character
    !! array in_file, ignoring comments and
    !! blank lines and converting everything
    !! to lowercase characters
    !================================================!

    use w90_utility, only: utility_lowercase
    use w90_error, only: w90_error_type, set_error_alloc, set_error_file, set_error_file

    implicit none

    character(len=*), intent(in)  :: seedname
    type(w90_error_type), allocatable, intent(out) :: error
    type(w90_comm_type), intent(in) :: comm
    type(settings_type), intent(inout) :: settings

    integer :: in_unit, tot_num_lines, ierr, line_counter, loop, in1, in2
    character(len=maxlen) :: dummy
    integer :: pos
    character, parameter :: TABCHAR = char(9)

    open (newunit=in_unit, file=trim(seedname)//'.win', form='formatted', status='old', err=101)

    settings%num_lines = 0; tot_num_lines = 0
    do
      read (in_unit, '(a)', iostat=ierr, err=200, end=210) dummy
      ! [GP-begin, Apr13, 2012]: I convert all tabulation characters to spaces
      pos = index(dummy, TABCHAR)
      do while (pos .ne. 0)
        dummy(pos:pos) = ' '
        pos = index(dummy, TABCHAR)
      end do
      ! [GP-end]
      dummy = adjustl(dummy)
      tot_num_lines = tot_num_lines + 1
      if (.not. dummy(1:1) == '!' .and. .not. dummy(1:1) == '#') then
        if (len(trim(dummy)) > 0) settings%num_lines = settings%num_lines + 1
      end if

    end do

101 call set_error_file(error, 'Error: Problem opening input file '//trim(seedname)//'.win', comm)
    return
200 call set_error_file(error, 'Error: Problem reading input file '//trim(seedname)//'.win', comm)
    return
210 continue
    rewind (in_unit)

    allocate (settings%in_data(settings%num_lines), stat=ierr)
    if (ierr /= 0) then
      call set_error_alloc(error, 'Error allocating settings%in_data in w90_readwrite_in_file', comm)
      return
    end if

    line_counter = 0
    do loop = 1, tot_num_lines
      read (in_unit, '(a)', iostat=ierr, err=200) dummy
      ! [GP-begin, Apr13, 2012]: I convert all tabulation characters to spaces
      pos = index(dummy, TABCHAR)
      do while (pos .ne. 0)
        dummy(pos:pos) = ' '
        pos = index(dummy, TABCHAR)
      end do
      ! [GP-end]
      dummy = utility_lowercase(dummy)
      dummy = adjustl(dummy)
      if (dummy(1:1) == '!' .or. dummy(1:1) == '#') cycle
      if (len(trim(dummy)) == 0) cycle
      line_counter = line_counter + 1
      in1 = index(dummy, '!')
      in2 = index(dummy, '#')
      if (in1 == 0 .and. in2 == 0) settings%in_data(line_counter) = dummy
      if (in1 == 0 .and. in2 > 0) settings%in_data(line_counter) = dummy(:in2 - 1)
      if (in2 == 0 .and. in1 > 0) settings%in_data(line_counter) = dummy(:in1 - 1)
      if (in2 > 0 .and. in1 > 0) settings%in_data(line_counter) = dummy(:min(in1, in2) - 1)
    end do

    close (in_unit)
  end subroutine w90_readwrite_in_file