My Project
linklist.f90
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 !/===========================================================================/
13 ! Copyright (c) 2007, The University of Massachusetts Dartmouth
14 ! Produced at the School of Marine Science & Technology
15 ! Marine Ecosystem Dynamics Modeling group
16 ! All rights reserved.
17 !
18 ! FVCOM has been developed by the joint UMASSD-WHOI research team. For
19 ! details of authorship and attribution of credit please see the FVCOM
20 ! technical manual or contact the MEDM group.
21 !
22 !
23 ! This file is part of FVCOM. For details, see http://fvcom.smast.umassd.edu
24 ! The full copyright notice is contained in the file COPYRIGHT located in the
25 ! root directory of the FVCOM code. This original header must be maintained
26 ! in all distributed versions.
27 !
28 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30 ! THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 ! PURPOSE ARE DISCLAIMED.
32 !
33 !/---------------------------------------------------------------------------/
34 ! CVS VERSION INFORMATION
35 ! $Id$
36 ! $Name$
37 ! $Revision$
38 !/===========================================================================/
39 
40 !---------------------------------------------------------
41 ! A linklist module
42 !---------------------------------------------------------
44  use lims, only : myid
45  use particle_class
46  implicit none
47 
48  type link_node
49 ! private
50  type(particle) :: v
51  type(link_node), pointer :: next
52  end type link_node
53 
54  type link_list
55 ! private
56  type(link_node), pointer :: first
57  end type link_list
58 
59  contains
60 
61  subroutine node_delete (links,obj,found)
62  implicit none
63  type(link_list), intent(inout) :: links
64  type(particle), intent(in) :: obj
65  logical , intent(out) :: found
66  type(link_node), pointer :: previous,current
67 
68  !find location of obj
69  previous => links%first
70  current => previous%next
71  found = .false.
72 
73  do
74  if(found .or. (.not. associated (current))) return
75  if(obj == current%v)then
76  found = .true. ; exit
77  else
78  previous => previous%next
79  current => current%next
80  endif
81  end do !find location of node with obj
82 
83  if (found) then
84  previous%next => current%next
85  deallocate(current)
86  endif
87 
88  end subroutine node_delete
89 
90  subroutine delete_not_mine(links,ME)
91  implicit none
92  type(link_list), intent(inout) :: links
93  integer, intent(in) :: ME
94  type(link_node), pointer :: previous,current
95 
96  !find location of obj
97  previous => links%first
98  current => previous%next
99 
100 
101  do
102  if(.not. associated (current)) return
103  if(myid /= current%v%PID)then
104  previous%next => current%next
105  deallocate(current)
106  current => previous%next
107  else
108  previous => previous%next
109  current => current%next
110  endif
111  end do !find location of node with obj
112 
113  end subroutine delete_not_mine
114 
115  subroutine delete_not_found (links)
116  implicit none
117  type(link_list), intent(inout) :: links
118  type(link_node), pointer :: previous,current
119 
120  !find location of obj
121  previous => links%first
122  current => previous%next
123 
124  do
125  if(.not. associated (current)) return
126  if(.not. current%v%found)then
127  previous%next => current%next
128  deallocate(current)
129  else
130  previous => previous%next
131  current => current%next
132  endif
133  end do !find location of node with obj
134 
135  end subroutine delete_not_found
136 
137  subroutine node_insert( links,obj )
138  type(link_list), intent(inout) :: links
139  type(particle), intent(in) :: obj
140  type(link_node), pointer :: previous,current
141 
142  previous => links%first
143  current => previous%next
144 
145  do
146  if( .not. associated (current) )exit
147  if( obj < current%v ) exit
148  previous => current
149  current => current%next
150  end do
151 
152  !insert before current
153  allocate(previous%next) !new node space
154  previous%next%v = obj !new object inserted
155  previous%next%next => current !new next pointer
156 
157  end subroutine node_insert
158 
159  function empty_list(links) result(t_or_f)
160  type(link_list), intent(in) :: links
161  logical :: t_or_f
162  t_or_f = .not. associated (links%first%next)
163  end function empty_list
164 
165  function new_list () result (OBJ)
166  type(link_list) :: obj
167  integer :: status
168  allocate ( obj%first, stat=status)
169  if(status/=0) CALL fatal_error("LinkList: Could not allocate new linklist")
170  nullify(obj%first%next)
171  end function new_list
172 
173  subroutine print_list (links)
174  type(link_list), intent(in) :: links
175  type(link_node), pointer :: current
176  logical :: headprint
177  integer :: count
178  current => links%first%next
179  headprint = .true.
180  count = 0
181  do
182  if(.not. associated(current) ) exit
183  call screen_write(current%v,headprint)
184  current => current%next
185  headprint = .false.
186  count = count +1
187  end do
188  write(ipt,*) "! PROC:",myid,"; # of local particles:", count
189  end subroutine print_list
190 
191  subroutine print_data (links)
192  type(link_list), intent(in) :: links
193  type(link_node), pointer :: current
194  current => links%first%next
195  do
196  if(.not. associated(current) ) exit
197  call particle_print(current%v)
198  current => current%next
199  end do
200  end subroutine print_data
201 
202 !!$ subroutine update_pathlength (links)
203 !!$ type(link_list), intent(in) :: links
204 !!$ type(link_node), pointer :: current
205 !!$ current => links%first%next
206 !!$ do
207 !!$ if(.not. associated(current) ) exit
208 !!$ call set_pathlength(current%v)
209 !!$ current => current%next
210 !!$ end do
211 !!$ end subroutine update_pathlength
212 
213 
214  subroutine print_id_list (links)
215  type(link_list), intent(in) :: links
216  type(link_node), pointer :: current
217  current => links%first%next
218  do
219  if(.not. associated(current) ) exit
220  write(*,*)current%v%id
221  current => current%next
222  end do
223  end subroutine print_id_list
224 
225  subroutine shift_pos_list (links)
226  type(link_list), intent(in) :: links
227  type(link_node), pointer :: current
228  logical :: headprint
229  current => links%first%next
230  headprint = .true.
231  do
232  if(.not. associated(current) ) exit
233  call shift_pos(current%v)
234  current => current%next
235  end do
236  end subroutine shift_pos_list
237 
238 
239  function listsize (links) result (counter)
240  type(link_list), intent(in) :: links
241  type(link_node), pointer :: current
242  integer :: counter
243  counter = 0
244  current => links%first%next
245 
246  do
247  if(.not. associated(current) ) exit
248  counter = counter + 1
249  current => current%next
250  end do
251  end function listsize
252 
253  subroutine set_not_found (links)
254  type(link_list), intent(in) :: links
255  type(link_node), pointer :: current
256 
257  current => links%first%next
258  do
259  if(.not. associated(current) ) exit
260  current%v%found = .false.
261  current => current%next
262  end do
263  end subroutine set_not_found
264 
265 
266 end module linked_list
267 
268 
subroutine screen_write(p, hprint)
Definition: particle.f90:127
subroutine delete_not_mine(links, ME)
Definition: linklist.f90:91
integer myid
Definition: mod_main.f90:67
type(link_list) function new_list()
Definition: linklist.f90:166
integer function listsize(links)
Definition: linklist.f90:240
subroutine shift_pos(p)
Definition: particle.f90:136
subroutine shift_pos_list(links)
Definition: linklist.f90:226
subroutine print_id_list(links)
Definition: linklist.f90:215
logical function empty_list(links)
Definition: linklist.f90:160
subroutine node_insert(links, obj)
Definition: linklist.f90:138
subroutine delete_not_found(links)
Definition: linklist.f90:116
subroutine node_delete(links, obj, found)
Definition: linklist.f90:62
subroutine print_list(links)
Definition: linklist.f90:174
subroutine particle_print(p)
Definition: particle.f90:147
subroutine set_not_found(links)
Definition: linklist.f90:254
subroutine print_data(links)
Definition: linklist.f90:192