(git:d18deda)
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-2025 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) &
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 section => section_vals%section
101 IF (root_sect) THEN
102 token = trim(adjustl(parser%input_line(parser%icol1:parser%icol2))) ! Ignore leading or trailing blanks
103 CALL uppercase(token)
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 " &
107 //trim(parser_location(parser)))
108 END IF
109 IF (.NOT. section%repeats .AND. SIZE(section_vals%values, 2) /= 0) &
110 CALL cp_abort(__location__, "Section "//trim(section%name)// &
111 " should not repeat "//trim(parser_location(parser)))
112 CALL section_vals_add_values(section_vals)
113 irs = SIZE(section_vals%values, 2)
114
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)
120 END IF
121
122 IF (ASSOCIATED(section%keywords(-1)%keyword)) THEN ! reads section params
123 keyword => section%keywords(-1)%keyword
124 NULLIFY (el)
125 IF (keyword%type_of_var == lchar_t) CALL parser_skip_space(parser)
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, &
130 parser=parser)
131 NULLIFY (new_val)
132 CALL cp_sll_val_create(new_val, el)
133 section_vals%values(-1, irs)%list => new_val
134 NULLIFY (el)
135 END IF
136 DO WHILE (.true.)
137 CALL parser_get_object(parser, token, newline=.true., &
138 lower_to_upper=.true., at_end=at_end)
139 token = trim(adjustl(token)) ! Ignore leading or trailing blanks
140 IF (at_end) THEN
141 IF (root_sect) &
142 CALL cp_abort(__location__, &
143 "unexpected end of file while parsing section "// &
144 trim(section%name)//" "//trim(parser_location(parser)))
145 EXIT
146 END IF
147 IF (token(1:1) == parser%section_character) THEN
148 IF (token == "&END") THEN
149 ! end of section
150 compatible_end = .true.
151 IF (parser_test_next_token(parser) /= "EOL") THEN
152 CALL parser_get_object(parser, token, newline=.false., &
153 lower_to_upper=.true.)
154 IF (token /= "SECTION" .AND. token /= section%name) THEN
155 compatible_end = .false.
156 END IF
157 END IF
158 IF (parser_test_next_token(parser) /= "EOL") THEN
159 CALL parser_get_object(parser, token, newline=.false., &
160 lower_to_upper=.true.)
161 IF (token /= section%name) THEN
162 print *, trim(token), "/=", trim(section%name)
163 compatible_end = .false.
164 END IF
165 END IF
166 IF (.NOT. compatible_end) THEN
167 CALL cp_abort(__location__, &
168 "non-compatible end of section "//trim(section%name)//" "// &
169 trim(parser_location(parser)))
170 END IF
171 ! RETURN
172 EXIT
173 END IF
174 is = section_get_subsection_index(section, token(2:))
175 IF (is > 0) THEN
176 CALL section_vals_parse(section_vals%subs_vals(is, irs)%section_vals, &
177 default_units=default_units, parser=parser)
178 ELSE
179 ! unknown subsection
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, *)
186 CALL section_typo_match(typo_match_section, trim(section%name), trim(token(2:)), "", &
188 DO imatch = 1, SIZE(typo_matching_rank)
189 WRITE (output_unit, '(T2,A,1X,I0)') trim(typo_matching_line(imatch))//" score: ", typo_matching_rank(imatch)
190 END DO
191 END IF
192 CALL cp_abort(__location__, &
193 "unknown subsection "//trim(token(2:))//" of section " &
194 //trim(section%name))
195 nsub = 1
196 DO WHILE (nsub > 0)
197 CALL parser_get_object(parser, token, newline=.true., &
198 lower_to_upper=.true.)
199 IF (token(1:1) == parser%section_character) THEN
200 IF (token == "&END") THEN
201 nsub = nsub - 1
202 ELSE
203 nsub = nsub + 1
204 END IF
205 END IF
206 END DO
207 END IF
208 ELSE ! token is a keyword
209 IF (token == "DESCRIBE") THEN
210 IF (output_unit > 0) WRITE (output_unit, "(/,' ****** DESCRIPTION ******',/)")
211 desc_level = 3
212 IF (parser_test_next_token(parser) == "INT") THEN
213 CALL parser_get_object(parser, desc_level)
214 END IF
215 whole_section = .true.
216 DO WHILE (parser_test_next_token(parser) == "STR")
217 whole_section = .false.
218 CALL parser_get_object(parser, token, newline=.false., &
219 lower_to_upper=.true.)
220 keyword => section_get_keyword(section, token)
221 IF (.NOT. ASSOCIATED(keyword)) THEN
222 CALL cp_warn(__location__, &
223 "unknown keyword to describe "//trim(token)// &
224 " in section "//trim(section%name))
225 ELSE
226 CALL keyword_describe(keyword, output_unit, desc_level)
227 END IF
228 END DO
229 IF (whole_section) THEN
230 CALL section_describe(section, output_unit, desc_level, hide_root=.NOT. root_sect)
231 END IF
232 IF (output_unit > 0) WRITE (output_unit, "(/,' ****** =========== ******',/)")
233
234 ELSE ! token is a "normal" keyword
235 ik = section_get_keyword_index(section, token)
236 IF (ik < 1) THEN ! don't accept pseudo keyword names
237 parser%icol = parser%icol1 - 1 ! re-read also the actual token
238 ik = 0
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, *)
246 CALL section_typo_match(typo_match_section, trim(section%name), trim(token), "", &
248 DO imatch = 1, SIZE(typo_matching_rank)
249 WRITE (output_unit, '(T2,A,1X,I0)') &
250 trim(typo_matching_line(imatch))//" score: ", typo_matching_rank(imatch)
251 END DO
252 END IF
253 CALL cp_abort(__location__, &
254 "found an unknown keyword "//trim(token)// &
255 " in section "//trim(section%name))
256 END IF
257 END IF
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)
265 ELSE
266 CALL cp_abort(__location__, &
267 "The specified keyword '"//trim(token)// &
268 "' is not available anymore, please consult the manual.")
269 END IF
270 END IF
271
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//".")
277
278 NULLIFY (el)
279 IF (ik /= 0 .AND. keyword%type_of_var == lchar_t) &
280 CALL parser_skip_space(parser)
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
286 NULLIFY (new_val)
287 CALL cp_sll_val_create(new_val, el)
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
291 ELSE
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
298 ELSE
299 previous_list => last_val
300 END IF
301 DO WHILE (ASSOCIATED(last_val%rest))
302 last_val => last_val%rest
303 END DO
304 last_val%rest => new_val
305 previous_last => new_val
306 END IF
307 END IF
308 END IF
309 END IF
310 END IF
311 END DO
312 CALL timestop(handle)
313 END SUBROUTINE section_vals_parse
314
315! **************************************************************************************************
316!> \brief creates a val_type object by parsing the values
317!> \param val the value that will be created
318!> \param type_of_var type of the value to be created
319!> \param n_var number of values to be parsed (-1: undefined)
320!> \param enum ...
321!> \param parser the parser from where the values should be read
322!> \param unit ...
323!> \param default_units ...
324!> \param default_value a default value if nothing is found (can be null)
325!> \author fawzi
326!> \note
327!> - no_t does not create a value
328! **************************************************************************************************
329 SUBROUTINE val_create_parsing(val, type_of_var, n_var, enum, &
330 parser, unit, default_units, default_value)
331 TYPE(val_type), POINTER :: val
332 INTEGER, INTENT(in) :: type_of_var, n_var
333 TYPE(enumeration_type), POINTER :: enum
334 TYPE(cp_parser_type), INTENT(INOUT) :: parser
335 TYPE(cp_unit_type), POINTER :: unit
336 TYPE(cp_unit_set_type), INTENT(IN) :: default_units
337 TYPE(val_type), OPTIONAL, POINTER :: default_value
338
339 CHARACTER(len=*), PARAMETER :: routinen = 'val_create_parsing'
340
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
350 TYPE(cp_sll_char_type), POINTER :: c_first, c_last, c_new
351 TYPE(cp_sll_int_type), POINTER :: i_first, i_last, i_new
352 TYPE(cp_sll_logical_type), POINTER :: l_first, l_last, l_new
353 TYPE(cp_sll_real_type), POINTER :: r_first, r_last, r_new
354
355 CALL timeset(routinen, handle)
356
357 cpassert(.NOT. ASSOCIATED(val))
358 SELECT CASE (type_of_var)
359 CASE (no_t)
360 CASE (logical_t)
361 NULLIFY (l_val_p)
362 IF (parser_test_next_token(parser) == "EOL") THEN
363 IF (.NOT. ASSOCIATED(default_value)) THEN
364 IF (n_var < 1) THEN
365 ALLOCATE (l_val_p(0))
366 CALL val_create(val, l_vals_ptr=l_val_p)
367 ELSE
368 CALL cp_abort(__location__, &
369 "no value was given and there is no default value"// &
370 trim(parser_location(parser)))
371 END IF
372 ELSE
373 cpassert(ASSOCIATED(default_value%l_val))
374 CALL val_create(val, l_vals=default_value%l_val)
375 END IF
376 ELSE
377 IF (n_var < 1) THEN
378 NULLIFY (l_last, l_first)
379 CALL parser_get_object(parser, l_val)
380 CALL cp_create(l_first, l_val)
381 l_last => l_first
382 DO WHILE (parser_test_next_token(parser) /= "EOL")
383 CALL parser_get_object(parser, l_val)
384 CALL cp_create(l_new, l_val)
385 l_last%rest => l_new
386 l_last => l_new
387 END DO
388 l_val_p => cp_to_array(l_first)
389 CALL cp_dealloc(l_first)
390 ELSE
391 ALLOCATE (l_val_p(n_var))
392 DO i = 1, n_var
393 CALL parser_get_object(parser, l_val_p(i))
394 END DO
395 END IF
396 IF (ASSOCIATED(l_val_p)) THEN
397 CALL val_create(val, l_vals_ptr=l_val_p)
398 END IF
399 END IF
400 CASE (integer_t)
401 NULLIFY (i_val_p)
402 IF (parser_test_next_token(parser) == "EOL") THEN
403 IF (.NOT. ASSOCIATED(default_value)) THEN
404 IF (n_var < 1) THEN
405 ALLOCATE (i_val_p(0))
406 CALL val_create(val, i_vals_ptr=i_val_p)
407 ELSE
408 CALL cp_abort(__location__, &
409 "no value was given and there is no default value"// &
410 trim(parser_location(parser)))
411 END IF
412 ELSE
413 check = ASSOCIATED(default_value%i_val)
414 cpassert(check)
415 CALL val_create(val, i_vals=default_value%i_val)
416 END IF
417 ELSE
418 IF (n_var < 1) THEN
419 NULLIFY (i_last, i_first)
420 CALL parser_get_object(parser, i_val)
421 CALL cp_create(i_first, i_val)
422 i_last => i_first
423 DO WHILE (parser_test_next_token(parser) /= "EOL")
424 CALL parser_get_object(parser, i_val)
425 CALL cp_create(i_new, i_val)
426 i_last%rest => i_new
427 i_last => i_new
428 END DO
429 i_val_p => cp_to_array(i_first)
430 CALL cp_dealloc(i_first)
431 ELSE
432 ALLOCATE (i_val_p(n_var))
433 DO i = 1, n_var
434 CALL parser_get_object(parser, i_val_p(i))
435 END DO
436 END IF
437 IF (ASSOCIATED(i_val_p)) THEN
438 CALL val_create(val, i_vals_ptr=i_val_p)
439 END IF
440 END IF
441 CASE (real_t)
442 NULLIFY (r_val_p)
443 IF (parser_test_next_token(parser) == "EOL") THEN
444 IF (.NOT. ASSOCIATED(default_value)) THEN
445 IF (n_var < 1) THEN
446 ALLOCATE (r_val_p(0))
447 CALL val_create(val, r_vals_ptr=r_val_p)
448 ELSE
449 CALL cp_abort(__location__, &
450 "no value was given and there is no default value"// &
451 trim(parser_location(parser)))
452 END IF
453 ELSE
454 cpassert(ASSOCIATED(default_value%r_val))
455 CALL val_create(val, r_vals=default_value%r_val)
456 END IF
457 ELSE
458 IF (n_var < 1) THEN
459 NULLIFY (r_last, r_first)
460 c_val = ""
461 CALL get_r_val(r_val, parser, unit, default_units, c_val)
462 CALL cp_create(r_first, r_val)
463 r_last => r_first
464 DO WHILE (parser_test_next_token(parser) /= "EOL")
465 CALL get_r_val(r_val, parser, unit, default_units, c_val)
466 CALL cp_create(r_new, r_val)
467 r_last%rest => r_new
468 r_last => r_new
469 END DO
470 NULLIFY (r_last)
471 r_val_p => cp_to_array(r_first)
472 CALL cp_dealloc(r_first)
473 ELSE
474 ALLOCATE (r_val_p(n_var))
475 c_val = ""
476 DO i = 1, n_var
477 CALL get_r_val(r_val_p(i), parser, unit, default_units, c_val)
478 END DO
479 END IF
480 IF (ASSOCIATED(r_val_p)) THEN
481 CALL val_create(val, r_vals_ptr=r_val_p)
482 END IF
483 END IF
484 CASE (char_t)
485 NULLIFY (c_val_p)
486 IF (parser_test_next_token(parser) == "EOL") THEN
487 IF (n_var < 1) THEN
488 ALLOCATE (c_val_p(1))
489 c_val_p(1) = ' '
490 CALL val_create(val, c_vals_ptr=c_val_p)
491 ELSE
492 IF (.NOT. ASSOCIATED(default_value)) THEN
493 CALL cp_abort(__location__, &
494 "no value was given and there is no default value"// &
495 trim(parser_location(parser)))
496 ELSE
497 cpassert(ASSOCIATED(default_value%c_val))
498 CALL val_create(val, c_vals=default_value%c_val)
499 END IF
500 END IF
501 ELSE
502 IF (n_var < 1) THEN
503 cpassert(n_var == -1)
504 NULLIFY (c_last, c_first)
505 CALL parser_get_object(parser, c_val)
506 CALL cp_create(c_first, c_val)
507 c_last => c_first
508 DO WHILE (parser_test_next_token(parser) /= "EOL")
509 CALL parser_get_object(parser, c_val)
510 CALL cp_create(c_new, c_val)
511 c_last%rest => c_new
512 c_last => c_new
513 END DO
514 c_val_p => cp_to_array(c_first)
515 CALL cp_dealloc(c_first)
516 ELSE
517 ALLOCATE (c_val_p(n_var))
518 DO i = 1, n_var
519 CALL parser_get_object(parser, c_val_p(i))
520 END DO
521 END IF
522 IF (ASSOCIATED(c_val_p)) THEN
523 CALL val_create(val, c_vals_ptr=c_val_p)
524 END IF
525 END IF
526 CASE (lchar_t)
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"// &
531 trim(parser_location(parser)))
532 IF (n_var /= 1) &
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"// &
536 trim(parser_location(parser)))
537 IF (parser_test_next_token(parser) == "EOL") THEN
538 ALLOCATE (c_val_p(1))
539 c_val_p(1) = ' '
540 ELSE
541 NULLIFY (c_last, c_first)
542 CALL parser_get_object(parser, c_val, string_length=len(c_val))
543 IF (c_val(1:1) == parser%quote_character) THEN
544 quoted = .true.
545 c_val(1:) = c_val(2:) ! Drop first quotation mark
546 i = index(c_val, parser%quote_character) ! Check for second quotation mark
547 IF (i > 0) THEN
548 c_val(i:) = "" ! Discard stuff after second quotation mark
549 eol = .true. ! Enforce end of line
550 ELSE
551 eol = .false.
552 END IF
553 ELSE
554 quoted = .false.
555 eol = .false.
556 END IF
557 CALL cp_create(c_first, c_val)
558 c_last => c_first
559 DO WHILE ((.NOT. eol) .AND. (parser_test_next_token(parser) /= "EOL"))
560 CALL parser_get_object(parser, c_val, string_length=len(c_val))
561 i = index(c_val, parser%quote_character) ! Check for quotation mark
562 IF (i > 0) THEN
563 IF (quoted) THEN
564 c_val(i:) = "" ! Discard stuff after second quotation mark
565 eol = .true. ! Enforce end of line
566 ELSE
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?"// &
570 trim(parser_location(parser)))
571 END IF
572 ELSE
573 eol = .false.
574 END IF
575 CALL cp_create(c_new, c_val)
576 c_last%rest => c_new
577 c_last => c_new
578 END DO
579 c_val_p => cp_to_array(c_first)
580 CALL cp_dealloc(c_first)
581 END IF
582 cpassert(ASSOCIATED(c_val_p))
583 CALL val_create(val, lc_vals_ptr=c_val_p)
584 CASE (enum_t)
585 cpassert(ASSOCIATED(enum))
586 NULLIFY (i_val_p)
587 IF (parser_test_next_token(parser) == "EOL") THEN
588 IF (.NOT. ASSOCIATED(default_value)) THEN
589 IF (n_var < 1) THEN
590 ALLOCATE (i_val_p(0))
591 CALL val_create(val, i_vals_ptr=i_val_p)
592 ELSE
593 CALL cp_abort(__location__, &
594 "no value was given and there is no default value"// &
595 trim(parser_location(parser)))
596 END IF
597 ELSE
598 cpassert(ASSOCIATED(default_value%i_val))
599 CALL val_create(val, i_vals=default_value%i_val, &
600 enum=default_value%enum)
601 END IF
602 ELSE
603 IF (n_var < 1) THEN
604 NULLIFY (i_last, i_first)
605 CALL parser_get_object(parser, c_val)
606 CALL cp_create(i_first, enum_c2i(enum, c_val))
607 i_last => i_first
608 DO WHILE (parser_test_next_token(parser) /= "EOL")
609 CALL parser_get_object(parser, c_val)
610 CALL cp_create(i_new, enum_c2i(enum, c_val))
611 i_last%rest => i_new
612 i_last => i_new
613 END DO
614 i_val_p => cp_to_array(i_first)
615 CALL cp_dealloc(i_first)
616 ELSE
617 ALLOCATE (i_val_p(n_var))
618 DO i = 1, n_var
619 CALL parser_get_object(parser, c_val)
620 i_val_p(i) = enum_c2i(enum, c_val)
621 END DO
622 END IF
623 IF (ASSOCIATED(i_val_p)) THEN
624 CALL val_create(val, i_vals_ptr=i_val_p, enum=enum)
625 END IF
626 END IF
627 CASE default
628 CALL cp_abort(__location__, &
629 "type "//cp_to_string(type_of_var)//"unknown to the parser")
630 END SELECT
631 IF (parser_test_next_token(parser) .NE. "EOL") THEN
632 location = trim(parser_location(parser))
633 CALL parser_get_object(parser, info)
634 CALL cp_abort(__location__, &
635 "found unexpected extra argument "//trim(info)//" at "//location)
636 END IF
637
638 CALL timestop(handle)
639
640 END SUBROUTINE val_create_parsing
641
642! **************************************************************************************************
643!> \brief Reads and convert a real number from the input file
644!> \param r_val ...
645!> \param parser the parser from where the values should be read
646!> \param unit ...
647!> \param default_units ...
648!> \param c_val ...
649!> \author Teodoro Laino - 11.2007 [tlaino] - University of Zurich
650! **************************************************************************************************
651 SUBROUTINE get_r_val(r_val, parser, unit, default_units, c_val)
652 REAL(kind=dp), INTENT(OUT) :: r_val
653 TYPE(cp_parser_type), INTENT(INOUT) :: parser
654 TYPE(cp_unit_type), POINTER :: unit
655 TYPE(cp_unit_set_type), INTENT(IN) :: default_units
656 CHARACTER(len=default_string_length), &
657 INTENT(INOUT) :: c_val
658
659 TYPE(cp_unit_type), POINTER :: my_unit
660
661 NULLIFY (my_unit)
662 IF (ASSOCIATED(unit)) THEN
663 IF ('STR' == parser_test_next_token(parser)) THEN
664 CALL parser_get_object(parser, c_val)
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: "// &
668 c_val)
669 END IF
670 ALLOCATE (my_unit)
671 CALL cp_unit_create(my_unit, c_val(2:len_trim(c_val) - 1))
672 ELSE
673 IF (c_val /= "") THEN
674 ALLOCATE (my_unit)
675 CALL cp_unit_create(my_unit, c_val(2:len_trim(c_val) - 1))
676 ELSE
677 my_unit => unit
678 END IF
679 END IF
680 IF (.NOT. cp_unit_compatible(unit, my_unit)) &
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!")
685 END IF
686 CALL parser_get_object(parser, r_val)
687 IF (ASSOCIATED(unit)) THEN
688 r_val = cp_unit_to_cp2k1(r_val, my_unit, default_units)
689 IF (.NOT. (ASSOCIATED(my_unit, unit))) THEN
690 CALL cp_unit_release(my_unit)
691 DEALLOCATE (my_unit)
692 END IF
693 END IF
694
695 END SUBROUTINE get_r_val
696
697END 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:1036
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:1085
subroutine, public cp_unit_create(unit, string)
creates a unit parsing a string
Definition cp_units.F:163
logical function, public cp_unit_compatible(ref_unit, unit)
returs true if the two units are compatible
Definition cp_units.F:1205
elemental subroutine, public cp_unit_release(unit)
releases the given unit
Definition cp_units.F:545
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:150
stores a unit
Definition cp_units.F:132
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