Skip to content

Commit 49eb64c

Browse files
marshallwardHallberg-NOAA
authored andcommitted
Fix rotation in set_coupler_type_data
`rotate_array` in `set_coupler_type_data` was trying to rotate an array to another of different size when `idim` and `jdim` are present. Some compilers seemed to let this through, but it raised a double-deallocation error in GCC. I'm guessing it's because the rotation was implicitly allocating to a new array which was automatically deallocated. But I did not confirm this. This was modified to rotate onto a new array of the same size. The `idim` and `jdim` are passed to `CT_set_data`, which (hopefully) sorts out the indexing.
1 parent 576fb41 commit 49eb64c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/framework/MOM_coupler_types.F90

+12-7
Original file line numberDiff line numberDiff line change
@@ -453,27 +453,32 @@ subroutine set_coupler_type_data(array_in, bc_index, var, solubility, scale_fact
453453
! as array_in [A]
454454
integer :: subfield ! An integer indicating which field to set.
455455
integer :: q_turns ! The number of quarter turns through which array_in is rotated
456-
integer :: is, ie, js, je, halo
457456

458457
q_turns = 0 ; if (present(turns)) q_turns = modulo(turns, 4)
459458

460459
subfield = ind_csurf
461460
if (present(solubility)) then ; if (solubility) subfield = ind_alpha ; endif
462461
if (present(field_index)) subfield = field_index
463-
halo = 0 ; if (present(halo_size)) halo = halo_size
464462

465463
! The case with non-trivial grid rotation is complicated by the fact that the data fields
466464
! in the coupler_2d_bc_type are never rotated, so they need to be handled separately.
467465
if (q_turns == 0) then
468466
call CT_set_data(array_in, bc_index, subfield, var, &
469467
scale_factor=scale_factor, halo_size=halo_size, idim=idim, jdim=jdim)
470468
elseif (present(idim) .and. present(jdim)) then
471-
! Work only on the computational domain plus symmetric halos.
472-
is = idim(2)-halo ; ie = idim(3)+halo ; js = jdim(2)-halo ; je = jdim(3)+halo
473-
call allocate_rotated_array(array_in(is:ie,js:je), [1,1], -q_turns, array_unrot)
469+
call allocate_rotated_array(array_in, [1,1], -q_turns, array_unrot)
474470
call rotate_array(array_in, -q_turns, array_unrot)
475-
call CT_set_data(array_unrot, bc_index, subfield, var, &
476-
scale_factor=scale_factor, halo_size=halo_size)
471+
472+
if (modulo(q_turns, 2) /= 0) then
473+
call CT_set_data(array_unrot, bc_index, subfield, var, &
474+
idim=jdim, jdim=idim, &
475+
scale_factor=scale_factor, halo_size=halo_size)
476+
else
477+
call CT_set_data(array_unrot, bc_index, subfield, var, &
478+
idim=idim, jdim=jdim, &
479+
scale_factor=scale_factor, halo_size=halo_size)
480+
endif
481+
477482
deallocate(array_unrot)
478483
else
479484
call allocate_rotated_array(array_in, [1,1], -q_turns, array_unrot)

0 commit comments

Comments
 (0)