1 | program sample |
---|
2 | call test_int |
---|
3 | call test_real |
---|
4 | |
---|
5 | contains |
---|
6 | subroutine test_int |
---|
7 | use dict_int_mod, only: dict, exists, get_size, get_val, insert_or_assign, remove |
---|
8 | implicit none |
---|
9 | |
---|
10 | type(dict) :: ages ! Initialized empty |
---|
11 | |
---|
12 | call insert_or_assign(ages, "Alice", 28) |
---|
13 | call insert_or_assign(ages, "Bob", 13) |
---|
14 | call insert_or_assign(ages, "Carol", 47) |
---|
15 | call insert_or_assign(ages, "Alice", 35) ! Updated |
---|
16 | |
---|
17 | print *, "Alice is", get_val(ages, "Alice"), "years old" ! 35 |
---|
18 | print *, "Do we know Dave's age?", exists(ages, "Dave") ! False |
---|
19 | |
---|
20 | call remove(ages, "Bob") |
---|
21 | |
---|
22 | print *, "Now we know the ages of", get_size(ages), "people" ! Alice and Caro |
---|
23 | end subroutine test_int |
---|
24 | subroutine test_real |
---|
25 | use dict_real_mod, only: dict, exists, get_size, get_val, insert_or_assign, remove |
---|
26 | implicit none |
---|
27 | |
---|
28 | type(dict) :: ages ! Initialized empty |
---|
29 | |
---|
30 | call insert_or_assign(ages, "Alice", 28.) |
---|
31 | call insert_or_assign(ages, "Bob", 13.) |
---|
32 | call insert_or_assign(ages, "Carol", 47.) |
---|
33 | call insert_or_assign(ages, "Alice", 35.) ! Updated |
---|
34 | |
---|
35 | print *, "Alice is", get_val(ages, "Alice"), "years old" ! 35 |
---|
36 | print *, "Do we know Dave's age?", exists(ages, "Dave") ! False |
---|
37 | |
---|
38 | call remove(ages, "Bob") |
---|
39 | |
---|
40 | print *, "Now we know the ages of", get_size(ages), "people" ! Alice and Caro |
---|
41 | end subroutine test_real |
---|
42 | end program sample |
---|
43 | |
---|