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) &
330 WRITE (unit=unit_nr, fmt=
"('*** section &',A,' ***')") trim(adjustl(section%name))
332 message = get_section_info(section)
333 CALL print_message(trim(
a2s(section%description))//trim(message), unit_nr, 0, 0, 0)
336 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
340 IF (
ASSOCIATED(section%keywords(0)%keyword))
THEN
344 DO ikeyword = 1, section%n_keywords
349 IF (section%n_subsections > 0 .AND. my_recurse >= 0)
THEN
350 IF (.NOT. my_hide_root) &
351 WRITE (unit=unit_nr, fmt=
"('** subsections **')")
352 DO isub = 1, section%n_subsections
353 IF (my_recurse > 0)
THEN
355 level, recurse=my_recurse - 1)
357 WRITE (unit=unit_nr, fmt=
"(1X,A)") section%subsections(isub)%section%name
361 IF (.NOT. my_hide_root) &
362 WRITE (unit=unit_nr, fmt=
"('*** &end section ',A,' ***')") trim(adjustl(section%name))
364 WRITE (unit_nr,
"(a)")
'<section *null*>'
382 CHARACTER(len=*),
INTENT(IN) :: subsection_name
385 CHARACTER(len=default_string_length) :: upc_name
388 cpassert(section%ref_count > 0)
390 upc_name = subsection_name
392 DO isub = 1, section%n_subsections
393 cpassert(
ASSOCIATED(section%subsections(isub)%section))
394 IF (section%subsections(isub)%section%name == upc_name)
THEN
412 CHARACTER(len=*),
INTENT(IN) :: subsection_name
419 res => section%subsections(isub)%section
438 CHARACTER(len=*),
INTENT(IN) :: keyword_name
442 CHARACTER(len=default_string_length) :: upc_name
444 cpassert(section%ref_count > 0)
445 cpassert(
ASSOCIATED(section%keywords))
447 upc_name = keyword_name
450 IF (
ASSOCIATED(section%keywords(ik)%keyword))
THEN
451 IF (section%keywords(ik)%keyword%names(1) == upc_name)
THEN
457 k_search_loop:
DO ik = 1, section%n_keywords
458 cpassert(
ASSOCIATED(section%keywords(ik)%keyword))
459 DO in = 1,
SIZE(section%keywords(ik)%keyword%names)
460 IF (section%keywords(ik)%keyword%names(in) == upc_name)
THEN
480 CHARACTER(len=*),
INTENT(IN) :: keyword_name
483 INTEGER :: ik, my_index
485 IF (index(keyword_name,
"%") /= 0)
THEN
486 my_index = index(keyword_name,
"%") + 1
487 cpassert(
ASSOCIATED(section%subsections))
488 DO ik = lbound(section%subsections, 1), ubound(section%subsections, 1)
489 IF (section%subsections(ik)%section%name == keyword_name(1:my_index - 2))
EXIT
491 cpassert(ik <= ubound(section%subsections, 1))
498 res => section%keywords(ik)%keyword
518 cpassert(section%ref_count > 0)
519 cpassert(.NOT. section%frozen)
520 cpassert(
ASSOCIATED(keyword))
521 cpassert(keyword%ref_count > 0)
523 IF (keyword%names(1) ==
"_SECTION_PARAMETERS_")
THEN
525 section%keywords(-1)%keyword => keyword
526 ELSE IF (keyword%names(1) ==
"_DEFAULT_KEYWORD_")
THEN
528 section%keywords(0)%keyword => keyword
530 DO k = 1,
SIZE(keyword%names)
531 DO i = 1, section%n_keywords
532 DO j = 1,
SIZE(section%keywords(i)%keyword%names)
533 IF (keyword%names(k) == section%keywords(i)%keyword%names(j))
THEN
534 CALL cp_abort(__location__, &
535 "trying to add a keyword with a name ("// &
536 trim(keyword%names(k))//
") that was already used in section " &
537 //trim(section%name))
543 IF (ubound(section%keywords, 1) == section%n_keywords)
THEN
544 ALLOCATE (new_keywords(-1:section%n_keywords + 10))
545 DO i = -1, section%n_keywords
546 new_keywords(i)%keyword => section%keywords(i)%keyword
548 DO i = section%n_keywords + 1, ubound(new_keywords, 1)
549 NULLIFY (new_keywords(i)%keyword)
551 DEALLOCATE (section%keywords)
552 section%keywords => new_keywords
554 section%n_keywords = section%n_keywords + 1
555 section%keywords(section%n_keywords)%keyword => keyword
572 TYPE(section_p_type),
DIMENSION(:),
POINTER :: new_subsections
574 cpassert(section%ref_count > 0)
575 cpassert(
ASSOCIATED(subsection))
576 cpassert(subsection%ref_count > 0)
577 IF (
SIZE(section%subsections) < section%n_subsections + 1)
THEN
578 ALLOCATE (new_subsections(section%n_subsections + 10))
579 DO i = 1, section%n_subsections
580 new_subsections(i)%section => section%subsections(i)%section
582 DO i = section%n_subsections + 1,
SIZE(new_subsections)
583 NULLIFY (new_subsections(i)%section)
585 DEALLOCATE (section%subsections)
586 section%subsections => new_subsections
588 DO i = 1, section%n_subsections
589 IF (subsection%name == section%subsections(i)%section%name) &
590 CALL cp_abort(__location__, &
591 "trying to add a subsection with a name ("// &
592 trim(subsection%name)//
") that was already used in section " &
593 //trim(section%name))
595 CALL section_retain(subsection)
596 section%n_subsections = section%n_subsections + 1
597 section%subsections(section%n_subsections)%section => subsection
614 cpassert(.NOT.
ASSOCIATED(section_vals))
615 ALLOCATE (section_vals)
616 section_vals%ref_count = 1
617 CALL section_retain(section)
618 section_vals%section => section
619 section%frozen = .true.
620 ALLOCATE (section_vals%values(-1:section%n_keywords, 0))
621 ALLOCATE (section_vals%subs_vals(section%n_subsections, 1))
622 DO i = 1, section%n_subsections
623 NULLIFY (section_vals%subs_vals(i, 1)%section_vals)
625 section=section%subsections(i)%section)
628 NULLIFY (section_vals%ibackup)
641 cpassert(
ASSOCIATED(section_vals))
642 cpassert(section_vals%ref_count > 0)
643 section_vals%ref_count = section_vals%ref_count + 1
660 IF (
ASSOCIATED(section_vals))
THEN
661 cpassert(section_vals%ref_count > 0)
662 section_vals%ref_count = section_vals%ref_count - 1
663 IF (section_vals%ref_count == 0)
THEN
665 DO j = 1,
SIZE(section_vals%values, 2)
666 DO i = -1, ubound(section_vals%values, 1)
667 vals => section_vals%values(i, j)%list
674 DEALLOCATE (section_vals%values)
675 DO j = 1,
SIZE(section_vals%subs_vals, 2)
676 DO i = 1,
SIZE(section_vals%subs_vals, 1)
680 DEALLOCATE (section_vals%subs_vals)
681 IF (
ASSOCIATED(section_vals%ibackup))
THEN
682 DEALLOCATE (section_vals%ibackup)
684 DEALLOCATE (section_vals)
703 n_subs_vals_rep, section, explicit)
706 INTEGER,
INTENT(out),
OPTIONAL :: ref_count, n_repetition, n_subs_vals_rep
708 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
710 cpassert(section_vals%ref_count > 0)
711 IF (
PRESENT(ref_count)) ref_count = section_vals%ref_count
712 IF (
PRESENT(section)) section => section_vals%section
713 IF (
PRESENT(n_repetition)) n_repetition =
SIZE(section_vals%values, 2)
714 IF (
PRESENT(n_subs_vals_rep)) n_subs_vals_rep =
SIZE(section_vals%subs_vals, 2)
715 IF (
PRESENT(explicit)) explicit = (
SIZE(section_vals%values, 2) > 0)
730 i_rep_section, can_return_null)
RESULT(res)
733 CHARACTER(len=*),
INTENT(IN) :: subsection_name
734 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_section
735 LOGICAL,
INTENT(IN),
OPTIONAL :: can_return_null
738 INTEGER :: irep, isection, my_index
739 LOGICAL :: is_path, my_can_return_null
741 cpassert(section_vals%ref_count > 0)
743 my_can_return_null = .false.
744 IF (
PRESENT(can_return_null)) my_can_return_null = can_return_null
747 IF (
PRESENT(i_rep_section)) irep = i_rep_section
750 my_index = index(subsection_name,
"%")
751 IF (my_index .EQ. 0)
THEN
753 my_index = len_trim(subsection_name)
757 my_index = my_index - 1
760 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
763 IF (isection > 0) res => section_vals%subs_vals(isection, irep)%section_vals
764 IF (.NOT. (
ASSOCIATED(res) .OR. my_can_return_null)) &
765 CALL cp_abort(__location__, &
766 "could not find subsection "//trim(subsection_name(1:my_index))//
" in section "// &
767 trim(section_vals%section%name)//
" at ")
768 IF (is_path .AND.
ASSOCIATED(res))
THEN
770 i_rep_section, can_return_null)
788 INTEGER,
INTENT(in) :: i_section
789 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
792 INTEGER :: i, irep, isect_att
794 cpassert(
ASSOCIATED(section_vals))
795 cpassert(section_vals%ref_count > 0)
798 IF (
PRESENT(i_rep_section)) irep = i_rep_section
799 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
801 DO i = 1, section_vals%section%n_subsections
802 IF (
SIZE(section_vals%subs_vals(i, irep)%section_vals%values, 2) > 0)
THEN
803 isect_att = isect_att + 1
804 IF (isect_att == i_section)
THEN
805 res => section_vals%subs_vals(i, irep)%section_vals
823 i_rep_section)
RESULT(res)
826 CHARACTER(LEN=*),
INTENT(IN) :: subsection_name
827 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
830 INTEGER :: i_section, irep
832 cpassert(section_vals%ref_count > 0)
835 IF (
PRESENT(i_rep_section)) irep = i_rep_section
836 cpassert(irep <=
SIZE(section_vals%subs_vals, 2))
838 res => section_vals%subs_vals(i_section, irep)%section_vals
853 TYPE(section_vals_p_type),
DIMENSION(:, :), &
856 cpassert(section_vals%ref_count > 0)
857 ALLOCATE (new_values(-1:ubound(section_vals%values, 1),
SIZE(section_vals%values, 2) + 1))
858 DO j = 1,
SIZE(section_vals%values, 2)
859 DO i = -1, ubound(section_vals%values, 1)
860 new_values(i, j)%list => section_vals%values(i, j)%list
863 DEALLOCATE (section_vals%values)
864 section_vals%values => new_values
865 j =
SIZE(new_values, 2)
866 DO i = -1, ubound(new_values, 1)
867 NULLIFY (new_values(i, j)%list)
870 IF (
SIZE(new_values, 2) > 1)
THEN
871 ALLOCATE (new_sps(
SIZE(section_vals%subs_vals, 1), &
872 SIZE(section_vals%subs_vals, 2) + 1))
873 DO j = 1,
SIZE(section_vals%subs_vals, 2)
874 DO i = 1,
SIZE(section_vals%subs_vals, 1)
875 new_sps(i, j)%section_vals => section_vals%subs_vals(i, j)%section_vals
878 DEALLOCATE (section_vals%subs_vals)
879 section_vals%subs_vals => new_sps
881 DO i = 1,
SIZE(new_sps, 1)
882 NULLIFY (new_sps(i, j)%section_vals)
884 section=section_vals%section%subsections(i)%section)
904 IF (
ASSOCIATED(section_vals))
THEN
905 cpassert(section_vals%ref_count > 0)
908 ALLOCATE (new_values(-1:section_vals%section%n_keywords, 0))
910 DO j = 1,
SIZE(section_vals%values, 2)
911 DO i = -1, ubound(section_vals%values, 1)
912 vals => section_vals%values(i, j)%list
919 DEALLOCATE (section_vals%values)
920 section_vals%values => new_values
931 FUNCTION section_get_cval(section_vals, keyword_name)
RESULT(res)
934 CHARACTER(len=*),
INTENT(in) :: keyword_name
935 CHARACTER(LEN=default_string_length) :: res
939 END FUNCTION section_get_cval
950 CHARACTER(len=*),
INTENT(in) :: keyword_name
963 FUNCTION section_get_rvals(section_vals, keyword_name)
RESULT(res)
966 CHARACTER(len=*),
INTENT(in) :: keyword_name
967 REAL(kind=
dp),
DIMENSION(:),
POINTER :: res
971 END FUNCTION section_get_rvals
982 CHARACTER(len=*),
INTENT(in) :: keyword_name
998 CHARACTER(len=*),
INTENT(in) :: keyword_name
999 INTEGER,
DIMENSION(:),
POINTER :: res
1014 CHARACTER(len=*),
INTENT(in) :: keyword_name
1045 i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, &
1049 CHARACTER(len=*),
INTENT(in) :: keyword_name
1050 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1051 INTEGER,
INTENT(out),
OPTIONAL :: n_rep_val
1052 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1053 LOGICAL,
INTENT(out),
OPTIONAL :: l_val
1054 INTEGER,
INTENT(out),
OPTIONAL :: i_val
1055 REAL(kind=
dp),
INTENT(out),
OPTIONAL :: r_val
1056 CHARACTER(LEN=*),
INTENT(out),
OPTIONAL :: c_val
1057 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals
1058 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals
1059 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals
1060 CHARACTER(LEN=default_string_length), &
1061 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals
1062 LOGICAL,
INTENT(out),
OPTIONAL :: explicit
1064 INTEGER :: ik, irk, irs, len_key, my_index, &
1066 LOGICAL :: valrequested
1073 cpassert(section_vals%ref_count > 0)
1075 my_index = index(keyword_name,
'%') + 1
1076 len_key = len_trim(keyword_name)
1077 IF (my_index > 1)
THEN
1079 tmp_index = index(keyword_name(my_index:len_key),
"%")
1080 IF (tmp_index <= 0)
EXIT
1081 my_index = my_index + tmp_index
1085 s_vals => section_vals
1090 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1091 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1092 IF (
PRESENT(val))
NULLIFY (val)
1093 IF (
PRESENT(explicit)) explicit = .false.
1094 section => s_vals%section
1095 valrequested =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1096 PRESENT(c_val) .OR.
PRESENT(l_vals) .OR.
PRESENT(i_vals) .OR. &
1097 PRESENT(r_vals) .OR.
PRESENT(c_vals)
1100 CALL cp_abort(__location__, &
1101 "section "//trim(section%name)//
" does not contain keyword "// &
1102 trim(keyword_name(my_index:len_key)))
1103 keyword => section%keywords(ik)%keyword
1104 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1105 CALL cp_abort(__location__, &
1106 "section repetition requested ("//
cp_to_string(irs)// &
1107 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1110 IF (
PRESENT(n_rep_val)) n_rep_val = 0
1111 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1112 vals => s_vals%values(ik, irs)%list
1114 IF (.NOT.
ASSOCIATED(vals))
THEN
1116 IF (
ASSOCIATED(keyword%default_value))
THEN
1117 my_val => keyword%default_value
1118 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1123 IF (
PRESENT(explicit)) explicit = .true.
1125 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1126 IF (
PRESENT(n_rep_val)) n_rep_val = 1
1127 my_val => keyword%default_value
1129 IF (
PRESENT(val)) val => my_val
1130 IF (valrequested)
THEN
1131 IF (.NOT.
ASSOCIATED(my_val)) &
1132 CALL cp_abort(__location__, &
1133 "Value requested, but no value set getting value from "// &
1134 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1136 CALL val_get(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1137 c_val=c_val, l_vals=l_vals, i_vals=i_vals, r_vals=r_vals, &
1158 CHARACTER(len=*),
INTENT(in) :: keyword_name
1159 INTEGER,
OPTIONAL :: i_rep_section
1162 INTEGER :: ik, irs, len_key, my_index, tmp_index
1166 cpassert(
ASSOCIATED(section_vals))
1167 cpassert(section_vals%ref_count > 0)
1169 my_index = index(keyword_name,
'%') + 1
1170 len_key = len_trim(keyword_name)
1171 IF (my_index > 1)
THEN
1173 tmp_index = index(keyword_name(my_index:len_key),
"%")
1174 IF (tmp_index <= 0)
EXIT
1175 my_index = my_index + tmp_index
1179 s_vals => section_vals
1183 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1184 section => s_vals%section
1187 CALL cp_abort(__location__, &
1188 "section "//trim(section%name)//
" does not contain keyword "// &
1189 trim(keyword_name(my_index:len_key)))
1190 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1191 CALL cp_abort(__location__, &
1192 "section repetition requested ("//
cp_to_string(irs)// &
1193 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1195 list => s_vals%values(ik, irs)%list
1222 val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
1225 CHARACTER(len=*),
INTENT(in) :: keyword_name
1226 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1227 TYPE(
val_type),
OPTIONAL,
POINTER :: val
1228 LOGICAL,
INTENT(in),
OPTIONAL :: l_val
1229 INTEGER,
INTENT(in),
OPTIONAL :: i_val
1230 REAL(kind=
dp),
INTENT(in),
OPTIONAL :: r_val
1231 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: c_val
1232 LOGICAL,
DIMENSION(:),
OPTIONAL,
POINTER :: l_vals_ptr
1233 INTEGER,
DIMENSION(:),
OPTIONAL,
POINTER :: i_vals_ptr
1234 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: r_vals_ptr
1235 CHARACTER(LEN=default_string_length), &
1236 DIMENSION(:),
OPTIONAL,
POINTER :: c_vals_ptr
1238 INTEGER :: ik, irk, irs, len_key, my_index, &
1245 TYPE(
val_type),
POINTER :: my_val, old_val
1247 cpassert(
ASSOCIATED(section_vals))
1248 cpassert(section_vals%ref_count > 0)
1250 my_index = index(keyword_name,
'%') + 1
1251 len_key = len_trim(keyword_name)
1252 IF (my_index > 1)
THEN
1254 tmp_index = index(keyword_name(my_index:len_key),
"%")
1255 IF (tmp_index <= 0)
EXIT
1256 my_index = my_index + tmp_index
1260 s_vals => section_vals
1265 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1266 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1267 section => s_vals%section
1270 CALL cp_abort(__location__, &
1271 "section "//trim(section%name)//
" does not contain keyword "// &
1272 trim(keyword_name(my_index:len_key)))
1275 IF (irs <=
SIZE(s_vals%values, 2))
EXIT
1278 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1279 CALL cp_abort(__location__, &
1280 "section repetition requested ("//
cp_to_string(irs)// &
1281 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1283 keyword => s_vals%section%keywords(ik)%keyword
1285 IF (
PRESENT(val)) my_val => val
1286 valset =
PRESENT(l_val) .OR.
PRESENT(i_val) .OR.
PRESENT(r_val) .OR. &
1287 PRESENT(c_val) .OR.
PRESENT(l_vals_ptr) .OR.
PRESENT(i_vals_ptr) .OR. &
1288 PRESENT(r_vals_ptr) .OR.
PRESENT(c_vals_ptr)
1289 IF (
ASSOCIATED(my_val))
THEN
1292 CALL cp_abort(__location__, &
1293 " both val and values present, in setting "// &
1294 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1299 CALL cp_abort(__location__, &
1300 " empty value in setting "// &
1301 "keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1304 IF (keyword%type_of_var ==
lchar_t)
THEN
1305 CALL val_create(my_val, lc_val=c_val, lc_vals_ptr=c_vals_ptr)
1307 CALL val_create(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
1308 c_val=c_val, l_vals_ptr=l_vals_ptr, i_vals_ptr=i_vals_ptr, &
1309 r_vals_ptr=r_vals_ptr, &
1310 c_vals_ptr=c_vals_ptr, enum=keyword%enum)
1312 cpassert(
ASSOCIATED(my_val))
1313 cpassert(my_val%type_of_var == keyword%type_of_var)
1315 vals => s_vals%values(ik, irs)%list
1320 CALL cp_abort(__location__, &
1322 " in keyword "//trim(keyword_name(my_index:len_key))//
" of section "// &
1329 CALL cp_abort(__location__, &
1330 "cannot add extra keyword repetitions to keyword" &
1331 //trim(keyword_name(my_index:len_key))//
" of section "// &
1336 s_vals%values(ik, irs)%list => vals
1356 CHARACTER(len=*),
INTENT(in) :: keyword_name
1357 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section, i_rep_val
1359 INTEGER :: ik, irk, irs, len_key, my_index, &
1367 cpassert(
ASSOCIATED(section_vals))
1368 cpassert(section_vals%ref_count > 0)
1370 my_index = index(keyword_name,
'%') + 1
1371 len_key = len_trim(keyword_name)
1372 IF (my_index > 1)
THEN
1374 tmp_index = index(keyword_name(my_index:len_key),
"%")
1375 IF (tmp_index <= 0)
EXIT
1376 my_index = my_index + tmp_index
1380 s_vals => section_vals
1385 IF (
PRESENT(i_rep_section)) irs = i_rep_section
1386 IF (
PRESENT(i_rep_val)) irk = i_rep_val
1387 section => s_vals%section
1390 CALL cp_abort(__location__, &
1391 "section "//trim(section%name)//
" does not contain keyword "// &
1392 trim(keyword_name(my_index:len_key)))
1394 IF (irs <=
SIZE(s_vals%values, 2))
THEN
1395 IF (.NOT. (irs > 0 .AND. irs <=
SIZE(s_vals%subs_vals, 2))) &
1396 CALL cp_abort(__location__, &
1397 "section repetition requested ("//
cp_to_string(irs)// &
1398 ") out of bounds (1:"//
cp_to_string(
SIZE(s_vals%subs_vals, 2)) &
1405 IF (
ASSOCIATED(pos))
THEN
1428 INTEGER,
INTENT(in) :: unit_nr
1429 LOGICAL,
INTENT(in),
OPTIONAL :: hide_root, hide_defaults
1431 INTEGER,
PARAMETER :: incr = 2
1433 CHARACTER(len=default_string_length) :: myfmt
1434 INTEGER :: i_rep_s, ik, isec, ival, nr, nval
1435 INTEGER,
SAVE :: indent = 1
1436 LOGICAL :: defaultsection, explicit, &
1437 my_hide_defaults, my_hide_root
1444 my_hide_root = .false.
1445 my_hide_defaults = .true.
1446 IF (
PRESENT(hide_root)) my_hide_root = hide_root
1447 IF (
PRESENT(hide_defaults)) my_hide_defaults = hide_defaults
1449 cpassert(section_vals%ref_count > 0)
1450 IF (unit_nr > 0)
THEN
1451 CALL section_vals_get(section_vals, explicit=explicit, n_repetition=nr, section=section)
1452 IF (explicit .OR. (.NOT. my_hide_defaults))
THEN
1454 IF (.NOT. my_hide_root)
THEN
1455 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1456 IF (
ASSOCIATED(section%keywords(-1)%keyword))
THEN
1457 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1460 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)") &
1464 defaultsection = (
SIZE(section_vals%values, 2) == 0)
1465 IF (.NOT. defaultsection)
THEN
1466 IF (.NOT. my_hide_root) indent = indent + incr
1467 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1468 DO ik = -1, section%n_keywords
1469 keyword => section%keywords(ik)%keyword
1470 IF (
ASSOCIATED(keyword))
THEN
1471 IF (keyword%type_of_var /=
no_t .AND. keyword%names(1) (1:2) /=
"__")
THEN
1473 i_rep_s, n_rep_val=nval)
1474 IF (i_rep_s <=
SIZE(section_vals%values, 2))
THEN
1476 vals => section_vals%values(ik, i_rep_s)%list
1481 new_pos => new_pos%rest
1483 IF (.NOT.
ASSOCIATED(new_pos))
THEN
1485 IF (
ASSOCIATED(keyword%default_value))
THEN
1486 val => keyword%default_value
1487 IF (my_hide_defaults) cycle
1490 val => new_pos%first_el
1492 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1493 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1494 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1495 trim(keyword%names(1))
1496 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1497 keyword%type_of_var /=
lchar_t)
THEN
1498 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
")", advance=
"NO")
1500 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1502 ELSE IF (
ASSOCIATED(keyword%default_value))
THEN
1504 IF (my_hide_defaults) cycle
1505 val => keyword%default_value
1506 IF (keyword%names(1) /=
'_DEFAULT_KEYWORD_' .AND. &
1507 keyword%names(1) /=
'_SECTION_PARAMETERS_')
THEN
1508 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)", advance=
"NO") &
1509 trim(keyword%names(1))
1510 ELSE IF (keyword%names(1) ==
'_DEFAULT_KEYWORD_' .AND. &
1511 keyword%type_of_var /=
lchar_t)
THEN
1512 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
")", advance=
"NO")
1514 CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, fmt=myfmt)
1519 IF (
ASSOCIATED(section_vals%subs_vals))
THEN
1520 DO isec = 1,
SIZE(section_vals%subs_vals, 1)
1521 sval => section_vals%subs_vals(isec, i_rep_s)%section_vals
1522 IF (
ASSOCIATED(sval))
THEN
1528 IF (.NOT. my_hide_root)
THEN
1529 indent = indent - incr
1530 WRITE (unit=myfmt, fmt=
"(I0,A1)") indent,
"X"
1531 WRITE (unit=unit_nr, fmt=
"("//trim(myfmt)//
",A)") &
1549 INTEGER,
INTENT(IN) :: level, unit_number
1551 CHARACTER(LEN=3) :: repeats
1552 CHARACTER(LEN=8) :: short_string
1553 INTEGER :: i, l0, l1, l2
1555 IF (
ASSOCIATED(section))
THEN
1557 cpassert(section%ref_count > 0)
1565 IF (section%repeats)
THEN
1571 WRITE (unit=unit_number, fmt=
"(A)") &
1572 repeat(
" ", l0)//
"<SECTION repeats="""//trim(repeats)//
""">", &
1573 repeat(
" ", l1)//
"<NAME>"//trim(section%name)//
"</NAME>", &
1574 repeat(
" ", l1)//
"<DESCRIPTION>"// &
1578 IF (
ALLOCATED(section%deprecation_notice)) &
1579 WRITE (unit=unit_number, fmt=
"(A)") repeat(
" ", l1)//
"<DEPRECATION_NOTICE>"// &
1581 //
"</DEPRECATION_NOTICE>"
1583 IF (
ASSOCIATED(section%citations))
THEN
1584 DO i = 1,
SIZE(section%citations, 1)
1586 WRITE (unit=short_string, fmt=
"(I8)") section%citations(i)
1587 WRITE (unit=unit_number, fmt=
"(A)") &
1588 repeat(
" ", l1)//
"<REFERENCE>", &
1589 repeat(
" ", l2)//
"<NAME>"//trim(
get_citation_key(section%citations(i)))//
"</NAME>", &
1590 repeat(
" ", l2)//
"<NUMBER>"//trim(adjustl(short_string))//
"</NUMBER>", &
1591 repeat(
" ", l1)//
"</REFERENCE>"
1595 WRITE (unit=unit_number, fmt=
"(A)") &
1596 repeat(
" ", l1)//
"<LOCATION>"//trim(section%location)//
"</LOCATION>"
1598 DO i = -1, section%n_keywords
1599 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1604 DO i = 1, section%n_subsections
1608 WRITE (unit=unit_number, fmt=
"(A)") repeat(
" ", l0)//
"</SECTION>"
1625 matching_rank, matching_string, bonus)
1628 CHARACTER(LEN=*) :: section_name, unknown_string, &
1630 INTEGER,
DIMENSION(:),
INTENT(INOUT) :: matching_rank
1631 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(INOUT) :: matching_string
1632 INTEGER,
INTENT(IN) :: bonus
1634 CHARACTER(LEN=LEN(matching_string(1))) :: line
1635 INTEGER :: i, imatch,
imax, irank, newbonus
1637 IF (
ASSOCIATED(section))
THEN
1638 cpassert(section%ref_count > 0)
1639 imatch =
typo_match(trim(section%name), trim(unknown_string))
1640 IF (imatch > 0)
THEN
1641 imatch = imatch + bonus
1642 WRITE (unit=line, fmt=
'(T2,A)') &
1643 " subsection "//trim(adjustl(section%name))// &
1644 " in section "//trim(adjustl(location_string))
1645 imax =
SIZE(matching_rank, 1)
1648 IF (imatch > matching_rank(i)) irank = i
1650 IF (irank <=
imax)
THEN
1651 matching_rank(irank + 1:
imax) = matching_rank(irank:
imax - 1)
1652 matching_string(irank + 1:
imax) = matching_string(irank:
imax - 1)
1653 matching_rank(irank) = imatch
1654 matching_string(irank) = line
1658 IF (section_name == section%name)
THEN
1664 DO i = -1, section%n_keywords
1665 IF (
ASSOCIATED(section%keywords(i)%keyword))
THEN
1666 CALL keyword_typo_match(section%keywords(i)%keyword, unknown_string, location_string// &
1667 "%"//trim(section%name), matching_rank, matching_string, newbonus)
1671 DO i = 1, section%n_subsections
1672 CALL section_typo_match(section%subsections(i)%section, section_name, unknown_string, &
1673 location_string//
"%"//trim(section%name), matching_rank, matching_string, newbonus)
1690 new_section_vals, i_rep_section)
1692 CHARACTER(len=*),
INTENT(in) :: subsection_name
1694 INTEGER,
INTENT(in),
OPTIONAL :: i_rep_section
1696 INTEGER :: irep, isection, len_key, my_index, &
1700 cpassert(
ASSOCIATED(section_vals))
1701 cpassert(section_vals%ref_count > 0)
1702 cpassert(
ASSOCIATED(new_section_vals))
1703 cpassert(new_section_vals%ref_count > 0)
1706 IF (
PRESENT(i_rep_section)) irep = i_rep_section
1708 my_index = index(subsection_name,
'%') + 1
1709 len_key = len_trim(subsection_name)
1710 IF (my_index > 1)
THEN
1712 tmp_index = index(subsection_name(my_index:len_key),
"%")
1713 IF (tmp_index <= 0)
EXIT
1714 my_index = my_index + tmp_index
1718 s_vals => section_vals
1721 cpassert(irep <=
SIZE(s_vals%subs_vals, 2))
1724 IF (isection <= 0) &
1725 CALL cp_abort(__location__, &
1726 "could not find subsection "//subsection_name(my_index:len_trim(subsection_name))//
" in section "// &
1727 trim(section_vals%section%name)//
" at ")
1730 s_vals%subs_vals(isection, irep)%section_vals => new_section_vals
1743 i_rep_start, i_rep_end)
1745 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_start, i_rep_end
1747 cpassert(
ASSOCIATED(section_vals_in))
1748 cpassert(.NOT.
ASSOCIATED(section_vals_out))
1750 CALL section_vals_copy(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
1763 RECURSIVE SUBROUTINE section_vals_copy(section_vals_in, section_vals_out, &
1764 i_rep_low, i_rep_high)
1766 INTEGER,
INTENT(IN),
OPTIONAL :: i_rep_low, i_rep_high
1768 INTEGER :: iend, irep, isec, istart, ival
1774 cpassert(
ASSOCIATED(section_vals_in))
1775 cpassert(
ASSOCIATED(section_vals_out))
1780 iend =
SIZE(section_vals_in%values, 2)
1781 IF (
PRESENT(i_rep_low)) istart = i_rep_low
1782 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1783 DO irep = istart, iend
1785 DO ival = lbound(section_vals_in%values, 1), ubound(section_vals_in%values, 1)
1786 v1 => section_vals_in%values(ival, irep)%list
1787 IF (
ASSOCIATED(v1))
THEN
1791 section_vals_out%values(ival, irep - istart + 1)%list => v2
1793 IF (.NOT.
ASSOCIATED(v1%rest))
EXIT
1803 IF (.NOT.
PRESENT(i_rep_low) .AND. (.NOT.
PRESENT(i_rep_high)))
THEN
1804 IF (.NOT. (
SIZE(section_vals_in%values, 2) ==
SIZE(section_vals_out%values, 2))) &
1806 IF (.NOT. (
SIZE(section_vals_in%subs_vals, 2) ==
SIZE(section_vals_out%subs_vals, 2))) &
1809 iend =
SIZE(section_vals_in%subs_vals, 2)
1810 IF (
PRESENT(i_rep_high)) iend = i_rep_high
1811 DO irep = istart, iend
1812 DO isec = 1,
SIZE(section_vals_in%subs_vals, 1)
1813 CALL section_vals_copy(section_vals_in%subs_vals(isec, irep)%section_vals, &
1814 section_vals_out%subs_vals(isec, irep - istart + 1)%section_vals)
1818 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.