Comparing Fortran-90 vs. Fortran-77 Array Syntax ************************************************ Fortran-90 is a superset of Fortran-77, and so the Fortran-77 style of using and passing arrays still work, but there are new features in Fortran-90 that involve non-obvious but important differences. Here are 4 different styles of array declaration, all acceptable in Fortran-90: real x(m,n) ! "fixed size" array (legal in Fortran 1.0) real x(m,*) ! "assumed size" (legal in Fortran77) real x(:,:) ! "assumed shape" (new in Fortran90) real, allocatable :: x(:,:) ! "deferred shape" (new in Fortran90) Here are examples of using the first 3 types in subroutines. Start with fixed-size array, where the dimensions can be passed as subroutine arguments: subroutine sub66(x,m,n) real x(m,n) print *, x(m,n) return end It is only the final index of an "assumed size" array that is allowed to be undetermined (*). If it is not passed as a subroutine argument, it can be determined from other information, such as info in a common block: subroutine sub77(x,m) real x(m,*) common /data/ imax n=imax print *, x(m,n) return end With Fortran-90, you can also use "assumed shape" arrays: subroutine sub90(x) real x(:,:) m=size(x,1) n=size(x,2) print *, x(m,n) return end This greatly simplifies the usage of subroutine libraries, since you don't have to specify the size of every passed array. Fortran-90 accomplishes this by passing some extra information about the array (x is passed as an array structure, including information about its size, not just the address of the first element of the array). When a program calls a subroutine, the fortran compiler uses the old fortran-77 convention for passing arrays unless it is given extra information that tells it to pass the full fortran-90 array size information as well. Thus the following program would be wrong: program main real x(3,3) common /data/ imax x=1.0 imax=3 call sub66(x,3,3) call sub77(x,3) call sub90(x) end The calls to sub66 and sub77 work fine, but the compiler would not know that sub90 needs to have x passed as a fortran 90 array structure to figure out its size. The extra information that is needed is generated by the "use module" command, or by an "interface command". If sub90 is in module sub90_mod, then inserting the following command at the beginning of the program (right after the "program main" statement) would get it to work right: use sub90_mod Since the old fortran-77 method of passing array arguments is the default, it is not necessary to have interface blocks or "use module" statements for them. But sometimes interface blocks are used to give the compiler extra argument-checking abilities at compile time. One word of caution though. If the subroutine is subroutine sub77b(x,m) real x(*) print *, x(m) end then the following interface for it is WRONG: interface subroutine sub77(x,m) real x(:) end subroutine sub77 end interface The compiler would think that sub77 wants x passed as an array structure (including its size information, not just the address of the beginning of the array). The RIGHT interface for it is: interface subroutine sub77(x,m) real x(*) end subroutine sub77 end interface or even interface subroutine sub77(x,m) real x(m) end subroutine sub77 end interface In general, it is probably best for the interface block to be identical to the actual declarations in the subroutine.