Prev: Strange result from coding error?
Next: Interoperability with C, Interoperability of global data in INTEL FORTRAN 11.1
From: JB on 17 Jun 2010 03:47 I have a module csr_m. The s_csr and d_csr have allocate, deallocate etc. procedures bind to the types. Is it possible to have the assingnment (=) (which is now handled with the interface) binded in the same way to type? The intention is to declare something like type, extends(csr) :: s_csr real(s_r), allocatable, dimension(:) :: a contains procedure allocate => s_csr_allocate procedure deallocate => s_csr_deallocate procedure assingment (=) => s_csr_to_array end type s_csr module csr_m use vardef_m, only: s_r, d_r ! get the working precision implicit none private ! define the derived data type for the CSR-matrices type csr integer :: n integer, allocatable, dimension(:) :: ia, ja end type type, extends(csr) :: s_csr real(s_r), allocatable, dimension(:) :: a contains procedure allocate => s_csr_allocate procedure deallocate => s_csr_deallocate end type s_csr type, extends(csr) :: d_csr real(d_r), allocatable, dimension(:) :: a contains procedure allocate => d_csr_allocate procedure deallocate => d_csr_deallocate end type d_csr type, extends(csr) :: z_csr complex(d_r), allocatable, dimension(:) :: a contains procedure allocate => z_csr_allocate procedure deallocate => z_csr_deallocate end type z_csr interface assignment (=) module procedure s_csr_to_array, d_csr_to_array end interface assignment (=) contains .. . . end module csr_m
From: Tobias Burnus on 17 Jun 2010 04:23 On 06/17/2010 09:47 AM, JB wrote: > I have a module csr_m. The s_csr and d_csr have allocate, deallocate > etc. procedures bind to the types. Is it possible to have the > assingnment (=) (which is now handled with the interface) binded in > the same way to type? Kind of but not exactly the way you did. Example: TYPE,PUBLIC :: rational PRIVATE INTEGER n,d CONTAINS PROCEDURE, PRIVATE :: rat_asgn_i GENERIC :: ASSIGNMENT(=) => rat_asgn_i END TYPE CONTAINS ELEMENTAL SUBROUTINE rat_asgn_i(a,b) CLASS(rational),INTENT(OUT) :: a INTEGER,INTENT(IN) :: b a%n = b a%d = 1 END SUBROUTINE Tobias
From: guoguo on 17 Jun 2010 04:34
you can do it like this: GENERIC :: ASSIGNMENT(=) => s_csr_to_array, d_csr_to_array but, it seems that many compilers can not compile it |