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 INTEGER,
POINTER,
DIMENSION(:) :: citations => null()
110 TYPE(section_p_type),
POINTER,
DIMENSION(:) :: subsections => null()
118 TYPE section_vals_p_type
120 END TYPE section_vals_p_type
127 INTEGER :: ref_count = 0
128 INTEGER,
POINTER,
DIMENSION(:) :: ibackup => null()
131 TYPE(section_vals_p_type),
DIMENSION(:, :),
POINTER :: subs_vals => null()
135 INTEGER,
PARAMETER :: n_typo_matches = 5
155 n_subsections, repeats, citations)
158 CHARACTER(len=*),
INTENT(in) :: location, name, description
159 INTEGER,
INTENT(in),
OPTIONAL :: n_keywords, n_subsections
160 LOGICAL,
INTENT(in),
OPTIONAL :: repeats
161 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: citations
163 INTEGER :: i, my_n_keywords, my_n_subsections, n
165 cpassert(.NOT.
ASSOCIATED(section))
167 IF (
PRESENT(n_keywords)) my_n_keywords = n_keywords
169 IF (
PRESENT(n_subsections)) my_n_subsections = n_subsections
172 section%ref_count = 1
174 section%n_keywords = 0
175 section%n_subsections = 0
176 section%location = location
178 cpassert(len_trim(name) > 0)
182 n = len_trim(description)
183 ALLOCATE (section%description(n))
185 section%description(i) = description(i:i)
188 section%frozen = .false.
189 section%repeats = .false.
190 IF (
PRESENT(repeats)) section%repeats = repeats
192 NULLIFY (section%citations)
193 IF (
PRESENT(citations))
THEN
194 ALLOCATE (section%citations(
SIZE(citations)))
195 section%citations = citations
198 ALLOCATE (section%keywords(-1:my_n_keywords))
199 DO i = -1, my_n_keywords
200 NULLIFY (section%keywords(i)%keyword)
203 ALLOCATE (section%subsections(my_n_subsections))
204 DO i = 1, my_n_subsections
205 NULLIFY (section%subsections(i)%section)
215 SUBROUTINE section_retain(section)
219 cpassert(
ASSOCIATED(section))
220 cpassert(section%ref_count > 0)
221 section%ref_count = section%ref_count + 1
223 END SUBROUTINE section_retain
236 IF (
ASSOCIATED(section))
THEN
237 cpassert(section%ref_count > 0)
238 section%ref_count = section%ref_count - 1
239 IF (section%ref_count == 0)
THEN
240 IF (
ASSOCIATED(section%citations))
THEN
241 DEALLOCATE (section%citations)
243 IF (
ASSOCIATED(section%keywords))
THEN
244 DO i = -1, ubound(section%keywords, 1)
247 DEALLOCATE (section%keywords)
249 section%n_keywords = 0
250 IF (
ASSOCIATED(section%subsections))
THEN
251 DO i = 1,
SIZE(section%subsections)
254 DEALLOCATE (section%subsections)
256 DEALLOCATE (section%description)
270 FUNCTION get_section_info(section)
RESULT(message)
273 CHARACTER(LEN=default_path_length) :: message
278 length = len_trim(
a2s(section%description))
280 IF (section%description(length) /=
".")
THEN
284 IF (section%repeats)
THEN
285 message = trim(message)//
" This section can be repeated."
287 message = trim(message)//
" This section can not be repeated."
290 END FUNCTION get_section_info
306 INTEGER,
INTENT(in) :: unit_nr, level
307 LOGICAL,
INTENT(in),
OPTIONAL :: hide_root
308 INTEGER,
INTENT(in),
OPTIONAL :: recurse
310 CHARACTER(LEN=default_path_length) :: message
311 INTEGER :: ikeyword, isub, my_recurse
312 LOGICAL :: my_hide_root
314 IF (unit_nr > 0)
THEN
315 my_hide_root = .false.
316 IF (
PRESENT(hide_root)) my_hide_root = hide_root
318 IF (
PRESENT(recurse)) my_recurse = recurse
319 IF (
ASSOCIATED(section))
THEN
320 cpassert(section%ref_count > 0)
322 IF (.NOT. my_hide_root) &
323 WRITE (unit=unit_nr, fmt=
"('*** section &',A,' ***')") trim(adjustl(section%name))
325 message = get_section_info(section)
326 CALL print_message(trim(
a2s(section%description))//trim(message), unit_nr, 0, 0, 0)
329 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
333 IF (
ASSOCIATED(section%keywords(0)%keyword))
THEN
337 DO ikeyword = 1, section%n_keywords
342 IF (section%n_subsections > 0 .AND. my_recurse >= 0)
THEN
343 IF (.NOT. my_hide_root) &
344 WRITE (unit=unit_nr, fmt=
"('** subsections **')")
345 DO isub = 1, section%n_subsections
346 IF (my_recurse > 0)
THEN
348 level, recurse=my_recurse - 1)
350 WRITE (unit=unit_nr, fmt=
"(1X,A)") section%subsections(isub)%section%name
354 IF (.NOT. my_hide_root) &
355 WRITE (unit=unit_nr, fmt=
"('*** &end section ',A,' ***')") trim(adjustl(section%name))
357 WRITE (unit_nr,
"(a)")
'<section *null*>'
375 CHARACTER(len=*),
INTENT(IN) :: subsection_name
378 CHARACTER(len=default_string_length) :: upc_name
381 cpassert(section%ref_count > 0)
383 upc_name = subsection_name
385 DO isub = 1, section%n_subsections
386 cpassert(
ASSOCIATED(section%subsections(isub)%section))
387 IF (section%subsections(isub)%section%name == upc_name)
THEN
405 CHARACTER(len=*),
INTENT(IN) :: subsection_name
412 res => section%subsections(isub)%section
431 CHARACTER(len=*),
INTENT(IN) :: keyword_name
435 CHARACTER(len=default_string_length) :: upc_name
437 cpassert(section%ref_count > 0)
438 cpassert(
ASSOCIATED(section%keywords))
440 upc_name = keyword_name
443 IF (
ASSOCIATED(section%keywords(ik)%keyword))
THEN
444 IF (section%keywords(ik)%keyword%names(1) == upc_name)
THEN
450 k_search_loop:
DO ik = 1, section%n_keywords
451 cpassert(
ASSOCIATED(section%keywords(ik)%keyword))
452 DO in = 1,
SIZE(section%keywords(ik)%keyword%names)
453 IF (section%keywords(ik)%keyword%names(in) == upc_name)
THEN
473 CHARACTER(len=*),
INTENT(IN) :: keyword_name
476 INTEGER :: ik, my_index
478 IF (index(keyword_name,
"%") /= 0)
THEN
479 my_index = index(keyword_name,
"%") + 1
480 cpassert(
ASSOCIATED(section%subsections))
481 DO ik = lbound(section%subsections, 1), ubound(section%subsections, 1)
482 IF (section%subsections(ik)%section%name == keyword_name(1:my_index - 2))
EXIT
484 cpassert(ik <= ubound(section%subsections, 1))
491 res => section%keywords(ik)%keyword
511 cpassert(section%ref_count > 0)
512 cpassert(.NOT. section%frozen)
513 cpassert(
ASSOCIATED(keyword))
514 cpassert(keyword%ref_count > 0)
516 IF (keyword%names(1) ==
"_SECTION_PARAMETERS_")
THEN
518 section%keywords(-1)%keyword => keyword
519 ELSE IF (keyword%names(1) ==
"_DEFAULT_KEYWORD_")
THEN
521 section%keywords(0)%keyword => keyword
523 DO k = 1,
SIZE(keyword%names)
524 DO i = 1, section%n_keywords
525 DO j = 1,
SIZE(section%keywords(i)%keyword%names)
526 IF (keyword%names(k) == section%keywords(i)%keyword%names(j))
THEN
527 CALL cp_abort(__location__, &
528 "trying to add a keyword with a name ("// &
529 trim(keyword%names(k))//
") that was already used in section " &
530 //trim(section%name))
536 IF (ubound(section%keywords, 1) == section%n_keywords)
THEN
537 ALLOCATE (new_keywords(-1:section%n_keywords + 10))
538 DO i = -1, section%n_keywords
539 new_keywords(i)%keyword => section%keywords(i)%keyword
541 DO i = section%n_keywords + 1, ubound(new_keywords, 1)
542 NULLIFY (new_keywords(i)%keyword)
544 DEALLOCATE (section%keywords)
545 section%keywords => new_keywords
547 section%n_keywords = section%n_keywords + 1
548 section%keywords(section%n_keywords)%keyword => keyword
565 TYPE(section_p_type),
DIMENSION(:),
POINTER :: new_subsections
567 cpassert(section%ref_count > 0)
568 cpassert(
ASSOCIATED(subsection))
569 cpassert(subsection%ref_count > 0)
570 IF (
SIZE(section%subsections) < section%n_subsections + 1)
THEN
571 ALLOCATE (new_subsections(section%n_subsections + 10))
572 DO i = 1, section%n_subsections
573 new_subsections(i)%section => section%subsections(i)%section
575 DO i = section%n_subsections + 1,
SIZE(new_subsections)
576 NULLIFY (new_subsections(i)%section)
578 DEALLOCATE (section%subsections)
579 section%subsections => new_subsections
581 DO i = 1, section%n_subsections
582 IF (subsection%name == section%subsections(i)%section%name) &
583 CALL cp_abort(__location__, &
584 "trying to add a subsection with a name ("// &
585 trim(subsection%name)//
") that was already used in section " &
586 //trim(section%name))
588 CALL section_retain(subsection)
589 section%n_subsections = section%n_subsections + 1
590 section%subsections(section%n_subsections)%section => subsection
607 cpassert(.NOT.
ASSOCIATED(section_vals))
608 ALLOCATE (section_vals)
609 section_vals%ref_count = 1
610 CALL section_retain(section)
611 section_vals%section => section
612 section%frozen = .true.
613 ALLOCATE (section_vals%values(-1:section%n_keywords, 0))
614 ALLOCATE (section_vals%subs_vals(section%n_subsections, 1))
615 DO i = 1, section%n_subsections
616 NULLIFY (section_vals%subs_vals(i, 1)%section_vals)
618 section=section%subsections(i)%section)
621 NULLIFY (section_vals%ibackup)
634 cpassert(
ASSOCIATED(section_vals))
635 cpassert(section_vals%ref_count > 0)
636 section_vals%ref_count = section_vals%ref_count + 1
653 IF (
ASSOCIATED(section_vals))
THEN
654 cpassert(section_vals%ref_count > 0)
655 section_vals%ref_count = section_vals%ref_count - 1
656 IF (section_vals%ref_count == 0)
THEN
658 DO j = 1,
SIZE(section_vals%values, 2)
659 DO i = -1, ubound(section_vals%values, 1)
660 vals => section_vals%values(i, j)%list
667 DEALLOCATE (section_vals%values)
668 DO j = 1,
SIZE(section_vals%subs_vals, 2)
669 DO i = 1,
SIZE(section_vals%subs_vals, 1)
673 DEALLOCATE (section_vals%subs_vals)
674 IF (
ASSOCIATED(section_vals%ibackup))
THEN
675 DEALLOCATE (section_vals%ibackup)
677 DEALLOCATE (section_vals)
696 n_subs_vals_rep, section, explicit)
699 INTEGER,
INTENT(out),
OPTIONAL :: ref_count, n_repetition, n_subs_vals_rep
701 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
703 cpassert(section_vals%ref_count > 0)
704 IF (
PRESENT(ref_count)) ref_count = section_vals%ref_count
705 IF (
PRESENT(section)) section => section_vals%section
706 IF (
PRESENT(n_repetition)) n_repetition =
SIZE(section_vals%values, 2)
707 IF (
PRESENT(n_subs_vals_rep)) n_subs_vals_rep =
SIZE(section_vals%subs_vals, 2)
708 IF (
PRESENT(explicit)) explicit = (
SIZE(section_vals%values, 2) > 0)
723 i_rep_section, can_return_null)
RESULT(res)
726 CHARACTER(len=*),
INTENT(IN) :: subsection_name
727 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_section
728 LOGICAL,
INTENT(IN),
OPTIONAL :: can_return_null
731 INTEGER :: irep, isection, my_index
732 LOGICAL :: is_path, my_can_return_null
734 cpassert(section_vals%ref_count > 0)
736 my_can_return_null = .false.
737 IF (
PRESENT(can_return_null)) my_can_return_null = can_return_null
740 IF (
PRESENT(i_rep_section)) irep = i_rep_section
743 my_index = index(subsection_name,
"%")
744 IF (my_index .EQ. 0)
THEN
746 my_index = len_trim(subsection_name)
750 my_index = my_index - 1
753 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
756 IF (isection > 0) res => section_vals%subs_vals(isection, irep)%section_vals
757 IF (.NOT. (
ASSOCIATED(res) .OR. my_can_return_null)) &
758 CALL cp_abort(__location__, &
759 "could not find subsection "//trim(subsection_name(1:my_index))//
" in section "// &
760 trim(section_vals%section%name)//
" at ")
761 IF (is_path .AND.
ASSOCIATED(res))
THEN
763 i_rep_section, can_return_null)
781 INTEGER,
INTENT(in) :: i_section
782 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
785 INTEGER :: i, irep, isect_att
787 cpassert(
ASSOCIATED(section_vals))
788 cpassert(section_vals%ref_count > 0)
791 IF (
PRESENT(i_rep_section)) irep = i_rep_section
792 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
794 DO i = 1, section_vals%section%n_subsections
795 IF (
SIZE(section_vals%subs_vals(i, irep)%section_vals%values, 2) > 0)
THEN
796 isect_att = isect_att + 1
797 IF (isect_att == i_section)
THEN
798 res => section_vals%subs_vals(i, irep)%section_vals
816 i_rep_section)
RESULT(res)
819 CHARACTER(LEN=*),
INTENT(IN) :: subsection_name
820 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
823 INTEGER :: i_section, irep
825 cpassert(section_vals%ref_count > 0)
828 IF (
PRESENT(i_rep_section)) irep = i_rep_section
829 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
831 res => section_vals%subs_vals(i_section, irep)%section_vals
846 TYPE(section_vals_p_type),
DIMENSION(:, :), &
849 cpassert(section_vals%ref_count > 0)
850 ALLOCATE (new_values(-1:ubound(section_vals%values, 1),
SIZE(section_vals%values, 2) + 1))
851 DO j = 1,
SIZE(section_vals%values, 2)
852 DO i = -1, ubound(section_vals%values, 1)
853 new_values(i, j)%list => section_vals%values(i, j)%list
856 DEALLOCATE (section_vals%values)
857 section_vals%values => new_values
858 j =
SIZE(new_values, 2)
859 DO i = -1, ubound(new_values, 1)
860 NULLIFY (new_values(i, j)%list)
863 IF (
SIZE(new_values, 2) > 1)
THEN
864 ALLOCATE (new_sps(
SIZE(section_vals%subs_vals, 1), &
865 SIZE(section_vals%subs_vals, 2) + 1))
866 DO j = 1,
SIZE(section_vals%subs_vals, 2)
867 DO i = 1,
SIZE(section_vals%subs_vals, 1)
868 new_sps(i, j)%section_vals => section_vals%subs_vals(i, j)%section_vals
871 DEALLOCATE (section_vals%subs_vals)
872 section_vals%subs_vals => new_sps
874 DO i = 1,
SIZE(new_sps, 1)
875 NULLIFY (new_sps(i, j)%section_vals)
877 section=section_vals%section%subsections(i)%section)
897 IF (
ASSOCIATED(section_vals))
THEN
898 cpassert(section_vals%ref_count > 0)
901 ALLOCATE (new_values(-1:section_vals%section%n_keywords, 0))
903 DO j = 1,
SIZE(section_vals%values, 2)
904 DO i = -1, ubound(section_vals%values, 1)
905 vals => section_vals%values(i, j)%list
912 DEALLOCATE (section_vals%values)
913 section_vals%values => new_values
924 FUNCTION section_get_cval(section_vals, keyword_name)
RESULT(res)
927 CHARACTER(len=*),
INTENT(in) :: keyword_name
928 CHARACTER(LEN=default_string_length) :: res
932 END FUNCTION section_get_cval
943 CHARACTER(len=*),
INTENT(in) :: keyword_name
956 FUNCTION section_get_rvals(section_vals, keyword_name)
RESULT(res)
959 CHARACTER(len=*),
INTENT(in) :: keyword_name
960 REAL(kind=
dp),
DIMENSION(:),
POINTER :: res
964 END FUNCTION section_get_rvals
975 CHARACTER(len=*),
INTENT(in) :: keyword_name
991 CHARACTER(len=*),
INTENT(in) :: keyword_name
992 INTEGER,
DIMENSION(:),
POINTER :: res
1007 CHARACTER(len=*),
INTENT(in) :: keyword_name
1038 i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, &
1042 CHARACTER(len=*),
INTENT(in) :: keyword_name
1043 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1044 INTEGER,
INTENT(out),
OPTIONAL :: n_rep_val
1045 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1046 LOGICAL,
INTENT(out),
OPTIONAL :: l_val
1047 INTEGER,
INTENT(out),
OPTIONAL :: i_val
1048 REAL(kind=
dp),
INTENT(out),
OPTIONAL :: r_val
1049 CHARACTER(LEN=*),
INTENT(out),
OPTIONAL :: c_val
1050 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals
1051 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals
1052 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals
1053 CHARACTER(LEN=default_string_length), &
1054 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals
1055 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
1057 INTEGER :: ik, irk, irs, len_key, my_index, &
1059 LOGICAL :: valrequested
1066 cpassert(section_vals%ref_count > 0)
1068 my_index = index(keyword_name,
'%') + 1
1069 len_key = len_trim(keyword_name)
1070 IF (my_index > 1)
THEN
1072 tmp_index = index(keyword_name(my_index:len_key),
"%")
1073 IF (tmp_index <= 0)
EXIT
1074 my_index = my_index + tmp_index
1078 s_vals => section_vals
1083 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1084 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1085 IF (
PRESENT(val))
NULLIFY (val)
1086 IF (
PRESENT(explicit)) explicit = .false.
1087 section => s_vals%section
1088 valrequested =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1089 PRESENT(c_val) .OR.
PRESENT(l_vals) .OR.
PRESENT(i_vals) .OR. &
1090 PRESENT(r_vals) .OR.
PRESENT(c_vals)
1093 CALL cp_abort(__location__, &
1094 "section "//trim(section%name)//
" does not contain keyword "// &
1095 trim(keyword_name(my_index:len_key)))
1096 keyword => section%keywords(ik)%keyword
1097 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1098 CALL cp_abort(__location__, &
1099 "section repetition requested ("//
cp_to_string(irs)// &
1100 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1103 IF (
PRESENT(n_rep_val)) n_rep_val = 0
1104 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1105 vals => s_vals%values(ik, irs)%list
1107 IF (.NOT.
ASSOCIATED(vals))
THEN
1109 IF (
ASSOCIATED(keyword%default_value))
THEN
1110 my_val => keyword%default_value
1111 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1116 IF (
PRESENT(explicit)) explicit = .true.
1118 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1119 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1120 my_val => keyword%default_value
1122 IF (
PRESENT(val)) val => my_val
1123 IF (valrequested)
THEN
1124 IF (.NOT.
ASSOCIATED(my_val)) &
1125 CALL cp_abort(__location__, &
1126 "Value requested, but no value set getting value from "// &
1127 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1129 CALL val_get(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1130 c_val=c_val, l_vals=l_vals, i_vals=i_vals, r_vals=r_vals, &
1151 CHARACTER(len=*),
INTENT(in) :: keyword_name
1152 INTEGER,
OPTIONAL :: i_rep_section
1155 INTEGER :: ik, irs, len_key, my_index, tmp_index
1159 cpassert(
ASSOCIATED(section_vals))
1160 cpassert(section_vals%ref_count > 0)
1162 my_index = index(keyword_name,
'%') + 1
1163 len_key = len_trim(keyword_name)
1164 IF (my_index > 1)
THEN
1166 tmp_index = index(keyword_name(my_index:len_key),
"%")
1167 IF (tmp_index <= 0)
EXIT
1168 my_index = my_index + tmp_index
1172 s_vals => section_vals
1176 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1177 section => s_vals%section
1180 CALL cp_abort(__location__, &
1181 "section "//trim(section%name)//
" does not contain keyword "// &
1182 trim(keyword_name(my_index:len_key)))
1183 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1184 CALL cp_abort(__location__, &
1185 "section repetition requested ("//
cp_to_string(irs)// &
1186 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1188 list => s_vals%values(ik, irs)%list
1215 val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
1218 CHARACTER(len=*),
INTENT(in) :: keyword_name
1219 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1220 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1221 LOGICAL,
INTENT(in),
OPTIONAL :: l_val
1222 INTEGER,
INTENT(in),
OPTIONAL :: i_val
1223 REAL(kind=
dp),
INTENT(in),
OPTIONAL :: r_val
1224 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: c_val
1225 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals_ptr
1226 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals_ptr
1227 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals_ptr
1228 CHARACTER(LEN=default_string_length), &
1229 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals_ptr
1231 INTEGER :: ik, irk, irs, len_key, my_index, &
1238 TYPE(
val_type),
POINTER :: my_val, old_val
1240 cpassert(
ASSOCIATED(section_vals))
1241 cpassert(section_vals%ref_count > 0)
1243 my_index = index(keyword_name,
'%') + 1
1244 len_key = len_trim(keyword_name)
1245 IF (my_index > 1)
THEN
1247 tmp_index = index(keyword_name(my_index:len_key),
"%")
1248 IF (tmp_index <= 0)
EXIT
1249 my_index = my_index + tmp_index
1253 s_vals => section_vals
1258 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1259 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1260 section => s_vals%section
1263 CALL cp_abort(__location__, &
1264 "section "//trim(section%name)//
" does not contain keyword "// &
1265 trim(keyword_name(my_index:len_key)))
1268 IF (irs <=
SIZE(s_vals%values, 2))
EXIT
1271 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1272 CALL cp_abort(__location__, &
1273 "section repetition requested ("//
cp_to_string(irs)// &
1274 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1276 keyword => s_vals%section%keywords(ik)%keyword
1278 IF (
PRESENT(val)) my_val => val
1279 valset =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1280 PRESENT(c_val) .OR.
PRESENT(l_vals_ptr) .OR.
PRESENT(i_vals_ptr) .OR. &
1281 PRESENT(r_vals_ptr) .OR.
PRESENT(c_vals_ptr)
1282 IF (
ASSOCIATED(my_val))
THEN
1285 CALL cp_abort(__location__, &
1286 " both val and values present, in setting "// &
1287 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1292 CALL cp_abort(__location__, &
1293 " empty value in setting "// &
1294 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1297 IF (keyword%type_of_var ==
lchar_t)
THEN
1298 CALL val_create(my_val, lc_val=c_val, lc_vals_ptr=c_vals_ptr)
1300 CALL val_create(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1301 c_val=c_val, l_vals_ptr=l_vals_ptr, i_vals_ptr=i_vals_ptr, &
1302 r_vals_ptr=r_vals_ptr, &
1303 c_vals_ptr=c_vals_ptr, enum=keyword%enum)
1305 cpassert(
ASSOCIATED(my_val))
1306 cpassert(my_val%type_of_var == keyword%type_of_var)
1308 vals => s_vals%values(ik, irs)%list
1313 CALL cp_abort(__location__, &
1315 " in keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1322 CALL cp_abort(__location__, &
1323 "cannot add extra keyword repetitions to keyword" &
1324 //trim(keyword_name(my_index:len_key))//
" of section "// &
1329 s_vals%values(ik, irs)%list => vals
1349 CHARACTER(len=*),
INTENT(in) :: keyword_name
1350 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1352 INTEGER :: ik, irk, irs, len_key, my_index, &
1360 cpassert(
ASSOCIATED(section_vals))
1361 cpassert(section_vals%ref_count > 0)
1363 my_index = index(keyword_name,
'%') + 1
1364 len_key = len_trim(keyword_name)
1365 IF (my_index > 1)
THEN
1367 tmp_index = index(keyword_name(my_index:len_key),
"%")
1368 IF (tmp_index <= 0)
EXIT
1369 my_index = my_index + tmp_index
1373 s_vals => section_vals
1378 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1379 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1380 section => s_vals%section
1383 CALL cp_abort(__location__, &
1384 "section "//trim(section%name)//
" does not contain keyword "// &
1385 trim(keyword_name(my_index:len_key)))
1387 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1388 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1389 CALL cp_abort(__location__, &
1390 "section repetition requested ("//
cp_to_string(irs)// &
1391 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1398 IF (
ASSOCIATED(pos))
THEN
1421 INTEGER,
INTENT(in) :: unit_nr
1422 LOGICAL,
INTENT(in),
OPTIONAL :: hide_root, hide_defaults
1424 INTEGER,
PARAMETER :: incr = 2
1426 CHARACTER(len=default_string_length) :: myfmt
1427 INTEGER :: i_rep_s, ik, isec, ival, nr, nval
1428 INTEGER,
SAVE :: indent = 1
1429 LOGICAL :: defaultsection, explicit, &
1430 my_hide_defaults, my_hide_root
1437 my_hide_root = .false.
1438 my_hide_defaults = .true.
1439 IF (
PRESENT(hide_root)) my_hide_root = hide_root
1440 IF (
PRESENT(hide_defaults)) my_hide_defaults = hide_defaults
1442 cpassert(section_vals%ref_count > 0)
1443 IF (unit_nr > 0)
THEN
1444 CALL section_vals_get(section_vals, explicit=explicit, n_repetition=nr, section=section)
1445 IF (explicit .OR. (.NOT. my_hide_defaults))
THEN
1447 IF (.NOT. my_hide_root)
THEN
1448 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1449 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
1450 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1453 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)") &
1457 defaultsection = (
SIZE(section_vals%values, 2) == 0)
1458 IF (.NOT. defaultsection)
THEN
1459 IF (.NOT. my_hide_root) indent = indent + incr
1460 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1461 DO ik = -1, section%n_keywords
1462 keyword => section%keywords(ik)%keyword
1463 IF (
ASSOCIATED(keyword))
THEN
1464 IF (keyword%type_of_var /=
no_t .AND. keyword%names(1) (1:2) /=
"__")
THEN
1466 i_rep_s, n_rep_val=nval)
1467 IF (i_rep_s <=
SIZE(section_vals%values, 2))
THEN
1469 vals => section_vals%values(ik, i_rep_s)%list
1474 new_pos => new_pos%rest
1476 IF (.NOT.
ASSOCIATED(new_pos))
THEN
1478 IF (
ASSOCIATED(keyword%default_value))
THEN
1479 val => keyword%default_value
1480 IF (my_hide_defaults) cycle
1483 val => new_pos%first_el
1485 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1486 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1487 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1488 trim(keyword%names(1))
1489 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1490 keyword%type_of_var /=
lchar_t)
THEN
1491 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
")", advance=
"NO")
1493 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1495 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1497 IF (my_hide_defaults) cycle
1498 val => keyword%default_value
1499 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1500 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1501 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1502 trim(keyword%names(1))
1503 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1504 keyword%type_of_var /=
lchar_t)
THEN
1505 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
")", advance=
"NO")
1507 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1512 IF (
ASSOCIATED(section_vals%subs_vals))
THEN
1513 DO isec = 1,
SIZE(section_vals%subs_vals, 1)
1514 sval => section_vals%subs_vals(isec, i_rep_s)%section_vals
1515 IF (
ASSOCIATED(sval))
THEN
1521 IF (.NOT. my_hide_root)
THEN
1522 indent = indent - incr
1523 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1524 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)") &
1542 INTEGER,
INTENT(IN) :: level, unit_number
1544 CHARACTER(LEN=3) :: repeats
1545 CHARACTER(LEN=8) :: short_string
1546 INTEGER :: i, l0, l1, l2
1548 IF (
ASSOCIATED(section))
THEN
1550 cpassert(section%ref_count > 0)
1558 IF (section%repeats)
THEN
1564 WRITE (unit=unit_number, fmt=
"(A)") &
1565 repeat(
" ", l0)//
"<SECTION repeats="""//trim(repeats)//
""">", &
1566 repeat(
" ", l1)//
"<NAME>"//trim(section%name)//
"</NAME>", &
1567 repeat(
" ", l1)//
"<DESCRIPTION>"// &
1571 IF (
ASSOCIATED(section%citations))
THEN
1572 DO i = 1,
SIZE(section%citations, 1)
1574 WRITE (unit=short_string, fmt=
"(I8)") section%citations(i)
1575 WRITE (unit=unit_number, fmt=
"(A)") &
1576 repeat(
" ", l1)//
"<REFERENCE>", &
1577 repeat(
" ", l2)//
"<NAME>"//trim(
get_citation_key(section%citations(i)))//
"</NAME>", &
1578 repeat(
" ", l2)//
"<NUMBER>"//trim(adjustl(short_string))//
"</NUMBER>", &
1579 repeat(
" ", l1)//
"</REFERENCE>"
1583 WRITE (unit=unit_number, fmt=
"(A)") &
1584 repeat(
" ", l1)//
"<LOCATION>"//trim(section%location)//
"</LOCATION>"
1586 DO i = -1, section%n_keywords
1587 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1592 DO i = 1, section%n_subsections
1596 WRITE (unit=unit_number, fmt=
"(A)") repeat(
" ", l0)//
"</SECTION>"
1613 matching_rank, matching_string, bonus)
1616 CHARACTER(LEN=*) :: section_name, unknown_string, &
1618 INTEGER,
DIMENSION(:),
INTENT(INOUT) :: matching_rank
1619 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(INOUT) :: matching_string
1620 INTEGER,
INTENT(IN) :: bonus
1622 CHARACTER(LEN=LEN(matching_string(1))) :: line
1623 INTEGER :: i, imatch,
imax, irank, newbonus
1625 IF (
ASSOCIATED(section))
THEN
1626 cpassert(section%ref_count > 0)
1627 imatch =
typo_match(trim(section%name), trim(unknown_string))
1628 IF (imatch > 0)
THEN
1629 imatch = imatch + bonus
1630 WRITE (unit=line, fmt=
'(T2,A)') &
1631 " subsection "//trim(adjustl(section%name))// &
1632 " in section "//trim(adjustl(location_string))
1633 imax =
SIZE(matching_rank, 1)
1636 IF (imatch > matching_rank(i)) irank = i
1638 IF (irank <=
imax)
THEN
1639 matching_rank(irank + 1:
imax) = matching_rank(irank:
imax - 1)
1640 matching_string(irank + 1:
imax) = matching_string(irank:
imax - 1)
1641 matching_rank(irank) = imatch
1642 matching_string(irank) = line
1646 IF (section_name == section%name)
THEN
1652 DO i = -1, section%n_keywords
1653 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1654 CALL keyword_typo_match(section%keywords(i)%keyword, unknown_string, location_string// &
1655 "%"//trim(section%name), matching_rank, matching_string, newbonus)
1659 DO i = 1, section%n_subsections
1660 CALL section_typo_match(section%subsections(i)%section, section_name, unknown_string, &
1661 location_string//
"%"//trim(section%name), matching_rank, matching_string, newbonus)
1678 new_section_vals, i_rep_section)
1680 CHARACTER(len=*),
INTENT(in) :: subsection_name
1682 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
1684 INTEGER :: irep, isection, len_key, my_index, &
1688 cpassert(
ASSOCIATED(section_vals))
1689 cpassert(section_vals%ref_count > 0)
1690 cpassert(
ASSOCIATED(new_section_vals))
1691 cpassert(new_section_vals%ref_count > 0)
1694 IF (
PRESENT(i_rep_section)) irep = i_rep_section
1696 my_index = index(subsection_name,
'%') + 1
1697 len_key = len_trim(subsection_name)
1698 IF (my_index > 1)
THEN
1700 tmp_index = index(subsection_name(my_index:len_key),
"%")
1701 IF (tmp_index <= 0)
EXIT
1702 my_index = my_index + tmp_index
1706 s_vals => section_vals
1709 cpassert(irep <=
SIZE(s_vals%subs_vals, 2))
1712 IF (isection <= 0) &
1713 CALL cp_abort(__location__, &
1714 "could not find subsection "//subsection_name(my_index:len_trim(subsection_name))//
" in section "// &
1715 trim(section_vals%section%name)//
" at ")
1718 s_vals%subs_vals(isection, irep)%section_vals => new_section_vals
1731 i_rep_start, i_rep_end)
1733 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_start, i_rep_end
1735 cpassert(
ASSOCIATED(section_vals_in))
1736 cpassert(.NOT.
ASSOCIATED(section_vals_out))
1738 CALL section_vals_copy(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
1751 RECURSIVE SUBROUTINE section_vals_copy(section_vals_in, section_vals_out, &
1752 i_rep_low, i_rep_high)
1754 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_low, i_rep_high
1756 INTEGER :: iend, irep, isec, istart, ival
1762 cpassert(
ASSOCIATED(section_vals_in))
1763 cpassert(
ASSOCIATED(section_vals_out))
1768 iend =
SIZE(section_vals_in%values, 2)
1769 IF (
PRESENT(i_rep_low)) istart = i_rep_low
1770 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1771 DO irep = istart, iend
1773 DO ival = lbound(section_vals_in%values, 1), ubound(section_vals_in%values, 1)
1774 v1 => section_vals_in%values(ival, irep)%list
1775 IF (
ASSOCIATED(v1))
THEN
1779 section_vals_out%values(ival, irep - istart + 1)%list => v2
1781 IF (.NOT.
ASSOCIATED(v1%rest))
EXIT
1791 IF (.NOT.
PRESENT(i_rep_low) .AND. (.NOT.
PRESENT(i_rep_high)))
THEN
1792 IF (.NOT. (
SIZE(section_vals_in%values, 2) ==
SIZE(section_vals_out%values, 2))) &
1794 IF (.NOT. (
SIZE(section_vals_in%subs_vals, 2) ==
SIZE(section_vals_out%subs_vals, 2))) &
1797 iend =
SIZE(section_vals_in%subs_vals, 2)
1798 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1799 DO irep = istart, iend
1800 DO isec = 1,
SIZE(section_vals_in%subs_vals, 1)
1801 CALL section_vals_copy(section_vals_in%subs_vals(isec, irep)%section_vals, &
1802 section_vals_out%subs_vals(isec, irep - istart + 1)%section_vals)
1806 END SUBROUTINE section_vals_copy
static int imax(int x, int y)
Returns the larger of two given integer (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.