28 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: real_arr
30 ALLOCATE (real_arr(10))
31 real_arr = [(idx, idx=1, 10)]
33 CALL reallocate(real_arr, 1, 20)
35 IF (.NOT. all(real_arr(1:10) == [(idx, idx=1, 10)])) &
36 error stop
"check_real_rank1_allocated: reallocating changed the initial values"
38 IF (.NOT. all(real_arr(11:20) == 0.)) &
39 error stop
"check_real_rank1_allocated: reallocation failed to initialise new values with 0."
43 print *,
"check_real_rank1_allocated: OK"
50 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: real_arr
54 CALL reallocate(real_arr, 1, 20)
56 IF (.NOT. all(real_arr(1:20) == 0.)) &
57 error stop
"check_real_rank1_unallocated: reallocation failed to initialise new values with 0."
61 print *,
"check_real_rank1_unallocated: OK"
69 REAL(KIND=
dp),
DIMENSION(:, :),
POINTER :: real_arr
71 ALLOCATE (real_arr(5, 2))
72 real_arr = reshape([(idx, idx=1, 10)], [5, 2])
74 CALL reallocate(real_arr, 1, 10, 1, 5)
76 IF (.NOT. (all(real_arr(1:5, 1) == [(idx, idx=1, 5)]) .AND. all(real_arr(1:5, 2) == [(idx, idx=6, 10)]))) &
77 error stop
"check_real_rank2_allocated: reallocating changed the initial values"
79 IF (.NOT. (all(real_arr(6:10, 1:2) == 0.) .AND. all(real_arr(1:10, 3:5) == 0.))) &
80 error stop
"check_real_rank2_allocated: reallocation failed to initialise new values with 0."
84 print *,
"check_real_rank1_allocated: OK"
91 REAL(KIND=
dp),
DIMENSION(:, :),
POINTER :: real_arr
95 CALL reallocate(real_arr, 1, 10, 1, 5)
97 IF (.NOT. all(real_arr(1:10, 1:5) == 0.)) &
98 error stop
"check_real_rank2_unallocated: reallocation failed to initialise new values with 0."
100 DEALLOCATE (real_arr)
102 print *,
"check_real_rank2_unallocated: OK"
109 CHARACTER(LEN=12),
DIMENSION(:),
POINTER :: str_arr
112 ALLOCATE (str_arr(10))
113 str_arr = [(
"hello, there", idx=1, 10)]
115 CALL reallocate(str_arr, 1, 20)
117 IF (.NOT. all(str_arr(1:10) == [(
"hello, there", idx=1, 10)])) &
118 error stop
"check_string_rank1_allocated: reallocating changed the initial values"
120 IF (.NOT. all(str_arr(11:20) ==
"")) &
121 error stop
"check_string_rank1_allocated: reallocation failed to initialise new values with ''."
125 print *,
"check_string_rank1_allocated: OK"
132 CHARACTER(LEN=12),
DIMENSION(:),
POINTER :: str_arr
136 CALL reallocate(str_arr, 1, 20)
138 IF (.NOT. all(str_arr(1:20) ==
"")) &
139 error stop
"check_string_rank1_allocated: reallocation failed to initialise new values with ''."
143 print *,
"check_string_rank1_unallocated: OK"
program memory_utilities_test
subroutine check_string_rank1_allocated()
Check that an allocated string array can be extended.
subroutine check_real_rank2_allocated()
Check that an allocated r2 array can be extended.
subroutine check_real_rank2_unallocated()
Check that an unallocated and unassociated (null) r2 array can be extended.
subroutine check_string_rank1_unallocated()
Check that an unallocated string array can be extended.
subroutine check_real_rank1_allocated()
Check that an allocated r1 array can be extended.
subroutine check_real_rank1_unallocated()
Check that an unallocated and unassociated (null) r1 array can be extended.
Defines the basic variable types.
integer, parameter, public dp
Utility routines for the memory handling.