Load the *.win file into a character array in_file, ignoring comments and blank lines and converting everything to lowercase characters
| Type | Intent | Optional | 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 |
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