Load the *.win file into a character array in_file, ignoring comments and blank lines and converting everything to lowercase characters
subroutine param_in_file
!=======================================!
!! Load the *.win file into a character
!! array in_file, ignoring comments and
!! blank lines and converting everything
!! to lowercase characters
!=======================================!
use w90_io, only: io_file_unit, io_error, seedname
use w90_utility, only: utility_lowercase
implicit none
integer :: in_unit, tot_num_lines, ierr, line_counter, loop, in1, in2
character(len=maxlen) :: dummy
integer :: pos
character, parameter :: TABCHAR = char(9)
in_unit = io_file_unit()
open (in_unit, file=trim(seedname)//'.win', form='formatted', status='old', err=101)
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) num_lines = num_lines + 1
endif
end do
101 call io_error('Error: Problem opening input file '//trim(seedname)//'.win')
200 call io_error('Error: Problem reading input file '//trim(seedname)//'.win')
210 continue
rewind (in_unit)
allocate (in_data(num_lines), stat=ierr)
if (ierr /= 0) call io_error('Error allocating in_data in param_in_file')
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) in_data(line_counter) = dummy
if (in1 == 0 .and. in2 > 0) in_data(line_counter) = dummy(:in2 - 1)
if (in2 == 0 .and. in1 > 0) in_data(line_counter) = dummy(:in1 - 1)
if (in2 > 0 .and. in1 > 0) in_data(line_counter) = dummy(:min(in1, in2) - 1)
end do
close (in_unit)
end subroutine param_in_file