Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Bound-type procedure using multiple interfaces

FlyingHermes
New Contributor I
1,404 Views
Hi,

I would like to implement a derived-type with a bound-type procedure whichcan be used using different type if arguments.

I have no problem to implement this type of procedure without it being inside a derived-type.
I simply use an interface block as follow:

[fortran]Module Test

interface Get_Value
  module procedure  Get_Value_i, Get_Value_r, Get_Value_l, Get_Value_c
end interface

contains

Subroutine Get_Value_i ( Par, Val )
  implicit none
  integer      ,intent(in)  :: Par
  integer      ,intent(out) :: Val 
  ...
End Subroutine

Subroutine Get_Value_r ( Par, Val )
  implicit none
  real         ,intent(in)  :: Par
  integer      ,intent(out) :: Val 
  ...
End Subroutine

Subroutine Get_Value_r ( Par, Val )
  implicit none
  character(*) ,intent(in)  :: Par
  integer      ,intent(out) :: Val 
  ...
End Subroutine

Subroutine Get_Value_l ( Par, Val )
  implicit none
  logical      ,intent(in)  :: Par
  integer      ,intent(out) :: Val 
  ...
End Subroutine

End Module[/fortran]

Calling the "Get_Value" procedure will work using any type (integer, real, character and logical) for the "Par" input argument.

Now, if this procedure is type-bound, I do not know how to implement it.
I've tried different implementations, but they all give me compilation errors.

Could someone provide me with any kind of solution for this issue.
Thanks.
0 Kudos
1 Solution
oleglebedev
New Contributor I
1,404 Views
You must specify only one type-binding procedure per a PROCEDURE statement.
If I were you I code
[fortran]type, public :: foo_type
!...
  CONTAINS
    generic, public :: Get_Value => Get_Value_i, Get_Value_r, Get_Value_l, Get_Value_c
    procedure, private :: Get_Value_i
    procedure, private :: Get_Value_r
    procedure, private :: Get_Value_c
    procedure, private :: Get_Value_l
end type foo_type[/fortran]
Best, Oleg.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,404 Views
What I think you want looks something like this:

type mytype
...
contains
procedure :: Get_Value_i,Get_Value_r,Get_Value_l,Get_Value_c
generic :: Get_Value => Get_Value_i,Get_Value_r,Get_Value_l,Get_Value_c
end type mytype

Does this help?
0 Kudos
FlyingHermes
New Contributor I
1,404 Views
Hi,
Thanks for your anwser.
I've tried your piece of code but it gives me the following error:

[bash]error #8259: The type bound procedure definition statement must contains only one binding name.   [GET_VALUE_R]
    procedure                           ::      Get_Value_i, Get_Value_r, Get_Value_c, Get_Value_l
-------------------------------------------------------------^[/bash]


By the way, I am using the following ifort version:

[bash]$ ifort -V
Intel Fortran Compiler XE for applications running on IA-32, Version 12.1.1.256 Build 20111011
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY[/bash]
Any recommendation ?



0 Kudos
oleglebedev
New Contributor I
1,405 Views
You must specify only one type-binding procedure per a PROCEDURE statement.
If I were you I code
[fortran]type, public :: foo_type
!...
  CONTAINS
    generic, public :: Get_Value => Get_Value_i, Get_Value_r, Get_Value_l, Get_Value_c
    procedure, private :: Get_Value_i
    procedure, private :: Get_Value_r
    procedure, private :: Get_Value_c
    procedure, private :: Get_Value_l
end type foo_type[/fortran]
Best, Oleg.
0 Kudos
FlyingHermes
New Contributor I
1,404 Views
It works just fine.
Thanks both of you.
0 Kudos
Reply