-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmyitem_list_m.f90
More file actions
35 lines (35 loc) · 888 Bytes
/
myitem_list_m.f90
File metadata and controls
35 lines (35 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
!
! Module to demonstrate extending anyitem to handle a user-defined type.
!
module myitem_list_m
use anylist_m
implicit none
type, extends(anyitem) :: myitem
contains
procedure :: print => myprint
end type
type rational
integer :: numerator = 0
integer :: denominator = 1
end type
contains
!
! Version of print that will handle type rational.
!
subroutine myprint(this)
class(myitem), intent(in) :: this
select type (v=>this%value)
class is (rational)
print *, 'rational =', v%numerator, '/', v%denominator
class default
call this%anyitem%print
end select
end subroutine
function new_myitem(anything)
class(*), intent(in) :: anything
class(myitem), pointer :: new_myitem
allocate (new_myitem)
allocate (new_myitem%value, source=anything)
end function
end module
!