(git:b6ef100)
Loading...
Searching...
No Matches
input_parsing.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief routines that parse the input
10!> \par History
11!> 06.2004 created
12!> \author fawzi
13! **************************************************************************************************
15 USE cp_linked_list_input, ONLY: &
25 USE cp_units, ONLY: cp_unit_compatible,&
36 USE input_section_types, ONLY: &
40 USE input_val_types, ONLY: &
42 USE kinds, ONLY: default_string_length,&
43 dp,&
46#include "../base/base_uses.f90"
47
48 IMPLICIT NONE
49 PRIVATE
50
51 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
52 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_parsing'
53
54 PUBLIC :: section_vals_parse
55!***
56CONTAINS
57
58! **************************************************************************************************
59!> \brief ...
60!> \param section_vals ...
61!> \param parser ...
62!> \param default_units ...
63!> \param root_section if the root section should be parsed (defaults to true)
64!> \author fawzi
65! **************************************************************************************************
66 RECURSIVE SUBROUTINE section_vals_parse(section_vals, parser, default_units, root_section)
67 TYPE(section_vals_type), POINTER :: section_vals
68 TYPE(cp_parser_type), INTENT(INOUT) :: parser
69 TYPE(cp_unit_set_type), INTENT(IN) :: default_units
70 LOGICAL, INTENT(in), OPTIONAL :: root_section
71
72 CHARACTER(len=*), PARAMETER :: routinen = 'section_vals_parse'
73
74 CHARACTER(len=max_line_length) :: token
75 INTEGER :: desc_level, handle, ik, imatch, irs, is, &
76 nsub, output_unit
77 LOGICAL :: at_end, compatible_end, root_sect, &
78 whole_section
79 TYPE(cp_sll_val_type), POINTER :: last_val, new_val, previous_last, &
80 previous_list
81 TYPE(keyword_type), POINTER :: keyword
82 TYPE(section_type), POINTER :: section
83 TYPE(val_type), POINTER :: el
84
85 CALL timeset(routinen, handle)
86
87 NULLIFY (previous_list, previous_last)
88
89 root_sect = .true.
90 IF (PRESENT(root_section)) root_sect = root_section
91
92 cpassert(ASSOCIATED(section_vals))
93 output_unit = cp_logger_get_default_io_unit()
94
95 cpassert(section_vals%ref_count > 0)
96 IF (root_sect .AND. parser%icol1 > parser%icol2) THEN
97 CALL cp_abort(__location__, &
98 "Error 1: this routine must be called just after having parsed the start of the section " &
99 //trim(parser_location(parser)))
100 END IF
101 section => section_vals%section
102 IF (root_sect) THEN
103 token = trim(adjustl(parser%input_line(parser%icol1:parser%icol2))) ! Ignore leading or trailing blanks
104 CALL uppercase(token)
105 IF (token /= parser%section_character//section%name) THEN
106 CALL cp_abort(__location__, &
107 "Error 2: this routine must be called just after having parsed the start of the section " &
108 //trim(parser_location(parser)))
109 END IF
110 END IF
111 IF (.NOT. section%repeats .AND. SIZE(section_vals%values, 2) /= 0) THEN
112 CALL cp_abort(__location__, "Section "//trim(section%name)// &
113 " should not repeat "//trim(parser_location(parser)))
114 END IF
115 CALL section_vals_add_values(section_vals)
116 irs = SIZE(section_vals%values, 2)
117
118 IF (ALLOCATED(section%deprecation_notice)) THEN
119 CALL cp_warn(__location__, &
120 "The specified section '"//trim(section%name)// &
121 "' is deprecated and may be removed in a future version: "// &
122 section%deprecation_notice)
123 END IF
124
125 IF (ASSOCIATED(section%keywords(-1)%keyword)) THEN ! reads section params
126 keyword => section%keywords(-1)%keyword
127 NULLIFY (el)
128 IF (keyword%type_of_var == lchar_t) CALL parser_skip_space(parser)
129 CALL val_create_parsing(el, type_of_var=keyword%type_of_var, &
130 n_var=keyword%n_var, default_value=keyword%lone_keyword_value, &
131 enum=keyword%enum, unit=keyword%unit, &
132 default_units=default_units, &
133 parser=parser)
134 NULLIFY (new_val)
135 CALL cp_sll_val_create(new_val, el)
136 section_vals%values(-1, irs)%list => new_val
137 NULLIFY (el)
138 END IF
139 DO WHILE (.true.)
140 CALL parser_get_object(parser, token, newline=.true., &
141 lower_to_upper=.true., at_end=at_end)
142 token = trim(adjustl(token)) ! Ignore leading or trailing blanks
143 IF (at_end) THEN
144 IF (root_sect) THEN
145 CALL cp_abort(__location__, &
146 "unexpected end of file while parsing section "// &
147 trim(section%name)//" "//trim(parser_location(parser)))
148 END IF
149 EXIT
150 END IF
151 IF (token(1:1) == parser%section_character) THEN
152 IF (token == "&END") THEN
153 ! end of section
154 compatible_end = .true.
155 IF (parser_test_next_token(parser) /= "EOL") THEN
156 CALL parser_get_object(parser, token, newline=.false., &
157 lower_to_upper=.true.)
158 IF (token /= "SECTION" .AND. token /= section%name) THEN
159 compatible_end = .false.
160 END IF
161 END IF
162 IF (parser_test_next_token(parser) /= "EOL") THEN
163 CALL parser_get_object(parser, token, newline=.false., &
164 lower_to_upper=.true.)
165 IF (token /= section%name) THEN
166 print *, trim(token), "/=", trim(section%name)
167 compatible_end = .false.
168 END IF
169 END IF
170 IF (.NOT. compatible_end) THEN
171 CALL cp_abort(__location__, &
172 "non-compatible end of section "//trim(section%name)//" "// &
173 trim(parser_location(parser)))
174 END IF
175 ! RETURN
176 EXIT
177 END IF
178 is = section_get_subsection_index(section, token(2:))
179 IF (is > 0) THEN
180 CALL section_vals_parse(section_vals%subs_vals(is, irs)%section_vals, &
181 default_units=default_units, parser=parser)
182 ELSE
183 ! unknown subsection
184 IF (output_unit > 0) THEN
185 WRITE (output_unit, *)
186 WRITE (output_unit, '(T2,A)') "Possible matches for unknown subsection "
187 WRITE (output_unit, *)
188 WRITE (output_unit, '(T2,A)') trim(token(2:))
189 WRITE (output_unit, *)
190 CALL section_typo_match(typo_match_section, trim(section%name), trim(token(2:)), "", &
192 DO imatch = 1, SIZE(typo_matching_rank)
193 WRITE (output_unit, '(T2,A,1X,I0)') trim(typo_matching_line(imatch))//" score: ", typo_matching_rank(imatch)
194 END DO
195 END IF
196 CALL cp_abort(__location__, &
197 "unknown subsection "//trim(token(2:))//" of section " &
198 //trim(section%name))
199 nsub = 1
200 DO WHILE (nsub > 0)
201 CALL parser_get_object(parser, token, newline=.true., &
202 lower_to_upper=.true.)
203 IF (token(1:1) == parser%section_character) THEN
204 IF (token == "&END") THEN
205 nsub = nsub - 1
206 ELSE
207 nsub = nsub + 1
208 END IF
209 END IF
210 END DO
211 END IF
212 ELSE ! token is a keyword
213 IF (token == "DESCRIBE") THEN
214 IF (output_unit > 0) WRITE (output_unit, "(/,' ****** DESCRIPTION ******',/)")
215 desc_level = 3
216 IF (parser_test_next_token(parser) == "INT") THEN
217 CALL parser_get_object(parser, desc_level)
218 END IF
219 whole_section = .true.
220 DO WHILE (parser_test_next_token(parser) == "STR")
221 whole_section = .false.
222 CALL parser_get_object(parser, token, newline=.false., &
223 lower_to_upper=.true.)
224 keyword => section_get_keyword(section, token)
225 IF (.NOT. ASSOCIATED(keyword)) THEN
226 CALL cp_warn(__location__, &
227 "unknown keyword to describe "//trim(token)// &
228 " in section "//trim(section%name))
229 ELSE
230 CALL keyword_describe(keyword, output_unit, desc_level)
231 END IF
232 END DO
233 IF (whole_section) THEN
234 CALL section_describe(section, output_unit, desc_level, hide_root=.NOT. root_sect)
235 END IF
236 IF (output_unit > 0) WRITE (output_unit, "(/,' ****** =========== ******',/)")
237
238 ELSE ! token is a "normal" keyword
239 ik = section_get_keyword_index(section, token)
240 IF (ik < 1) THEN ! don't accept pseudo keyword names
241 parser%icol = parser%icol1 - 1 ! re-read also the actual token
242 ik = 0
243 IF (.NOT. ASSOCIATED(section%keywords(0)%keyword)) THEN
244 IF (output_unit > 0) THEN
245 WRITE (output_unit, *)
246 WRITE (output_unit, '(T2,A)') "Possible matches for unknown keyword "
247 WRITE (output_unit, *)
248 WRITE (output_unit, '(T2,A)') trim(token)
249 WRITE (output_unit, *)
250 CALL section_typo_match(typo_match_section, trim(section%name), trim(token), "", &
252 DO imatch = 1, SIZE(typo_matching_rank)
253 WRITE (output_unit, '(T2,A,1X,I0)') &
254 trim(typo_matching_line(imatch))//" score: ", typo_matching_rank(imatch)
255 END DO
256 END IF
257 CALL cp_abort(__location__, &
258 "found an unknown keyword "//trim(token)// &
259 " in section "//trim(section%name))
260 END IF
261 END IF
262 keyword => section%keywords(ik)%keyword
263 IF (ASSOCIATED(keyword)) THEN
264 IF (keyword%removed) THEN
265 IF (ALLOCATED(keyword%deprecation_notice)) THEN
266 CALL cp_abort(__location__, &
267 "The specified keyword '"//trim(token)//"' is not available anymore: "// &
268 keyword%deprecation_notice)
269 ELSE
270 CALL cp_abort(__location__, &
271 "The specified keyword '"//trim(token)// &
272 "' is not available anymore, please consult the manual.")
273 END IF
274 END IF
275
276 IF (ALLOCATED(keyword%deprecation_notice)) THEN
277 CALL cp_warn(__location__, &
278 "The specified keyword '"//trim(token)// &
279 "' is deprecated and may be removed in a future version: "// &
280 keyword%deprecation_notice)
281 END IF
282
283 NULLIFY (el)
284 IF (ik /= 0 .AND. keyword%type_of_var == lchar_t) THEN
285 CALL parser_skip_space(parser)
286 END IF
287 CALL val_create_parsing(el, type_of_var=keyword%type_of_var, &
288 n_var=keyword%n_var, default_value=keyword%lone_keyword_value, &
289 enum=keyword%enum, unit=keyword%unit, &
290 default_units=default_units, parser=parser)
291 IF (ASSOCIATED(el)) THEN
292 NULLIFY (new_val)
293 CALL cp_sll_val_create(new_val, el)
294 last_val => section_vals%values(ik, irs)%list
295 IF (.NOT. ASSOCIATED(last_val)) THEN
296 section_vals%values(ik, irs)%list => new_val
297 ELSE
298 IF (.NOT. keyword%repeats) THEN
299 CALL cp_abort(__location__, &
300 "Keyword "//trim(token)// &
301 " in section "//trim(section%name)//" should not repeat.")
302 END IF
303 IF (ASSOCIATED(last_val, previous_list)) THEN
304 last_val => previous_last
305 ELSE
306 previous_list => last_val
307 END IF
308 DO WHILE (ASSOCIATED(last_val%rest))
309 last_val => last_val%rest
310 END DO
311 last_val%rest => new_val
312 previous_last => new_val
313 END IF
314 END IF
315 END IF
316 END IF
317 END IF
318 END DO
319 CALL timestop(handle)
320 END SUBROUTINE section_vals_parse
321
322! **************************************************************************************************
323!> \brief creates a val_type object by parsing the values
324!> \param val the value that will be created
325!> \param type_of_var type of the value to be created
326!> \param n_var number of values to be parsed (-1: undefined)
327!> \param enum ...
328!> \param parser the parser from where the values should be read
329!> \param unit ...
330!> \param default_units ...
331!> \param default_value a default value if nothing is found (can be null)
332!> \author fawzi
333!> \note
334!> - no_t does not create a value
335! **************************************************************************************************
336 SUBROUTINE val_create_parsing(val, type_of_var, n_var, enum, &
337 parser, unit, default_units, default_value)
338 TYPE(val_type), POINTER :: val
339 INTEGER, INTENT(in) :: type_of_var, n_var
340 TYPE(enumeration_type), POINTER :: enum
341 TYPE(cp_parser_type), INTENT(INOUT) :: parser
342 TYPE(cp_unit_type), POINTER :: unit
343 TYPE(cp_unit_set_type), INTENT(IN) :: default_units
344 TYPE(val_type), OPTIONAL, POINTER :: default_value
345
346 CHARACTER(len=*), PARAMETER :: routinen = 'val_create_parsing'
347
348 CHARACTER(len=default_string_length) :: c_val, info, location
349 CHARACTER(len=default_string_length), &
350 DIMENSION(:), POINTER :: c_val_p
351 INTEGER :: handle, i, i_val
352 INTEGER, DIMENSION(:), POINTER :: i_val_p
353 LOGICAL :: check, eol, l_val, quoted
354 LOGICAL, DIMENSION(:), POINTER :: l_val_p
355 REAL(kind=dp) :: r_val
356 REAL(kind=dp), DIMENSION(:), POINTER :: r_val_p
357 TYPE(cp_sll_char_type), POINTER :: c_first, c_last, c_new
358 TYPE(cp_sll_int_type), POINTER :: i_first, i_last, i_new
359 TYPE(cp_sll_logical_type), POINTER :: l_first, l_last, l_new
360 TYPE(cp_sll_real_type), POINTER :: r_first, r_last, r_new
361
362 CALL timeset(routinen, handle)
363
364 cpassert(.NOT. ASSOCIATED(val))
365 SELECT CASE (type_of_var)
366 CASE (no_t)
367 CASE (logical_t)
368 NULLIFY (l_val_p)
369 IF (parser_test_next_token(parser) == "EOL") THEN
370 IF (.NOT. ASSOCIATED(default_value)) THEN
371 IF (n_var < 1) THEN
372 ALLOCATE (l_val_p(0))
373 CALL val_create(val, l_vals_ptr=l_val_p)
374 ELSE
375 CALL cp_abort(__location__, &
376 "no value was given and there is no default value"// &
377 trim(parser_location(parser)))
378 END IF
379 ELSE
380 cpassert(ASSOCIATED(default_value%l_val))
381 CALL val_create(val, l_vals=default_value%l_val)
382 END IF
383 ELSE
384 IF (n_var < 1) THEN
385 NULLIFY (l_last, l_first)
386 CALL parser_get_object(parser, l_val)
387 CALL cp_create(l_first, l_val)
388 l_last => l_first
389 DO WHILE (parser_test_next_token(parser) /= "EOL")
390 CALL parser_get_object(parser, l_val)
391 CALL cp_create(l_new, l_val)
392 l_last%rest => l_new
393 l_last => l_new
394 END DO
395 l_val_p => cp_to_array(l_first)
396 CALL cp_dealloc(l_first)
397 ELSE
398 ALLOCATE (l_val_p(n_var))
399 DO i = 1, n_var
400 CALL parser_get_object(parser, l_val_p(i))
401 END DO
402 END IF
403 IF (ASSOCIATED(l_val_p)) THEN
404 CALL val_create(val, l_vals_ptr=l_val_p)
405 END IF
406 END IF
407 CASE (integer_t)
408 NULLIFY (i_val_p)
409 IF (parser_test_next_token(parser) == "EOL") THEN
410 IF (.NOT. ASSOCIATED(default_value)) THEN
411 IF (n_var < 1) THEN
412 ALLOCATE (i_val_p(0))
413 CALL val_create(val, i_vals_ptr=i_val_p)
414 ELSE
415 CALL cp_abort(__location__, &
416 "no value was given and there is no default value"// &
417 trim(parser_location(parser)))
418 END IF
419 ELSE
420 check = ASSOCIATED(default_value%i_val)
421 cpassert(check)
422 CALL val_create(val, i_vals=default_value%i_val)
423 END IF
424 ELSE
425 IF (n_var < 1) THEN
426 NULLIFY (i_last, i_first)
427 CALL parser_get_object(parser, i_val)
428 CALL cp_create(i_first, i_val)
429 i_last => i_first
430 DO WHILE (parser_test_next_token(parser) /= "EOL")
431 CALL parser_get_object(parser, i_val)
432 CALL cp_create(i_new, i_val)
433 i_last%rest => i_new
434 i_last => i_new
435 END DO
436 i_val_p => cp_to_array(i_first)
437 CALL cp_dealloc(i_first)
438 ELSE
439 ALLOCATE (i_val_p(n_var))
440 DO i = 1, n_var
441 CALL parser_get_object(parser, i_val_p(i))
442 END DO
443 END IF
444 IF (ASSOCIATED(i_val_p)) THEN
445 CALL val_create(val, i_vals_ptr=i_val_p)
446 END IF
447 END IF
448 CASE (real_t)
449 NULLIFY (r_val_p)
450 IF (parser_test_next_token(parser) == "EOL") THEN
451 IF (.NOT. ASSOCIATED(default_value)) THEN
452 IF (n_var < 1) THEN
453 ALLOCATE (r_val_p(0))
454 CALL val_create(val, r_vals_ptr=r_val_p)
455 ELSE
456 CALL cp_abort(__location__, &
457 "no value was given and there is no default value"// &
458 trim(parser_location(parser)))
459 END IF
460 ELSE
461 cpassert(ASSOCIATED(default_value%r_val))
462 CALL val_create(val, r_vals=default_value%r_val)
463 END IF
464 ELSE
465 IF (n_var < 1) THEN
466 NULLIFY (r_last, r_first)
467 c_val = ""
468 CALL get_r_val(r_val, parser, unit, default_units, c_val)
469 CALL cp_create(r_first, r_val)
470 r_last => r_first
471 DO WHILE (parser_test_next_token(parser) /= "EOL")
472 CALL get_r_val(r_val, parser, unit, default_units, c_val)
473 CALL cp_create(r_new, r_val)
474 r_last%rest => r_new
475 r_last => r_new
476 END DO
477 NULLIFY (r_last)
478 r_val_p => cp_to_array(r_first)
479 CALL cp_dealloc(r_first)
480 ELSE
481 ALLOCATE (r_val_p(n_var))
482 c_val = ""
483 DO i = 1, n_var
484 CALL get_r_val(r_val_p(i), parser, unit, default_units, c_val)
485 END DO
486 END IF
487 IF (ASSOCIATED(r_val_p)) THEN
488 CALL val_create(val, r_vals_ptr=r_val_p)
489 END IF
490 END IF
491 CASE (char_t)
492 NULLIFY (c_val_p)
493 IF (parser_test_next_token(parser) == "EOL") THEN
494 IF (ASSOCIATED(default_value)) THEN
495 cpassert(ASSOCIATED(default_value%c_val))
496 CALL val_create(val, c_vals=default_value%c_val)
497 ELSE IF (n_var < 1) THEN
498 ALLOCATE (c_val_p(1))
499 c_val_p(1) = ' '
500 CALL val_create(val, c_vals_ptr=c_val_p)
501 ELSE
502 CALL cp_abort(__location__, &
503 "no value was given and there is no default value"// &
504 trim(parser_location(parser)))
505 END IF
506 ELSE
507 IF (n_var < 1) THEN
508 cpassert(n_var == -1)
509 NULLIFY (c_last, c_first)
510 CALL parser_get_object(parser, c_val)
511 CALL cp_create(c_first, c_val)
512 c_last => c_first
513 DO WHILE (parser_test_next_token(parser) /= "EOL")
514 CALL parser_get_object(parser, c_val)
515 CALL cp_create(c_new, c_val)
516 c_last%rest => c_new
517 c_last => c_new
518 END DO
519 c_val_p => cp_to_array(c_first)
520 CALL cp_dealloc(c_first)
521 ELSE
522 ALLOCATE (c_val_p(n_var))
523 DO i = 1, n_var
524 CALL parser_get_object(parser, c_val_p(i))
525 END DO
526 END IF
527 IF (ASSOCIATED(c_val_p)) THEN
528 CALL val_create(val, c_vals_ptr=c_val_p)
529 END IF
530 END IF
531 CASE (lchar_t)
532 IF (ASSOCIATED(default_value)) THEN
533 CALL cp_abort(__location__, &
534 "input variables of type lchar_t cannot have a lone keyword attribute,"// &
535 " no value is interpreted as empty string"// &
536 trim(parser_location(parser)))
537 END IF
538 IF (n_var /= 1) THEN
539 CALL cp_abort(__location__, &
540 "input variables of type lchar_t cannot be repeated,"// &
541 " one always represent a whole line, till the end"// &
542 trim(parser_location(parser)))
543 END IF
544 IF (parser_test_next_token(parser) == "EOL") THEN
545 ALLOCATE (c_val_p(1))
546 c_val_p(1) = ' '
547 ELSE
548 NULLIFY (c_last, c_first)
549 CALL parser_get_object(parser, c_val, string_length=len(c_val))
550 IF (c_val(1:1) == parser%quote_character) THEN
551 quoted = .true.
552 c_val(1:) = c_val(2:) ! Drop first quotation mark
553 i = index(c_val, parser%quote_character) ! Check for second quotation mark
554 IF (i > 0) THEN
555 c_val(i:) = "" ! Discard stuff after second quotation mark
556 eol = .true. ! Enforce end of line
557 ELSE
558 eol = .false.
559 END IF
560 ELSE
561 quoted = .false.
562 eol = .false.
563 END IF
564 CALL cp_create(c_first, c_val)
565 c_last => c_first
566 DO WHILE ((.NOT. eol) .AND. (parser_test_next_token(parser) /= "EOL"))
567 CALL parser_get_object(parser, c_val, string_length=len(c_val))
568 i = index(c_val, parser%quote_character) ! Check for quotation mark
569 IF (i > 0) THEN
570 IF (quoted) THEN
571 c_val(i:) = "" ! Discard stuff after second quotation mark
572 eol = .true. ! Enforce end of line
573 ELSE
574 CALL cp_abort(__location__, &
575 "Quotation mark found which is not the first non-blank character. "// &
576 "Possibly the first quotation mark is missing?"// &
577 trim(parser_location(parser)))
578 END IF
579 ELSE
580 eol = .false.
581 END IF
582 CALL cp_create(c_new, c_val)
583 c_last%rest => c_new
584 c_last => c_new
585 END DO
586 c_val_p => cp_to_array(c_first)
587 CALL cp_dealloc(c_first)
588 END IF
589 cpassert(ASSOCIATED(c_val_p))
590 CALL val_create(val, lc_vals_ptr=c_val_p)
591 CASE (enum_t)
592 cpassert(ASSOCIATED(enum))
593 NULLIFY (i_val_p)
594 IF (parser_test_next_token(parser) == "EOL") THEN
595 IF (.NOT. ASSOCIATED(default_value)) THEN
596 IF (n_var < 1) THEN
597 ALLOCATE (i_val_p(0))
598 CALL val_create(val, i_vals_ptr=i_val_p)
599 ELSE
600 CALL cp_abort(__location__, &
601 "no value was given and there is no default value"// &
602 trim(parser_location(parser)))
603 END IF
604 ELSE
605 cpassert(ASSOCIATED(default_value%i_val))
606 CALL val_create(val, i_vals=default_value%i_val, &
607 enum=default_value%enum)
608 END IF
609 ELSE
610 IF (n_var < 1) THEN
611 NULLIFY (i_last, i_first)
612 CALL parser_get_object(parser, c_val)
613 CALL cp_create(i_first, enum_c2i(enum, c_val))
614 i_last => i_first
615 DO WHILE (parser_test_next_token(parser) /= "EOL")
616 CALL parser_get_object(parser, c_val)
617 CALL cp_create(i_new, enum_c2i(enum, c_val))
618 i_last%rest => i_new
619 i_last => i_new
620 END DO
621 i_val_p => cp_to_array(i_first)
622 CALL cp_dealloc(i_first)
623 ELSE
624 ALLOCATE (i_val_p(n_var))
625 DO i = 1, n_var
626 CALL parser_get_object(parser, c_val)
627 i_val_p(i) = enum_c2i(enum, c_val)
628 END DO
629 END IF
630 IF (ASSOCIATED(i_val_p)) THEN
631 CALL val_create(val, i_vals_ptr=i_val_p, enum=enum)
632 END IF
633 END IF
634 CASE default
635 CALL cp_abort(__location__, &
636 "type "//cp_to_string(type_of_var)//"unknown to the parser")
637 END SELECT
638 IF (parser_test_next_token(parser) /= "EOL") THEN
639 location = trim(parser_location(parser))
640 CALL parser_get_object(parser, info)
641 CALL cp_abort(__location__, &
642 "found unexpected extra argument "//trim(info)//" at "//location)
643 END IF
644
645 CALL timestop(handle)
646
647 END SUBROUTINE val_create_parsing
648
649! **************************************************************************************************
650!> \brief Reads and convert a real number from the input file
651!> \param r_val ...
652!> \param parser the parser from where the values should be read
653!> \param unit ...
654!> \param default_units ...
655!> \param c_val ...
656!> \author Teodoro Laino - 11.2007 [tlaino] - University of Zurich
657! **************************************************************************************************
658 SUBROUTINE get_r_val(r_val, parser, unit, default_units, c_val)
659 REAL(kind=dp), INTENT(OUT) :: r_val
660 TYPE(cp_parser_type), INTENT(INOUT) :: parser
661 TYPE(cp_unit_type), POINTER :: unit
662 TYPE(cp_unit_set_type), INTENT(IN) :: default_units
663 CHARACTER(len=default_string_length), &
664 INTENT(INOUT) :: c_val
665
666 TYPE(cp_unit_type), POINTER :: my_unit
667
668 NULLIFY (my_unit)
669 IF (ASSOCIATED(unit)) THEN
670 IF ('STR' == parser_test_next_token(parser)) THEN
671 CALL parser_get_object(parser, c_val)
672 IF (c_val(1:1) /= "[" .OR. c_val(len_trim(c_val):len_trim(c_val)) /= "]") THEN
673 CALL cp_abort(__location__, &
674 "Invalid unit specifier or function found when parsing a number: "// &
675 c_val)
676 END IF
677 ALLOCATE (my_unit)
678 CALL cp_unit_create(my_unit, c_val(2:len_trim(c_val) - 1))
679 ELSE
680 IF (c_val /= "") THEN
681 ALLOCATE (my_unit)
682 CALL cp_unit_create(my_unit, c_val(2:len_trim(c_val) - 1))
683 ELSE
684 my_unit => unit
685 END IF
686 END IF
687 IF (.NOT. cp_unit_compatible(unit, my_unit)) THEN
688 CALL cp_abort(__location__, &
689 "Incompatible units. Defined as ("// &
690 trim(cp_unit_desc(unit))//") specified in input as ("// &
691 trim(cp_unit_desc(my_unit))//"). These units are incompatible!")
692 END IF
693 END IF
694 CALL parser_get_object(parser, r_val)
695 IF (ASSOCIATED(unit)) THEN
696 r_val = cp_unit_to_cp2k1(r_val, my_unit, default_units)
697 IF (.NOT. (ASSOCIATED(my_unit, unit))) THEN
698 CALL cp_unit_release(my_unit)
699 DEALLOCATE (my_unit)
700 END IF
701 END IF
702
703 END SUBROUTINE get_r_val
704
705END MODULE input_parsing
subroutine, public cp_sll_val_create(sll, first_el, rest)
allocates and initializes a single linked list
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.
unit conversion facility
Definition cp_units.F:30
character(len=cp_unit_desc_length) function, public cp_unit_desc(unit, defaults, accept_undefined)
returns the "name" of the given unit
Definition cp_units.F:1108
real(kind=dp) function, public cp_unit_to_cp2k1(value, unit, defaults, power)
transform a value to the internal cp2k units
Definition cp_units.F:1157
subroutine, public cp_unit_create(unit, string)
creates a unit parsing a string
Definition cp_units.F:168
logical function, public cp_unit_compatible(ref_unit, unit)
returs true if the two units are compatible
Definition cp_units.F:1277
elemental subroutine, public cp_unit_release(unit)
releases the given unit
Definition cp_units.F:566
represents an enumeration, i.e. a mapping between integers and strings
integer function, public enum_c2i(enum, c)
maps a string to an integer
represents keywords in an input
subroutine, public keyword_describe(keyword, unit_nr, level)
writes out a description of the keyword
routines that parse the input
recursive subroutine, public section_vals_parse(section_vals, parser, default_units, root_section)
...
objects that represent the structure of input sections and the data contained in an input section
recursive subroutine, public section_typo_match(section, section_name, unknown_string, location_string, matching_rank, matching_string, bonus)
...
type(section_type), pointer, save, public typo_match_section
integer function, public section_get_keyword_index(section, keyword_name)
returns the index of the requested keyword (or -2 if not found)
integer, dimension(n_typo_matches), public typo_matching_rank
recursive type(keyword_type) function, pointer, public section_get_keyword(section, keyword_name)
returns the requested keyword
recursive subroutine, public section_describe(section, unit_nr, level, hide_root, recurse)
prints a description of the given section
integer function, public section_get_subsection_index(section, subsection_name)
returns the index of requested subsection (-1 if not found)
character(len=default_string_length *5), dimension(n_typo_matches), public typo_matching_line
subroutine, public section_vals_add_values(section_vals)
adds the place to store the values of a repetition of the section
a wrapper for basic fortran types.
integer, parameter, public real_t
integer, parameter, public lchar_t
integer, parameter, public logical_t
subroutine, public val_create(val, l_val, l_vals, l_vals_ptr, i_val, i_vals, i_vals_ptr, r_val, r_vals, r_vals_ptr, c_val, c_vals, c_vals_ptr, lc_val, lc_vals, lc_vals_ptr, enum)
creates a keyword value
integer, parameter, public char_t
integer, parameter, public integer_t
integer, parameter, public no_t
integer, parameter, public enum_t
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public max_line_length
Definition kinds.F:59
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
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.
represent a single linked list that stores pointers to the elements
represent a single linked list that stores pointers to the elements
represent a single linked list that stores pointers to the elements
represent a single linked list that stores pointers to the elements
represent a single linked list that stores pointers to the elements
stores the default units to be used
Definition cp_units.F:155
stores a unit
Definition cp_units.F:137
represent a keyword in the input
represent a section of the input file
a type to have a wrapper that stores any basic fortran type