-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvar_array.f90
46 lines (33 loc) · 848 Bytes
/
var_array.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
module var_array
implicit none
private
type int_array
integer, dimension(:), allocatable :: val
end type int_array
type double2_array
real*8, dimension(:, :), allocatable :: val
end type double2_array
public :: int_array, push_int_2_array
public :: double2_array
contains
subroutine push_int_2_array(a, i)
implicit none
integer, dimension(:), allocatable :: a
integer, intent(in) :: i
! local vars
integer :: n
integer, dimension(:), allocatable :: itmp
if ( .not. allocated(a) ) then
n = 1
else
n = size(a) + 1
end if
allocate(itmp(n))
if ( n > 1 ) itmp(1:(n-1)) = a(1:(n-1))
itmp(n) = i
call move_alloc(itmp, a)
! clean
if ( allocated(itmp) ) deallocate(itmp)
! done here
end subroutine push_int_2_array
end module var_array