Consider an old FORTRAN program that’s organised like this:
program main
implicit none
integer rr_sz
parameter(rr_sz=10)
real,dimension(:),allocatable :: rr
allocate(rr(rr_sz))
call sub1(rr_sz/2,rr)
print *, rr_sz, rr
deallocate(rr)
end
subroutine sub1(cc_sz,cc)
implicit none
integer cc_sz,min_cc_sz,i
complex cc
dimension cc(cc_sz)
c here we can determine what array size is really required
min_cc_sz = 6
if (cc_sz.lt.min_cc_sz)
& error stop
do i=1,min_cc_sz
cc(i) = complex(i,i)
end do
end
I would like to put the rr
array allocation into sub1
, so that when rr
needs more space than the hardcoded rr_sz
, the program can continue if the system have enough RAM.
It seems like doing so will require an explicit interface, which makes the compiler fail with a Type mismatch in argument ‘cc’: REAL(4) to COMPLEX(4)
.
How can I get around this problem with the least possible modifications to the original code?