MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_phys_dict.t
Go to the documentation of this file.
1!> Quick module that mimics the behaviour of python dictionaries for passing attributes around
2!> without explicit dependencies
3
4!> Jack Jenkins Dec 2025
5
8
9 implicit none
10 private
11
13 character(len=std_len) :: physics_type
14 integer :: n = 0
15 character(len=std_len), allocatable :: keys(:)
16 logical, allocatable :: values(:)
17 end type phys_dict
18
20
21contains
22
23 subroutine set_dict_flag(d, key, val)
24 type(phys_dict), intent(inout) :: d
25 character(len=*), intent(in) :: key
26 logical, intent(in) :: val
27
28 character(len=std_len), allocatable :: new_keys(:)
29 logical, allocatable :: new_values(:)
30
31 integer :: i
32
33 !> If key exists, update it
34 do i = 1, d%n
35 if (trim(d%keys(i)) == trim(key)) then
36 d%values(i) = val
37 return
38 end if
39 end do
40
41 !> Otherwise, append
42 if (.not. allocated(d%keys)) then
43 allocate(d%keys(1))
44 allocate(d%values(1))
45 d%n = 1
46 d%keys(1) = trim(key)
47 d%values(1)= val
48 else
49 !> Extend by 1
50
51 allocate(new_keys(d%n+1))
52 allocate(new_values(d%n+1))
53
54 new_keys(1:d%n) = d%keys
55 new_values(1:d%n) = d%values
56
57 new_keys(d%n+1) = trim(key)
58 new_values(d%n+1) = val
59
60 call move_alloc(new_keys, d%keys)
61 call move_alloc(new_values, d%values)
62
63 d%n = d%n + 1
64 end if
65 end subroutine set_dict_flag
66
67
68 function get_dict_flag(d, key) result(val)
69 type(phys_dict), intent(in) :: d
70 character(len=*), intent(in) :: key
71 logical :: val
72
73 integer :: i
74
75 do i = 1, d%n
76 if (trim(d%keys(i)) == trim(key)) then
77 val = d%values(i)
78 return
79 end if
80 end do
81 !> If key not found, return false
82 val = .false.
83 end function get_dict_flag
84
85end module mod_phys_dict
This module contains definitions of global parameters and variables and some generic functions/subrou...
double precision, dimension(:), allocatable, parameter d
Quick module that mimics the behaviour of python dictionaries for passing attributes around without e...
logical function, public get_dict_flag(d, key)
subroutine, public set_dict_flag(d, key, val)