Type-bound procedures contained in the program instead of a module

Type-bound procedures contained in the program instead of a module

Hello,

consider the program below. It defines an extended derived type and tries to
fill in one procedure via a contained function. I can imagine that this is
not standard-conforming, as the function has access to the variables from the
main program, but the error message I got was rather puzzling:

"The specified interface is not declared [ACTUAL_DERIV]"

It took me quite a while to figure out what was wrong, as the interface seemed to be perfectly okay.

The solution is of course to put the definition of ode_actual_t and the function in a module, but that
is not suggested by the error message. (If this has been improved in Intel Fortran 12.x, then I apologize
for the noise.)

Regards,

Arjen

-----
! question.f90 --
! Can actual_derive not be part of the program? Should it be a module procedure?
!
module ode_types
implicit none

private
integer, parameter, public :: wp = kind(1.0)

type, abstract, public :: ode_system_t
integer :: size = 0
contains
procedure(ode_derivative), deferred, pass(this) :: deriv
end type ode_system_t

abstract interface
function ode_derivative( this, x, time ) result(deriv)
import :: ode_system_t, wp
class(ode_system_t) :: this
real(wp), dimension(:) :: x
real(wp) :: time
real(wp), dimension(size(x)) :: deriv
end function ode_derivative
end interface

end module ode_types

! test --
! Simple test program
!
program test
use ode_types

implicit none

type, extends(ode_system_t) :: ode_actual_t
contains
procedure :: deriv => actual_deriv
end type ode_actual_t

type(ode_actual_t) :: ode

contains

function actual_deriv( this, x, time ) result(deriv)
class(ode_actual_t) :: this
real(wp), dimension(:) :: x
real(wp) :: time
real(wp), dimension(size(x)) :: deriv

end function actual_deriv

end program test

publicaciones de 6 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Hello Arjen,

The Fortran standard states The procedure-name [of a type bound procedure] shall be the name of an accessible module procedure or an external procedure that has an explicit interface., so a contained procedure from the main program is not allowed to be a type bound procedure.

I agree that the error message could be clearer. What this error message is trying to say is that the compiler can't find a procedure or interface for a procedure matching the name actual_deriv. It doesn't know why it can't find the procedure or interface. Keeping that in mind, do you have any suggestions on how to make the error message so the issue would have been clearer?

Thanks,
Annalee
Intel Developer Support

When I compiled the program with gfortran it came up with the message that the procedure in question must be a module procedure or an external procedure with an explicit interface. I think that covers the issue quite
weill (at least in retrospect ;)).

So, my suggestion is something like:

The actual procedure for this type-bound procedure should be a module procedure or an external procedure with an explicit interface [DERIV]

(I suggest using the type-bound name, rather than the name given after the "=>", as that is where you
should correct things)

Regards,

Arjen

Hello Arjen,

I have escalated this request to the developers. The issue number is DPD200232581. I will post any updates I receiveto this thread.

Regards,
Annalee

Hello Arjen,

We are planning to improve the error message in a future release (not the one scheduled for later this year).

Regards,
Annalee

Imagen de Ronald W Green (Intel)

This bug was fixed in the recent Composer XE 2013 SP1 release, released in early September ( version 14.0 of the compiler )

ron

Inicie sesión para dejar un comentario.