13 integer,
parameter ::
dp = kind(1.0d0)
28 ,keyvector_int,valvector_int,keyvector_re,valvector_re,&
29 keyvector_log,valvector_log,filename,startstop)
31 character(1),
allocatable :: tempc(:)
32 character(100),
allocatable :: vect(:,:)
33 character(50) :: keyvector_char(:), keyvector_int(:), keyvector_log(:), keyvector_re(:)
34 character(100) :: valvector_char(:)
35 character(len=*) :: filename
36 character(len=*),
intent(in),
optional :: startstop(2)
37 character(len=100) :: tempcflex
38 integer :: i, io_control, ios, j
39 integer :: k, l, lenc, nkey_char
40 integer :: nkey_int, nkey_log, nkey_re, readmaxi
41 integer :: readmaxj, readmini, valvector_int(:)
42 integer :: startatj, totalwords
43 logical :: start, stopl, valid, valvector_log(:), stopparsing, defaultnone
44 logical,
allocatable :: checkmissing_char(:), checkmissing_int(:), checkmissing_log(:), checkmissing_re(:)
45 real(
dp) :: valvector_re(:)
47 readmaxi = 5 ; readmaxj = 1000
48 allocate(vect(readmaxi,readmaxj))
49 nkey_char =
size(keyvector_char,dim=1)
50 nkey_re =
size(keyvector_re,dim=1)
51 nkey_int =
size(keyvector_int,dim=1)
52 nkey_log =
size(keyvector_log,dim=1)
56 allocate(checkmissing_char(nkey_char),checkmissing_re(nkey_re), &
57 checkmissing_int(nkey_int), checkmissing_log(nkey_log))
60 checkmissing_char = .false.
61 checkmissing_re = .false.
62 checkmissing_int = .false.
63 checkmissing_log = .false.
69 read(io_control,*,iostat=ios)(vect(i,j),j=1,readmaxj)
78 if(adjustl(trim(vect(i,k))).ne.
"")totalwords = totalwords + 1
79 if(adjustl(trim(vect(i,k))).eq.
"#")
then
81 write(*,*)
"ERROR in the the input file ..."
83 write(*,*)
"For this parsing routine everything is a comment by default unless theres an = sign"
84 write(*,*)
"next to a word, in which case, it will be recognized as a keyword."
85 write(*,*)
"This parser does not accept floating hashes (#). This is done in order to make sure"
86 write(*,*)
"that a specific keyword is commented"
88 write(*,*)
"If you have a commented keyword make sure there is a # symbol right next to it"
90 write(*,*)
" The following commented keyword is correct: "
91 write(*,*)
" #KeyWord= 1 "
93 write(*,*)
" The following commented keyword is NOT correct: "
94 write(*,*)
" # KeyWord= 1 "
98 if(adjustl(trim(vect(i,k))).eq.
"STOP{}")stopparsing = .true.
99 if(adjustl(trim(vect(i,k))).eq.
"DEFAULTNONE")defaultnone = .true.
103 if(totalwords > readmaxi*readmaxj - 100)
then
104 write(*,*)
"";
write(*,*)
"Stopping ... Maximum allowed (keys + values + comments) words close to the limit "
105 write(*,*)
"Increase the readmaxj variable in the prg_parsing_kernel subroutine or reduce the comments in the input"
112 if(
present(startstop))
then
115 if(trim(vect(i,k)).eq.trim(startstop(1)))
then
120 if(start.and.trim(vect(i,k)).eq.trim(startstop(2)))
then
132 do i=readmini,readmaxi
134 if(trim(vect(i,k)).eq.trim(startstop(1)))start=.true.
137 if(vect(i,k).ne.
' ')
then
139 if(trim(vect(i,k)).eq.trim(keyvector_char(j)))
then
144 if(trim(vect(i,k)).eq.trim(keyvector_int(j)))
then
149 if(trim(vect(i,k)).eq.trim(keyvector_re(j)))
then
154 if(trim(vect(i,k)).eq.trim(keyvector_log(j)))
then
158 if(trim(vect(i,k)).eq.trim(startstop(2)))
then
169 do i=readmini,readmaxi
173 if(vect(i,k).ne.
' ')
then
175 if(readmaxj*(i-1)+k .ge.readmaxj*(readmini-1)+startatj)
then
176 if(trim(vect(i,k)).ne.
'}')
then
178 if(adjustl(trim(vect(i,k))).eq.adjustl(trim(keyvector_char(j))))
then
179 valvector_char(j)=adjustl(trim(vect(i,k+1)))
180 checkmissing_char(j) = .true.
189 if(trim(vect(i,k)).eq.trim(keyvector_char(j)))
then
190 valvector_char(j)=trim(vect(i,k+1))
191 checkmissing_char(j) = .true.
202 do i=readmini,readmaxi
206 if(vect(i,k).ne.
' ')
then
208 if(readmaxj*(i-1)+k .ge.readmaxj*(readmini-1)+startatj)
then
209 if(adjustl(trim(vect(i,k))).ne.
'}')
then
211 if(trim(vect(i,k)).eq.trim(keyvector_int(j)))
then
212 read(vect(i,k+1),*)valvector_int(j)
213 checkmissing_int(j) = .true.
222 if(trim(vect(i,k)).eq.trim(keyvector_int(j)))
then
223 read(vect(i,k+1),*)valvector_int(j)
224 checkmissing_int(j) = .true.
235 do i=readmini,readmaxi
239 if(vect(i,k).ne.
' ')
then
241 if(readmaxj*(i-1)+k .ge.readmaxj*(readmini-1)+startatj)
then
242 if(trim(vect(i,k)).ne.
'}')
then
244 if(trim(vect(i,k)).eq.trim(keyvector_re(j)))
then
245 read(vect(i,k+1),*)valvector_re(j)
246 checkmissing_re(j) = .true.
255 if(trim(vect(i,k)).eq.trim(keyvector_re(j)))
then
256 read(vect(i,k+1),*)valvector_re(j)
257 checkmissing_re(j) = .true.
272 if(vect(i,k).ne.
' ')
then
274 if(readmaxj*(i-1)+k .ge.readmaxj*(readmini-1)+startatj)
then
275 if(trim(vect(i,k)).ne.
'}')
then
277 if(trim(vect(i,k)).eq.trim(keyvector_log(j)))
then
278 read(vect(i,k+1),*)valvector_log(j)
279 checkmissing_log(j) = .true.
288 if(trim(vect(i,k)).eq.trim(keyvector_log(j)))
then
289 read(vect(i,k+1),*)valvector_log(j)
290 checkmissing_log(j) = .true.
303 if(defaultnone .eqv..true.)
then
304 if(checkmissing_char(i).neqv..true..and.trim(keyvector_char(i)).ne.
"DUMMY=")
then
305 write(*,*)
'ERROR: variable ',trim(keyvector_char(i)),&
306 ' is missing. Set this variable or remove the DEFAULTNONE keyword from the input file...'
307 write(*,*)
'Default value is:',valvector_char(i)
311 if(checkmissing_char(i).neqv..true.)
write(*,*)
'WARNING: variable ',trim(keyvector_char(i)),&
312 ' is missing. I will use a default value instead ...'
315 if(defaultnone .eqv..true.)
then
316 if(checkmissing_int(i).neqv..true..and.trim(keyvector_int(i)).ne.
"DUMMY=")
then
317 write(*,*)
'ERROR: variable ',trim(keyvector_int(i)),&
318 ' is missing. Set this variable or remove the DEFAULTNONE keyword from the input file...'
319 write(*,*)
'Default value is:',valvector_int(i)
323 if(checkmissing_int(i).neqv..true.)
write(*,*)
'WARNING: variable ',trim(keyvector_int(i)),&
324 ' is missing. I will use a default value instead ...'
327 if(defaultnone .eqv..true.)
then
328 if(checkmissing_re(i).neqv..true..and.trim(keyvector_re(i)).ne.
"DUMMY=")
then
329 write(*,*)
'ERROR: variable ',trim(keyvector_re(i)),&
330 ' is missing. Set this variable or remove the DEFAULTNONE keyword from the input file...'
331 write(*,*)
'Default value is:',valvector_re(i)
335 if(checkmissing_re(i).neqv..true.)
write(*,*)
'WARNING: variable ',trim(keyvector_re(i)),&
336 ' is missing. I will use a default value instead ...'
339 if(defaultnone .eqv..true.)
then
340 if(checkmissing_log(i).neqv..true..and.trim(keyvector_log(i)).ne.
"DUMMY=")
then
341 write(*,*)
'ERROR: variable ',trim(keyvector_log(i)),&
342 ' is missing. Set this variable or remove the DEFAULTNONE keyword from the input file...'
343 write(*,*)
'Default value is:',valvector_log(i)
347 if(checkmissing_log(i).neqv..true.)
write(*,*)
'WARNING: variable ',trim(keyvector_log(i)),&
348 ' is missing. I will use a default value instead ...'
352 deallocate(checkmissing_char,checkmissing_re, checkmissing_int, checkmissing_log)
358 write(*,*)
"############### Parameters used for this run ################"
359 if(start)
write(*,*)
" ",startstop(1)
361 write(*,*)
" ",trim(keyvector_int(j)),valvector_int(j)
365 write(*,*)
" ",trim(keyvector_re(j)),valvector_re(j)
369 write(*,*)
" ",trim(keyvector_char(j)),valvector_char(j)
373 write(*,*)
" ",trim(keyvector_log(j)),valvector_log(j)
375 if(start)
write(*,*)
" ",startstop(2)
381 write(*,*)
"" ;
write(*,*)
"STOP key found. Stop parsing ... ";
write(*,*)
""
394 character(1),
allocatable :: tempc(:)
395 character(len=*),
intent(in) :: invalidc
396 character(len=100) :: tempcflex
399 lenc=len(adjustl(trim(invalidc)))
400 if(.not.
allocated(tempc))
allocate(tempc(lenc))
401 do l = 1,len(adjustl(trim(invalidc)))
402 tempcflex = adjustl(trim(invalidc))
403 tempc(l) = tempcflex(l:l)
404 if(tempc(l).eq.
"=".and.tempc(1).ne.
"#")
then
405 write(*,*)
"Input ERROR: ",adjustl(trim(invalidc)),
" is not a valid keyword"
Some general parsing functions.
subroutine prg_check_valid(invalidc)
Check for valid keywords (checks for an = sign)
subroutine, public prg_parsing_kernel(keyvector_char, valvector_char, keyvector_int, valvector_int, keyvector_re, valvector_re, keyvector_log, valvector_log, filename, startstop)
The general parsing function. It is used to vectorize a set of "keywords" "value" pairs as included i...
Module to handle input output files for the PROGRESS lib.
subroutine, public prg_open_file_to_read(io, name)
Opens a file to read.
integer function, public printrank()