0

Dear all,

I'm working on a project and need to define explicit interfaces.

Problem

For those two subroutines (information_agents and information_grid) i tried to write interfaces, because I want to be able to call modell_information(agents=..., num_agents=..., m=...) and modell_information(grid=..., overlap_grid=...,m=...) with two different subroutines being called. My code currently looks like that:

module modell_module
use agentTools
implicit none

private
...
public modell_information
...
interface modell_information
    module subroutine information_agents(agents, num_agents, m)
        type(agent), dimension(:), pointer :: agents
        integer(KIND=4) :: num_agents
        type(modell) :: m
    end subroutine information_agents
    module subroutine information_grid(input_grid, input_overlap_grid, input_m)
        type(list), dimension(:,:), pointer :: input_grid
        type(list), dimension(:,:,:), pointer :: input_overlap_grid
        type(modell) :: input_m
    end subroutine information_grid
end interface


type, public :: modell
    type(agent), dimension(:), allocatable :: a !List of agents
    type(list), dimension(:,:), pointer, private :: grid 
    type(list), dimension(:,:,:), pointer, private :: overlap_grid
    ...
end type modell

contains
...
subroutine information_agents(agents, num_agents, m)
        type(agent), dimension(:), pointer :: agents
        integer(KIND=4) :: num_agents
        type(modell) :: m
        agents => m%a
        num_agents = m%n_agents
end subroutine information_agents
subroutine information_grid(input_grid, input_overlap_grid, input_m)
        type(list), dimension(:,:), pointer :: input_grid
        type(list), dimension(:,:,:), pointer :: input_overlap_grid
        type(modell) :: input_m
        input_grid => input_m%grid
        input_overlap_grid => input_m%overlap_grid
end subroutine information_grid

I get two errors,

error #6645: The name of the module procedure conflicts with a name in the encompassing scoping unit.   [INFORMATION_GRID]      D:\Code\Fortran\EpidemicSimulation\modell.f90   90  

where the second one is equal to the first one but its about information_agents.

Question

How should I define an explicit Interface or did I understand the concept behind interfaces wrong? I'm new to Fortran and would look forwaring learning.

Community
  • 1
  • 1
Znerual
  • 173
  • 1
  • 10
  • 1
    Please do not conflate explicit interfaces and `interface` blocks. They are something completely different. The best way to get an explicit interface is to use modules. Interface blocks are bad for this purpose. https://stackoverflow.com/questions/16486822/fortran-explicit-interface – Vladimir F Героям слава Apr 17 '20 at 09:39
  • An *explicit interface* is *a concept*, it is NOT a block of code that starts with the `interface` keyword, that is an interface block. There is no reason to make an interface block for a module subroutine. – Vladimir F Героям слава Apr 17 '20 at 09:40

0 Answers0