5 ! function to go beyond domain boundary if tile is next to it
6 integer function snode(t
,d
,i
)
8 integer, intent(in
)::t
,d
,i
17 print *,'press enter to continue'
24 end subroutine message
28 ! terminate with error
29 character(len
=*),intent(in
)::msg
30 write(*,*)'FATAL:',trim(msg
)
34 subroutine read_array(a
,name
)
36 !*** purpose read array from text file
40 real, pointer, intent(out
):: a(:,:,:) ! the array pointer; remember to deallocate when done with it
41 character(len
=*),intent(in
)::name
! file name root, .txt will be added
47 open(iu
,file
=trim(name
)//'.txt',form
='formatted',status
='old')
49 if(j
.ne
.456)call crash('read_array: wrong magic number')
51 if(j
.ne
.3)call crash('read_array: must have 3 dimensions')
53 1 format('reading matrix size ',3i5
,' from file ',a
)
54 write(*,1)n
,trim(name
)//'.txt'
55 allocate(a(n(1),n(2),n(3)))
58 end subroutine read_array
61 subroutine write_scalar(a
,name
)
63 character(len
=*),intent(in
)::name
! file name root, .txt will be added
64 call write_array_nd((/a
/),(/1/),name
)
65 end subroutine write_scalar
69 subroutine write_array(a
,name
)
70 !*** purpose write array to text file
72 real, intent(in
):: a(:,:,:)
73 character(len
=*),intent(in
)::name
! file name root, .txt will be added
76 integer:: n(3),iu
=8,i1
,i2
,i3
80 open(iu
,file
=trim(name
)//'.txt',form
='formatted',status
='unknown')
87 1 format('writing matrix size ',3i5
,' to file ',a
)
88 write(*,1)n
,trim(name
)//'.txt.'
92 write(iu
,*)a(i1
,i2
,i3
)
97 end subroutine write_array
99 subroutine read_array_nd(a
,s
,name
)
100 !*** purpose read nd array from text file
102 ! integer :: s(k) ! k is constant
103 ! real, pointer :: a(:)
104 ! call read_array_nd(a,s,'file')
105 ! target_array = reshape(a,s)
110 integer, intent(out
):: s(:) ! the array shape pointer
111 real, pointer, intent(out
):: a(:) ! the array data pointer
112 character(len
=*),intent(in
)::name
! file name root, .txt will be added
115 integer:: iu
=8,n
,j
,sn(1)
118 open(iu
,file
=trim(name
)//'.txt',form
='formatted',status
='old')
120 if(j
.ne
.456)call crash('read_array: wrong magic number')
123 if(j
.ne
.sn(1))call crash('read_array: wrong number of dimensions')
124 if(j
.lt
.1.or
.j
.gt
.7)call crash('read_array: must have 1 to 7 dimensions')
127 1 format('file ',a
,' reading matrix size ',7i8
)
128 write(*,1)trim(name
)//'.txt.',s
129 allocate(a(product(s
)))
132 end subroutine read_array_nd
134 subroutine write_array_nd(a
,s
,name
)
135 !*** purpose write array to text file
138 ! call write_array_nd(reshape(a,(/product(s)\)),'file')
142 integer, intent(in
):: s(:)
143 real, intent(in
):: a(:)
144 character(len
=*),intent(in
)::name
! file name root, .txt will be added
147 integer::n(1),m(1),i
,iu
150 1 format('writing ',a
,' matrix size ',7i5
)
151 write(*,1)trim(name
)//'.txt',s
154 if (product(s
).ne
.m(1))call crash('write_array_nd: wrong size of a')
155 open(iu
,file
=trim(name
)//'.txt',form
='formatted',status
='unknown')
165 end subroutine write_array_nd
168 subroutine set_indices(n
,nwrap
, &
169 ifds
, ifde
, kfds
,kfde
, jfds
,jfde
, & ! fire grid dimensions
170 ifms
, ifme
, kfms
,kfme
, jfms
,jfme
, &
171 ifts
, ifte
, kfts
,kfte
, jfts
,jfte
)
174 integer, intent(in
)::n(3),nwrap
175 integer, intent(out
):: &
176 ifds
, ifde
, kfds
,kfde
, jfds
,jfde
, & ! fire grid dimensions
177 ifms
, ifme
, kfms
,kfme
, jfms
,jfme
, &
178 ifts
, ifte
, kfts
,kfte
, jfts
,jfte
180 ! tile dimensions from matrix size
201 end subroutine set_indices
203 integer function get_chsum(a
)
204 ! xor check sum of 3D real array
207 real, intent(in
)::a(:,:,:)
209 integer::lb(3),ub(3),i
,j
,k
,lsum
,iel
221 !print *,i,k,j,rel,iel,lsum
228 end function get_chsum
230 end module module_utils