-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid_coordinate.f03
74 lines (60 loc) · 1.72 KB
/
grid_coordinate.f03
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module grid_coordinate_mod
implicit none
private
public :: GridCoordinate, DefaultGridCoordinate
!
! GridCoordinate interface
!
type, abstract :: GridCoordinate
private
contains
procedure (getterTemplate), deferred :: getRow
procedure (getterTemplate), deferred :: getColumn
end type GridCoordinate
abstract interface
function getterTemplate(self)
import GridCoordinate
CLASS(GridCoordinate), intent(in) :: self
integer :: getterTemplate
end function
end interface
!
! Default GridCoordinate declaration
!
type, extends(GridCoordinate) :: DefaultGridCoordinate
private
integer :: row, col
contains
procedure :: getRow => defaultGetRow
procedure :: getColumn => defaultGetColumn
end type DefaultGridCoordinate
!
! Here we tell the compiler which of the functions is the
! constructor.
!
interface DefaultGridCoordinate
procedure constructor
end interface DefaultGridCoordinate
contains
function defaultGetRow(self)
CLASS(DefaultGridCoordinate), intent(in) :: self
integer :: defaultGetRow
defaultGetRow = self%row
end function
function defaultGetColumn(self)
CLASS(DefaultGridCoordinate), intent(in) :: self
integer :: defaultGetColumn
defaultGetColumn = self%col
end function
!
! This function allocates and returns a new GridCoordinate object.
! Thou shalt deallocate it.
!
function constructor(col, row)
integer, intent(in) :: col, row
CLASS(DefaultGridCoordinate), pointer :: constructor
ALLOCATE(constructor)
constructor%row = row
constructor%col = col
end function constructor
end module grid_coordinate_mod