- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In a previous thread I asked for help because of a circular depenendy. I solved it by using submodules. Now I want to have a type bound overloaded subroutine in a submodul.
Current status which is working fine
PROJECT.f90
MODULE mProject IMPLICIT NONE PRIVATE PUBLIC :: tElement TYPE tElement CONTAINS PROCEDURE, PUBLIC :: other_subroutine => other_subroutine_element END TYPE tElement INTERFACE MODULE SUBROUTINE other_subroutine_element(this) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this END SUBROUTINE other_subroutine_element END INTERFACE END MODULE mProject
ELMENT.f90
SUBMODULE (mProject) mElements IMPLICIT NONE CONTAINS MODULE SUBROUTINE other_subroutine_element(this) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this ! doing smth here END SUBROUTINE other_subroutine_element END SUBMODULE
Now I want to add to tElement a overloaded type bound subroutine. How do i do that
MODULE mProject IMPLICIT NONE PRIVATE PUBLIC :: tElement TYPE tElement CONTAINS PROCEDURE, PUBLIC :: overloaded_subroutine => overloaded_subroutine_element PROCEDURE, PUBLIC :: other_subroutine => other_subroutine_element END TYPE tElement INTERFACE overloaded_subroutine_element MODULE PROCEDURE overloaded_sub1 MODULE PROCEDURE overloaded_sub2 END INTERFACE overloaded_subroutine_element INTERFACE MODULE SUBROUTINE other_subroutine_element(this) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this END SUBROUTINE other_subroutine_element MODULE SUBROUTINE overloaded_sub1(this, int) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this INTEGER(4), INTENT(IN) :: int END SUBROUTINE overloaded_sub1 MODULE SUBROUTINE overloaded_sub2(this, real) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this REAL(8), INTENT(IN) :: real END SUBROUTINE overloaded_sub2 END INTERFACE END MODULE mProject
and for ELEMENT.f90
SUBMODULE (mProject) mElements IMPLICIT NONE CONTAINS MODULE SUBROUTINE other_subroutine_element(this) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this ! doing smth here END SUBROUTINE other_subroutine_element MODULE SUBROUTINE overloaded_sub1(this, int) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this INTEGER(4), INTENT(IN) :: int ! doing smth here END SUBROUTINE overloaded_sub1 MODULE SUBROUTINE overloaded_sub2(this, real) IMPLICIT NONE CLASS(tElement), INTENT(INOUT) :: this REAL(8), INTENT(IN) :: real ! doing smth here END SUBROUTINE overloaded_sub2 END SUBMODULE
unfortunately this is not how its working.
PROJECT.f90(9): error #8182: The name is neither an abstract interface nor a procedure with an explicit interface. [OVERLOADED_SUBROUTINE_ELEMENT]
PROJECT.f90(9): error #8258: The procedure name in a type-bound procedure declaration should be the name of an accessible module procedure or an external procedure that has an explicit interface. [OVERLOADED_SUBROUTINE_ELEMENT]
Someone has any thoughts on this?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Julian wrote:
.. Now I want to add to tElement a overloaded type bound subroutine. How do i do that ..
Add a GENERIC binding to your type, as shown below:
module mProject implicit none private public :: tElement type tElement contains private ! <-- Look into this, consider making this the default procedure, pass(this) :: overloaded_sub1 !<-- suggestion: explicitly declare the PASS attribute procedure, pass(this) :: overloaded_sub2 procedure, pass(this), public :: other_subroutine => other_subroutine_element generic, public :: overloaded_subroutine_element => overloaded_sub1, overloaded_sub2 !<-- overloading end type tElement interface module subroutine other_subroutine_element(this) implicit none class(tElement), intent(inout) :: this end subroutine other_subroutine_element module subroutine overloaded_sub1(this, int) implicit none class(tElement), intent(inout) :: this integer(4), intent(in) :: int end subroutine overloaded_sub1 module subroutine overloaded_sub2(this, real) implicit none class(tElement), intent(inout) :: this real(8), intent(in) :: real end subroutine overloaded_sub2 end interface end module mProject
Also look in the references for more such details:
https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page