How to pass allocatable arrays to subroutines in Fortran

If a procedure has a dummy argument that is an allocatable, then an explicit interface is required in any calling scope.

(There are numerous things that require an explicit interface, an allocatable dummy is but one.)

You can provide that explicit interface yourself by putting an interface block for your subroutine inside the main program. An alternative and far, far, far better option is to put the subroutine inside a module and then USE that module in the main program – the explicit interface is then automatically created. There is an example of this on the eng-tips site that you provided a link to – see the post by xwb.

Note that it only makes sense for a dummy argument to have the allocatable attribute if you are going to do something related to its allocation status – query its status, reallocate it, deallocate it, etc.

Leave a Comment