-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_alloc.f90
60 lines (53 loc) · 2.58 KB
/
m_alloc.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
MODULE m_alloc
use m_gldat
use precision
implicit none
!allocation of necessary fields
contains
subroutine alloc(N)
! ---------------------------------------------------------------------------------------
! Description: Allocates memory for arrays u, u_old, f, x, y, and z.
! Inputs:
! - N: Integer representing the size of the domain (number of grid points along each dimension)
! Outputs:
! - Allocates memory for the arrays u, u_old, f, x, y, and z.
! - Checks the allocation status using the 'iostat' variable.
! - If allocation fails, prints an error message and stops execution.
! Notes:
! - The arrays u, u_old, and f are three-dimensional.
! - The vectors x, y, and z are one-dimensional.
! ---------------------------------------------------------------------------------------
integer :: N
allocate(u(N,N,N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'u' matrix!")
allocate(u_old(N,N,N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'u_old' matrix!")
allocate(f(N,N,N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'f' matrix!")
allocate(x(N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'x' vector!")
allocate(y(N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'y' vector!")
allocate(z(N), stat=iostat)
call check_iostat(iostat, "Could not allocate 'z' vector!")
end subroutine alloc
subroutine check_iostat(iostat, msg)
! ---------------------------------------------------------------------------------------
! Description: Allocates memory for arrays u, u_old, f, x, y, and z.
! Inputs:
! - N: Integer representing the size of the domain (number of grid points along each dimension)
! Outputs:
! - Allocates memory for the arrays u, u_old, f, x, y, and z.
! - Checks the allocation status using the 'iostat' variable.
! - If allocation fails, prints an error message and stops execution.
! Notes:
! - The arrays u, u_old, and f are three-dimensional.
! - The vectors x, y, and z are one-dimensional.
! ---------------------------------------------------------------------------------------
integer, intent(in) :: iostat
character(len=*), intent(in) :: msg
if ( iostat == 0 ) return
write(*,'(a,i0,/,tr3,a)') 'ERROR = ', iostat, msg
stop
end subroutine check_iostat
END MODULE m_alloc