46#include "../base/base_uses.f90"
51 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
52 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'input_parsing'
70 LOGICAL,
INTENT(in),
OPTIONAL :: root_section
72 CHARACTER(len=*),
PARAMETER :: routinen =
'section_vals_parse'
74 CHARACTER(len=max_line_length) :: token
75 INTEGER :: desc_level, handle, ik, imatch, irs, is, &
77 LOGICAL :: at_end, compatible_end, root_sect, &
85 CALL timeset(routinen, handle)
87 NULLIFY (previous_list, previous_last)
90 IF (
PRESENT(root_section)) root_sect = root_section
92 cpassert(
ASSOCIATED(section_vals))
95 cpassert(section_vals%ref_count > 0)
96 IF (root_sect .AND. parser%icol1 > parser%icol2) &
97 CALL cp_abort(__location__, &
98 "Error 1: this routine must be called just after having parsed the start of the section " &
100 section => section_vals%section
102 token = trim(adjustl(parser%input_line(parser%icol1:parser%icol2)))
104 IF (token /= parser%section_character//section%name) &
105 CALL cp_abort(__location__, &
106 "Error 2: this routine must be called just after having parsed the start of the section " &
109 IF (.NOT. section%repeats .AND.
SIZE(section_vals%values, 2) /= 0) &
110 CALL cp_abort(__location__,
"Section "//trim(section%name)// &
113 irs =
SIZE(section_vals%values, 2)
115 IF (
ALLOCATED(section%deprecation_notice))
THEN
116 CALL cp_warn(__location__, &
117 "The specified section '"//trim(section%name)// &
118 "' is deprecated and may be removed in a future version: "// &
119 section%deprecation_notice)
122 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
123 keyword => section%keywords(-1)%keyword
126 CALL val_create_parsing(el, type_of_var=keyword%type_of_var, &
127 n_var=keyword%n_var, default_value=keyword%lone_keyword_value, &
128 enum=keyword%enum, unit=keyword%unit, &
129 default_units=default_units, &
133 section_vals%values(-1, irs)%list => new_val
138 lower_to_upper=.true., at_end=at_end)
139 token = trim(adjustl(token))
142 CALL cp_abort(__location__, &
143 "unexpected end of file while parsing section "// &
147 IF (token(1:1) == parser%section_character)
THEN
148 IF (token ==
"&END")
THEN
150 compatible_end = .true.
153 lower_to_upper=.true.)
154 IF (token /=
"SECTION" .AND. token /= section%name)
THEN
155 compatible_end = .false.
160 lower_to_upper=.true.)
161 IF (token /= section%name)
THEN
162 print *, trim(token),
"/=", trim(section%name)
163 compatible_end = .false.
166 IF (.NOT. compatible_end)
THEN
167 CALL cp_abort(__location__, &
168 "non-compatible end of section "//trim(section%name)//
" "// &
177 default_units=default_units, parser=parser)
180 IF (output_unit > 0)
THEN
181 WRITE (output_unit, *)
182 WRITE (output_unit,
'(T2,A)')
"Possible matches for unknown subsection "
183 WRITE (output_unit, *)
184 WRITE (output_unit,
'(T2,A)') trim(token(2:))
185 WRITE (output_unit, *)
192 CALL cp_abort(__location__, &
193 "unknown subsection "//trim(token(2:))//
" of section " &
194 //trim(section%name))
198 lower_to_upper=.true.)
199 IF (token(1:1) == parser%section_character)
THEN
200 IF (token ==
"&END")
THEN
209 IF (token ==
"DESCRIBE")
THEN
210 IF (output_unit > 0)
WRITE (output_unit,
"(/,' ****** DESCRIPTION ******',/)")
215 whole_section = .true.
217 whole_section = .false.
219 lower_to_upper=.true.)
221 IF (.NOT.
ASSOCIATED(keyword))
THEN
222 CALL cp_warn(__location__, &
223 "unknown keyword to describe "//trim(token)// &
224 " in section "//trim(section%name))
229 IF (whole_section)
THEN
230 CALL section_describe(section, output_unit, desc_level, hide_root=.NOT. root_sect)
232 IF (output_unit > 0)
WRITE (output_unit,
"(/,' ****** =========== ******',/)")
237 parser%icol = parser%icol1 - 1
239 IF (.NOT.
ASSOCIATED(section%keywords(0)%keyword))
THEN
240 IF (output_unit > 0)
THEN
241 WRITE (output_unit, *)
242 WRITE (output_unit,
'(T2,A)')
"Possible matches for unknown keyword "
243 WRITE (output_unit, *)
244 WRITE (output_unit,
'(T2,A)') trim(token)
245 WRITE (output_unit, *)
249 WRITE (output_unit,
'(T2,A,1X,I0)') &
253 CALL cp_abort(__location__, &
254 "found an unknown keyword "//trim(token)// &
255 " in section "//trim(section%name))
258 keyword => section%keywords(ik)%keyword
259 IF (
ASSOCIATED(keyword))
THEN
260 IF (keyword%removed)
THEN
261 IF (
ALLOCATED(keyword%deprecation_notice))
THEN
262 CALL cp_abort(__location__, &
263 "The specified keyword '"//trim(token)//
"' is not available anymore: "// &
264 keyword%deprecation_notice)
266 CALL cp_abort(__location__, &
267 "The specified keyword '"//trim(token)// &
268 "' is not available anymore, please consult the manual.")
272 IF (
ALLOCATED(keyword%deprecation_notice)) &
273 CALL cp_warn(__location__, &
274 "The specified keyword '"//trim(token)// &
275 "' is deprecated and may be removed in a future version: "// &
276 keyword%deprecation_notice//
".")
279 IF (ik /= 0 .AND. keyword%type_of_var ==
lchar_t) &
281 CALL val_create_parsing(el, type_of_var=keyword%type_of_var, &
282 n_var=keyword%n_var, default_value=keyword%lone_keyword_value, &
283 enum=keyword%enum, unit=keyword%unit, &
284 default_units=default_units, parser=parser)
285 IF (
ASSOCIATED(el))
THEN
288 last_val => section_vals%values(ik, irs)%list
289 IF (.NOT.
ASSOCIATED(last_val))
THEN
290 section_vals%values(ik, irs)%list => new_val
292 IF (.NOT. keyword%repeats) &
293 CALL cp_abort(__location__, &
294 "Keyword "//trim(token)// &
295 " in section "//trim(section%name)//
" should not repeat.")
296 IF (
ASSOCIATED(last_val, previous_list))
THEN
297 last_val => previous_last
299 previous_list => last_val
301 DO WHILE (
ASSOCIATED(last_val%rest))
302 last_val => last_val%rest
304 last_val%rest => new_val
305 previous_last => new_val
312 CALL timestop(handle)
329 SUBROUTINE val_create_parsing(val, type_of_var, n_var, enum, &
330 parser, unit, default_units, default_value)
332 INTEGER,
INTENT(in) :: type_of_var, n_var
337 TYPE(
val_type),
OPTIONAL,
POINTER :: default_value
339 CHARACTER(len=*),
PARAMETER :: routinen =
'val_create_parsing'
341 CHARACTER(len=default_string_length) :: c_val, info, location
342 CHARACTER(len=default_string_length), &
343 DIMENSION(:),
POINTER :: c_val_p
344 INTEGER :: handle, i, i_val
345 INTEGER,
DIMENSION(:),
POINTER :: i_val_p
346 LOGICAL :: check, eol, l_val, quoted
347 LOGICAL,
DIMENSION(:),
POINTER :: l_val_p
348 REAL(kind=
dp) :: r_val
349 REAL(kind=
dp),
DIMENSION(:),
POINTER :: r_val_p
355 CALL timeset(routinen, handle)
357 cpassert(.NOT.
ASSOCIATED(val))
358 SELECT CASE (type_of_var)
363 IF (.NOT.
ASSOCIATED(default_value))
THEN
365 ALLOCATE (l_val_p(0))
368 CALL cp_abort(__location__, &
369 "no value was given and there is no default value"// &
373 cpassert(
ASSOCIATED(default_value%l_val))
374 CALL val_create(val, l_vals=default_value%l_val)
378 NULLIFY (l_last, l_first)
391 ALLOCATE (l_val_p(n_var))
396 IF (
ASSOCIATED(l_val_p))
THEN
403 IF (.NOT.
ASSOCIATED(default_value))
THEN
405 ALLOCATE (i_val_p(0))
408 CALL cp_abort(__location__, &
409 "no value was given and there is no default value"// &
413 check =
ASSOCIATED(default_value%i_val)
415 CALL val_create(val, i_vals=default_value%i_val)
419 NULLIFY (i_last, i_first)
432 ALLOCATE (i_val_p(n_var))
437 IF (
ASSOCIATED(i_val_p))
THEN
444 IF (.NOT.
ASSOCIATED(default_value))
THEN
446 ALLOCATE (r_val_p(0))
449 CALL cp_abort(__location__, &
450 "no value was given and there is no default value"// &
454 cpassert(
ASSOCIATED(default_value%r_val))
455 CALL val_create(val, r_vals=default_value%r_val)
459 NULLIFY (r_last, r_first)
461 CALL get_r_val(r_val, parser, unit, default_units, c_val)
465 CALL get_r_val(r_val, parser, unit, default_units, c_val)
474 ALLOCATE (r_val_p(n_var))
477 CALL get_r_val(r_val_p(i), parser, unit, default_units, c_val)
480 IF (
ASSOCIATED(r_val_p))
THEN
488 ALLOCATE (c_val_p(1))
492 IF (.NOT.
ASSOCIATED(default_value))
THEN
493 CALL cp_abort(__location__, &
494 "no value was given and there is no default value"// &
497 cpassert(
ASSOCIATED(default_value%c_val))
498 CALL val_create(val, c_vals=default_value%c_val)
503 cpassert(n_var == -1)
504 NULLIFY (c_last, c_first)
517 ALLOCATE (c_val_p(n_var))
522 IF (
ASSOCIATED(c_val_p))
THEN
527 IF (
ASSOCIATED(default_value)) &
528 CALL cp_abort(__location__, &
529 "input variables of type lchar_t cannot have a lone keyword attribute,"// &
530 " no value is interpreted as empty string"// &
533 CALL cp_abort(__location__, &
534 "input variables of type lchar_t cannot be repeated,"// &
535 " one always represent a whole line, till the end"// &
538 ALLOCATE (c_val_p(1))
541 NULLIFY (c_last, c_first)
543 IF (c_val(1:1) == parser%quote_character)
THEN
545 c_val(1:) = c_val(2:)
546 i = index(c_val, parser%quote_character)
561 i = index(c_val, parser%quote_character)
567 CALL cp_abort(__location__, &
568 "Quotation mark found which is not the first non-blank character. "// &
569 "Possibly the first quotation mark is missing?"// &
582 cpassert(
ASSOCIATED(c_val_p))
585 cpassert(
ASSOCIATED(enum))
588 IF (.NOT.
ASSOCIATED(default_value))
THEN
590 ALLOCATE (i_val_p(0))
593 CALL cp_abort(__location__, &
594 "no value was given and there is no default value"// &
598 cpassert(
ASSOCIATED(default_value%i_val))
599 CALL val_create(val, i_vals=default_value%i_val, &
600 enum=default_value%enum)
604 NULLIFY (i_last, i_first)
617 ALLOCATE (i_val_p(n_var))
623 IF (
ASSOCIATED(i_val_p))
THEN
624 CALL val_create(val, i_vals_ptr=i_val_p, enum=enum)
628 CALL cp_abort(__location__, &
629 "type "//
cp_to_string(type_of_var)//
"unknown to the parser")
634 CALL cp_abort(__location__, &
635 "found unexpected extra argument "//trim(info)//
" at "//location)
638 CALL timestop(handle)
640 END SUBROUTINE val_create_parsing
651 SUBROUTINE get_r_val(r_val, parser, unit, default_units, c_val)
652 REAL(kind=
dp),
INTENT(OUT) :: r_val
656 CHARACTER(len=default_string_length), &
657 INTENT(INOUT) :: c_val
662 IF (
ASSOCIATED(unit))
THEN
665 IF (c_val(1:1) /=
"[" .OR. c_val(len_trim(c_val):len_trim(c_val)) /=
"]")
THEN
666 CALL cp_abort(__location__, &
667 "Invalid unit specifier or function found when parsing a number: "// &
673 IF (c_val /=
"")
THEN
681 CALL cp_abort(__location__, &
682 "Incompatible units. Defined as ("// &
683 trim(
cp_unit_desc(unit))//
") specified in input as ("// &
684 trim(
cp_unit_desc(my_unit))//
"). These units are incompatible!")
687 IF (
ASSOCIATED(unit))
THEN
689 IF (.NOT. (
ASSOCIATED(my_unit, unit)))
THEN
695 END SUBROUTINE get_r_val
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_skip_space(parser)
Skips the whitespaces.
character(len=3) function, public parser_test_next_token(parser, string_length)
Test next input object.
character(len=default_path_length+default_string_length) function, public parser_location(parser)
return a description of the part of the file actually parsed
Utility routines to read data from files. Kept as close as possible to the old parser because.
character(len=cp_unit_desc_length) function, public cp_unit_desc(unit, defaults, accept_undefined)
returns the "name" of the given unit
real(kind=dp) function, public cp_unit_to_cp2k1(value, unit, defaults, power)
transform a value to the internal cp2k units
subroutine, public cp_unit_create(unit, string)
creates a unit parsing a string
logical function, public cp_unit_compatible(ref_unit, unit)
returs true if the two units are compatible
elemental subroutine, public cp_unit_release(unit)
releases the given unit
Defines the basic variable types.
integer, parameter, public max_line_length
integer, parameter, public dp
integer, parameter, public default_string_length
Utilities for string manipulations.
character(len=1), parameter, public newline
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
stores the default units to be used