I am modifying a Fortran code which has some arrays declared as allocatable. The changes I am doing require changing the allocatable arrays to pointer arrays as they are being passed to C++ routines and back. The problem is that, there are subroutines on the Fortran side that still expect these arrays to be passed as allocatable, and I need to make sure that my changes don't affect the declaration of these subroutines as the code has multiple developers.
I was trying a small test example on passing an array that has been declared as a pointer, to a routine that expects an allocatable array. The solution I found is not very great, and requires using another allocatable array. I give the snippet below.
program test implicit none integer, parameter :: VAL = 2 integer, pointer, dimension(:,:,:) :: a integer, allocatable, dimension(:,:,:) :: b allocate(a(VAL,VAL,VAL), stat=ierr) allocate(b(VAL,VAL,VAL), stat=ierr) !set values in a b = a call checkval(b) contains subroutine checkval(arr) implicit none integer, dimension(:,:,:), allocatable :: arr arr(:, :, :) = -1 end subroutine checkval end program array
This seems to be a very trivial way to solve this, and will make use of more memory due to the allocatable array b, when VAL is large. Is it possible to do this in a smarter way.