My practice is to use the return function when the function changes only one variable and does not make another exit. If several variables are changed or the procedure performs other actions, I would put the output variables in the argument list. This is a style choice. It is possible to create memory leaks with pointers, especially with pointers returned as arguments to a function, so I would avoid this option if there was no convincing reason in a particular case.
UPDATE: there is no problem with the argument of the intent array (out) ... no assumptions are needed about the size of the array, as shown in the following example:
module example_one implicit none contains subroutine two_arrays ( in_arr, out_arr ) integer, dimension (:), intent (in) :: in_arr integer, dimension (:), allocatable, intent (out) :: out_arr integer :: i, len len = size (in_arr) allocate ( out_arr (1:len) ) do i=1, len out_arr (i) = 3 * in_arr (i) end do return end subroutine two_arrays end module example_one program test use example_one implicit none integer, dimension (1:5) :: in_arr = [ 1, 2, 4, 5, 10 ] integer, dimension (:), allocatable :: out_arr write (*, *) allocated ( out_arr) call two_arrays ( in_arr, out_arr ) write (*, *) size (out_arr) write (*, *) out_arr write (*, *) allocated ( out_arr) deallocate ( out_arr ) write (*, *) allocated ( out_arr) stop end program test
Msb
source share