-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoxModule.f90
163 lines (123 loc) · 4.03 KB
/
BoxModule.f90
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
! ____ _ __ ____ __ ____
! / __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
! _\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
! /___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
!
!
! Copyright 2010 SciberQuest Inc.
!
! No permission is granted to reproduce this software.
!
! This is experimental software and is provided ‘‘as is’’, with no
! warranties of any kind whatsoever, no support, no promise of updates,
! or printed documentation.
!==============================================================================
module BoxModule
!============================================================================
! multidimensional cartesian index space.
type Box
integer I(6)
end type Box
interface NewBox
module procedure NewBox0
module procedure NewBox6
end interface
interface BoxSetExtents
module procedure BoxSetExtents1
module procedure BoxSetExtents6
end interface
interface BoxPrintSelf
module procedure BoxPrintSelfUnit
module procedure BoxPrintSelfString
end interface
contains
!----------------------------------------------------------------------------
function NewBox0() result(b)
implicit none
type(Box), pointer :: b
b => NewBox(1,-1,1,-1,1,-1)
end function
!----------------------------------------------------------------------------
function NewBox6(ilo,ihi,jlo,jhi,klo,khi) result(b)
implicit none
type(Box), pointer :: b
integer, intent(in) :: ilo,ihi,jlo,jhi,klo,khi
integer iErr
allocate(b,stat=iErr)
if (iErr.ne.0) then
write(0,*)"Error: failed to allocate Box."
stop
end if
call BoxSetExtents(b,ilo,ihi,jlo,jhi,klo,khi)
end function
!----------------------------------------------------------------------------
subroutine DeleteBox(b)
implicit none
type(Box), pointer :: b
if (associated(b)) then
deallocate(b)
end if
nullify(b)
end subroutine
!----------------------------------------------------------------------------
! Set the box extents (the index space in the simulation grid)
!interface SetExtents
subroutine BoxSetExtents6(b,ilo,ihi,jlo,jhi,klo,khi)
implicit none
type(Box) b
integer, intent(in) :: ilo,ihi,jlo,jhi,klo,khi
b%I(1)=ilo; b%I(2)=ihi;
b%I(3)=jlo; b%I(4)=jhi;
b%I(5)=klo; b%I(6)=khi;
end subroutine
!----------------------------------------------------------------------------
subroutine BoxSetExtents1(b,I)
implicit none
type(Box) b
integer, intent(in) :: I(6)
b%I(1)=I(1); b%I(2)=I(2);
b%I(3)=I(3); b%I(4)=I(4);
b%I(5)=I(5); b%I(6)=I(6);
end subroutine
!----------------------------------------------------------------------------
! write the box to the prescribed unit
subroutine BoxPrintSelfString(b,string)
implicit none
type(Box), intent(in) :: b
character(len=*) string
write(string,'(A,3(I5,A,I5),A)')'(' &
,b%I(1),', ',b%I(2) &
,b%I(3),', ',b%I(4) &
,b%I(5),', ',b%I(6),')'
end subroutine
!----------------------------------------------------------------------------
! write the box to the prescribed unit
subroutine BoxPrintSelfUnit(b,unitNo)
implicit none
type(Box) b
integer unitNo
character(len=512) buffer
call BoxPrintSelf(b,buffer)
write(unitNo,*)trim(buffer)
end subroutine
!----------------------------------------------------------------------------
! Computes the box's size in each dimension.
subroutine BoxGetDimensions(b, dims)
implicit none
type(Box) b
integer dims(3)
dims(1)=b%I(2)-b%I(1)+1
dims(2)=b%I(4)-b%I(3)+1
dims(3)=b%I(6)-b%I(5)+1
end subroutine
!----------------------------------------------------------------------------
! Computes the number of cells,(box size) in all dimensions.
function BoxGetSize(b) result(n)
implicit none
type(Box) b
integer n
integer dims(3)
call BoxGetDimensions(b,dims)
n=dims(1)*dims(2)*dims(3)
end function
end module