File: N:\mfix\model\des\list.f
1 #include "version.inc"
2
3 module list
4
5
6
7
8
9
10
11
12
13
14 type list_t
15 integer, dimension(:), allocatable :: list
16 integer :: list_len
17 end type list_t
18
19 contains
20
21
22
23
24
25
26
27
28
29 subroutine list_init(this)
30 implicit none
31 type(list_t), intent(inout) :: this
32
33 allocate(this%list(10))
34 this%list = 0
35 this%list_len = 0
36
37 end subroutine list_init
38
39
40
41
42
43
44
45
46
47 subroutine list_add(this,value)
48 use resize, only: integer_grow
49 implicit none
50 type(list_t), intent(inout) :: this
51 integer, intent(in) :: value
52 integer :: old_len
53
54 this%list_len = this%list_len + 1
55 if (size(this%list) < this%list_len) then
56 old_len = size(this%list)
57 call integer_GROW(this%list,this%list_len)
58 this%list(old_len+1:size(this%list)) = 0
59 endif
60
61 if (0.eq.this%list(this%list_len)) then
62 this%list(this%list_len) = value
63 else
64 print *,"LIST SHOULD END IN ZERO"
65 print *,"value = ",value
66 do old_len = 1, size(this%list)
67 print *,"list: ",old_len,this%list(old_len)
68 enddo
69 ERROR_STOP __LINE__
70 endif
71 end subroutine list_add
72
73
74
75
76
77
78
79
80
81 integer function list_pop(this)
82 implicit none
83 type(list_t), intent(inout) :: this
84
85 if (this%list_len .eq. 0) then
86 list_pop = -1
87 return
88 endif
89
90 list_pop = this%list(this%list_len)
91 this%list(this%list_len) = 0
92
93 this%list_len = this%list_len - 1
94
95 end function list_pop
96
97
98
99
100
101
102
103
104
105 subroutine list_del(this,value)
106 implicit none
107 type(list_t), intent(inout) :: this
108 integer, intent(in) :: value
109 integer :: ai, aa
110
111 do ai=1, size(this%list)
112 aa = this%list(ai)
113 if (value.eq.aa) then
114 this%list(ai) = this%list(this%list_len)
115 this%list(this%list_len) = 0
116 this%list_len = this%list_len - 1
117 exit
118 endif
119 enddo
120
121 end subroutine list_del
122
123
124
125
126
127
128
129
130
131 integer function list_get(this,index)
132 implicit none
133 type(list_t), intent(in) :: this
134 integer :: index
135
136 list_get = this%list(index)
137
138 end function list_get
139
140
141
142
143
144
145
146
147
148 integer function list_get_length(this)
149 implicit none
150 type(list_t), intent(in) :: this
151
152 list_get_length = this%list_len
153
154 end function list_get_length
155
156 end module list
157