Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief a module to allow simple internal preprocessing in input files.
10 : !> \par History
11 : !> - standalone proof-of-concept implementation (20.02.2008,AK)
12 : !> - integration into cp2k (22.02.2008,tlaino)
13 : !> - variables added (25.02.2008,AK)
14 : !> \author Axel Kohlmeyer [AK] - CMM/UPenn Philadelphia
15 : !> \date 25.02.2008
16 : ! **************************************************************************************************
17 : MODULE cp_parser_ilist_methods
18 : USE cp_log_handling, ONLY: cp_to_string
19 : USE cp_parser_ilist_types, ONLY: ilist_type
20 : #include "../base/base_uses.f90"
21 :
22 : IMPLICIT NONE
23 : PRIVATE
24 :
25 : PUBLIC :: ilist_setup, ilist_update, ilist_reset
26 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_parser_ilist_methods'
27 :
28 : CONTAINS
29 :
30 : ! ****************************************************************************
31 : !> \brief setup the integer listing type
32 : !> \param ilist ...
33 : !> \param token ...
34 : !> \date 08.2008
35 : !> \author Teodoro Laino [tlaino] - University of Zurich
36 : ! **************************************************************************************************
37 622 : SUBROUTINE ilist_setup(ilist, token)
38 : TYPE(ilist_type), POINTER :: ilist
39 : CHARACTER(LEN=*) :: token
40 :
41 : INTEGER :: ind
42 :
43 622 : CPASSERT(ASSOCIATED(ilist))
44 622 : ind = INDEX(token, "..")
45 622 : READ (UNIT=token(:ind - 1), FMT=*) ilist%istart
46 622 : READ (UNIT=token(ind + 2:), FMT=*) ilist%iend
47 622 : IF (ilist%istart > ilist%iend) THEN
48 : CALL cp_abort(__LOCATION__, &
49 : "Invalid list range specified: "// &
50 : TRIM(ADJUSTL(cp_to_string(ilist%istart)))//".."// &
51 0 : TRIM(ADJUSTL(cp_to_string(ilist%iend))))
52 : END IF
53 622 : ilist%nel_list = ilist%iend - ilist%istart + 1
54 622 : ilist%ipresent = ilist%istart
55 622 : ilist%in_use = .TRUE.
56 :
57 622 : END SUBROUTINE ilist_setup
58 :
59 : ! ****************************************************************************
60 : !> \brief updates the integer listing type
61 : !> \param ilist ...
62 : !> \date 08.2008
63 : !> \author Teodoro Laino [tlaino] - University of Zurich
64 : ! **************************************************************************************************
65 14308 : SUBROUTINE ilist_update(ilist)
66 : TYPE(ilist_type), POINTER :: ilist
67 :
68 14308 : CPASSERT(ASSOCIATED(ilist))
69 14308 : ilist%ipresent = ilist%ipresent + 1
70 14308 : IF (ilist%ipresent > ilist%iend) THEN
71 0 : CALL ilist_reset(ilist)
72 : END IF
73 14308 : END SUBROUTINE ilist_update
74 :
75 : ! ****************************************************************************
76 : !> \brief updates the integer listing type
77 : !> \param ilist ...
78 : !> \date 08.2008
79 : !> \author Teodoro Laino [tlaino] - University of Zurich
80 : ! **************************************************************************************************
81 14930 : SUBROUTINE ilist_reset(ilist)
82 : TYPE(ilist_type), POINTER :: ilist
83 :
84 14930 : CPASSERT(ASSOCIATED(ilist))
85 14930 : IF (ilist%ipresent == ilist%iend) THEN
86 622 : ilist%istart = HUGE(0)
87 622 : ilist%iend = HUGE(0)
88 622 : ilist%nel_list = HUGE(0)
89 622 : ilist%ipresent = HUGE(0)
90 622 : ilist%in_use = .FALSE.
91 : END IF
92 14930 : END SUBROUTINE ilist_reset
93 :
94 : END MODULE cp_parser_ilist_methods
|