47#include "../base/base_uses.f90"
52 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
53 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'input_section_types'
81 TYPE(section_type),
POINTER :: section => null()
82 END TYPE section_p_type
103 LOGICAL :: frozen = .false., repeats = .false.
104 INTEGER :: ref_count = 0, n_keywords = 0, n_subsections = 0
105 CHARACTER(len=default_string_length) :: name =
""
106 CHARACTER(len=default_string_length) :: location =
""
107 CHARACTER,
DIMENSION(:),
POINTER :: description => null()
108 CHARACTER(LEN=:),
ALLOCATABLE :: deprecation_notice
109 INTEGER,
POINTER,
DIMENSION(:) :: citations => null()
111 TYPE(section_p_type),
POINTER,
DIMENSION(:) :: subsections => null()
119 TYPE section_vals_p_type
121 END TYPE section_vals_p_type
128 INTEGER :: ref_count = 0
129 INTEGER,
POINTER,
DIMENSION(:) :: ibackup => null()
132 TYPE(section_vals_p_type),
DIMENSION(:, :),
POINTER :: subs_vals => null()
136 INTEGER,
PARAMETER :: n_typo_matches = 5
157 n_subsections, repeats, citations, deprecation_notice)
160 CHARACTER(len=*),
INTENT(in) :: location, name, description
161 INTEGER,
INTENT(in),
OPTIONAL :: n_keywords, n_subsections
162 LOGICAL,
INTENT(in),
OPTIONAL :: repeats
163 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: citations
164 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: deprecation_notice
166 INTEGER :: i, my_n_keywords, my_n_subsections, n
168 cpassert(.NOT.
ASSOCIATED(section))
170 IF (
PRESENT(n_keywords)) my_n_keywords = n_keywords
172 IF (
PRESENT(n_subsections)) my_n_subsections = n_subsections
175 section%ref_count = 1
177 section%n_keywords = 0
178 section%n_subsections = 0
179 section%location = location
181 cpassert(len_trim(name) > 0)
185 n = len_trim(description)
186 ALLOCATE (section%description(n))
188 section%description(i) = description(i:i)
191 section%frozen = .false.
192 section%repeats = .false.
193 IF (
PRESENT(repeats)) section%repeats = repeats
195 NULLIFY (section%citations)
196 IF (
PRESENT(citations))
THEN
197 ALLOCATE (section%citations(
SIZE(citations)))
198 section%citations = citations
201 ALLOCATE (section%keywords(-1:my_n_keywords))
202 DO i = -1, my_n_keywords
203 NULLIFY (section%keywords(i)%keyword)
206 ALLOCATE (section%subsections(my_n_subsections))
207 DO i = 1, my_n_subsections
208 NULLIFY (section%subsections(i)%section)
211 IF (
PRESENT(deprecation_notice))
THEN
212 section%deprecation_notice = trim(deprecation_notice)
222 SUBROUTINE section_retain(section)
226 cpassert(
ASSOCIATED(section))
227 cpassert(section%ref_count > 0)
228 section%ref_count = section%ref_count + 1
230 END SUBROUTINE section_retain
243 IF (
ASSOCIATED(section))
THEN
244 cpassert(section%ref_count > 0)
245 section%ref_count = section%ref_count - 1
246 IF (section%ref_count == 0)
THEN
247 IF (
ASSOCIATED(section%citations))
THEN
248 DEALLOCATE (section%citations)
250 IF (
ASSOCIATED(section%keywords))
THEN
251 DO i = -1, ubound(section%keywords, 1)
254 DEALLOCATE (section%keywords)
256 section%n_keywords = 0
257 IF (
ASSOCIATED(section%subsections))
THEN
258 DO i = 1,
SIZE(section%subsections)
261 DEALLOCATE (section%subsections)
263 DEALLOCATE (section%description)
277 FUNCTION get_section_info(section)
RESULT(message)
280 CHARACTER(LEN=default_path_length) :: message
285 length = len_trim(
a2s(section%description))
287 IF (section%description(length) /=
".")
THEN
291 IF (section%repeats)
THEN
292 message = trim(message)//
" This section can be repeated."
294 message = trim(message)//
" This section can not be repeated."
297 END FUNCTION get_section_info
313 INTEGER,
INTENT(in) :: unit_nr, level
314 LOGICAL,
INTENT(in),
OPTIONAL :: hide_root
315 INTEGER,
INTENT(in),
OPTIONAL :: recurse
317 CHARACTER(LEN=default_path_length) :: message
318 INTEGER :: ikeyword, isub, my_recurse
319 LOGICAL :: my_hide_root
321 IF (unit_nr > 0)
THEN
322 my_hide_root = .false.
323 IF (
PRESENT(hide_root)) my_hide_root = hide_root
325 IF (
PRESENT(recurse)) my_recurse = recurse
326 IF (
ASSOCIATED(section))
THEN
327 cpassert(section%ref_count > 0)
329 IF (.NOT. my_hide_root)
THEN
330 WRITE (unit=unit_nr, fmt=
"('*** section &',A,' ***')") trim(adjustl(section%name))
333 message = get_section_info(section)
334 CALL print_message(trim(
a2s(section%description))//trim(message), unit_nr, 0, 0, 0)
337 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
341 IF (
ASSOCIATED(section%keywords(0)%keyword))
THEN
345 DO ikeyword = 1, section%n_keywords
350 IF (section%n_subsections > 0 .AND. my_recurse >= 0)
THEN
351 IF (.NOT. my_hide_root)
THEN
352 WRITE (unit=unit_nr, fmt=
"('** subsections **')")
354 DO isub = 1, section%n_subsections
355 IF (my_recurse > 0)
THEN
357 level, recurse=my_recurse - 1)
359 WRITE (unit=unit_nr, fmt=
"(1X,A)") section%subsections(isub)%section%name
363 IF (.NOT. my_hide_root)
THEN
364 WRITE (unit=unit_nr, fmt=
"('*** &end section ',A,' ***')") trim(adjustl(section%name))
367 WRITE (unit_nr,
"(a)")
'<section *null*>'
385 CHARACTER(len=*),
INTENT(IN) :: subsection_name
388 CHARACTER(len=default_string_length) :: upc_name
391 cpassert(section%ref_count > 0)
393 upc_name = subsection_name
395 DO isub = 1, section%n_subsections
396 cpassert(
ASSOCIATED(section%subsections(isub)%section))
397 IF (section%subsections(isub)%section%name == upc_name)
THEN
415 CHARACTER(len=*),
INTENT(IN) :: subsection_name
422 res => section%subsections(isub)%section
441 CHARACTER(len=*),
INTENT(IN) :: keyword_name
445 CHARACTER(len=default_string_length) :: upc_name
447 cpassert(section%ref_count > 0)
448 cpassert(
ASSOCIATED(section%keywords))
450 upc_name = keyword_name
453 IF (
ASSOCIATED(section%keywords(ik)%keyword))
THEN
454 IF (section%keywords(ik)%keyword%names(1) == upc_name)
THEN
460 k_search_loop:
DO ik = 1, section%n_keywords
461 cpassert(
ASSOCIATED(section%keywords(ik)%keyword))
462 DO in = 1,
SIZE(section%keywords(ik)%keyword%names)
463 IF (section%keywords(ik)%keyword%names(in) == upc_name)
THEN
483 CHARACTER(len=*),
INTENT(IN) :: keyword_name
486 INTEGER :: ik, my_index
488 IF (index(keyword_name,
"%") /= 0)
THEN
489 my_index = index(keyword_name,
"%") + 1
490 cpassert(
ASSOCIATED(section%subsections))
491 DO ik = lbound(section%subsections, 1), ubound(section%subsections, 1)
492 IF (section%subsections(ik)%section%name == keyword_name(1:my_index - 2))
EXIT
494 cpassert(ik <= ubound(section%subsections, 1))
501 res => section%keywords(ik)%keyword
521 cpassert(section%ref_count > 0)
522 cpassert(.NOT. section%frozen)
523 cpassert(
ASSOCIATED(keyword))
524 cpassert(keyword%ref_count > 0)
526 IF (keyword%names(1) ==
"_SECTION_PARAMETERS_")
THEN
528 section%keywords(-1)%keyword => keyword
529 ELSE IF (keyword%names(1) ==
"_DEFAULT_KEYWORD_")
THEN
531 section%keywords(0)%keyword => keyword
533 DO k = 1,
SIZE(keyword%names)
534 DO i = 1, section%n_keywords
535 DO j = 1,
SIZE(section%keywords(i)%keyword%names)
536 IF (keyword%names(k) == section%keywords(i)%keyword%names(j))
THEN
537 CALL cp_abort(__location__, &
538 "trying to add a keyword with a name ("// &
539 trim(keyword%names(k))//
") that was already used in section " &
540 //trim(section%name))
546 IF (ubound(section%keywords, 1) == section%n_keywords)
THEN
547 ALLOCATE (new_keywords(-1:section%n_keywords + 10))
548 DO i = -1, section%n_keywords
549 new_keywords(i)%keyword => section%keywords(i)%keyword
551 DO i = section%n_keywords + 1, ubound(new_keywords, 1)
552 NULLIFY (new_keywords(i)%keyword)
554 DEALLOCATE (section%keywords)
555 section%keywords => new_keywords
557 section%n_keywords = section%n_keywords + 1
558 section%keywords(section%n_keywords)%keyword => keyword
575 TYPE(section_p_type),
DIMENSION(:),
POINTER :: new_subsections
577 cpassert(section%ref_count > 0)
578 cpassert(
ASSOCIATED(subsection))
579 cpassert(subsection%ref_count > 0)
580 IF (
SIZE(section%subsections) < section%n_subsections + 1)
THEN
581 ALLOCATE (new_subsections(section%n_subsections + 10))
582 DO i = 1, section%n_subsections
583 new_subsections(i)%section => section%subsections(i)%section
585 DO i = section%n_subsections + 1,
SIZE(new_subsections)
586 NULLIFY (new_subsections(i)%section)
588 DEALLOCATE (section%subsections)
589 section%subsections => new_subsections
591 DO i = 1, section%n_subsections
592 IF (subsection%name == section%subsections(i)%section%name)
THEN
593 CALL cp_abort(__location__, &
594 "trying to add a subsection with a name ("// &
595 trim(subsection%name)//
") that was already used in section " &
596 //trim(section%name))
599 CALL section_retain(subsection)
600 section%n_subsections = section%n_subsections + 1
601 section%subsections(section%n_subsections)%section => subsection
618 cpassert(.NOT.
ASSOCIATED(section_vals))
619 ALLOCATE (section_vals)
620 section_vals%ref_count = 1
621 CALL section_retain(section)
622 section_vals%section => section
623 section%frozen = .true.
624 ALLOCATE (section_vals%values(-1:section%n_keywords, 0))
625 ALLOCATE (section_vals%subs_vals(section%n_subsections, 1))
626 DO i = 1, section%n_subsections
627 NULLIFY (section_vals%subs_vals(i, 1)%section_vals)
629 section=section%subsections(i)%section)
632 NULLIFY (section_vals%ibackup)
645 cpassert(
ASSOCIATED(section_vals))
646 cpassert(section_vals%ref_count > 0)
647 section_vals%ref_count = section_vals%ref_count + 1
664 IF (
ASSOCIATED(section_vals))
THEN
665 cpassert(section_vals%ref_count > 0)
666 section_vals%ref_count = section_vals%ref_count - 1
667 IF (section_vals%ref_count == 0)
THEN
669 DO j = 1,
SIZE(section_vals%values, 2)
670 DO i = -1, ubound(section_vals%values, 1)
671 vals => section_vals%values(i, j)%list
678 DEALLOCATE (section_vals%values)
679 DO j = 1,
SIZE(section_vals%subs_vals, 2)
680 DO i = 1,
SIZE(section_vals%subs_vals, 1)
684 DEALLOCATE (section_vals%subs_vals)
685 IF (
ASSOCIATED(section_vals%ibackup))
THEN
686 DEALLOCATE (section_vals%ibackup)
688 DEALLOCATE (section_vals)
707 n_subs_vals_rep, section, explicit)
710 INTEGER,
INTENT(out),
OPTIONAL :: ref_count, n_repetition, n_subs_vals_rep
712 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
714 cpassert(section_vals%ref_count > 0)
715 IF (
PRESENT(ref_count)) ref_count = section_vals%ref_count
716 IF (
PRESENT(section)) section => section_vals%section
717 IF (
PRESENT(n_repetition)) n_repetition =
SIZE(section_vals%values, 2)
718 IF (
PRESENT(n_subs_vals_rep)) n_subs_vals_rep =
SIZE(section_vals%subs_vals, 2)
719 IF (
PRESENT(explicit)) explicit = (
SIZE(section_vals%values, 2) > 0)
734 i_rep_section, can_return_null)
RESULT(res)
737 CHARACTER(len=*),
INTENT(IN) :: subsection_name
738 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_section
739 LOGICAL,
INTENT(IN),
OPTIONAL :: can_return_null
742 INTEGER :: irep, isection, my_index
743 LOGICAL :: is_path, my_can_return_null
745 cpassert(section_vals%ref_count > 0)
747 my_can_return_null = .false.
748 IF (
PRESENT(can_return_null)) my_can_return_null = can_return_null
751 IF (
PRESENT(i_rep_section)) irep = i_rep_section
754 my_index = index(subsection_name,
"%")
755 IF (my_index == 0)
THEN
757 my_index = len_trim(subsection_name)
761 my_index = my_index - 1
764 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
767 IF (isection > 0) res => section_vals%subs_vals(isection, irep)%section_vals
768 IF (.NOT. (
ASSOCIATED(res) .OR. my_can_return_null))
THEN
769 CALL cp_abort(__location__, &
770 "could not find subsection "//trim(subsection_name(1:my_index))//
" in section "// &
771 trim(section_vals%section%name)//
" at ")
773 IF (is_path .AND.
ASSOCIATED(res))
THEN
775 i_rep_section, can_return_null)
793 INTEGER,
INTENT(in) :: i_section
794 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
797 INTEGER :: i, irep, isect_att
799 cpassert(
ASSOCIATED(section_vals))
800 cpassert(section_vals%ref_count > 0)
803 IF (
PRESENT(i_rep_section)) irep = i_rep_section
804 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
806 DO i = 1, section_vals%section%n_subsections
807 IF (
SIZE(section_vals%subs_vals(i, irep)%section_vals%values, 2) > 0)
THEN
808 isect_att = isect_att + 1
809 IF (isect_att == i_section)
THEN
810 res => section_vals%subs_vals(i, irep)%section_vals
828 i_rep_section)
RESULT(res)
831 CHARACTER(LEN=*),
INTENT(IN) :: subsection_name
832 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
835 INTEGER :: i_section, irep
837 cpassert(section_vals%ref_count > 0)
840 IF (
PRESENT(i_rep_section)) irep = i_rep_section
841 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
843 res => section_vals%subs_vals(i_section, irep)%section_vals
858 TYPE(section_vals_p_type),
DIMENSION(:, :), &
861 cpassert(section_vals%ref_count > 0)
862 ALLOCATE (new_values(-1:ubound(section_vals%values, 1),
SIZE(section_vals%values, 2) + 1))
863 DO j = 1,
SIZE(section_vals%values, 2)
864 DO i = -1, ubound(section_vals%values, 1)
865 new_values(i, j)%list => section_vals%values(i, j)%list
868 DEALLOCATE (section_vals%values)
869 section_vals%values => new_values
870 j =
SIZE(new_values, 2)
871 DO i = -1, ubound(new_values, 1)
872 NULLIFY (new_values(i, j)%list)
875 IF (
SIZE(new_values, 2) > 1)
THEN
876 ALLOCATE (new_sps(
SIZE(section_vals%subs_vals, 1), &
877 SIZE(section_vals%subs_vals, 2) + 1))
878 DO j = 1,
SIZE(section_vals%subs_vals, 2)
879 DO i = 1,
SIZE(section_vals%subs_vals, 1)
880 new_sps(i, j)%section_vals => section_vals%subs_vals(i, j)%section_vals
883 DEALLOCATE (section_vals%subs_vals)
884 section_vals%subs_vals => new_sps
886 DO i = 1,
SIZE(new_sps, 1)
887 NULLIFY (new_sps(i, j)%section_vals)
889 section=section_vals%section%subsections(i)%section)
909 IF (
ASSOCIATED(section_vals))
THEN
910 cpassert(section_vals%ref_count > 0)
913 ALLOCATE (new_values(-1:section_vals%section%n_keywords, 0))
915 DO j = 1,
SIZE(section_vals%values, 2)
916 DO i = -1, ubound(section_vals%values, 1)
917 vals => section_vals%values(i, j)%list
924 DEALLOCATE (section_vals%values)
925 section_vals%values => new_values
936 FUNCTION section_get_cval(section_vals, keyword_name)
RESULT(res)
939 CHARACTER(len=*),
INTENT(in) :: keyword_name
940 CHARACTER(LEN=default_string_length) :: res
944 END FUNCTION section_get_cval
955 CHARACTER(len=*),
INTENT(in) :: keyword_name
968 FUNCTION section_get_rvals(section_vals, keyword_name)
RESULT(res)
971 CHARACTER(len=*),
INTENT(in) :: keyword_name
972 REAL(kind=
dp),
DIMENSION(:),
POINTER :: res
976 END FUNCTION section_get_rvals
987 CHARACTER(len=*),
INTENT(in) :: keyword_name
1003 CHARACTER(len=*),
INTENT(in) :: keyword_name
1004 INTEGER,
DIMENSION(:),
POINTER :: res
1019 CHARACTER(len=*),
INTENT(in) :: keyword_name
1050 i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, &
1054 CHARACTER(len=*),
INTENT(in) :: keyword_name
1055 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1056 INTEGER,
INTENT(out),
OPTIONAL :: n_rep_val
1057 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1058 LOGICAL,
INTENT(out),
OPTIONAL :: l_val
1059 INTEGER,
INTENT(out),
OPTIONAL :: i_val
1060 REAL(kind=
dp),
INTENT(out),
OPTIONAL :: r_val
1061 CHARACTER(LEN=*),
INTENT(out),
OPTIONAL :: c_val
1062 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals
1063 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals
1064 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals
1065 CHARACTER(LEN=default_string_length), &
1066 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals
1067 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
1069 INTEGER :: ik, irk, irs, len_key, my_index, &
1071 LOGICAL :: valrequested
1078 cpassert(section_vals%ref_count > 0)
1080 my_index = index(keyword_name,
'%') + 1
1081 len_key = len_trim(keyword_name)
1082 IF (my_index > 1)
THEN
1084 tmp_index = index(keyword_name(my_index:len_key),
"%")
1085 IF (tmp_index <= 0)
EXIT
1086 my_index = my_index + tmp_index
1090 s_vals => section_vals
1095 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1096 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1097 IF (
PRESENT(val))
NULLIFY (val)
1098 IF (
PRESENT(explicit)) explicit = .false.
1099 section => s_vals%section
1100 valrequested =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1101 PRESENT(c_val) .OR.
PRESENT(l_vals) .OR.
PRESENT(i_vals) .OR. &
1102 PRESENT(r_vals) .OR.
PRESENT(c_vals)
1105 CALL cp_abort(__location__, &
1106 "section "//trim(section%name)//
" does not contain keyword "// &
1107 trim(keyword_name(my_index:len_key)))
1109 keyword => section%keywords(ik)%keyword
1110 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2)))
THEN
1111 CALL cp_abort(__location__, &
1112 "section repetition requested ("//
cp_to_string(irs)// &
1113 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1117 IF (
PRESENT(n_rep_val)) n_rep_val = 0
1118 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1119 vals => s_vals%values(ik, irs)%list
1121 IF (.NOT.
ASSOCIATED(vals))
THEN
1123 IF (
ASSOCIATED(keyword%default_value))
THEN
1124 my_val => keyword%default_value
1125 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1130 IF (
PRESENT(explicit)) explicit = .true.
1132 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1133 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1134 my_val => keyword%default_value
1136 IF (
PRESENT(val)) val => my_val
1137 IF (valrequested)
THEN
1138 IF (.NOT.
ASSOCIATED(my_val))
THEN
1139 CALL cp_abort(__location__, &
1140 "Value requested, but no value set getting value from "// &
1141 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1144 CALL val_get(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1145 c_val=c_val, l_vals=l_vals, i_vals=i_vals, r_vals=r_vals, &
1166 CHARACTER(len=*),
INTENT(in) :: keyword_name
1167 INTEGER,
OPTIONAL :: i_rep_section
1170 INTEGER :: ik, irs, len_key, my_index, tmp_index
1174 cpassert(
ASSOCIATED(section_vals))
1175 cpassert(section_vals%ref_count > 0)
1177 my_index = index(keyword_name,
'%') + 1
1178 len_key = len_trim(keyword_name)
1179 IF (my_index > 1)
THEN
1181 tmp_index = index(keyword_name(my_index:len_key),
"%")
1182 IF (tmp_index <= 0)
EXIT
1183 my_index = my_index + tmp_index
1187 s_vals => section_vals
1191 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1192 section => s_vals%section
1195 CALL cp_abort(__location__, &
1196 "section "//trim(section%name)//
" does not contain keyword "// &
1197 trim(keyword_name(my_index:len_key)))
1199 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2)))
THEN
1200 CALL cp_abort(__location__, &
1201 "section repetition requested ("//
cp_to_string(irs)// &
1202 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1205 list => s_vals%values(ik, irs)%list
1232 val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
1235 CHARACTER(len=*),
INTENT(in) :: keyword_name
1236 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1237 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1238 LOGICAL,
INTENT(in),
OPTIONAL :: l_val
1239 INTEGER,
INTENT(in),
OPTIONAL :: i_val
1240 REAL(kind=
dp),
INTENT(in),
OPTIONAL :: r_val
1241 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: c_val
1242 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals_ptr
1243 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals_ptr
1244 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals_ptr
1245 CHARACTER(LEN=default_string_length), &
1246 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals_ptr
1248 INTEGER :: ik, irk, irs, len_key, my_index, &
1255 TYPE(
val_type),
POINTER :: my_val, old_val
1257 cpassert(
ASSOCIATED(section_vals))
1258 cpassert(section_vals%ref_count > 0)
1260 my_index = index(keyword_name,
'%') + 1
1261 len_key = len_trim(keyword_name)
1262 IF (my_index > 1)
THEN
1264 tmp_index = index(keyword_name(my_index:len_key),
"%")
1265 IF (tmp_index <= 0)
EXIT
1266 my_index = my_index + tmp_index
1270 s_vals => section_vals
1275 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1276 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1277 section => s_vals%section
1280 CALL cp_abort(__location__, &
1281 "section "//trim(section%name)//
" does not contain keyword "// &
1282 trim(keyword_name(my_index:len_key)))
1286 IF (irs <=
SIZE(s_vals%values, 2))
EXIT
1289 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2)))
THEN
1290 CALL cp_abort(__location__, &
1291 "section repetition requested ("//
cp_to_string(irs)// &
1292 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1295 keyword => s_vals%section%keywords(ik)%keyword
1297 IF (
PRESENT(val)) my_val => val
1298 valset =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1299 PRESENT(c_val) .OR.
PRESENT(l_vals_ptr) .OR.
PRESENT(i_vals_ptr) .OR. &
1300 PRESENT(r_vals_ptr) .OR.
PRESENT(c_vals_ptr)
1301 IF (
ASSOCIATED(my_val))
THEN
1304 CALL cp_abort(__location__, &
1305 " both val and values present, in setting "// &
1306 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1311 IF (.NOT. valset)
THEN
1312 CALL cp_abort(__location__, &
1313 " empty value in setting "// &
1314 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1318 IF (keyword%type_of_var ==
lchar_t)
THEN
1319 CALL val_create(my_val, lc_val=c_val, lc_vals_ptr=c_vals_ptr)
1321 CALL val_create(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1322 c_val=c_val, l_vals_ptr=l_vals_ptr, i_vals_ptr=i_vals_ptr, &
1323 r_vals_ptr=r_vals_ptr, &
1324 c_vals_ptr=c_vals_ptr, enum=keyword%enum)
1326 cpassert(
ASSOCIATED(my_val))
1327 cpassert(my_val%type_of_var == keyword%type_of_var)
1329 vals => s_vals%values(ik, irs)%list
1334 CALL cp_abort(__location__, &
1336 " in keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1344 CALL cp_abort(__location__, &
1345 "cannot add extra keyword repetitions to keyword" &
1346 //trim(keyword_name(my_index:len_key))//
" of section "// &
1351 s_vals%values(ik, irs)%list => vals
1371 CHARACTER(len=*),
INTENT(in) :: keyword_name
1372 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1374 INTEGER :: ik, irk, irs, len_key, my_index, &
1382 cpassert(
ASSOCIATED(section_vals))
1383 cpassert(section_vals%ref_count > 0)
1385 my_index = index(keyword_name,
'%') + 1
1386 len_key = len_trim(keyword_name)
1387 IF (my_index > 1)
THEN
1389 tmp_index = index(keyword_name(my_index:len_key),
"%")
1390 IF (tmp_index <= 0)
EXIT
1391 my_index = my_index + tmp_index
1395 s_vals => section_vals
1400 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1401 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1402 section => s_vals%section
1405 CALL cp_abort(__location__, &
1406 "section "//trim(section%name)//
" does not contain keyword "// &
1407 trim(keyword_name(my_index:len_key)))
1410 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1411 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2)))
THEN
1412 CALL cp_abort(__location__, &
1413 "section repetition requested ("//
cp_to_string(irs)// &
1414 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1422 IF (
ASSOCIATED(pos))
THEN
1445 INTEGER,
INTENT(in) :: unit_nr
1446 LOGICAL,
INTENT(in),
OPTIONAL :: hide_root, hide_defaults
1448 INTEGER,
PARAMETER :: incr = 2
1450 CHARACTER(LEN=1) :: first_key_char, first_sec_char
1451 CHARACTER(LEN=25) :: myfmt
1452 INTEGER :: i_rep_s, ik, isec, ival, nr, nval
1453 INTEGER,
SAVE :: indent = 1
1454 LOGICAL :: defaultsection, explicit, &
1455 my_hide_defaults, my_hide_root
1462 my_hide_root = .false.
1463 my_hide_defaults = .true.
1464 IF (
PRESENT(hide_root)) my_hide_root = hide_root
1465 IF (
PRESENT(hide_defaults)) my_hide_defaults = hide_defaults
1467 cpassert(section_vals%ref_count > 0)
1468 IF (unit_nr > 0)
THEN
1469 CALL section_vals_get(section_vals, explicit=explicit, n_repetition=nr, section=section)
1470 IF (
ALLOCATED(section%deprecation_notice))
THEN
1471 first_sec_char =
"#"
1473 first_sec_char =
" "
1475 IF (explicit .OR. (.NOT. my_hide_defaults))
THEN
1477 IF (.NOT. my_hide_root)
THEN
1478 WRITE (unit=myfmt, fmt=
"(A1,I0,A4)")
"(", indent,
"X,A)"
1479 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
1480 WRITE (unit=unit_nr, fmt=myfmt, advance=
"NO") &
1483 WRITE (unit=unit_nr, fmt=myfmt) &
1487 defaultsection = (
SIZE(section_vals%values, 2) == 0)
1488 IF (.NOT. defaultsection)
THEN
1489 IF (.NOT. my_hide_root) indent = indent + incr
1490 WRITE (unit=myfmt, fmt=
"(A1,I0,A4)")
"(", indent,
"X,A)"
1491 DO ik = -1, section%n_keywords
1492 keyword => section%keywords(ik)%keyword
1493 IF (
ASSOCIATED(keyword))
THEN
1494 IF (
ALLOCATED(keyword%deprecation_notice) .OR. &
1495 ALLOCATED(section%deprecation_notice))
THEN
1497 first_key_char =
"#"
1499 first_key_char =
" "
1501 IF (keyword%type_of_var /=
no_t .AND. keyword%names(1) (1:2) /=
"__")
THEN
1503 i_rep_s, n_rep_val=nval)
1504 IF (i_rep_s <=
SIZE(section_vals%values, 2))
THEN
1506 vals => section_vals%values(ik, i_rep_s)%list
1511 new_pos => new_pos%rest
1513 IF (.NOT.
ASSOCIATED(new_pos))
THEN
1515 IF (
ASSOCIATED(keyword%default_value))
THEN
1516 val => keyword%default_value
1517 IF (my_hide_defaults) cycle
1520 val => new_pos%first_el
1522 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1523 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1524 WRITE (unit=unit_nr, fmt=myfmt, advance=
"NO") &
1525 trim(first_key_char)//trim(keyword%names(1))
1526 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1527 keyword%type_of_var /=
lchar_t)
THEN
1528 WRITE (unit=unit_nr, fmt=myfmt, advance=
"NO")
1530 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1532 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1534 IF (my_hide_defaults) cycle
1535 val => keyword%default_value
1536 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1537 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1538 WRITE (unit=unit_nr, fmt=myfmt, advance=
"NO") &
1539 trim(first_key_char)//trim(keyword%names(1))
1540 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1541 keyword%type_of_var /=
lchar_t)
THEN
1542 WRITE (unit=unit_nr, fmt=myfmt, advance=
"NO")
1544 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1549 IF (
ASSOCIATED(section_vals%subs_vals))
THEN
1550 DO isec = 1,
SIZE(section_vals%subs_vals, 1)
1551 sval => section_vals%subs_vals(isec, i_rep_s)%section_vals
1552 IF (
ASSOCIATED(sval))
THEN
1558 IF (.NOT. my_hide_root)
THEN
1559 indent = indent - incr
1560 WRITE (unit=myfmt, fmt=
"(A1,I0,A4)")
"(", indent,
"X,A)"
1561 WRITE (unit=unit_nr, fmt=myfmt) &
1563 "END "//trim(adjustl(section%name))
1580 INTEGER,
INTENT(IN) :: level, unit_number
1582 CHARACTER(LEN=3) :: repeats
1583 CHARACTER(LEN=8) :: short_string
1584 INTEGER :: i, l0, l1, l2
1586 IF (
ASSOCIATED(section))
THEN
1588 cpassert(section%ref_count > 0)
1596 IF (section%repeats)
THEN
1602 WRITE (unit=unit_number, fmt=
"(A)") &
1603 repeat(
" ", l0)//
"<SECTION repeats="""//trim(repeats)//
""">", &
1604 repeat(
" ", l1)//
"<NAME>"//trim(section%name)//
"</NAME>", &
1605 repeat(
" ", l1)//
"<DESCRIPTION>"// &
1609 IF (
ALLOCATED(section%deprecation_notice))
THEN
1610 WRITE (unit=unit_number, fmt=
"(A)") repeat(
" ", l1)//
"<DEPRECATION_NOTICE>"// &
1612 //
"</DEPRECATION_NOTICE>"
1615 IF (
ASSOCIATED(section%citations))
THEN
1616 DO i = 1,
SIZE(section%citations, 1)
1618 WRITE (unit=short_string, fmt=
"(I8)") section%citations(i)
1619 WRITE (unit=unit_number, fmt=
"(A)") &
1620 repeat(
" ", l1)//
"<REFERENCE>", &
1621 repeat(
" ", l2)//
"<NAME>"//trim(
get_citation_key(section%citations(i)))//
"</NAME>", &
1622 repeat(
" ", l2)//
"<NUMBER>"//trim(adjustl(short_string))//
"</NUMBER>", &
1623 repeat(
" ", l1)//
"</REFERENCE>"
1627 WRITE (unit=unit_number, fmt=
"(A)") &
1628 repeat(
" ", l1)//
"<LOCATION>"//trim(section%location)//
"</LOCATION>"
1630 DO i = -1, section%n_keywords
1631 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1636 DO i = 1, section%n_subsections
1640 WRITE (unit=unit_number, fmt=
"(A)") repeat(
" ", l0)//
"</SECTION>"
1657 matching_rank, matching_string, bonus)
1660 CHARACTER(LEN=*) :: section_name, unknown_string, &
1662 INTEGER,
DIMENSION(:),
INTENT(INOUT) :: matching_rank
1663 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(INOUT) :: matching_string
1664 INTEGER,
INTENT(IN) :: bonus
1666 CHARACTER(LEN=LEN(matching_string(1))) :: line
1667 INTEGER :: i, imatch,
imax, irank, newbonus
1669 IF (
ASSOCIATED(section))
THEN
1670 cpassert(section%ref_count > 0)
1671 imatch =
typo_match(trim(section%name), trim(unknown_string))
1672 IF (imatch > 0)
THEN
1673 imatch = imatch + bonus
1674 WRITE (unit=line, fmt=
'(T2,A)') &
1675 " subsection "//trim(adjustl(section%name))// &
1676 " in section "//trim(adjustl(location_string))
1677 imax =
SIZE(matching_rank, 1)
1680 IF (imatch > matching_rank(i)) irank = i
1682 IF (irank <=
imax)
THEN
1683 matching_rank(irank + 1:
imax) = matching_rank(irank:
imax - 1)
1684 matching_string(irank + 1:
imax) = matching_string(irank:
imax - 1)
1685 matching_rank(irank) = imatch
1686 matching_string(irank) = line
1690 IF (section_name == section%name)
THEN
1696 DO i = -1, section%n_keywords
1697 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1698 CALL keyword_typo_match(section%keywords(i)%keyword, unknown_string, location_string// &
1699 "%"//trim(section%name), matching_rank, matching_string, newbonus)
1703 DO i = 1, section%n_subsections
1704 CALL section_typo_match(section%subsections(i)%section, section_name, unknown_string, &
1705 location_string//
"%"//trim(section%name), matching_rank, matching_string, newbonus)
1722 new_section_vals, i_rep_section)
1724 CHARACTER(len=*),
INTENT(in) :: subsection_name
1726 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
1728 INTEGER :: irep, isection, len_key, my_index, &
1732 cpassert(
ASSOCIATED(section_vals))
1733 cpassert(section_vals%ref_count > 0)
1734 cpassert(
ASSOCIATED(new_section_vals))
1735 cpassert(new_section_vals%ref_count > 0)
1738 IF (
PRESENT(i_rep_section)) irep = i_rep_section
1740 my_index = index(subsection_name,
'%') + 1
1741 len_key = len_trim(subsection_name)
1742 IF (my_index > 1)
THEN
1744 tmp_index = index(subsection_name(my_index:len_key),
"%")
1745 IF (tmp_index <= 0)
EXIT
1746 my_index = my_index + tmp_index
1750 s_vals => section_vals
1753 cpassert(irep <=
SIZE(s_vals%subs_vals, 2))
1756 IF (isection <= 0)
THEN
1757 CALL cp_abort(__location__, &
1758 "could not find subsection "//subsection_name(my_index:len_trim(subsection_name))//
" in section "// &
1759 trim(section_vals%section%name)//
" at ")
1763 s_vals%subs_vals(isection, irep)%section_vals => new_section_vals
1776 i_rep_start, i_rep_end)
1778 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_start, i_rep_end
1780 cpassert(
ASSOCIATED(section_vals_in))
1781 cpassert(.NOT.
ASSOCIATED(section_vals_out))
1783 CALL section_vals_copy(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
1796 RECURSIVE SUBROUTINE section_vals_copy(section_vals_in, section_vals_out, &
1797 i_rep_low, i_rep_high)
1799 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_low, i_rep_high
1801 INTEGER :: iend, irep, isec, istart, ival
1807 cpassert(
ASSOCIATED(section_vals_in))
1808 cpassert(
ASSOCIATED(section_vals_out))
1811 iend =
SIZE(section_vals_in%values, 2)
1812 IF (
PRESENT(i_rep_low)) istart = i_rep_low
1813 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1814 DO irep = istart, iend
1816 DO ival = lbound(section_vals_in%values, 1), ubound(section_vals_in%values, 1)
1817 v1 => section_vals_in%values(ival, irep)%list
1818 IF (
ASSOCIATED(v1))
THEN
1822 section_vals_out%values(ival, irep - istart + 1)%list => v2
1824 IF (.NOT.
ASSOCIATED(v1%rest))
EXIT
1834 IF (.NOT.
PRESENT(i_rep_low) .AND. (.NOT.
PRESENT(i_rep_high)))
THEN
1835 IF (.NOT. (
SIZE(section_vals_in%values, 2) ==
SIZE(section_vals_out%values, 2)))
THEN
1836 cpabort(
"Incompatible sizes of values between input and output")
1838 IF (.NOT. (
SIZE(section_vals_in%subs_vals, 2) ==
SIZE(section_vals_out%subs_vals, 2)))
THEN
1839 cpabort(
"Incompatible sizes of subsections between input and output")
1842 iend =
SIZE(section_vals_in%subs_vals, 2)
1843 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1844 DO irep = istart, iend
1845 DO isec = 1,
SIZE(section_vals_in%subs_vals, 1)
1846 CALL section_vals_copy(section_vals_in%subs_vals(isec, irep)%section_vals, &
1847 section_vals_out%subs_vals(isec, irep - istart + 1)%section_vals)
1851 END SUBROUTINE section_vals_copy
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard)
various routines to log and control the output. The idea is that decisions about where to log should ...
Utility routines to read data from files. Kept as close as possible to the old parser because.
character(len=1), parameter, public default_section_character
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Perform an abnormal program termination.
subroutine, public print_message(message, output_unit, declev, before, after)
Perform a basic blocking of the text in message and print it optionally decorated with a frame of sta...
provides a uniform framework to add references to CP2K cite and output these
pure character(len=default_string_length) function, public get_citation_key(key)
...
Utilities for string manipulations.
elemental integer function, public typo_match(string, typo_string)
returns a non-zero positive value if typo_string equals string apart from a few typos....
pure character(len=size(array)) function, public a2s(array)
Converts a character-array into a string.
character(len=2 *len(inp_string)) function, public substitute_special_xml_tokens(inp_string)
Substitutes the five predefined XML entities: &, <, >, ', and ".
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.