- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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.
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.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your anwser.
I've tried your piece of code but it gives me the following error:
By the way, I am using the following ifort version:
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works just fine.
Thanks both of you.
Thanks both of you.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page