

Fortran 90 frees the program of much of these burdens by packaging the array dimensions into the passed array reference. All the routine needs to know is the array shape (i.e. 1,2,3, or more dimensions). This is the assumed-shape specification.
These are mutually exclusive and often lead to either compiling or run-time problems. The solution is to provide an INTERFACE block, which gives the Fortran 90 compiler more information regarding the Fortran 77 routine.
Code examples
real function oldfun(itype, na, nb, array)
integer itype, na, nb, maxa
parameter (maxa = 8)
c use linearized array and assume leading dimension of maxa if rank 2
real array(1)
integer i,j
c
c sum values in this array
c
oldfun = 0.0
if (itype .eq. 1) then
c column only
do 100 i=1,na
oldfun = oldfun + array(i)
100 continue
else
do 200 j=1,nb
do 200 i=1,na
oldfun = oldfun + array(i + (j-1)*maxa)
200 continue
endif
return
end
program toldfun
integer maxa, maxb, i, j
parameter (maxa = 8, maxb = 6)
real array(maxa, maxb)
c set up array
do 100 j = 1,maxb
do 100 i = 1,maxa
array(i,j) = i+j-1
100 continue
c write (6,*) array
write (6,*) 'sum34 = ', oldfun(2, 3,4, array)
write (6,*) 'sum43 = ', oldfun(2, 4,3, array)
write (6,*) 'should = ', 42.
write (6,*) 'sum_3 = ', oldfun(1, 4,0, array(1,3))
write (6,*) 'should = ', 18.
end
program tnewint implicit none integer, parameter :: maxa = 8, maxb = 6 real, dimension(maxa,maxb) :: array integer i,j ! add an interface block for oldfun ... ! this gives the compiler more info regarding ! the f77 fn,but does have some limits interface real function oldfun(itype,na,nb,array) integer, intent(in) :: itype, na, nb ! must use assumed-size specification for f77 array real, dimension(*), intent(in) :: array end function oldfun end interface ! set up array do j = 1,maxb do i = 1,maxa array(i,j) = i+j-1 enddo enddo ! write (6,*) array ! can pass entire array write (6,*) 'sum34 = ', oldfun(2, 3,4, array) ! address of 1st element write (6,*) 'sum34 = ', oldfun(2, 3,4, array(1,1)) ! linearize the array (repacks it) write (6,*) 'sum43 = ', oldfun(2, 4,3, pack(array,.true.)) write (6,*) 'should = ', 42. ! can just give address of 1st element for F77 fns write (6,*) 'sum_3 = ', oldfun(1, 4,0, array(1,3)) ! pass an array slice write (6,*) 'sum_3 = ', oldfun(1, 4,0, array(:,3)) write (6,*) 'should = ', 18. end program tnewint
sum34 = 42. sum34 = 42. sum43 = 42. should = 42. sum_3 = 18. sum_3 = 18. should = 18.

