| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! PR fortran/90608 |
| 4 |
! Check the correct behaviour of the inline MINLOC implementation, |
| 5 |
! when there is a mask argument. |
| 6 |
|
| 7 |
program p |
| 8 |
implicit none |
| 9 |
integer, parameter :: data10(*) = (/ 2, 5, 2, 3, 3, 5, 3, 6, 0, 1 /) |
| 10 |
logical, parameter :: mask10(*) = (/ .false., .true., .false., & |
| 11 |
.false., .true., .true., & |
| 12 |
.true. , .true., .false., & |
| 13 |
.false. /) |
| 14 |
integer, parameter :: data64(*) = (/ 7, 4, 5, 3, 9, 0, 6, 4, & |
| 15 |
5, 5, 8, 2, 6, 7, 8, 7, & |
| 16 |
4, 5, 3, 9, 0, 6, 4, 5, & |
| 17 |
5, 8, 2, 6, 7, 8, 7, 4, & |
| 18 |
5, 3, 9, 0, 6, 4, 5, 5, & |
| 19 |
8, 2, 6, 7, 8, 7, 4, 5, & |
| 20 |
3, 9, 0, 6, 4, 5, 5, 8, & |
| 21 |
2, 6, 7, 8, 7, 4, 5, 3 /) |
| 22 |
logical, parameter :: mask64(*) = (/ .true. , .false., .false., .false., & |
| 23 |
.true. , .false., .true. , .false., & |
| 24 |
.false., .true. , .true. , .false., & |
| 25 |
.true. , .true. , .true. , .true. , & |
| 26 |
.false., .true. , .false., .true. , & |
| 27 |
.false., .true. , .false., .true. , & |
| 28 |
.true. , .false., .false., .true. , & |
| 29 |
.true. , .true. , .true. , .false., & |
| 30 |
.false., .false., .true. , .false., & |
| 31 |
.true. , .false., .true. , .true. , & |
| 32 |
.true. , .false., .true. , .true. , & |
| 33 |
.false., .true. , .false., .true. , & |
| 34 |
.false., .true. , .false., .false., & |
| 35 |
.false., .true. , .true. , .true. , & |
| 36 |
.false., .true. , .false., .true. , & |
| 37 |
.true. , .false., .false., .false. /) |
| 38 |
call check_int_const_shape_rank_1 |
| 39 |
call check_int_const_shape_rank_3 |
| 40 |
call check_int_const_shape_rank_3_true_mask |
| 41 |
call check_int_const_shape_rank_3_false_mask |
| 42 |
call check_int_const_shape_rank_3_optional_mask_present |
| 43 |
call check_int_const_shape_rank_3_optional_mask_absent |
| 44 |
call check_int_const_shape_empty_4 |
| 45 |
call check_int_alloc_rank_1 |
| 46 |
call check_int_alloc_rank_3 |
| 47 |
call check_int_alloc_rank_3_true_mask |
| 48 |
call check_int_alloc_rank_3_false_mask |
| 49 |
call check_int_alloc_empty_4 |
| 50 |
call check_real_const_shape_rank_1 |
| 51 |
call check_real_const_shape_rank_3 |
| 52 |
call check_real_const_shape_rank_3_true_mask |
| 53 |
call check_real_const_shape_rank_3_false_mask |
| 54 |
call check_real_const_shape_rank_3_optional_mask_present |
| 55 |
call check_real_const_shape_rank_3_optional_mask_absent |
| 56 |
call check_real_const_shape_empty_4 |
| 57 |
call check_real_alloc_rank_1 |
| 58 |
call check_real_alloc_rank_3 |
| 59 |
call check_real_alloc_rank_3_true_mask |
| 60 |
call check_real_alloc_rank_3_false_mask |
| 61 |
call check_real_alloc_empty_4 |
| 62 |
call check_lower_bounds |
| 63 |
call check_dependencies |
| 64 |
contains |
| 65 |
subroutine check_int_const_shape_rank_1() |
| 66 |
integer :: a(10) |
| 67 |
logical :: m(10) |
| 68 |
integer, allocatable :: r(:) |
| 69 |
a = data10 |
| 70 |
m = mask10 |
| 71 |
r = minloc(a, mask = m) |
| 72 |
if (size(r, dim = 1) /= 1) stop 11 |
| 73 |
if (any(r /= (/ 5 /))) stop 12 |
| 74 |
end subroutine |
| 75 |
subroutine check_int_const_shape_rank_3() |
| 76 |
integer :: a(4,4,4) |
| 77 |
logical :: m(4,4,4) |
| 78 |
integer, allocatable :: r(:) |
| 79 |
a = reshape(data64, shape(a)) |
| 80 |
m = reshape(mask64, shape(m)) |
| 81 |
r = minloc(a, mask = m) |
| 82 |
if (size(r, dim = 1) /= 3) stop 21 |
| 83 |
if (any(r /= (/ 2, 3, 1 /))) stop 22 |
| 84 |
end subroutine |
| 85 |
subroutine check_int_const_shape_rank_3_true_mask() |
| 86 |
integer :: a(4,4,4) |
| 87 |
integer, allocatable :: r(:) |
| 88 |
a = reshape(data64, shape(a)) |
| 89 |
r = minloc(a, mask = .true.) |
| 90 |
if (size(r, dim = 1) /= 3) stop 31 |
| 91 |
if (any(r /= (/ 2, 2, 1 /))) stop 32 |
| 92 |
end subroutine |
| 93 |
subroutine check_int_const_shape_rank_3_false_mask() |
| 94 |
integer :: a(4,4,4) |
| 95 |
integer, allocatable :: r(:) |
| 96 |
a = reshape(data64, shape(a)) |
| 97 |
r = minloc(a, mask = .false.) |
| 98 |
if (size(r, dim = 1) /= 3) stop 41 |
| 99 |
if (any(r /= (/ 0, 0, 0 /))) stop 42 |
| 100 |
end subroutine |
| 101 |
subroutine call_minloc_int(r, a, m) |
| 102 |
integer :: a(:,:,:) |
| 103 |
logical, optional :: m(:,:,:) |
| 104 |
integer, allocatable :: r(:) |
| 105 |
r = minloc(a, mask = m) |
| 106 |
end subroutine |
| 107 |
subroutine check_int_const_shape_rank_3_optional_mask_present() |
| 108 |
integer :: a(4,4,4) |
| 109 |
logical :: m(4,4,4) |
| 110 |
integer, allocatable :: r(:) |
| 111 |
a = reshape(data64, shape(a)) |
| 112 |
m = reshape(mask64, shape(m)) |
| 113 |
call call_minloc_int(r, a, m) |
| 114 |
if (size(r, dim = 1) /= 3) stop 51 |
| 115 |
if (any(r /= (/ 2, 3, 1 /))) stop 52 |
| 116 |
end subroutine |
| 117 |
subroutine check_int_const_shape_rank_3_optional_mask_absent() |
| 118 |
integer :: a(4,4,4) |
| 119 |
integer, allocatable :: r(:) |
| 120 |
a = reshape(data64, shape(a)) |
| 121 |
call call_minloc_int(r, a) |
| 122 |
if (size(r, dim = 1) /= 3) stop 61 |
| 123 |
if (any(r /= (/ 2, 2, 1 /))) stop 62 |
| 124 |
end subroutine |
| 125 |
subroutine check_int_const_shape_empty_4() |
| 126 |
integer :: a(9,3,0,7) |
| 127 |
logical :: m(9,3,0,7) |
| 128 |
integer, allocatable :: r(:) |
| 129 |
a = reshape((/ integer:: /), shape(a)) |
| 130 |
m = reshape((/ logical:: /), shape(m)) |
| 131 |
r = minloc(a, mask = m) |
| 132 |
if (size(r, dim = 1) /= 4) stop 71 |
| 133 |
if (any(r /= (/ 0, 0, 0, 0 /))) stop 72 |
| 134 |
end subroutine |
| 135 |
subroutine check_int_alloc_rank_1() |
| 136 |
integer, allocatable :: a(:) |
| 137 |
logical, allocatable :: m(:) |
| 138 |
integer, allocatable :: r(:) |
| 139 |
allocate(a(10), m(10)) |
| 140 |
a(:) = data10 |
| 141 |
m(:) = mask10 |
| 142 |
r = minloc(a, mask = m) |
| 143 |
if (size(r, dim = 1) /= 1) stop 81 |
| 144 |
if (any(r /= (/ 5 /))) stop 82 |
| 145 |
end subroutine |
| 146 |
subroutine check_int_alloc_rank_3() |
| 147 |
integer, allocatable :: a(:,:,:) |
| 148 |
logical, allocatable :: m(:,:,:) |
| 149 |
integer, allocatable :: r(:) |
| 150 |
allocate(a(4,4,4), m(4,4,4)) |
| 151 |
a(:,:,:) = reshape(data64, shape(a)) |
| 152 |
m(:,:,:) = reshape(mask64, shape(m)) |
| 153 |
r = minloc(a, mask = m) |
| 154 |
if (size(r, dim = 1) /= 3) stop 91 |
| 155 |
if (any(r /= (/ 2, 3, 1 /))) stop 92 |
| 156 |
end subroutine |
| 157 |
subroutine check_int_alloc_rank_3_true_mask() |
| 158 |
integer, allocatable :: a(:,:,:) |
| 159 |
integer, allocatable :: r(:) |
| 160 |
allocate(a(4,4,4)) |
| 161 |
a(:,:,:) = reshape(data64, shape(a)) |
| 162 |
r = minloc(a, mask = .true.) |
| 163 |
if (size(r, dim = 1) /= 3) stop 101 |
| 164 |
if (any(r /= (/ 2, 2, 1 /))) stop 102 |
| 165 |
end subroutine |
| 166 |
subroutine check_int_alloc_rank_3_false_mask() |
| 167 |
integer, allocatable :: a(:,:,:) |
| 168 |
integer, allocatable :: r(:) |
| 169 |
allocate(a(4,4,4)) |
| 170 |
a(:,:,:) = reshape(data64, shape(a)) |
| 171 |
r = minloc(a, mask = .false.) |
| 172 |
if (size(r, dim = 1) /= 3) stop 111 |
| 173 |
if (any(r /= (/ 0, 0, 0 /))) stop 112 |
| 174 |
end subroutine |
| 175 |
subroutine check_int_alloc_empty_4() |
| 176 |
integer, allocatable :: a(:,:,:,:) |
| 177 |
logical, allocatable :: m(:,:,:,:) |
| 178 |
integer, allocatable :: r(:) |
| 179 |
allocate(a(9,3,0,7), m(9,3,0,7)) |
| 180 |
a(:,:,:,:) = reshape((/ integer:: /), shape(a)) |
| 181 |
m(:,:,:,:) = reshape((/ logical:: /), shape(m)) |
| 182 |
r = minloc(a, mask = m) |
| 183 |
if (size(r, dim = 1) /= 4) stop 121 |
| 184 |
if (any(r /= (/ 0, 0, 0, 0 /))) stop 122 |
| 185 |
end subroutine |
| 186 |
subroutine check_real_const_shape_rank_1() |
| 187 |
real :: a(10) |
| 188 |
logical :: m(10) |
| 189 |
integer, allocatable :: r(:) |
| 190 |
a = (/ real:: data10 /) |
| 191 |
m = mask10 |
| 192 |
r = minloc(a, mask = m) |
| 193 |
if (size(r, dim = 1) /= 1) stop 131 |
| 194 |
if (any(r /= (/ 5 /))) stop 132 |
| 195 |
end subroutine |
| 196 |
subroutine check_real_const_shape_rank_3() |
| 197 |
real :: a(4,4,4) |
| 198 |
logical :: m(4,4,4) |
| 199 |
integer, allocatable :: r(:) |
| 200 |
a = reshape((/ real:: data64 /), shape(a)) |
| 201 |
m = reshape(mask64, shape(m)) |
| 202 |
r = minloc(a, mask = m) |
| 203 |
if (size(r, dim = 1) /= 3) stop 141 |
| 204 |
if (any(r /= (/ 2, 3, 1 /))) stop 142 |
| 205 |
end subroutine |
| 206 |
subroutine check_real_const_shape_rank_3_true_mask() |
| 207 |
real :: a(4,4,4) |
| 208 |
integer, allocatable :: r(:) |
| 209 |
a = reshape((/ real:: data64 /), shape(a)) |
| 210 |
r = minloc(a, mask = .true.) |
| 211 |
if (size(r, dim = 1) /= 3) stop 151 |
| 212 |
if (any(r /= (/ 2, 2, 1 /))) stop 152 |
| 213 |
end subroutine |
| 214 |
subroutine check_real_const_shape_rank_3_false_mask() |
| 215 |
real :: a(4,4,4) |
| 216 |
integer, allocatable :: r(:) |
| 217 |
a = reshape((/ real:: data64 /), shape(a)) |
| 218 |
r = minloc(a, mask = .false.) |
| 219 |
if (size(r, dim = 1) /= 3) stop 161 |
| 220 |
if (any(r /= (/ 0, 0, 0 /))) stop 162 |
| 221 |
end subroutine |
| 222 |
subroutine call_minloc_real(r, a, m) |
| 223 |
real :: a(:,:,:) |
| 224 |
logical, optional :: m(:,:,:) |
| 225 |
integer, allocatable :: r(:) |
| 226 |
r = minloc(a, mask = m) |
| 227 |
end subroutine |
| 228 |
subroutine check_real_const_shape_rank_3_optional_mask_present() |
| 229 |
real :: a(4,4,4) |
| 230 |
logical :: m(4,4,4) |
| 231 |
integer, allocatable :: r(:) |
| 232 |
a = reshape((/ real:: data64 /), shape(a)) |
| 233 |
m = reshape(mask64, shape(m)) |
| 234 |
call call_minloc_real(r, a, m) |
| 235 |
if (size(r, dim = 1) /= 3) stop 171 |
| 236 |
if (any(r /= (/ 2, 3, 1 /))) stop 172 |
| 237 |
end subroutine |
| 238 |
subroutine check_real_const_shape_rank_3_optional_mask_absent() |
| 239 |
real :: a(4,4,4) |
| 240 |
integer, allocatable :: r(:) |
| 241 |
a = reshape((/ real:: data64 /), shape(a)) |
| 242 |
call call_minloc_real(r, a) |
| 243 |
if (size(r, dim = 1) /= 3) stop 181 |
| 244 |
if (any(r /= (/ 2, 2, 1 /))) stop 182 |
| 245 |
end subroutine |
| 246 |
subroutine check_real_const_shape_empty_4() |
| 247 |
real :: a(9,3,0,7) |
| 248 |
logical :: m(9,3,0,7) |
| 249 |
integer, allocatable :: r(:) |
| 250 |
a = reshape((/ real:: /), shape(a)) |
| 251 |
m = reshape((/ logical:: /), shape(m)) |
| 252 |
r = minloc(a, mask = m) |
| 253 |
if (size(r, dim = 1) /= 4) stop 191 |
| 254 |
if (any(r /= (/ 0, 0, 0, 0 /))) stop 192 |
| 255 |
end subroutine |
| 256 |
subroutine check_real_alloc_rank_1() |
| 257 |
real, allocatable :: a(:) |
| 258 |
logical, allocatable :: m(:) |
| 259 |
integer, allocatable :: r(:) |
| 260 |
allocate(a(10), m(10)) |
| 261 |
a(:) = (/ real:: data10 /) |
| 262 |
m(:) = mask10 |
| 263 |
r = minloc(a, mask = m) |
| 264 |
if (size(r, dim = 1) /= 1) stop 201 |
| 265 |
if (any(r /= (/ 5 /))) stop 202 |
| 266 |
end subroutine |
| 267 |
subroutine check_real_alloc_rank_3() |
| 268 |
real, allocatable :: a(:,:,:) |
| 269 |
logical, allocatable :: m(:,:,:) |
| 270 |
integer, allocatable :: r(:) |
| 271 |
allocate(a(4,4,4), m(4,4,4)) |
| 272 |
a(:,:,:) = reshape((/ real:: data64 /), shape(a)) |
| 273 |
m(:,:,:) = reshape(mask64, shape(m)) |
| 274 |
r = minloc(a, mask = m) |
| 275 |
if (size(r, dim = 1) /= 3) stop 211 |
| 276 |
if (any(r /= (/ 2, 3, 1 /))) stop 212 |
| 277 |
end subroutine |
| 278 |
subroutine check_real_alloc_rank_3_true_mask() |
| 279 |
real, allocatable :: a(:,:,:) |
| 280 |
integer, allocatable :: r(:) |
| 281 |
allocate(a(4,4,4)) |
| 282 |
a(:,:,:) = reshape((/ real:: data64 /), shape(a)) |
| 283 |
r = minloc(a, mask = .true.) |
| 284 |
if (size(r, dim = 1) /= 3) stop 221 |
| 285 |
if (any(r /= (/ 2, 2, 1 /))) stop 222 |
| 286 |
end subroutine |
| 287 |
subroutine check_real_alloc_rank_3_false_mask() |
| 288 |
real, allocatable :: a(:,:,:) |
| 289 |
integer, allocatable :: r(:) |
| 290 |
allocate(a(4,4,4)) |
| 291 |
a(:,:,:) = reshape((/ real:: data64 /), shape(a)) |
| 292 |
r = minloc(a, mask = .false.) |
| 293 |
if (size(r, dim = 1) /= 3) stop 231 |
| 294 |
if (any(r /= (/ 0, 0, 0 /))) stop 232 |
| 295 |
end subroutine |
| 296 |
subroutine check_real_alloc_empty_4() |
| 297 |
real, allocatable :: a(:,:,:,:) |
| 298 |
logical, allocatable :: m(:,:,:,:) |
| 299 |
integer, allocatable :: r(:) |
| 300 |
allocate(a(9,3,0,7), m(9,3,0,7)) |
| 301 |
a(:,:,:,:) = reshape((/ real:: /), shape(a)) |
| 302 |
m(:,:,:,:) = reshape((/ logical :: /), shape(m)) |
| 303 |
r = minloc(a, mask = m) |
| 304 |
if (size(r, dim = 1) /= 4) stop 241 |
| 305 |
if (any(r /= (/ 0, 0, 0, 0 /))) stop 242 |
| 306 |
end subroutine |
| 307 |
subroutine check_lower_bounds() |
| 308 |
real, allocatable :: a(:,:,:) |
| 309 |
logical, allocatable :: m(:,:,:) |
| 310 |
integer, allocatable :: r(:) |
| 311 |
allocate(a(3:6,-1:2,4), m(3:6,-1:2,4)) |
| 312 |
a(:,:,:) = reshape((/ real:: data64 /), shape(a)) |
| 313 |
m = reshape(mask64, shape(m)) |
| 314 |
r = minloc(a, mask = m) |
| 315 |
if (size(r, dim = 1) /= 3) stop 251 |
| 316 |
if (any(r /= (/ 2, 3, 1 /))) stop 252 |
| 317 |
end subroutine |
| 318 |
elemental subroutine set(o, i) |
| 319 |
integer, intent(out) :: o |
| 320 |
integer, intent(in) :: i |
| 321 |
o = i |
| 322 |
end subroutine |
| 323 |
subroutine check_dependencies() |
| 324 |
integer, allocatable :: a(:,:,:) |
| 325 |
allocate(a(3,3,3)) |
| 326 |
! Direct assignment |
| 327 |
a(:,:,:) = reshape(data64(1:27), shape(a)) |
| 328 |
a(1,1,:) = minloc(a, mask=a<8) |
| 329 |
if (any(a(1,1,:) /= (/ 3, 2, 1 /))) stop 171 |
| 330 |
a(:,:,:) = reshape(data64(2:28), shape(a)) |
| 331 |
a(3,3,:) = minloc(a, mask=a<8) |
| 332 |
if (any(a(3,3,:) /= (/ 2, 2, 1 /))) stop 172 |
| 333 |
a(:,:,:) = reshape(data64(3:29), shape(a)) |
| 334 |
a(1,:,1) = minloc(a, mask=a<8) |
| 335 |
if (any(a(1,:,1) /= (/ 1, 2, 1 /))) stop 173 |
| 336 |
a(:,:,:) = reshape(data64(5:31), shape(a)) |
| 337 |
a(2,:,2) = minloc(a, mask=a<8) |
| 338 |
if (any(a(2,:,2) /= (/ 2, 1, 1 /))) stop 174 |
| 339 |
a(:,:,:) = reshape(data64(6:32), shape(a)) |
| 340 |
a(3,:,3) = minloc(a, mask=a<8) |
| 341 |
if (any(a(3,:,3) /= (/ 1, 1, 1 /))) stop 175 |
| 342 |
a(:,:,:) = reshape(data64(7:33), shape(a)) |
| 343 |
a(:,1,1) = minloc(a, mask=a<8) |
| 344 |
if (any(a(:,1,1) /= (/ 3, 2, 2 /))) stop 176 |
| 345 |
a(:,:,:) = reshape(data64(8:34), shape(a)) |
| 346 |
a(:,3,3) = minloc(a, mask=a<8) |
| 347 |
if (any(a(:,3,3) /= (/ 2, 2, 2 /))) stop 177 |
| 348 |
! Subroutine assignment |
| 349 |
a(:,:,:) = reshape(data64(9:35), shape(a)) |
| 350 |
call set(a(1,1,:), minloc(a, mask=a<8)) |
| 351 |
if (any(a(1,1,:) /= (/ 1, 2, 2 /))) stop 181 |
| 352 |
a(:,:,:) = reshape(data64(10:36), shape(a)) |
| 353 |
call set(a(3,3,:), minloc(a, mask=a<8)) |
| 354 |
if (any(a(3,3,:) /= (/ 3, 1, 2 /))) stop 182 |
| 355 |
a(:,:,:) = reshape(data64(11:37), shape(a)) |
| 356 |
call set(a(1,:,1), minloc(a, mask=a<8)) |
| 357 |
if (any(a(1,:,1) /= (/ 2, 1, 2 /))) stop 183 |
| 358 |
a(:,:,:) = reshape(data64(12:38), shape(a)) |
| 359 |
call set(a(2,:,2), minloc(a, mask=a<8)) |
| 360 |
if (any(a(2,:,2) /= (/ 1, 1, 2 /))) stop 184 |
| 361 |
a(:,:,:) = reshape(data64(13:39), shape(a)) |
| 362 |
call set(a(3,:,3), minloc(a, mask=a<8)) |
| 363 |
if (any(a(3,:,3) /= (/ 3, 3, 1 /))) stop 185 |
| 364 |
a(:,:,:) = reshape(data64(14:40), shape(a)) |
| 365 |
call set(a(:,1,1), minloc(a, mask=a<8)) |
| 366 |
if (any(a(:,1,1) /= (/ 2, 3, 1 /))) stop 186 |
| 367 |
a(:,:,:) = reshape(data64(15:41), shape(a)) |
| 368 |
call set(a(:,3,3), minloc(a, mask=a<8)) |
| 369 |
if (any(a(:,3,3) /= (/ 1, 3, 1 /))) stop 187 |
| 370 |
call set(a(1,:,:), minloc(a, dim=1)) |
| 371 |
end subroutine check_dependencies |
| 372 |
end program p |