Open, read in, and process the GROMACS-style index file, storing information in memory.
68 class(indexfile),
intent(inout) :: this
69 character (len=*),
intent(in) :: filename
70 character (len=2048) :: line, ncols_string, fmt_string
71 integer :: index_file_unit, io_status, ngrps, i, j, ncols
72 integer,
allocatable :: indices_tmp(:), title_loc(:), num_array(:)
74 integer,
intent(in),
optional :: n
77 inquire(file=trim(filename), exist=ex)
78 if (ex .eqv. .false.)
call error_stop_program(trim(filename)//
" does not exist.")
81 open(newunit=index_file_unit, file=trim(filename), status=
"old")
82 read(index_file_unit,
'(a)', iostat=io_status) line
83 if (index(line,
"[") .eq. 0)
call error_stop_program(trim(filename)//
" is not a valid index file.")
86 rewind index_file_unit
89 do while (io_status .eq. 0)
90 read(index_file_unit,
'(a)', iostat=io_status) line
91 if (io_status .ne. 0)
goto 100
92 if (index(line,
"[") .ne. 0) ngrps = ngrps + 1
97 if (
allocated(this%group))
deallocate(this%group)
98 allocate(this%group(ngrps), title_loc(ngrps+1))
101 rewind index_file_unit
105 do while (io_status .eq. 0)
107 read(index_file_unit,
'(a)', iostat=io_status) line
108 if (io_status .ne. 0)
goto 200
109 if (index(line,
"[") .ne. 0)
then 110 this%group(i)%title = trim(line(index(line,
"[")+2:index(line,
"]")-2))
120 if (this%group(1)%title .ne.
"System")
call error_stop_program(
"Index file does not have 'System' group as first group.")
126 allocate(num_array(ncols))
128 do while (io_status .ne. 0)
130 write(ncols_string,
'(i0)') ncols
131 write(fmt_string,
'(a)')
'('//trim(ncols_string)//
'i0)' 132 rewind index_file_unit
133 read(index_file_unit,
'(a)', iostat=io_status) line
134 read(index_file_unit,
'(a)', iostat=io_status) line
135 read(line, *, iostat=io_status) num_array(1:ncols)
142 allocate(indices_tmp(n))
147 this%group(i)%NUMATOMS = (title_loc(i+1)-title_loc(i)-1)*ncols + 1
149 if (n < this%group(i)%NUMATOMS) this%group(i)%NUMATOMS = n + 1
152 do while (io_status .ne. 0)
155 rewind index_file_unit
156 this%group(i)%NUMATOMS = this%group(i)%NUMATOMS - 1
157 if (this%group(i)%NUMATOMS .le. 0)
then 158 this%group(i)%NUMATOMS = 0
163 do j = 1, title_loc(i);
read(index_file_unit,
'(a)', iostat=io_status) line;
end do 166 read(index_file_unit, *, iostat=io_status) indices_tmp(1:this%group(i)%NUMATOMS)
171 allocate(this%group(i)%LOC(1:this%group(i)%NUMATOMS), source=indices_tmp(1:this%group(i)%NUMATOMS))
176 deallocate(indices_tmp)
181 if (this%group(i)%title .eq. this%group(j)%title)
then 183 write(error_unit,
'(a, a, a)')
"LIBDCDFORT WARNING: Index group ", this%group(i)%title, &
184 " was specified more than once in index file." 194 if (this%group(1)%numatoms .ne. n .or. this%group(1)%loc(this%group(1)%numatoms) .ne. n)
then 195 call error_stop_program(
"Index file does not match dcd file.")
202 if (this%group(i)%numatoms .gt. n)
call error_stop_program(
"Index file does not match dcd file.")
205 do j = 1, this%group(i)%numatoms
206 if (this%group(i)%loc(j) .gt. n)
call error_stop_program(
"Index file does not match dcd file.")
212 close(index_file_unit)