0

I am trying to pass an array of unspecified size to a subroutine like so

PROGRAM GOL
IMPLICIT NONE

INTEGER, PARAMETER :: size_x = 16, size_y = 16
LOGICAL, DIMENSION(1:size_x,1:size_y) :: universe
universe(:,:) = .FALSE.

CALL COUNT_NEIGHBOURS(universe, 1, 1)

END PROGRAM GOL

SUBROUTINE COUNT_NEIGHBOURS (universe, x, y)
LOGICAL, DIMENSION(:,:) :: universe
INTEGER :: x,y

!test
universe(x,y) = .TRUE.

RETURN
END SUBROUTINE COUNT_NEIGHBOURS

However I get the error from gfortran

CALL COUNT_NEIGHBOURS(universe, 1, 1)
                     1
Error: Procedure 'count_neighbours' at (1) with assumed-shape dummy argument 'universe' must have an explicit interface

What is the correct way to do this?

1
  • There are many questions to be found if you search for "must have an explicit interface". Commented Nov 23, 2017 at 12:12

1 Answer 1

0

As described in the error message the compiler needs the explicit interface for your callable procedure. This answer shows three ways how to provide an interface.

In most cases the preferred way to put the procedure in a module or make it a contained procedure, but sometimes it's easier to use the interface block (in the code below) when, for example, you need to update some old code.

PROGRAM GOL
IMPLICIT NONE

interface
    subroutine COUNT_NEIGHBOURS(universe, x, y)
        logical :: universe(:,:)
        integer :: x, y
    end subroutine COUNT_NEIGHBOURS
end interface


INTEGER, PARAMETER :: size_x = 16, size_y = 16
LOGICAL, DIMENSION(1:size_x,1:size_y) :: universe
universe(:,:) = .FALSE.

CALL COUNT_NEIGHBOURS(universe, 1, 1)

END PROGRAM GOL

SUBROUTINE COUNT_NEIGHBOURS (universe, x, y)
LOGICAL :: universe(:,:)
INTEGER :: x,y

!test
universe(x,y) = .TRUE.

RETURN
END SUBROUTINE COUNT_NEIGHBOURS
Sign up to request clarification or add additional context in comments.

2 Comments

As noted in this answer to the question linked in comment above, there are other ways to provide the required explicit interface. This solution is, rightly, the least desirable, unless you can explain why it should be preferred?
Modules are much better. Or make it internal for such a small example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.