LCOV - code coverage report
Current view: top level - src/input - input_section_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b1c14e6) Lines: 569 680 83.7 %
Date: 2022-07-02 11:36:49 Functions: 32 40 80.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2022 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief objects that represent the structure of input sections and the data
      10             : !>      contained in an input section
      11             : !> \par History
      12             : !>      06.2004 created [fawzi]
      13             : !> \author fawzi
      14             : ! **************************************************************************************************
      15             : MODULE input_section_types
      16             :    USE cp_linked_list_input,            ONLY: &
      17             :         cp_sll_val_create, cp_sll_val_dealloc, cp_sll_val_get_el_at, cp_sll_val_get_length, &
      18             :         cp_sll_val_get_rest, cp_sll_val_insert_el_at, cp_sll_val_next, cp_sll_val_p_type, &
      19             :         cp_sll_val_rm_el_at, cp_sll_val_set_el_at, cp_sll_val_type
      20             :    USE cp_log_handling,                 ONLY: cp_to_string
      21             :    USE input_keyword_types,             ONLY: keyword_describe,&
      22             :                                               keyword_p_type,&
      23             :                                               keyword_release,&
      24             :                                               keyword_retain,&
      25             :                                               keyword_type,&
      26             :                                               keyword_typo_match,&
      27             :                                               write_keyword_xml
      28             :    USE input_val_types,                 ONLY: lchar_t,&
      29             :                                               no_t,&
      30             :                                               val_create,&
      31             :                                               val_duplicate,&
      32             :                                               val_get,&
      33             :                                               val_release,&
      34             :                                               val_type,&
      35             :                                               val_write
      36             :    USE kinds,                           ONLY: default_path_length,&
      37             :                                               default_string_length,&
      38             :                                               dp
      39             :    USE print_messages,                  ONLY: print_message
      40             :    USE reference_manager,               ONLY: get_citation_key
      41             :    USE string_utilities,                ONLY: a2s,&
      42             :                                               compress,&
      43             :                                               substitute_special_xml_tokens,&
      44             :                                               typo_match,&
      45             :                                               uppercase
      46             : #include "../base/base_uses.f90"
      47             : 
      48             :    IMPLICIT NONE
      49             :    PRIVATE
      50             : 
      51             :    INTEGER, SAVE, PRIVATE :: last_section_id = 0, last_section_vals_id = 0
      52             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      53             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_section_types'
      54             : 
      55             :    PUBLIC :: section_type
      56             :    PUBLIC :: section_create, section_release, section_describe, &
      57             :              section_get_subsection, section_get_keyword, &
      58             :              section_add_keyword, section_add_subsection
      59             :    PUBLIC :: section_get_subsection_index, section_get_keyword_index
      60             : 
      61             :    PUBLIC :: section_vals_type
      62             :    PUBLIC :: section_vals_create, section_vals_retain, section_vals_release, &
      63             :              section_vals_get, section_vals_get_subs_vals, section_vals_val_get, section_vals_list_get, &
      64             :              section_vals_write, section_vals_add_values, section_vals_get_subs_vals2, &
      65             :              section_vals_val_set, section_vals_val_unset, section_vals_get_subs_vals3, &
      66             :              section_vals_set_subs_vals, section_vals_duplicate, section_vals_remove_values
      67             :    PUBLIC :: write_section_xml
      68             : 
      69             :    PUBLIC :: section_get_ival, &
      70             :              section_get_ivals, &
      71             :              section_get_rval, &
      72             :              section_get_lval
      73             :    PUBLIC :: section_typo_match, typo_match_section, typo_matching_rank, typo_matching_line
      74             : 
      75             : ! **************************************************************************************************
      76             : !> \brief represent a pointer to a section (to make arrays of pointers)
      77             : !> \param section the pointer to the section
      78             : !> \author fawzi
      79             : ! **************************************************************************************************
      80             :    TYPE section_p_type
      81             :       TYPE(section_type), POINTER :: section
      82             :    END TYPE section_p_type
      83             : 
      84             : ! **************************************************************************************************
      85             : !> \brief represent a section of the input file
      86             : !> \note
      87             : !>      - frozen: if the section has been frozen (and no keyword/subsections
      88             : !>        can be added)
      89             : !>      - repeats: if the section can be repeated more than once in the same
      90             : !>        context
      91             : !>      - id_nr: identification number (different in each instance)
      92             : !>      - ref_count: reference count (see doc/ReferenceCounting.html)
      93             : !>      - n_keywords: the number of keywords in this section
      94             : !>      - name: name of the section
      95             : !>      - location where in the source code (file and line) the section is created
      96             : !>      - description: description of the section
      97             : !>      - citations: references to literature associated to this section
      98             : !>      - keywords: array with the keywords of this section (might be
      99             : !>        oversized)
     100             : !>      - subsections: sections contained in this section
     101             : !> \author fawzi
     102             : ! **************************************************************************************************
     103             :    TYPE section_type
     104             :       LOGICAL :: frozen, repeats
     105             :       INTEGER :: id_nr, ref_count, n_keywords, n_subsections
     106             :       CHARACTER(len=default_string_length)        :: name
     107             :       CHARACTER(len=default_string_length)        :: location
     108             :       CHARACTER, DIMENSION(:), POINTER              :: description => Null()
     109             :       INTEGER, POINTER, DIMENSION(:)              :: citations
     110             :       TYPE(keyword_p_type), DIMENSION(:), POINTER :: keywords
     111             :       TYPE(section_p_type), POINTER, DIMENSION(:) :: subsections
     112             :    END TYPE section_type
     113             : 
     114             : ! **************************************************************************************************
     115             : !> \brief repesents a pointer to a parsed section (to make arrays of pointers)
     116             : !> \param section_vals the pointer to the parsed section
     117             : !> \author fawzi
     118             : ! **************************************************************************************************
     119             :    TYPE section_vals_p_type
     120             :       TYPE(section_vals_type), POINTER :: section_vals
     121             :    END TYPE section_vals_p_type
     122             : 
     123             : ! **************************************************************************************************
     124             : !> \brief stores the values of a section
     125             : !> \author fawzi
     126             : ! **************************************************************************************************
     127             :    TYPE section_vals_type
     128             :       INTEGER :: ref_count, id_nr
     129             :       INTEGER, POINTER, DIMENSION(:)                     :: ibackup
     130             :       TYPE(section_type), POINTER                         :: section
     131             :       TYPE(cp_sll_val_p_type), DIMENSION(:, :), POINTER   :: values
     132             :       TYPE(section_vals_p_type), DIMENSION(:, :), POINTER :: subs_vals
     133             :    END TYPE section_vals_type
     134             : 
     135             :    TYPE(section_type), POINTER, SAVE                                :: typo_match_section => NULL()
     136             :    INTEGER, PARAMETER                                               :: n_typo_matches = 5
     137             :    INTEGER, DIMENSION(n_typo_matches)                               :: typo_matching_rank = 0
     138             :    CHARACTER(LEN=default_string_length*5), DIMENSION(n_typo_matches):: typo_matching_line = ""
     139             : 
     140             : CONTAINS
     141             : 
     142             : ! **************************************************************************************************
     143             : !> \brief creates a list of keywords
     144             : !> \param section the list to be created
     145             : !> \param location from where in the source code section_create() is called
     146             : !> \param name ...
     147             : !> \param description ...
     148             : !> \param n_keywords hint about the number of keywords, defaults to 10
     149             : !> \param n_subsections a hint about how many sections will be added to this
     150             : !>        structure, defaults to 0
     151             : !> \param repeats if this section can repeat (defaults to false)
     152             : !> \param citations ...
     153             : !> \author fawzi
     154             : ! **************************************************************************************************
     155    62579545 :    SUBROUTINE section_create(section, location, name, description, n_keywords, &
     156     3778371 :                              n_subsections, repeats, citations)
     157             :       TYPE(section_type), POINTER                        :: section
     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
     162             : 
     163             :       INTEGER                                            :: i, my_n_keywords, my_n_subsections, n
     164             : 
     165    62579545 :       CPASSERT(.NOT. ASSOCIATED(section))
     166    62579545 :       my_n_keywords = 10
     167    62579545 :       IF (PRESENT(n_keywords)) my_n_keywords = n_keywords
     168    62579545 :       my_n_subsections = 0
     169    62579545 :       IF (PRESENT(n_subsections)) my_n_subsections = n_subsections
     170             : 
     171    62579545 :       ALLOCATE (section)
     172    62579545 :       last_section_id = last_section_id + 1
     173    62579545 :       section%id_nr = last_section_id
     174    62579545 :       section%ref_count = 1
     175             : 
     176    62579545 :       section%n_keywords = 0
     177    62579545 :       section%n_subsections = 0
     178    62579545 :       section%location = location
     179    62579545 :       section%name = name
     180    62579545 :       CALL uppercase(section%name)
     181             : 
     182    62579545 :       n = LEN_TRIM(description)
     183   187632741 :       ALLOCATE (section%description(n))
     184  5907584228 :       DO i = 1, n
     185  5907584228 :          section%description(i) = description(i:i)
     186             :       END DO
     187             : 
     188    62579545 :       section%frozen = .FALSE.
     189    62579545 :       section%repeats = .FALSE.
     190    62579545 :       IF (PRESENT(repeats)) section%repeats = repeats
     191             : 
     192    62579545 :       NULLIFY (section%citations)
     193    62579545 :       IF (PRESENT(citations)) THEN
     194    11335113 :          ALLOCATE (section%citations(SIZE(citations)))
     195    10599875 :          section%citations = citations
     196             :       END IF
     197             : 
     198   187738635 :       ALLOCATE (section%keywords(-1:my_n_keywords))
     199   501221823 :       DO i = -1, my_n_keywords
     200   501221823 :          NULLIFY (section%keywords(i)%keyword)
     201             :       END DO
     202             : 
     203   128370356 :       ALLOCATE (section%subsections(my_n_subsections))
     204    68338779 :       DO i = 1, my_n_subsections
     205    68338779 :          NULLIFY (section%subsections(i)%section)
     206             :       END DO
     207    62579545 :    END SUBROUTINE section_create
     208             : 
     209             : ! **************************************************************************************************
     210             : !> \brief retains the given keyword list (see doc/ReferenceCounting.html)
     211             : !> \param section the list to retain
     212             : !> \author fawzi
     213             : ! **************************************************************************************************
     214   134902059 :    SUBROUTINE section_retain(section)
     215             :       TYPE(section_type), POINTER                        :: section
     216             : 
     217   134902059 :       CPASSERT(ASSOCIATED(section))
     218   134902059 :       CPASSERT(section%ref_count > 0)
     219   134902059 :       section%ref_count = section%ref_count + 1
     220   134902059 :    END SUBROUTINE section_retain
     221             : 
     222             : ! **************************************************************************************************
     223             : !> \brief releases the given keyword list (see doc/ReferenceCounting.html)
     224             : !> \param section the list to release
     225             : !> \author fawzi
     226             : ! **************************************************************************************************
     227   279241778 :    RECURSIVE SUBROUTINE section_release(section)
     228             :       TYPE(section_type), POINTER                        :: section
     229             : 
     230             :       INTEGER                                            :: i
     231             : 
     232   279241778 :       IF (ASSOCIATED(section)) THEN
     233   197481604 :          CPASSERT(section%ref_count > 0)
     234   197481604 :          section%ref_count = section%ref_count - 1
     235   197481604 :          IF (section%ref_count == 0) THEN
     236    62579545 :             IF (ASSOCIATED(section%citations)) THEN
     237     3778371 :                DEALLOCATE (section%citations)
     238             :             END IF
     239    62579545 :             IF (ASSOCIATED(section%keywords)) THEN
     240   813299318 :                DO i = -1, UBOUND(section%keywords, 1)
     241   750719773 :                   CALL keyword_release(section%keywords(i)%keyword)
     242             :                END DO
     243    62579545 :                DEALLOCATE (section%keywords)
     244             :             END IF
     245    62579545 :             section%n_keywords = 0
     246    62579545 :             IF (ASSOCIATED(section%subsections)) THEN
     247   206854409 :                DO i = 1, SIZE(section%subsections)
     248   206854409 :                   CALL section_release(section%subsections(i)%section)
     249             :                END DO
     250    62579545 :                DEALLOCATE (section%subsections)
     251             :             END IF
     252    62579545 :             DEALLOCATE (section%description)
     253    62579545 :             DEALLOCATE (section)
     254             :          END IF
     255   197481604 :          NULLIFY (section)
     256             :       END IF
     257   279241778 :    END SUBROUTINE section_release
     258             : 
     259             : ! **************************************************************************************************
     260             : !> \brief collects additional information on the section for IO + documentation
     261             : !> \param section ...
     262             : !> \return ...
     263             : !> \author fawzi
     264             : ! **************************************************************************************************
     265           1 :    FUNCTION get_section_info(section) RESULT(message)
     266             :       TYPE(section_type), INTENT(IN)                     :: section
     267             :       CHARACTER(LEN=default_path_length)                 :: message
     268             : 
     269             :       INTEGER                                            :: length
     270             : 
     271           1 :       message = " "
     272           1 :       length = LEN_TRIM(a2s(section%description))
     273           1 :       IF (length > 0) THEN
     274           1 :          IF (section%description(length) /= ".") THEN
     275           0 :             message = "."
     276             :          END IF
     277             :       END IF
     278           1 :       IF (section%repeats) THEN
     279           0 :          message = TRIM(message)//" This section can be repeated."
     280             :       ELSE
     281           1 :          message = TRIM(message)//" This section can not be repeated."
     282             :       END IF
     283             : 
     284           1 :    END FUNCTION get_section_info
     285             : 
     286             : ! **************************************************************************************************
     287             : !> \brief prints a description of the given section
     288             : !> \param section the section to describe
     289             : !> \param unit_nr the unit to write to
     290             : !> \param level the level of output: 0: just section name, 1:keywords,
     291             : !>        then see keyword_describe :-)
     292             : !> \param hide_root if the name of the first section should be hidden
     293             : !>        (defaults to false).
     294             : !> \param recurse ...
     295             : !> \author fawzi
     296             : ! **************************************************************************************************
     297           2 :    RECURSIVE SUBROUTINE section_describe(section, unit_nr, level, hide_root, recurse)
     298             :       TYPE(section_type), INTENT(IN), POINTER            :: section
     299             :       INTEGER, INTENT(in)                                :: unit_nr, level
     300             :       LOGICAL, INTENT(in), OPTIONAL                      :: hide_root
     301             :       INTEGER, INTENT(in), OPTIONAL                      :: recurse
     302             : 
     303             :       CHARACTER(LEN=default_path_length)                 :: message
     304             :       INTEGER                                            :: ikeyword, isub, my_recurse
     305             :       LOGICAL                                            :: my_hide_root
     306             : 
     307           2 :       IF (unit_nr > 0) THEN
     308           1 :          my_hide_root = .FALSE.
     309           1 :          IF (PRESENT(hide_root)) my_hide_root = hide_root
     310           1 :          my_recurse = 0
     311           1 :          IF (PRESENT(recurse)) my_recurse = recurse
     312           1 :          IF (ASSOCIATED(section)) THEN
     313           1 :             CPASSERT(section%ref_count > 0)
     314             : 
     315           1 :             IF (.NOT. my_hide_root) &
     316           1 :                WRITE (unit_nr, "('*** section &',a,' ***')") TRIM(section%name)
     317           1 :             IF (level > 1) THEN
     318           1 :                message = get_section_info(section)
     319           1 :                CALL print_message(TRIM(a2s(section%description))//TRIM(message), unit_nr, 0, 0, 0)
     320             :             END IF
     321           1 :             IF (level > 0) THEN
     322           1 :                IF (ASSOCIATED(section%keywords(-1)%keyword)) THEN
     323             :                   CALL keyword_describe(section%keywords(-1)%keyword, unit_nr, &
     324           0 :                                         level)
     325             :                END IF
     326           1 :                IF (ASSOCIATED(section%keywords(0)%keyword)) THEN
     327             :                   CALL keyword_describe(section%keywords(0)%keyword, unit_nr, &
     328           0 :                                         level)
     329             :                END IF
     330          20 :                DO ikeyword = 1, section%n_keywords
     331             :                   CALL keyword_describe(section%keywords(ikeyword)%keyword, unit_nr, &
     332          20 :                                         level)
     333             :                END DO
     334             :             END IF
     335           1 :             IF (section%n_subsections > 0 .AND. my_recurse >= 0) THEN
     336           1 :                IF (.NOT. my_hide_root) &
     337           1 :                   WRITE (unit_nr, "('** subsections **')")
     338          15 :                DO isub = 1, section%n_subsections
     339          15 :                   IF (my_recurse > 0) THEN
     340             :                      CALL section_describe(section%subsections(isub)%section, unit_nr, &
     341           0 :                                            level, recurse=my_recurse - 1)
     342             :                   ELSE
     343          14 :                      WRITE (unit_nr, "(' ',a)") section%subsections(isub)%section%name
     344             :                   END IF
     345             :                END DO
     346             :             END IF
     347           1 :             IF (.NOT. my_hide_root) &
     348           1 :                WRITE (unit_nr, "('*** &end section ',a,' ***')") TRIM(section%name)
     349             :          ELSE
     350           0 :             WRITE (unit_nr, "(a)") '<section *null*>'
     351             :          END IF
     352             :       END IF
     353           2 :    END SUBROUTINE section_describe
     354             : 
     355             : ! **************************************************************************************************
     356             : !> \brief returns the index of requested subsection (-1 if not found)
     357             : !> \param section the root section
     358             : !> \param subsection_name the name of the subsection you want to get
     359             : !> \return ...
     360             : !> \author fawzi
     361             : !> \note
     362             : !>      private utility function
     363             : ! **************************************************************************************************
     364    32230534 :    FUNCTION section_get_subsection_index(section, subsection_name) RESULT(res)
     365             :       TYPE(section_type), INTENT(IN)                     :: section
     366             :       CHARACTER(len=*), INTENT(IN)                       :: subsection_name
     367             :       INTEGER                                            :: res
     368             : 
     369             :       CHARACTER(len=default_string_length)               :: upc_name
     370             :       INTEGER                                            :: isub
     371             : 
     372           0 :       CPASSERT(section%ref_count > 0)
     373    32230534 :       res = -1
     374    32230534 :       upc_name = subsection_name
     375    32230534 :       CALL uppercase(upc_name)
     376   250446302 :       DO isub = 1, section%n_subsections
     377   250446194 :          CPASSERT(ASSOCIATED(section%subsections(isub)%section))
     378   250446302 :          IF (section%subsections(isub)%section%name == upc_name) THEN
     379             :             res = isub
     380             :             EXIT
     381             :          END IF
     382             :       END DO
     383    32230534 :    END FUNCTION section_get_subsection_index
     384             : 
     385             : ! **************************************************************************************************
     386             : !> \brief returns the requested subsection
     387             : !> \param section the root section
     388             : !> \param subsection_name the name of the subsection you want to get
     389             : !> \return ...
     390             : !> \author fawzi
     391             : ! **************************************************************************************************
     392         164 :    FUNCTION section_get_subsection(section, subsection_name) RESULT(res)
     393             :       TYPE(section_type), INTENT(IN)                     :: section
     394             :       CHARACTER(len=*), INTENT(IN)                       :: subsection_name
     395             :       TYPE(section_type), POINTER                        :: res
     396             : 
     397             :       INTEGER                                            :: isub
     398             : 
     399         164 :       isub = section_get_subsection_index(section, subsection_name)
     400         164 :       IF (isub > 0) THEN
     401         164 :          res => section%subsections(isub)%section
     402             :       ELSE
     403             :          NULLIFY (res)
     404             :       END IF
     405         164 :    END FUNCTION section_get_subsection
     406             : 
     407             : ! **************************************************************************************************
     408             : !> \brief returns the index of the requested keyword (or -2 if not found)
     409             : !> \param section the section the keyword is in
     410             : !> \param keyword_name the keyword you are interested in
     411             : !> \return ...
     412             : !> \author fawzi
     413             : !> \note
     414             : !>      private utility function
     415             : ! **************************************************************************************************
     416    41441121 :    FUNCTION section_get_keyword_index(section, keyword_name) RESULT(res)
     417             :       TYPE(section_type), INTENT(IN)                     :: section
     418             :       CHARACTER(len=*), INTENT(IN)                       :: keyword_name
     419             :       INTEGER                                            :: res
     420             : 
     421             :       INTEGER                                            :: ik, in
     422             :       CHARACTER(len=default_string_length)               :: upc_name
     423             : 
     424           0 :       CPASSERT(section%ref_count > 0)
     425    41441121 :       CPASSERT(ASSOCIATED(section%keywords))
     426    41441121 :       res = -2
     427    41441121 :       upc_name = keyword_name
     428    41441121 :       CALL uppercase(upc_name)
     429   124323363 :       DO ik = -1, 0
     430   124323363 :          IF (ASSOCIATED(section%keywords(ik)%keyword)) THEN
     431    22287616 :             IF (section%keywords(ik)%keyword%names(1) == upc_name) THEN
     432     7433849 :                res = ik
     433             :             END IF
     434             :          END IF
     435             :       END DO
     436    41441121 :       IF (res == -2) THEN
     437   147038391 :          k_search_loop: DO ik = 1, section%n_keywords
     438   146758217 :             CPASSERT(ASSOCIATED(section%keywords(ik)%keyword))
     439   274797937 :             DO in = 1, SIZE(section%keywords(ik)%keyword%names)
     440   274517763 :                IF (section%keywords(ik)%keyword%names(in) == upc_name) THEN
     441             :                   res = ik
     442             :                   EXIT k_search_loop
     443             :                END IF
     444             :             END DO
     445             :          END DO k_search_loop
     446             :       END IF
     447    41441121 :    END FUNCTION section_get_keyword_index
     448             : 
     449             : ! **************************************************************************************************
     450             : !> \brief returns the requested keyword
     451             : !> \param section the section the keyword is in
     452             : !> \param keyword_name the keyword you are interested in
     453             : !> \return ...
     454             : !> \author fawzi
     455             : ! **************************************************************************************************
     456       46711 :    RECURSIVE FUNCTION section_get_keyword(section, keyword_name) RESULT(res)
     457             :       TYPE(section_type), INTENT(IN)                     :: section
     458             :       CHARACTER(len=*), INTENT(IN)                       :: keyword_name
     459             :       TYPE(keyword_type), POINTER                        :: res
     460             : 
     461             :       INTEGER                                            :: ik, my_index
     462             : 
     463       46711 :       IF (INDEX(keyword_name, "%") /= 0) THEN
     464        1704 :          my_index = INDEX(keyword_name, "%") + 1
     465        1704 :          CPASSERT(ASSOCIATED(section%subsections))
     466       11559 :          DO ik = LBOUND(section%subsections, 1), UBOUND(section%subsections, 1)
     467        8151 :             IF (section%subsections(ik)%section%name == keyword_name(1:my_index - 2)) EXIT
     468             :          END DO
     469        1704 :          CPASSERT(ik <= UBOUND(section%subsections, 1))
     470        1704 :          res => section_get_keyword(section%subsections(ik)%section, keyword_name(my_index:))
     471             :       ELSE
     472       45007 :          ik = section_get_keyword_index(section, keyword_name)
     473       45007 :          IF (ik == -2) THEN
     474             :             NULLIFY (res)
     475             :          ELSE
     476       45007 :             res => section%keywords(ik)%keyword
     477             :          END IF
     478             :       END IF
     479       46711 :    END FUNCTION section_get_keyword
     480             : 
     481             : ! **************************************************************************************************
     482             : !> \brief adds a keyword to the given section
     483             : !> \param section the section to which the keyword should be added
     484             : !> \param keyword the keyword to add
     485             : !> \author fawzi
     486             : ! **************************************************************************************************
     487   458895277 :    SUBROUTINE section_add_keyword(section, keyword)
     488             :       TYPE(section_type), INTENT(INOUT)                  :: section
     489             :       TYPE(keyword_type), INTENT(IN), POINTER            :: keyword
     490             : 
     491             :       INTEGER                                            :: i, j, k
     492   458895277 :       TYPE(keyword_p_type), DIMENSION(:), POINTER        :: new_keywords
     493             : 
     494           0 :       CPASSERT(section%ref_count > 0)
     495   458895277 :       CPASSERT(.NOT. section%frozen)
     496   458895277 :       CPASSERT(ASSOCIATED(keyword))
     497   458895277 :       CPASSERT(keyword%ref_count > 0)
     498   458895277 :       CALL keyword_retain(keyword)
     499   458895277 :       IF (keyword%names(1) == "_SECTION_PARAMETERS_") THEN
     500    46251110 :          CALL keyword_release(section%keywords(-1)%keyword)
     501    46251110 :          section%keywords(-1)%keyword => keyword
     502   412644167 :       ELSE IF (keyword%names(1) == "_DEFAULT_KEYWORD_") THEN
     503     1757324 :          CALL keyword_release(section%keywords(0)%keyword)
     504     1757324 :          section%keywords(0)%keyword => keyword
     505             :       ELSE
     506   830057153 :          DO k = 1, SIZE(keyword%names)
     507  3698860619 :             DO i = 1, section%n_keywords
     508  6208107408 :                DO j = 1, SIZE(section%keywords(i)%keyword%names)
     509  5788937098 :                   IF (keyword%names(k) == section%keywords(i)%keyword%names(j)) THEN
     510             :                      CALL cp_abort(__LOCATION__, &
     511             :                                    "trying to add a keyword with a name ("// &
     512             :                                    TRIM(keyword%names(k))//") that was already used in section " &
     513           0 :                                    //TRIM(section%name))
     514             :                   END IF
     515             :                END DO
     516             :             END DO
     517             :          END DO
     518             : 
     519   821773686 :          IF (UBOUND(section%keywords, 1) == section%n_keywords) THEN
     520    74849385 :             ALLOCATE (new_keywords(-1:section%n_keywords + 10))
     521   195437586 :             DO i = -1, section%n_keywords
     522   195437586 :                new_keywords(i)%keyword => section%keywords(i)%keyword
     523             :             END DO
     524   299397540 :             DO i = section%n_keywords + 1, UBOUND(new_keywords, 1)
     525   274447745 :                NULLIFY (new_keywords(i)%keyword)
     526             :             END DO
     527    24949795 :             DEALLOCATE (section%keywords)
     528    24949795 :             section%keywords => new_keywords
     529             :          END IF
     530   410886843 :          section%n_keywords = section%n_keywords + 1
     531   410886843 :          section%keywords(section%n_keywords)%keyword => keyword
     532             :       END IF
     533   458895277 :    END SUBROUTINE section_add_keyword
     534             : 
     535             : ! **************************************************************************************************
     536             : !> \brief adds a subsection to the given section
     537             : !> \param section to section to which you want to add a subsection
     538             : !> \param subsection the subsection to add
     539             : !> \author fawzi
     540             : ! **************************************************************************************************
     541    62540807 :    SUBROUTINE section_add_subsection(section, subsection)
     542             :       TYPE(section_type), INTENT(INOUT)                  :: section
     543             :       TYPE(section_type), INTENT(IN), POINTER            :: subsection
     544             : 
     545             :       INTEGER                                            :: i
     546    62540807 :       TYPE(section_p_type), DIMENSION(:), POINTER        :: new_subsections
     547             : 
     548           0 :       CPASSERT(section%ref_count > 0)
     549    62540807 :       CPASSERT(ASSOCIATED(subsection))
     550    62540807 :       CPASSERT(subsection%ref_count > 0)
     551    62540807 :       IF (SIZE(section%subsections) < section%n_subsections + 1) THEN
     552    41554689 :          ALLOCATE (new_subsections(section%n_subsections + 10))
     553  1263237534 :          DO i = 1, section%n_subsections
     554  1263237534 :             new_subsections(i)%section => section%subsections(i)%section
     555             :          END DO
     556   152367193 :          DO i = section%n_subsections + 1, SIZE(new_subsections)
     557   152367193 :             NULLIFY (new_subsections(i)%section)
     558             :          END DO
     559    13851563 :          DEALLOCATE (section%subsections)
     560    13851563 :          section%subsections => new_subsections
     561             :       END IF
     562 12662923636 :       DO i = 1, section%n_subsections
     563 12600382829 :          IF (subsection%name == section%subsections(i)%section%name) &
     564             :             CALL cp_abort(__LOCATION__, &
     565             :                           "trying to add a subsection with a name ("// &
     566             :                           TRIM(subsection%name)//") that was already used in section " &
     567    62540807 :                           //TRIM(section%name))
     568             :       END DO
     569    62540807 :       CALL section_retain(subsection)
     570    62540807 :       section%n_subsections = section%n_subsections + 1
     571    62540807 :       section%subsections(section%n_subsections)%section => subsection
     572    62540807 :    END SUBROUTINE section_add_subsection
     573             : 
     574             : ! **************************************************************************************************
     575             : !> \brief creates a object where to store the values of a section
     576             : !> \param section_vals the parsed section that will be created
     577             : !> \param section the structure of the section that you want to parse
     578             : !> \author fawzi
     579             : ! **************************************************************************************************
     580    72361252 :    RECURSIVE SUBROUTINE section_vals_create(section_vals, section)
     581             :       TYPE(section_vals_type), POINTER                   :: section_vals
     582             :       TYPE(section_type), POINTER                        :: section
     583             : 
     584             :       INTEGER                                            :: i
     585             : 
     586    72361252 :       CPASSERT(.NOT. ASSOCIATED(section_vals))
     587    72361252 :       ALLOCATE (section_vals)
     588    72361252 :       last_section_vals_id = last_section_vals_id + 1
     589    72361252 :       section_vals%id_nr = last_section_vals_id
     590    72361252 :       section_vals%ref_count = 1
     591    72361252 :       CALL section_retain(section)
     592    72361252 :       section_vals%section => section
     593    72361252 :       section%frozen = .TRUE.
     594   144722504 :       ALLOCATE (section_vals%values(-1:section%n_keywords, 0))
     595   156441013 :       ALLOCATE (section_vals%subs_vals(section%n_subsections, 1))
     596   144663948 :       DO i = 1, section%n_subsections
     597    72302696 :          NULLIFY (section_vals%subs_vals(i, 1)%section_vals)
     598             :          CALL section_vals_create(section_vals%subs_vals(i, 1)%section_vals, &
     599   144663948 :                                   section=section%subsections(i)%section)
     600             :       END DO
     601    72361252 :       NULLIFY (section_vals%ibackup)
     602    72361252 :    END SUBROUTINE section_vals_create
     603             : 
     604             : ! **************************************************************************************************
     605             : !> \brief retains the given section values (see doc/ReferenceCounting.html)
     606             : !> \param section_vals the object to retain
     607             : !> \author fawzi
     608             : ! **************************************************************************************************
     609       67793 :    SUBROUTINE section_vals_retain(section_vals)
     610             :       TYPE(section_vals_type), POINTER                   :: section_vals
     611             : 
     612       67793 :       CPASSERT(ASSOCIATED(section_vals))
     613       67793 :       CPASSERT(section_vals%ref_count > 0)
     614       67793 :       section_vals%ref_count = section_vals%ref_count + 1
     615       67793 :    END SUBROUTINE section_vals_retain
     616             : 
     617             : ! **************************************************************************************************
     618             : !> \brief releases the given object
     619             : !> \param section_vals the section_vals to release
     620             : !> \author fawzi
     621             : ! **************************************************************************************************
     622    72441731 :    RECURSIVE SUBROUTINE section_vals_release(section_vals)
     623             :       TYPE(section_vals_type), POINTER                   :: section_vals
     624             : 
     625             :       INTEGER                                            :: i, j
     626             :       TYPE(cp_sll_val_type), POINTER                     :: vals
     627             :       TYPE(val_type), POINTER                            :: el
     628             : 
     629    72441731 :       IF (ASSOCIATED(section_vals)) THEN
     630    72429045 :          CPASSERT(section_vals%ref_count > 0)
     631    72429045 :          section_vals%ref_count = section_vals%ref_count - 1
     632    72429045 :          IF (section_vals%ref_count == 0) THEN
     633    72361252 :             CALL section_release(section_vals%section)
     634    72597247 :             DO j = 1, SIZE(section_vals%values, 2)
     635    75560255 :                DO i = -1, UBOUND(section_vals%values, 1)
     636     2727013 :                   vals => section_vals%values(i, j)%list
     637     3769210 :                   DO WHILE (cp_sll_val_next(vals, el_att=el))
     638     1042197 :                      CALL val_release(el)
     639             :                   END DO
     640     2963008 :                   CALL cp_sll_val_dealloc(section_vals%values(i, j)%list)
     641             :                END DO
     642             :             END DO
     643    72361252 :             DEALLOCATE (section_vals%values)
     644   144743760 :             DO j = 1, SIZE(section_vals%subs_vals, 2)
     645   217095218 :                DO i = 1, SIZE(section_vals%subs_vals, 1)
     646   144733966 :                   CALL section_vals_release(section_vals%subs_vals(i, j)%section_vals)
     647             :                END DO
     648             :             END DO
     649    72361252 :             DEALLOCATE (section_vals%subs_vals)
     650    72361252 :             IF (ASSOCIATED(section_vals%ibackup)) THEN
     651        3228 :                DEALLOCATE (section_vals%ibackup)
     652             :             END IF
     653    72361252 :             DEALLOCATE (section_vals)
     654             :          END IF
     655             :       END IF
     656    72441731 :    END SUBROUTINE section_vals_release
     657             : 
     658             : ! **************************************************************************************************
     659             : !> \brief returns various attributes about the section_vals
     660             : !> \param section_vals the section vals you want information from
     661             : !> \param ref_count ...
     662             : !> \param id_nr ...
     663             : !> \param n_repetition number of repetitions of the section
     664             : !> \param n_subs_vals_rep number of repetitions of the subsections values
     665             : !>        (max(1,n_repetition))
     666             : !> \param section ...
     667             : !> \param explicit if the section was explicitly present in
     668             : !> \author fawzi
     669             : !> \note     For the other arguments see the attributes of section_vals_type
     670             : ! **************************************************************************************************
     671     3640153 :    SUBROUTINE section_vals_get(section_vals, ref_count, id_nr, n_repetition, &
     672             :                                n_subs_vals_rep, section, explicit)
     673             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     674             :       INTEGER, INTENT(out), OPTIONAL                     :: ref_count, id_nr, n_repetition, &
     675             :                                                             n_subs_vals_rep
     676             :       TYPE(section_type), OPTIONAL, POINTER              :: section
     677             :       LOGICAL, INTENT(out), OPTIONAL                     :: explicit
     678             : 
     679     3640153 :       CPASSERT(section_vals%ref_count > 0)
     680     3640153 :       IF (PRESENT(ref_count)) ref_count = section_vals%ref_count
     681     3640153 :       IF (PRESENT(id_nr)) id_nr = section_vals%id_nr
     682     3640153 :       IF (PRESENT(section)) section => section_vals%section
     683     3640153 :       IF (PRESENT(n_repetition)) n_repetition = SIZE(section_vals%values, 2)
     684     3640153 :       IF (PRESENT(n_subs_vals_rep)) n_subs_vals_rep = SIZE(section_vals%subs_vals, 2)
     685     3640153 :       IF (PRESENT(explicit)) explicit = (SIZE(section_vals%values, 2) > 0)
     686     3640153 :    END SUBROUTINE section_vals_get
     687             : 
     688             : ! **************************************************************************************************
     689             : !> \brief returns the values of the requested subsection
     690             : !> \param section_vals the root section
     691             : !> \param subsection_name the name of the requested subsection
     692             : !> \param i_rep_section index of the repetition of section_vals from which
     693             : !>        you want to extract the subsection (defaults to 1)
     694             : !> \param can_return_null if the results can be null (defaults to false)
     695             : !> \return ...
     696             : !> \author fawzi
     697             : ! **************************************************************************************************
     698    31951314 :    RECURSIVE FUNCTION section_vals_get_subs_vals(section_vals, subsection_name, &
     699             :                                                  i_rep_section, can_return_null) RESULT(res)
     700             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     701             :       CHARACTER(len=*), INTENT(IN)                       :: subsection_name
     702             :       INTEGER, INTENT(IN), OPTIONAL                      :: i_rep_section
     703             :       LOGICAL, INTENT(IN), OPTIONAL                      :: can_return_null
     704             :       TYPE(section_vals_type), POINTER                   :: res
     705             : 
     706             :       INTEGER                                            :: irep, isection, my_index
     707             :       LOGICAL                                            :: is_path, my_can_return_null
     708             : 
     709    31951314 :       CPASSERT(section_vals%ref_count > 0)
     710             : 
     711    31951314 :       my_can_return_null = .FALSE.
     712    31951314 :       IF (PRESENT(can_return_null)) my_can_return_null = can_return_null
     713    31951314 :       NULLIFY (res)
     714    31951314 :       irep = 1
     715    31951314 :       IF (PRESENT(i_rep_section)) irep = i_rep_section
     716             : 
     717             :       ! prepare for recursive parsing of subsections. i_rep_section will be used for last section
     718    31951314 :       my_index = INDEX(subsection_name, "%")
     719    31951314 :       IF (my_index .EQ. 0) THEN
     720    18701231 :          is_path = .FALSE.
     721    18701231 :          my_index = LEN_TRIM(subsection_name)
     722             :       ELSE
     723    13250083 :          is_path = .TRUE.
     724    13250083 :          irep = 1
     725    13250083 :          my_index = my_index - 1
     726             :       END IF
     727             : 
     728    31951314 :       CPASSERT(irep <= SIZE(section_vals%subs_vals, 2))
     729             : 
     730    31951314 :       isection = section_get_subsection_index(section_vals%section, subsection_name(1:my_index))
     731    31951314 :       IF (isection > 0) res => section_vals%subs_vals(isection, irep)%section_vals
     732    31951314 :       IF (.NOT. (ASSOCIATED(res) .OR. my_can_return_null)) &
     733             :          CALL cp_abort(__LOCATION__, &
     734             :                        "could not find subsection "//TRIM(subsection_name(1:my_index))//" in section "// &
     735           0 :                        TRIM(section_vals%section%name)//" at ")
     736    31951314 :       IF (is_path .AND. ASSOCIATED(res)) THEN
     737             :          res => section_vals_get_subs_vals(res, subsection_name(my_index + 2:LEN_TRIM(subsection_name)), &
     738    13250083 :                                            i_rep_section, can_return_null)
     739             :       END IF
     740             : 
     741    31951314 :    END FUNCTION section_vals_get_subs_vals
     742             : 
     743             : ! **************************************************************************************************
     744             : !> \brief returns the values of the n-th non default subsection (null if no
     745             : !>      such section exists (not so many non default section))
     746             : !> \param section_vals the root section
     747             : !> \param i_section index of the section
     748             : !> \param i_rep_section index of the repetition of section_vals from which
     749             : !>        you want to extract the subsection (defaults to 1)
     750             : !> \return ...
     751             : !> \author fawzi
     752             : ! **************************************************************************************************
     753      624497 :    FUNCTION section_vals_get_subs_vals2(section_vals, i_section, i_rep_section) RESULT(res)
     754             :       TYPE(section_vals_type), POINTER                   :: section_vals
     755             :       INTEGER, INTENT(in)                                :: i_section
     756             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section
     757             :       TYPE(section_vals_type), POINTER                   :: res
     758             : 
     759             :       INTEGER                                            :: i, irep, isect_att
     760             : 
     761      624497 :       CPASSERT(ASSOCIATED(section_vals))
     762      624497 :       CPASSERT(section_vals%ref_count > 0)
     763      624497 :       NULLIFY (res)
     764      624497 :       irep = 1
     765      624497 :       IF (PRESENT(i_rep_section)) irep = i_rep_section
     766      624497 :       CPASSERT(irep <= SIZE(section_vals%subs_vals, 2))
     767      624497 :       isect_att = 0
     768   291213554 :       DO i = 1, section_vals%section%n_subsections
     769   291213554 :          IF (SIZE(section_vals%subs_vals(i, irep)%section_vals%values, 2) > 0) THEN
     770      699736 :             isect_att = isect_att + 1
     771      699736 :             IF (isect_att == i_section) THEN
     772             :                res => section_vals%subs_vals(i, irep)%section_vals
     773             :                EXIT
     774             :             END IF
     775             :          END IF
     776             :       END DO
     777      624497 :    END FUNCTION section_vals_get_subs_vals2
     778             : 
     779             : ! **************************************************************************************************
     780             : !> \brief returns the values of the n-th non default subsection (null if no
     781             : !>      such section exists (not so many non default section))
     782             : !> \param section_vals the root section
     783             : !> \param subsection_name ...
     784             : !> \param i_rep_section index of the repetition of section_vals from which
     785             : !>        you want to extract the subsection (defaults to 1)
     786             : !> \return ...
     787             : !> \author fawzi
     788             : ! **************************************************************************************************
     789       67580 :    FUNCTION section_vals_get_subs_vals3(section_vals, subsection_name, &
     790             :                                         i_rep_section) RESULT(res)
     791             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     792             :       CHARACTER(LEN=*), INTENT(IN)                       :: subsection_name
     793             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section
     794             :       TYPE(section_vals_type), POINTER                   :: res
     795             : 
     796             :       INTEGER                                            :: i_section, irep
     797             : 
     798       67580 :       CPASSERT(section_vals%ref_count > 0)
     799       67580 :       NULLIFY (res)
     800       67580 :       irep = 1
     801       67580 :       IF (PRESENT(i_rep_section)) irep = i_rep_section
     802       67580 :       CPASSERT(irep <= SIZE(section_vals%subs_vals, 2))
     803       67580 :       i_section = section_get_subsection_index(section_vals%section, subsection_name)
     804       67580 :       res => section_vals%subs_vals(i_section, irep)%section_vals
     805       67580 :    END FUNCTION section_vals_get_subs_vals3
     806             : 
     807             : ! **************************************************************************************************
     808             : !> \brief adds the place to store the values of a repetition of the section
     809             : !> \param section_vals the section you want to extend
     810             : !> \author fawzi
     811             : ! **************************************************************************************************
     812      245481 :    SUBROUTINE section_vals_add_values(section_vals)
     813             :       TYPE(section_vals_type), INTENT(INOUT)             :: section_vals
     814             : 
     815             :       INTEGER                                            :: i, j
     816      245481 :       TYPE(cp_sll_val_p_type), DIMENSION(:, :), POINTER  :: new_values
     817             :       TYPE(section_vals_p_type), DIMENSION(:, :), &
     818      245481 :          POINTER                                         :: new_sps
     819             : 
     820           0 :       CPASSERT(section_vals%ref_count > 0)
     821      981924 :       ALLOCATE (new_values(-1:UBOUND(section_vals%values, 1), SIZE(section_vals%values, 2) + 1))
     822      298671 :       DO j = 1, SIZE(section_vals%values, 2)
     823     1014780 :          DO i = -1, UBOUND(section_vals%values, 1)
     824      716109 :             new_values(i, j)%list => section_vals%values(i, j)%list
     825             :          END DO
     826             :       END DO
     827      245481 :       DEALLOCATE (section_vals%values)
     828      245481 :       section_vals%values => new_values
     829      245481 :       j = SIZE(new_values, 2)
     830     3294610 :       DO i = -1, UBOUND(new_values, 1)
     831     3049129 :          NULLIFY (new_values(i, j)%list)
     832             :       END DO
     833             : 
     834      245481 :       IF (SIZE(new_values, 2) > 1) THEN
     835             :          ALLOCATE (new_sps(SIZE(section_vals%subs_vals, 1), &
     836       71508 :                            SIZE(section_vals%subs_vals, 2) + 1))
     837       74446 :          DO j = 1, SIZE(section_vals%subs_vals, 2)
     838      172622 :             DO i = 1, SIZE(section_vals%subs_vals, 1)
     839      151366 :                new_sps(i, j)%section_vals => section_vals%subs_vals(i, j)%section_vals
     840             :             END DO
     841             :          END DO
     842       21256 :          DEALLOCATE (section_vals%subs_vals)
     843       21256 :          section_vals%subs_vals => new_sps
     844       21256 :          j = SIZE(new_sps, 2)
     845       70018 :          DO i = 1, SIZE(new_sps, 1)
     846       48762 :             NULLIFY (new_sps(i, j)%section_vals)
     847             :             CALL section_vals_create(new_sps(i, SIZE(new_sps, 2))%section_vals, &
     848       70018 :                                      section=section_vals%section%subsections(i)%section)
     849             :          END DO
     850             :       END IF
     851      245481 :    END SUBROUTINE section_vals_add_values
     852             : 
     853             : ! **************************************************************************************************
     854             : !> \brief removes the values of a repetition of the section
     855             : !> \param section_vals the section you want to extend
     856             : !> \author fawzi
     857             : ! **************************************************************************************************
     858       67581 :    SUBROUTINE section_vals_remove_values(section_vals)
     859             :       TYPE(section_vals_type), POINTER                   :: section_vals
     860             : 
     861             :       INTEGER                                            :: i, j
     862       67581 :       TYPE(cp_sll_val_p_type), DIMENSION(:, :), POINTER  :: new_values
     863             :       TYPE(cp_sll_val_type), POINTER                     :: vals
     864             :       TYPE(val_type), POINTER                            :: el
     865             : 
     866       67581 :       IF (ASSOCIATED(section_vals)) THEN
     867       67581 :          CPASSERT(section_vals%ref_count > 0)
     868       67581 :          NULLIFY (el, vals)
     869             :          ! Allocate a null 0 dimension array of values
     870      135162 :          ALLOCATE (new_values(-1:section_vals%section%n_keywords, 0))
     871             :          ! Release old values
     872       77067 :          DO j = 1, SIZE(section_vals%values, 2)
     873      163188 :             DO i = -1, UBOUND(section_vals%values, 1)
     874       76635 :                vals => section_vals%values(i, j)%list
     875      680464 :                DO WHILE (cp_sll_val_next(vals, el_att=el))
     876      603829 :                   CALL val_release(el)
     877             :                END DO
     878       86121 :                CALL cp_sll_val_dealloc(section_vals%values(i, j)%list)
     879             :             END DO
     880             :          END DO
     881       67581 :          DEALLOCATE (section_vals%values)
     882       67581 :          section_vals%values => new_values
     883             :       END IF
     884       67581 :    END SUBROUTINE section_vals_remove_values
     885             : 
     886             : ! These accessor functions can be used instead of passing a variable
     887             : ! in the parameter list of a subroutine call. This should make the
     888             : ! code a lot simpler. See xc_rho_set_and_dset_create in xc.F as
     889             : ! an example.
     890             : 
     891             : ! **************************************************************************************************
     892             : !> \brief ...
     893             : !> \param section_vals ...
     894             : !> \param keyword_name ...
     895             : !> \return ...
     896             : ! **************************************************************************************************
     897           0 :    FUNCTION section_get_cval(section_vals, keyword_name) RESULT(res)
     898             : 
     899             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     900             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     901             :       CHARACTER(LEN=default_string_length)               :: res
     902             : 
     903           0 :       CALL section_vals_val_get(section_vals, keyword_name, c_val=res)
     904             : 
     905           0 :    END FUNCTION section_get_cval
     906             : 
     907             : ! **************************************************************************************************
     908             : !> \brief ...
     909             : !> \param section_vals ...
     910             : !> \param keyword_name ...
     911             : !> \return ...
     912             : ! **************************************************************************************************
     913      325580 :    FUNCTION section_get_rval(section_vals, keyword_name) RESULT(res)
     914             : 
     915             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     916             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     917             :       REAL(kind=dp)                                      :: res
     918             : 
     919      325580 :       CALL section_vals_val_get(section_vals, keyword_name, r_val=res)
     920             : 
     921      325580 :    END FUNCTION section_get_rval
     922             : 
     923             : ! **************************************************************************************************
     924             : !> \brief ...
     925             : !> \param section_vals ...
     926             : !> \param keyword_name ...
     927             : !> \return ...
     928             : ! **************************************************************************************************
     929           0 :    FUNCTION section_get_rvals(section_vals, keyword_name) RESULT(res)
     930             : 
     931             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     932             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     933             :       REAL(kind=dp), DIMENSION(:), POINTER               :: res
     934             : 
     935           0 :       CALL section_vals_val_get(section_vals, keyword_name, r_vals=res)
     936             : 
     937           0 :    END FUNCTION section_get_rvals
     938             : 
     939             : ! **************************************************************************************************
     940             : !> \brief ...
     941             : !> \param section_vals ...
     942             : !> \param keyword_name ...
     943             : !> \return ...
     944             : ! **************************************************************************************************
     945      286014 :    FUNCTION section_get_ival(section_vals, keyword_name) RESULT(res)
     946             : 
     947             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     948             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     949             :       INTEGER                                            :: res
     950             : 
     951      286014 :       CALL section_vals_val_get(section_vals, keyword_name, i_val=res)
     952             : 
     953      286014 :    END FUNCTION section_get_ival
     954             : 
     955             : ! **************************************************************************************************
     956             : !> \brief ...
     957             : !> \param section_vals ...
     958             : !> \param keyword_name ...
     959             : !> \return ...
     960             : ! **************************************************************************************************
     961        3468 :    FUNCTION section_get_ivals(section_vals, keyword_name) RESULT(res)
     962             : 
     963             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     964             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     965             :       INTEGER, DIMENSION(:), POINTER                     :: res
     966             : 
     967        3468 :       CALL section_vals_val_get(section_vals, keyword_name, i_vals=res)
     968             : 
     969        3468 :    END FUNCTION section_get_ivals
     970             : 
     971             : ! **************************************************************************************************
     972             : !> \brief ...
     973             : !> \param section_vals ...
     974             : !> \param keyword_name ...
     975             : !> \return ...
     976             : ! **************************************************************************************************
     977       68127 :    FUNCTION section_get_lval(section_vals, keyword_name) RESULT(res)
     978             : 
     979             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
     980             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
     981             :       LOGICAL                                            :: res
     982             : 
     983       68127 :       CALL section_vals_val_get(section_vals, keyword_name, l_val=res)
     984             : 
     985       68127 :    END FUNCTION section_get_lval
     986             : 
     987             : ! **************************************************************************************************
     988             : !> \brief returns the requested value
     989             : !> \param section_vals ...
     990             : !> \param keyword_name the name of the keyword you want
     991             : !> \param i_rep_section which repetition of the section you are interested in
     992             : !>        (defaults to 1)
     993             : !> \param i_rep_val which repetition of the keyword/val you are interested in
     994             : !>        (defaults to 1)
     995             : !> \param n_rep_val returns number of val available
     996             : !> \param val ...
     997             : !> \param l_val ,i_val,r_val,c_val: returns the logical,integer,real or
     998             : !>        character value
     999             : !> \param i_val ...
    1000             : !> \param r_val ...
    1001             : !> \param c_val ...
    1002             : !> \param l_vals ,i_vals,r_vals,c_vals: returns the logical,integer,real or
    1003             : !>        character arrays. The val reamins the owner of the array
    1004             : !> \param i_vals ...
    1005             : !> \param r_vals ...
    1006             : !> \param c_vals ...
    1007             : !> \param explicit ...
    1008             : !> \author fawzi
    1009             : ! **************************************************************************************************
    1010    40381734 :    SUBROUTINE section_vals_val_get(section_vals, keyword_name, i_rep_section, &
    1011             :                                    i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, &
    1012             :                                    c_vals, explicit)
    1013             :       TYPE(section_vals_type), INTENT(IN), TARGET        :: section_vals
    1014             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
    1015             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section, i_rep_val
    1016             :       INTEGER, INTENT(out), OPTIONAL                     :: n_rep_val
    1017             :       TYPE(val_type), OPTIONAL, POINTER                  :: val
    1018             :       LOGICAL, INTENT(out), OPTIONAL                     :: l_val
    1019             :       INTEGER, INTENT(out), OPTIONAL                     :: i_val
    1020             :       REAL(KIND=DP), INTENT(out), OPTIONAL               :: r_val
    1021             :       CHARACTER(LEN=*), INTENT(out), OPTIONAL            :: c_val
    1022             :       LOGICAL, DIMENSION(:), OPTIONAL, POINTER           :: l_vals
    1023             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: i_vals
    1024             :       REAL(KIND=DP), DIMENSION(:), OPTIONAL, POINTER     :: r_vals
    1025             :       CHARACTER(LEN=default_string_length), &
    1026             :          DIMENSION(:), OPTIONAL, POINTER                 :: c_vals
    1027             :       LOGICAL, INTENT(out), OPTIONAL                     :: explicit
    1028             : 
    1029             :       INTEGER                                            :: ik, irk, irs, len_key, my_index, &
    1030             :                                                             tmp_index
    1031             :       LOGICAL                                            :: valRequested
    1032             :       TYPE(cp_sll_val_type), POINTER                     :: vals
    1033             :       TYPE(keyword_type), POINTER                        :: keyword
    1034             :       TYPE(section_type), POINTER                        :: section
    1035             :       TYPE(section_vals_type), POINTER                   :: s_vals
    1036             :       TYPE(val_type), POINTER                            :: my_val
    1037             : 
    1038    40381734 :       CPASSERT(section_vals%ref_count > 0)
    1039             : 
    1040    40381734 :       my_index = INDEX(keyword_name, '%') + 1
    1041    40381734 :       len_key = LEN_TRIM(keyword_name)
    1042    40381734 :       IF (my_index > 1) THEN
    1043     2407181 :          DO
    1044     9632401 :             tmp_index = INDEX(keyword_name(my_index:len_key), "%")
    1045     9632401 :             IF (tmp_index <= 0) EXIT
    1046     2407181 :             my_index = my_index + tmp_index
    1047             :          END DO
    1048     7225220 :          s_vals => section_vals_get_subs_vals(section_vals, keyword_name(1:my_index - 2))
    1049             :       ELSE
    1050             :          s_vals => section_vals
    1051             :       END IF
    1052             : 
    1053    40381734 :       irk = 1
    1054    40381734 :       irs = 1
    1055    40381734 :       IF (PRESENT(i_rep_section)) irs = i_rep_section
    1056    40381734 :       IF (PRESENT(i_rep_val)) irk = i_rep_val
    1057    40381734 :       IF (PRESENT(val)) NULLIFY (val)
    1058    40381734 :       IF (PRESENT(explicit)) explicit = .FALSE.
    1059    40381734 :       section => s_vals%section
    1060             :       valRequested = PRESENT(l_val) .OR. PRESENT(i_val) .OR. PRESENT(r_val) .OR. &
    1061             :                      PRESENT(c_val) .OR. PRESENT(l_vals) .OR. PRESENT(i_vals) .OR. &
    1062    40381734 :                      PRESENT(r_vals) .OR. PRESENT(c_vals)
    1063    40381734 :       ik = section_get_keyword_index(s_vals%section, keyword_name(my_index:len_key))
    1064    40381734 :       IF (ik == -2) &
    1065             :          CALL cp_abort(__LOCATION__, &
    1066             :                        "section "//TRIM(section%name)//" does not contain keyword "// &
    1067           0 :                        TRIM(keyword_name(my_index:len_key)))
    1068    40381734 :       keyword => section%keywords(ik)%keyword
    1069    40381734 :       IF (.NOT. (irs > 0 .AND. irs <= SIZE(s_vals%subs_vals, 2))) &
    1070             :          CALL cp_abort(__LOCATION__, &
    1071             :                        "section repetition requested ("//cp_to_string(irs)// &
    1072             :                        ") out of bounds (1:"//cp_to_string(SIZE(s_vals%subs_vals, 2)) &
    1073           0 :                        //")")
    1074    40381734 :       NULLIFY (my_val)
    1075    40381734 :       IF (PRESENT(n_rep_val)) n_rep_val = 0
    1076    40381734 :       IF (irs <= SIZE(s_vals%values, 2)) THEN ! the section was parsed
    1077    16975844 :          vals => s_vals%values(ik, irs)%list
    1078    16975844 :          IF (PRESENT(n_rep_val)) n_rep_val = cp_sll_val_get_length(vals)
    1079    16975844 :          IF (.NOT. ASSOCIATED(vals)) THEN
    1080             :             ! this keyword was not parsed
    1081     8876098 :             IF (ASSOCIATED(keyword%default_value)) THEN
    1082     7421417 :                my_val => keyword%default_value
    1083     7421417 :                IF (PRESENT(n_rep_val)) n_rep_val = 1
    1084             :             END IF
    1085             :          ELSE
    1086             :             my_val => cp_sll_val_get_el_at(s_vals%values(ik, irs)%list, &
    1087     8099746 :                                            irk)
    1088     8099746 :             IF (PRESENT(explicit)) explicit = .TRUE.
    1089             :          END IF
    1090    23405890 :       ELSE IF (ASSOCIATED(keyword%default_value)) THEN
    1091    23388467 :          IF (PRESENT(n_rep_val)) n_rep_val = 1
    1092    23388467 :          my_val => keyword%default_value
    1093             :       END IF
    1094    40381734 :       IF (PRESENT(val)) val => my_val
    1095    40381734 :       IF (valRequested) THEN
    1096    34865324 :          IF (.NOT. ASSOCIATED(my_val)) &
    1097             :             CALL cp_abort(__LOCATION__, &
    1098             :                           "Value requested, but no value set getting value from "// &
    1099             :                           "keyword "//TRIM(keyword_name(my_index:len_key))//" of section "// &
    1100           0 :                           TRIM(section%name))
    1101             :          CALL val_get(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
    1102             :                       c_val=c_val, l_vals=l_vals, i_vals=i_vals, r_vals=r_vals, &
    1103   270001497 :                       c_vals=c_vals)
    1104             :       END IF
    1105             : 
    1106    40381734 :    END SUBROUTINE section_vals_val_get
    1107             : 
    1108             : ! **************************************************************************************************
    1109             : !> \brief returns the requested list
    1110             : !> \param section_vals ...
    1111             : !> \param keyword_name the name of the keyword you want
    1112             : !> \param i_rep_section which repetition of the section you are interested in
    1113             : !>        (defaults to 1)
    1114             : !> \param list ...
    1115             : !> \author Joost VandeVondele
    1116             : !> \note
    1117             : !>      - most useful if the full list is needed anyway, so that faster iteration can be used
    1118             : ! **************************************************************************************************
    1119        7639 :    SUBROUTINE section_vals_list_get(section_vals, keyword_name, i_rep_section, &
    1120             :                                     list)
    1121             :       TYPE(section_vals_type), INTENT(IN), POINTER       :: section_vals
    1122             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
    1123             :       INTEGER, OPTIONAL                                  :: i_rep_section
    1124             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1125             : 
    1126             :       INTEGER                                            :: ik, irs, len_key, my_index, tmp_index
    1127             :       TYPE(section_type), POINTER                        :: section
    1128             :       TYPE(section_vals_type), POINTER                   :: s_vals
    1129             : 
    1130        7639 :       CPASSERT(ASSOCIATED(section_vals))
    1131        7639 :       CPASSERT(section_vals%ref_count > 0)
    1132        7639 :       NULLIFY (list)
    1133        7639 :       my_index = INDEX(keyword_name, '%') + 1
    1134        7639 :       len_key = LEN_TRIM(keyword_name)
    1135        7639 :       IF (my_index > 1) THEN
    1136           0 :          DO
    1137           0 :             tmp_index = INDEX(keyword_name(my_index:len_key), "%")
    1138           0 :             IF (tmp_index <= 0) EXIT
    1139           0 :             my_index = my_index + tmp_index
    1140             :          END DO
    1141           0 :          s_vals => section_vals_get_subs_vals(section_vals, keyword_name(1:my_index - 2))
    1142             :       ELSE
    1143        7639 :          s_vals => section_vals
    1144             :       END IF
    1145             : 
    1146        7639 :       irs = 1
    1147        7639 :       IF (PRESENT(i_rep_section)) irs = i_rep_section
    1148        7639 :       section => s_vals%section
    1149        7639 :       ik = section_get_keyword_index(s_vals%section, keyword_name(my_index:len_key))
    1150        7639 :       IF (ik == -2) &
    1151             :          CALL cp_abort(__LOCATION__, &
    1152             :                        "section "//TRIM(section%name)//" does not contain keyword "// &
    1153           0 :                        TRIM(keyword_name(my_index:len_key)))
    1154        7639 :       IF (.NOT. (irs > 0 .AND. irs <= SIZE(s_vals%subs_vals, 2))) &
    1155             :          CALL cp_abort(__LOCATION__, &
    1156             :                        "section repetition requested ("//cp_to_string(irs)// &
    1157             :                        ") out of bounds (1:"//cp_to_string(SIZE(s_vals%subs_vals, 2)) &
    1158           0 :                        //")")
    1159        7639 :       list => s_vals%values(ik, irs)%list
    1160             : 
    1161        7639 :    END SUBROUTINE section_vals_list_get
    1162             : 
    1163             : ! **************************************************************************************************
    1164             : !> \brief sets the requested value
    1165             : !> \param section_vals ...
    1166             : !> \param keyword_name the name of the keyword you want (can be a path
    1167             : !>        separated by '%')
    1168             : !> \param i_rep_section isection which repetition of the section you are
    1169             : !>        nterested in (defaults to 1)
    1170             : !> \param i_rep_val which repetition of the keyword/val you are interested in
    1171             : !>        (defaults to 1)
    1172             : !> \param val ...
    1173             : !> \param l_val ,i_val,r_val,c_val: sets the logical,integer,real or
    1174             : !>        character value
    1175             : !> \param i_val ...
    1176             : !> \param r_val ...
    1177             : !> \param c_val ...
    1178             : !> \param l_vals_ptr ,i_vals_ptr,r_vals,c_vals: sets the logical,integer,real or
    1179             : !>        character arrays. The val becomes the owner of the array
    1180             : !> \param i_vals_ptr ...
    1181             : !> \param r_vals_ptr ...
    1182             : !> \param c_vals_ptr ...
    1183             : !> \author fawzi
    1184             : ! **************************************************************************************************
    1185      336212 :    SUBROUTINE section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, &
    1186             :                                    val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
    1187             :       TYPE(section_vals_type), POINTER                   :: section_vals
    1188             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
    1189             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section, i_rep_val
    1190             :       TYPE(val_type), OPTIONAL, POINTER                  :: val
    1191             :       LOGICAL, INTENT(in), OPTIONAL                      :: l_val
    1192             :       INTEGER, INTENT(in), OPTIONAL                      :: i_val
    1193             :       REAL(KIND=DP), INTENT(in), OPTIONAL                :: r_val
    1194             :       CHARACTER(LEN=*), INTENT(in), OPTIONAL             :: c_val
    1195             :       LOGICAL, DIMENSION(:), OPTIONAL, POINTER           :: l_vals_ptr
    1196             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: i_vals_ptr
    1197             :       REAL(KIND=DP), DIMENSION(:), OPTIONAL, POINTER     :: r_vals_ptr
    1198             :       CHARACTER(LEN=default_string_length), &
    1199             :          DIMENSION(:), OPTIONAL, POINTER                 :: c_vals_ptr
    1200             : 
    1201             :       INTEGER                                            :: ik, irk, irs, len_key, my_index, &
    1202             :                                                             tmp_index
    1203             :       LOGICAL                                            :: valSet
    1204             :       TYPE(cp_sll_val_type), POINTER                     :: vals
    1205             :       TYPE(keyword_type), POINTER                        :: keyword
    1206             :       TYPE(section_type), POINTER                        :: section
    1207             :       TYPE(section_vals_type), POINTER                   :: s_vals
    1208             :       TYPE(val_type), POINTER                            :: my_val, old_val
    1209             : 
    1210      336212 :       CPASSERT(ASSOCIATED(section_vals))
    1211      336212 :       CPASSERT(section_vals%ref_count > 0)
    1212             : 
    1213      336212 :       my_index = INDEX(keyword_name, '%') + 1
    1214      336212 :       len_key = LEN_TRIM(keyword_name)
    1215      336212 :       IF (my_index > 1) THEN
    1216        7771 :          DO
    1217       80727 :             tmp_index = INDEX(keyword_name(my_index:len_key), "%")
    1218       80727 :             IF (tmp_index <= 0) EXIT
    1219        7771 :             my_index = my_index + tmp_index
    1220             :          END DO
    1221       72956 :          s_vals => section_vals_get_subs_vals(section_vals, keyword_name(1:my_index - 2))
    1222             :       ELSE
    1223      263256 :          s_vals => section_vals
    1224             :       END IF
    1225             : 
    1226      336212 :       irk = 1
    1227      336212 :       irs = 1
    1228      336212 :       IF (PRESENT(i_rep_section)) irs = i_rep_section
    1229      336212 :       IF (PRESENT(i_rep_val)) irk = i_rep_val
    1230      336212 :       section => s_vals%section
    1231      336212 :       ik = section_get_keyword_index(s_vals%section, keyword_name(my_index:len_key))
    1232      336212 :       IF (ik == -2) &
    1233             :          CALL cp_abort(__LOCATION__, &
    1234             :                        "section "//TRIM(section%name)//" does not contain keyword "// &
    1235           0 :                        TRIM(keyword_name(my_index:len_key)))
    1236             :       ! Add values..
    1237       22782 :       DO
    1238      358994 :          IF (irs <= SIZE(s_vals%values, 2)) EXIT
    1239       22782 :          CALL section_vals_add_values(s_vals)
    1240             :       END DO
    1241      336212 :       IF (.NOT. (irs > 0 .AND. irs <= SIZE(s_vals%subs_vals, 2))) &
    1242             :          CALL cp_abort(__LOCATION__, &
    1243             :                        "section repetition requested ("//cp_to_string(irs)// &
    1244             :                        ") out of bounds (1:"//cp_to_string(SIZE(s_vals%subs_vals, 2)) &
    1245           0 :                        //")")
    1246      336212 :       keyword => s_vals%section%keywords(ik)%keyword
    1247      336212 :       NULLIFY (my_val)
    1248      336212 :       IF (PRESENT(val)) my_val => val
    1249             :       valSet = PRESENT(l_val) .OR. PRESENT(i_val) .OR. PRESENT(r_val) .OR. &
    1250             :                PRESENT(c_val) .OR. PRESENT(l_vals_ptr) .OR. PRESENT(i_vals_ptr) .OR. &
    1251      336212 :                PRESENT(r_vals_ptr) .OR. PRESENT(c_vals_ptr)
    1252      336212 :       IF (ASSOCIATED(my_val)) THEN
    1253             :          ! check better?
    1254           0 :          IF (valSet) &
    1255             :             CALL cp_abort(__LOCATION__, &
    1256             :                           " both val and values present, in setting "// &
    1257             :                           "keyword "//TRIM(keyword_name(my_index:len_key))//" of section "// &
    1258           0 :                           TRIM(section%name))
    1259             :       ELSE
    1260             :          ! ignore ?
    1261      336212 :          IF (.NOT. valSet) &
    1262             :             CALL cp_abort(__LOCATION__, &
    1263             :                           " empty value in setting "// &
    1264             :                           "keyword "//TRIM(keyword_name(my_index:len_key))//" of section "// &
    1265           0 :                           TRIM(section%name))
    1266      336212 :          CPASSERT(valSet)
    1267      336212 :          IF (keyword%type_of_var == lchar_t) THEN
    1268      134814 :             CALL val_create(my_val, lc_val=c_val, lc_vals_ptr=c_vals_ptr)
    1269             :          ELSE
    1270             :             CALL val_create(my_val, l_val=l_val, i_val=i_val, r_val=r_val, &
    1271             :                             c_val=c_val, l_vals_ptr=l_vals_ptr, i_vals_ptr=i_vals_ptr, &
    1272             :                             r_vals_ptr=r_vals_ptr, &
    1273     2239944 :                             c_vals_ptr=c_vals_ptr, enum=keyword%enum)
    1274             :          END IF
    1275      336212 :          CPASSERT(ASSOCIATED(my_val))
    1276      336212 :          CPASSERT(my_val%type_of_var == keyword%type_of_var)
    1277             :       END IF
    1278      336212 :       vals => s_vals%values(ik, irs)%list
    1279      336212 :       IF (irk == -1) THEN
    1280           0 :          CALL cp_sll_val_insert_el_at(vals, my_val, index=-1)
    1281      336212 :       ELSE IF (irk <= cp_sll_val_get_length(vals)) THEN
    1282      207621 :          IF (irk <= 0) &
    1283             :             CALL cp_abort(__LOCATION__, &
    1284             :                           "invalid irk "//TRIM(ADJUSTL(cp_to_string(irk)))// &
    1285             :                           " in keyword "//TRIM(keyword_name(my_index:len_key))//" of section "// &
    1286           0 :                           TRIM(section%name))
    1287      207621 :          old_val => cp_sll_val_get_el_at(vals, index=irk)
    1288      207621 :          CALL val_release(old_val)
    1289      207621 :          CALL cp_sll_val_set_el_at(vals, value=my_val, index=irk)
    1290      128591 :       ELSE IF (irk > cp_sll_val_get_length(vals) + 1) THEN
    1291             :          ! change?
    1292             :          CALL cp_abort(__LOCATION__, &
    1293             :                        "cannot add extra keyword repetitions to keyword" &
    1294             :                        //TRIM(keyword_name(my_index:len_key))//" of section "// &
    1295           0 :                        TRIM(section%name))
    1296             :       ELSE
    1297      128591 :          CALL cp_sll_val_insert_el_at(vals, my_val, index=irk)
    1298             :       END IF
    1299      336212 :       s_vals%values(ik, irs)%list => vals
    1300             :       NULLIFY (my_val)
    1301      336212 :    END SUBROUTINE section_vals_val_set
    1302             : 
    1303             : ! **************************************************************************************************
    1304             : !> \brief unsets (removes) the requested value (if it is a keyword repetitions
    1305             : !>      removes the repetition, so be careful: the repetition indices bigger
    1306             : !>      than the actual change.
    1307             : !> \param section_vals ...
    1308             : !> \param keyword_name the name of the keyword you want (can be a path
    1309             : !>        separated by '%')
    1310             : !> \param i_rep_section which repetition of the section you are interested in
    1311             : !>        (defaults to 1)
    1312             : !> \param i_rep_val which repetition of the keyword/val you are interested in
    1313             : !>        (defaults to 1)
    1314             : !> \author fawzi
    1315             : ! **************************************************************************************************
    1316       37026 :    SUBROUTINE section_vals_val_unset(section_vals, keyword_name, i_rep_section, &
    1317             :                                      i_rep_val)
    1318             :       TYPE(section_vals_type), POINTER                   :: section_vals
    1319             :       CHARACTER(len=*), INTENT(in)                       :: keyword_name
    1320             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section, i_rep_val
    1321             : 
    1322             :       INTEGER                                            :: ik, irk, irs, len_key, my_index, &
    1323             :                                                             tmp_index
    1324             :       TYPE(cp_sll_val_type), POINTER                     :: pos
    1325             :       TYPE(section_type), POINTER                        :: section
    1326             :       TYPE(section_vals_type), POINTER                   :: s_vals
    1327             :       TYPE(val_type), POINTER                            :: old_val
    1328             : 
    1329       37026 :       NULLIFY (pos)
    1330       37026 :       CPASSERT(ASSOCIATED(section_vals))
    1331       37026 :       CPASSERT(section_vals%ref_count > 0)
    1332             : 
    1333       37026 :       my_index = INDEX(keyword_name, '%') + 1
    1334       37026 :       len_key = LEN_TRIM(keyword_name)
    1335       37026 :       IF (my_index > 1) THEN
    1336         316 :          DO
    1337         686 :             tmp_index = INDEX(keyword_name(my_index:len_key), "%")
    1338         686 :             IF (tmp_index <= 0) EXIT
    1339         316 :             my_index = my_index + tmp_index
    1340             :          END DO
    1341         370 :          s_vals => section_vals_get_subs_vals(section_vals, keyword_name(1:my_index - 2))
    1342             :       ELSE
    1343       36656 :          s_vals => section_vals
    1344             :       END IF
    1345             : 
    1346       37026 :       irk = 1
    1347       37026 :       irs = 1
    1348       37026 :       IF (PRESENT(i_rep_section)) irs = i_rep_section
    1349       37026 :       IF (PRESENT(i_rep_val)) irk = i_rep_val
    1350       37026 :       section => s_vals%section
    1351       37026 :       ik = section_get_keyword_index(s_vals%section, keyword_name(my_index:len_key))
    1352       37026 :       IF (ik == -2) &
    1353             :          CALL cp_abort(__LOCATION__, &
    1354             :                        "section "//TRIM(section%name)//" does not contain keyword "// &
    1355           0 :                        TRIM(keyword_name(my_index:len_key)))
    1356             :       ! ignore unset of non set values
    1357       37026 :       IF (irs <= SIZE(s_vals%values, 2)) THEN
    1358       37026 :          IF (.NOT. (irs > 0 .AND. irs <= SIZE(s_vals%subs_vals, 2))) &
    1359             :             CALL cp_abort(__LOCATION__, &
    1360             :                           "section repetition requested ("//cp_to_string(irs)// &
    1361             :                           ") out of bounds (1:"//cp_to_string(SIZE(s_vals%subs_vals, 2)) &
    1362           0 :                           //")")
    1363       37026 :          IF (irk == -1) THEN
    1364           0 :             pos => cp_sll_val_get_rest(s_vals%values(ik, irs)%list, iter=-1)
    1365             :          ELSE
    1366       37026 :             pos => cp_sll_val_get_rest(s_vals%values(ik, irs)%list, iter=irk - 1)
    1367             :          END IF
    1368       37026 :          IF (ASSOCIATED(pos)) THEN
    1369        7040 :             old_val => cp_sll_val_get_el_at(s_vals%values(ik, irs)%list, index=irk)
    1370        7040 :             CALL val_release(old_val)
    1371        7040 :             CALL cp_sll_val_rm_el_at(s_vals%values(ik, irs)%list, index=irk)
    1372             :          END IF
    1373             :       END IF
    1374             : 
    1375       37026 :    END SUBROUTINE section_vals_val_unset
    1376             : 
    1377             : ! **************************************************************************************************
    1378             : !> \brief writes the values in the given section in a way that is suitable to
    1379             : !>      the automatic parsing
    1380             : !> \param section_vals the section to write out
    1381             : !> \param unit_nr the unit where to write to
    1382             : !> \param hide_root ...
    1383             : !> \param hide_defaults ...
    1384             : !> \author fawzi
    1385             : !> \note
    1386             : !>      skips required sections which weren't read
    1387             : ! **************************************************************************************************
    1388     2047573 :    RECURSIVE SUBROUTINE section_vals_write(section_vals, unit_nr, hide_root, hide_defaults)
    1389             :       TYPE(section_vals_type), INTENT(IN)                :: section_vals
    1390             :       INTEGER, INTENT(in)                                :: unit_nr
    1391             :       LOGICAL, INTENT(in), OPTIONAL                      :: hide_root, hide_defaults
    1392             : 
    1393             :       CHARACTER(len=default_string_length)               :: myfmt
    1394             :       INTEGER                                            :: i_rep_s, ik, isec, ival, nr, nval
    1395             :       INTEGER, SAVE                                      :: indent = 1
    1396             :       LOGICAL                                            :: defaultSection, explicit, &
    1397             :                                                             my_hide_defaults, my_hide_root
    1398             :       TYPE(cp_sll_val_type), POINTER                     :: new_pos, vals
    1399             :       TYPE(keyword_type), POINTER                        :: keyword
    1400             :       TYPE(section_type), POINTER                        :: section
    1401             :       TYPE(section_vals_type), POINTER                   :: sval
    1402             :       TYPE(val_type), POINTER                            :: val
    1403             : 
    1404     2047573 :       my_hide_root = .FALSE.
    1405     2047573 :       my_hide_defaults = .TRUE.
    1406     2047573 :       IF (PRESENT(hide_root)) my_hide_root = hide_root
    1407     2047573 :       IF (PRESENT(hide_defaults)) my_hide_defaults = hide_defaults
    1408             : 
    1409     2047573 :       CPASSERT(section_vals%ref_count > 0)
    1410     2047573 :       IF (unit_nr > 0) THEN
    1411     2047558 :          CALL section_vals_get(section_vals, explicit=explicit, n_repetition=nr, section=section)
    1412     2047558 :          IF (explicit .OR. (.NOT. my_hide_defaults)) THEN
    1413      555516 :             DO i_rep_s = 1, nr
    1414      281769 :                IF (.NOT. my_hide_root) THEN
    1415      273473 :                   WRITE (myfmt, *) indent, "X"
    1416      273473 :                   CALL compress(myfmt, full=.TRUE.)
    1417      273473 :                   IF (ASSOCIATED(section%keywords(-1)%keyword)) THEN
    1418       51634 :                      WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//",'&',a,' ')", advance="NO") TRIM(section%name)
    1419             :                   ELSE
    1420      221839 :                      WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//",'&',a)") TRIM(section%name)
    1421             :                   END IF
    1422             :                END IF
    1423      281769 :                defaultSection = (SIZE(section_vals%values, 2) == 0)
    1424      281769 :                IF (.NOT. defaultSection) THEN
    1425      281769 :                   IF (.NOT. my_hide_root) indent = indent + 2
    1426      281769 :                   WRITE (myfmt, *) indent, "X"
    1427      281769 :                   CALL compress(myfmt, full=.TRUE.)
    1428     2888343 :                   DO ik = -1, section%n_keywords
    1429     2606574 :                      keyword => section%keywords(ik)%keyword
    1430     2888343 :                      IF (ASSOCIATED(keyword)) THEN
    1431     2124545 :                         IF (keyword%type_of_var /= no_t .AND. keyword%names(1) (1:2) /= "__") THEN
    1432             :                            CALL section_vals_val_get(section_vals, keyword%names(1), &
    1433     2070624 :                                                      i_rep_s, n_rep_val=nval)
    1434     2070624 :                            IF (i_rep_s <= SIZE(section_vals%values, 2)) THEN
    1435             :                               ! Section was parsed
    1436     2070624 :                               vals => section_vals%values(ik, i_rep_s)%list
    1437     5486401 :                               DO ival = 1, nval
    1438     3415777 :                                  IF (ival == 1) THEN
    1439             :                                     new_pos => vals
    1440             :                                  ELSE
    1441     1498552 :                                     new_pos => new_pos%rest
    1442             :                                  END IF
    1443     3415777 :                                  IF (.NOT. ASSOCIATED(new_pos)) THEN
    1444             :                                     ! this keyword was not parsed
    1445     1357037 :                                     IF (ASSOCIATED(keyword%default_value)) THEN
    1446     1357037 :                                        val => keyword%default_value
    1447     1357037 :                                        IF (my_hide_defaults) CYCLE
    1448             :                                     END IF
    1449             :                                  ELSE
    1450     2058740 :                                     val => new_pos%first_el
    1451             :                                  END IF
    1452     2065852 :                                  IF (keyword%names(1) /= '_DEFAULT_KEYWORD_' .AND. &
    1453             :                                      keyword%names(1) /= '_SECTION_PARAMETERS_') THEN
    1454             :                                     WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//",a,' ')", advance="NO") &
    1455      486965 :                                        TRIM(keyword%names(1))
    1456     1578887 :                                  ELSEIF (keyword%names(1) == '_DEFAULT_KEYWORD_' .AND. &
    1457             :                                          keyword%type_of_var /= lchar_t) THEN
    1458      589886 :                                     WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//")", advance="NO")
    1459             :                                  END IF
    1460             :                                  CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, &
    1461     5486401 :                                                 fmt=myfmt)
    1462             :                               END DO
    1463           0 :                            ELSEIF (ASSOCIATED(keyword%default_value)) THEN
    1464             :                               ! Section was not parsed but default for the keywords may exist
    1465           0 :                               IF (my_hide_defaults) CYCLE
    1466           0 :                               val => keyword%default_value
    1467           0 :                               IF (keyword%names(1) /= '_DEFAULT_KEYWORD_' .AND. &
    1468             :                                   keyword%names(1) /= '_SECTION_PARAMETERS_') THEN
    1469             :                                  WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//",a,' ')", advance="NO") &
    1470           0 :                                     TRIM(keyword%names(1))
    1471           0 :                               ELSEIF (keyword%names(1) == '_DEFAULT_KEYWORD_' .AND. &
    1472             :                                       keyword%type_of_var /= lchar_t) THEN
    1473           0 :                                  WRITE (unit=unit_nr, fmt="("//TRIM(myfmt)//")", advance="NO")
    1474             :                               END IF
    1475             :                               CALL val_write(val, unit_nr=unit_nr, unit=keyword%unit, &
    1476           0 :                                              fmt=myfmt)
    1477             :                            END IF
    1478             :                         END IF
    1479             :                      END IF
    1480             :                   END DO
    1481      281769 :                   IF (ASSOCIATED(section_vals%subs_vals)) THEN
    1482     2321031 :                      DO isec = 1, SIZE(section_vals%subs_vals, 1)
    1483     2039262 :                         sval => section_vals%subs_vals(isec, i_rep_s)%section_vals
    1484     2321031 :                         IF (ASSOCIATED(sval)) THEN
    1485     2039262 :                            CALL section_vals_write(sval, unit_nr=unit_nr, hide_defaults=hide_defaults)
    1486             :                         END IF
    1487             :                      END DO
    1488             :                   END IF
    1489             :                END IF
    1490     2329327 :                IF (.NOT. my_hide_root) THEN
    1491      273473 :                   indent = indent - 2
    1492           0 :                   WRITE (UNIT=unit_nr, FMT="(A)") &
    1493     1739204 :                      REPEAT(" ", indent)//"&END "//TRIM(section%name)
    1494             :                END IF
    1495             :             END DO
    1496             :          END IF
    1497             :       END IF
    1498             : 
    1499     2047573 :    END SUBROUTINE section_vals_write
    1500             : 
    1501             : ! **************************************************************************************************
    1502             : !> \brief writes the values in the given section in xml
    1503             : !> \param section ...
    1504             : !> \param level ...
    1505             : !> \param unit_number ...
    1506             : ! **************************************************************************************************
    1507           0 :    RECURSIVE SUBROUTINE write_section_xml(section, level, unit_number)
    1508             : 
    1509             :       TYPE(section_type), POINTER                        :: section
    1510             :       INTEGER, INTENT(IN)                                :: level, unit_number
    1511             : 
    1512             :       CHARACTER(LEN=3)                                   :: repeats
    1513             :       CHARACTER(LEN=8)                                   :: short_string
    1514             :       INTEGER                                            :: i, l0, l1, l2
    1515             : 
    1516           0 :       IF (ASSOCIATED(section)) THEN
    1517             : 
    1518           0 :          CPASSERT(section%ref_count > 0)
    1519             : 
    1520             :          ! Indentation for current level, next level, etc.
    1521             : 
    1522           0 :          l0 = level
    1523           0 :          l1 = level + 1
    1524           0 :          l2 = level + 2
    1525             : 
    1526           0 :          IF (section%repeats) THEN
    1527           0 :             repeats = "yes"
    1528             :          ELSE
    1529           0 :             repeats = "no "
    1530             :          END IF
    1531             : 
    1532           0 :          WRITE (UNIT=unit_number, FMT="(A)") &
    1533           0 :             REPEAT(" ", l0)//"<SECTION repeats="""//TRIM(repeats)//""">", &
    1534           0 :             REPEAT(" ", l1)//"<NAME>"//TRIM(section%name)//"</NAME>", &
    1535             :             REPEAT(" ", l1)//"<DESCRIPTION>"// &
    1536             :             TRIM(substitute_special_xml_tokens(a2s(section%description))) &
    1537           0 :             //"</DESCRIPTION>"
    1538             : 
    1539           0 :          IF (ASSOCIATED(section%citations)) THEN
    1540           0 :             DO i = 1, SIZE(section%citations, 1)
    1541           0 :                short_string = ""
    1542           0 :                WRITE (UNIT=short_string, FMT="(I8)") section%citations(i)
    1543           0 :                WRITE (UNIT=unit_number, FMT="(A)") &
    1544           0 :                   REPEAT(" ", l1)//"<REFERENCE>", &
    1545           0 :                   REPEAT(" ", l2)//"<NAME>"//TRIM(get_citation_key(section%citations(i)))//"</NAME>", &
    1546           0 :                   REPEAT(" ", l2)//"<NUMBER>"//TRIM(ADJUSTL(short_string))//"</NUMBER>", &
    1547           0 :                   REPEAT(" ", l1)//"</REFERENCE>"
    1548             :             END DO
    1549             :          END IF
    1550             : 
    1551           0 :          WRITE (UNIT=unit_number, FMT="(A)") &
    1552           0 :             REPEAT(" ", l1)//"<LOCATION>"//TRIM(section%location)//"</LOCATION>"
    1553             : 
    1554           0 :          DO i = -1, section%n_keywords
    1555           0 :             IF (ASSOCIATED(section%keywords(i)%keyword)) THEN
    1556           0 :                CALL write_keyword_xml(section%keywords(i)%keyword, l1, unit_number)
    1557             :             END IF
    1558             :          END DO
    1559             : 
    1560           0 :          DO i = 1, section%n_subsections
    1561           0 :             CALL write_section_xml(section%subsections(i)%section, l1, unit_number)
    1562             :          END DO
    1563             : 
    1564           0 :          WRITE (UNIT=unit_number, FMT="(A)") REPEAT(" ", l0)//"</SECTION>"
    1565             : 
    1566             :       END IF
    1567             : 
    1568           0 :    END SUBROUTINE write_section_xml
    1569             : 
    1570             : ! **************************************************************************************************
    1571             : !> \brief ...
    1572             : !> \param section ...
    1573             : !> \param section_name ...
    1574             : !> \param unknown_string ...
    1575             : !> \param location_string ...
    1576             : !> \param matching_rank ...
    1577             : !> \param matching_string ...
    1578             : !> \param bonus ...
    1579             : ! **************************************************************************************************
    1580           0 :    RECURSIVE SUBROUTINE section_typo_match(section, section_name, unknown_string, location_string, &
    1581           0 :                                            matching_rank, matching_string, bonus)
    1582             : 
    1583             :       TYPE(section_type), INTENT(IN), POINTER            :: section
    1584             :       CHARACTER(LEN=*)                                   :: section_name, unknown_string, &
    1585             :                                                             location_string
    1586             :       INTEGER, DIMENSION(:), INTENT(INOUT)               :: matching_rank
    1587             :       CHARACTER(LEN=*), DIMENSION(:), INTENT(INOUT)      :: matching_string
    1588             :       INTEGER, INTENT(IN)                                :: bonus
    1589             : 
    1590           0 :       CHARACTER(LEN=LEN(matching_string(1)))             :: line
    1591             :       INTEGER                                            :: i, imatch, imax, irank, newbonus
    1592             : 
    1593           0 :       IF (ASSOCIATED(section)) THEN
    1594           0 :          CPASSERT(section%ref_count > 0)
    1595           0 :          imatch = typo_match(TRIM(section%name), TRIM(unknown_string))
    1596           0 :          IF (imatch > 0) THEN
    1597           0 :             imatch = imatch + bonus
    1598           0 :             WRITE (line, '(T2,A)') " subsection "//TRIM(section%name)//" in section "//TRIM(location_string)
    1599           0 :             imax = SIZE(matching_rank, 1)
    1600           0 :             irank = imax + 1
    1601           0 :             DO I = imax, 1, -1
    1602           0 :                IF (imatch > matching_rank(I)) irank = i
    1603             :             END DO
    1604           0 :             IF (irank <= imax) THEN
    1605           0 :                matching_rank(irank + 1:imax) = matching_rank(irank:imax - 1)
    1606           0 :                matching_string(irank + 1:imax) = matching_string(irank:imax - 1)
    1607           0 :                matching_rank(irank) = imatch
    1608           0 :                matching_string(irank) = line
    1609             :             END IF
    1610             :          END IF
    1611             : 
    1612           0 :          IF (section_name == section%name) THEN
    1613           0 :             newbonus = 10
    1614             :          ELSE
    1615           0 :             newbonus = 0
    1616             :          END IF
    1617             : 
    1618           0 :          DO i = -1, section%n_keywords
    1619           0 :             IF (ASSOCIATED(section%keywords(i)%keyword)) THEN
    1620             :                CALL keyword_typo_match(section%keywords(i)%keyword, unknown_string, location_string// &
    1621           0 :                                        "%"//TRIM(section%name), matching_rank, matching_string, newbonus)
    1622             :             END IF
    1623             :          END DO
    1624             : 
    1625           0 :          DO i = 1, section%n_subsections
    1626             :             CALL section_typo_match(section%subsections(i)%section, section_name, unknown_string, &
    1627           0 :                                     location_string//"%"//TRIM(section%name), matching_rank, matching_string, newbonus)
    1628             :          END DO
    1629             : 
    1630             :       END IF
    1631             : 
    1632           0 :    END SUBROUTINE section_typo_match
    1633             : 
    1634             : ! **************************************************************************************************
    1635             : !> \brief replaces of the requested subsection with the one given
    1636             : !> \param section_vals the root section
    1637             : !> \param subsection_name the name of the subsection to replace
    1638             : !> \param new_section_vals the new section_vals to use
    1639             : !> \param i_rep_section index of the repetition of section_vals of which
    1640             : !>        you want to replace the subsection (defaults to 1)
    1641             : !> \author fawzi
    1642             : ! **************************************************************************************************
    1643       16063 :    SUBROUTINE section_vals_set_subs_vals(section_vals, subsection_name, &
    1644             :                                          new_section_vals, i_rep_section)
    1645             :       TYPE(section_vals_type), POINTER                   :: section_vals
    1646             :       CHARACTER(len=*), INTENT(in)                       :: subsection_name
    1647             :       TYPE(section_vals_type), POINTER                   :: new_section_vals
    1648             :       INTEGER, INTENT(in), OPTIONAL                      :: i_rep_section
    1649             : 
    1650             :       INTEGER                                            :: irep, isection, len_key, my_index, &
    1651             :                                                             tmp_index
    1652             :       TYPE(section_vals_type), POINTER                   :: s_vals
    1653             : 
    1654       16063 :       CPASSERT(ASSOCIATED(section_vals))
    1655       16063 :       CPASSERT(section_vals%ref_count > 0)
    1656       16063 :       CPASSERT(ASSOCIATED(new_section_vals))
    1657       16063 :       CPASSERT(new_section_vals%ref_count > 0)
    1658             : 
    1659       16063 :       irep = 1
    1660       16063 :       IF (PRESENT(i_rep_section)) irep = i_rep_section
    1661             : 
    1662       16063 :       my_index = INDEX(subsection_name, '%') + 1
    1663       16063 :       len_key = LEN_TRIM(subsection_name)
    1664       16063 :       IF (my_index > 1) THEN
    1665       17315 :          DO
    1666       31586 :             tmp_index = INDEX(subsection_name(my_index:len_key), "%")
    1667       31586 :             IF (tmp_index <= 0) EXIT
    1668       17315 :             my_index = my_index + tmp_index
    1669             :          END DO
    1670       14271 :          s_vals => section_vals_get_subs_vals(section_vals, subsection_name(1:my_index - 2))
    1671             :       ELSE
    1672        1792 :          s_vals => section_vals
    1673             :       END IF
    1674             : 
    1675       16063 :       CPASSERT(irep <= SIZE(s_vals%subs_vals, 2))
    1676             : 
    1677       16063 :       isection = section_get_subsection_index(s_vals%section, subsection_name(my_index:LEN_TRIM(subsection_name)))
    1678       16063 :       IF (isection <= 0) &
    1679             :          CALL cp_abort(__LOCATION__, &
    1680             :                        "could not find subsection "//subsection_name(my_index:LEN_TRIM(subsection_name))//" in section "// &
    1681           0 :                        TRIM(section_vals%section%name)//" at ")
    1682       16063 :       CALL section_vals_retain(new_section_vals)
    1683       16063 :       CALL section_vals_release(s_vals%subs_vals(isection, irep)%section_vals)
    1684       16063 :       s_vals%subs_vals(isection, irep)%section_vals => new_section_vals
    1685             : 
    1686       16063 :    END SUBROUTINE section_vals_set_subs_vals
    1687             : 
    1688             : ! **************************************************************************************************
    1689             : !> \brief creates a deep copy from section_vals_in to section_vals_out
    1690             : !> \param section_vals_in the section_vals to copy
    1691             : !> \param section_vals_out the section_vals to create
    1692             : !> \param i_rep_start ...
    1693             : !> \param i_rep_end ...
    1694             : !> \author fawzi
    1695             : ! **************************************************************************************************
    1696        1189 :    SUBROUTINE section_vals_duplicate(section_vals_in, section_vals_out, &
    1697             :                                      i_rep_start, i_rep_end)
    1698             :       TYPE(section_vals_type), POINTER                   :: section_vals_in, section_vals_out
    1699             :       INTEGER, INTENT(IN), OPTIONAL                      :: i_rep_start, i_rep_end
    1700             : 
    1701        1189 :       CPASSERT(ASSOCIATED(section_vals_in))
    1702        1189 :       CPASSERT(.NOT. ASSOCIATED(section_vals_out))
    1703        1189 :       CALL section_vals_create(section_vals_out, section_vals_in%section)
    1704        1189 :       CALL section_vals_copy(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
    1705        1189 :    END SUBROUTINE section_vals_duplicate
    1706             : 
    1707             : ! **************************************************************************************************
    1708             : !> \brief deep copy from section_vals_in to section_vals_out
    1709             : !> \param section_vals_in the section_vals to copy
    1710             : !> \param section_vals_out the section_vals where to copy
    1711             : !> \param i_rep_low ...
    1712             : !> \param i_rep_high ...
    1713             : !> \author fawzi
    1714             : !> \note
    1715             : !>      private, only works with a newly initialized section_vals_out
    1716             : ! **************************************************************************************************
    1717     3733073 :    RECURSIVE SUBROUTINE section_vals_copy(section_vals_in, section_vals_out, &
    1718             :                                           i_rep_low, i_rep_high)
    1719             :       TYPE(section_vals_type), POINTER                   :: section_vals_in, section_vals_out
    1720             :       INTEGER, INTENT(IN), OPTIONAL                      :: i_rep_low, i_rep_high
    1721             : 
    1722             :       INTEGER                                            :: iend, irep, isec, istart, ival
    1723             :       TYPE(cp_sll_val_type), POINTER                     :: v1, v2
    1724             :       TYPE(val_type), POINTER                            :: el
    1725             : 
    1726     3733073 :       NULLIFY (v2, el)
    1727             : 
    1728     3733073 :       CPASSERT(ASSOCIATED(section_vals_in))
    1729     3733073 :       CPASSERT(ASSOCIATED(section_vals_out))
    1730             :       !  IF(section_vals_in%section%id_nr/=section_vals_out%section%id_nr)&
    1731             :       !     CPABORT("")
    1732             : 
    1733     3733073 :       istart = 1
    1734     3733073 :       iend = SIZE(section_vals_in%values, 2)
    1735     3733073 :       IF (PRESENT(i_rep_low)) istart = i_rep_low
    1736     3733073 :       IF (PRESENT(i_rep_high)) iend = i_rep_high
    1737     3748376 :       DO irep = istart, iend
    1738       15303 :          CALL section_vals_add_values(section_vals_out)
    1739     3928745 :          DO ival = LBOUND(section_vals_in%values, 1), UBOUND(section_vals_in%values, 1)
    1740      149763 :             v1 => section_vals_in%values(ival, irep)%list
    1741      165066 :             IF (ASSOCIATED(v1)) THEN
    1742       31071 :                CALL val_duplicate(v1%first_el, el)
    1743       31071 :                CALL cp_sll_val_create(v2, el)
    1744       31071 :                NULLIFY (el)
    1745       31071 :                section_vals_out%values(ival, irep - istart + 1)%list => v2
    1746       45938 :                DO
    1747       77009 :                   IF (.NOT. ASSOCIATED(v1%rest)) EXIT
    1748       45938 :                   v1 => v1%rest
    1749       45938 :                   CALL val_duplicate(v1%first_el, el)
    1750       45938 :                   CALL cp_sll_val_create(v2%rest, first_el=el)
    1751       45938 :                   NULLIFY (el)
    1752       45938 :                   v2 => v2%rest
    1753             :                END DO
    1754             :             END IF
    1755             :          END DO
    1756             :       END DO
    1757     3733073 :       IF (.NOT. PRESENT(i_rep_low) .AND. (.NOT. PRESENT(i_rep_high))) THEN
    1758     3732569 :          IF (.NOT. (SIZE(section_vals_in%values, 2) == SIZE(section_vals_out%values, 2))) &
    1759           0 :             CPABORT("")
    1760     3732569 :          IF (.NOT. (SIZE(section_vals_in%subs_vals, 2) == SIZE(section_vals_out%subs_vals, 2))) &
    1761           0 :             CPABORT("")
    1762             :       END IF
    1763     3733073 :       iend = SIZE(section_vals_in%subs_vals, 2)
    1764     3733073 :       IF (PRESENT(i_rep_high)) iend = i_rep_high
    1765     7467275 :       DO irep = istart, iend
    1766    11199159 :          DO isec = 1, SIZE(section_vals_in%subs_vals, 1)
    1767             :             CALL section_vals_copy(section_vals_in%subs_vals(isec, irep)%section_vals, &
    1768     7466086 :                                    section_vals_out%subs_vals(isec, irep - istart + 1)%section_vals)
    1769             :          END DO
    1770             :       END DO
    1771     3733073 :    END SUBROUTINE section_vals_copy
    1772             : 
    1773           0 : END MODULE input_section_types

Generated by: LCOV version 1.15