- #1
hobmarcus
- 10
- 0
Im trying to pass an unknown size of array to the subroutine. Then I will define the size of array in subroutine and pass it back to main program. I tried to use interface but the complier said invalid memory reference
or Explicit interface required for ' ' at (1): allocatable argument
. Any suggestions or helps? I would really appreciate for any advice/tips.
or Explicit interface required for ' ' at (1): allocatable argument
. Any suggestions or helps? I would really appreciate for any advice/tips.
Fortran:
program
implicit none
integer :: data_1(10)
integer :: data_2(9)
integer, allocatable :: third_array(:)
data_1= (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /)
data_2 = (/ 3, 4, 5, 6, 7, 8, 9, 10,11 /)
interface
subroutine abc (d1,d2,ta)
implicit none
integer, INTENT(IN) :: n1
integer, INTENT(IN) :: n2
integer, INTENT(OUT), allocatable :: ta(:)
end subroutine abc
end interfacecall abc (data_1,data_2, third_array)
write(*,*) "third_array", third_array
stop
endprogram
!-------------------------------------------------------------------------subroutine abc (d1,d2,ta)
implicit none
integer, INTENT(IN) :: d1
integer, INTENT(IN) :: d2
integer, INTENT(OUT), allocatable :: ta(:)
integer :: i
allocate(ta(19))
do i=1,10
ta(i)=d1(i)
end do
do i=11,19
ta(i)=d1(i-10)
end do
return
end subroutine abc
Last edited: