ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/generic_list_functions.i90
Revision: 260
Committed: Fri Jan 31 21:04:27 2003 UTC (21 years, 5 months ago) by chuckv
File size: 3698 byte(s)
Log Message:
Fixed some bugs, made some more.

File Contents

# Content
1 !! include file for adding generic linked list routines for atype list
2
3
4
5 !! generic routine to add an atype to a list
6 subroutine add_atype(this_node,head,tail,status)
7 !! atype node to be added to a list
8 type (generic_atype), pointer :: this_node
9 !! list to which atype is added, if null, we allocate a new list
10 type (generic_atype), pointer :: head
11 type (generic_atype), pointer :: tail
12
13 !! status 0 = success, -1 = failure
14 integer, intent(out) :: status
15
16 type (generic_atype), pointer :: current => null()
17
18 status = 0
19
20 !! We need to allocate and set this node before calling add_list
21 if (.not. associated(this_node)) then
22 status = -1
23 return
24 endif
25
26 !! if list is not associated, we are the first node on the list
27 if (.not. associated(head)) then
28 head => this_node
29 tail => this_node
30 else
31 this_node%prev => tail
32 tail%next => this_node
33 tail => this_node
34
35 endif
36 end subroutine add_atype
37
38 subroutine find_atype(ident,this_list, atype)
39 integer, intent(in) :: ident
40 type (generic_atype), pointer :: this_list
41 type (generic_atype), pointer :: atype
42
43 type (generic_atype), pointer :: temp
44
45 atype => null()
46 if (.not. associated(this_list)) return
47
48 temp => this_list
49
50 do while (associated(temp))
51 if (temp%atype_ident == ident) then
52 atype => temp
53 exit
54 endif
55
56 temp => temp%next
57 end do
58
59 end subroutine find_atype
60
61 subroutine create_identPtrList(ident,this_list,identPtrList,status)
62 use definitions
63 integer, dimension(:) :: ident
64 type(generic_atype), pointer :: this_list
65 type(generic_atype), pointer :: tmpPtr
66 type(generic_identPtrList), dimension(:),pointer :: identPtrList
67 integer, intent(out), optional :: status
68
69 integer :: list_size
70 integer :: i
71 integer :: this_ident
72 integer :: alloc_stat
73
74 status = 0
75 list_size = size(ident)
76
77
78 !! Allocate space for pointer list.
79 if (.not. associated(identPtrList)) then
80 allocate(identPtrList(list_size),stat=alloc_stat)
81 if (alloc_stat /= 0) then
82 status = -1
83 return
84 end if
85
86 else if ( list_size > size(identPtrList)) then
87 !! We've already allocated this list and need to make it bigger
88
89 deallocate(identPtrList)
90 allocate(identPtrList(list_size),stat=alloc_stat)
91 if (alloc_stat /= 0) then
92 status = -1
93 return
94 end if
95 else
96 !! nullify entire list....
97 do i = 1, list_size
98 identPtrList(i)%this => null()
99 end do
100 end if
101
102
103 do i = 1, list_size
104 this_ident = ident(i)
105
106 call find_atype(this_ident,this_list,tmpPtr)
107 !! If we can't find the atype corresponding to the ident, return w/ error.
108 if (.not. associated(tmpPtr)) then
109 status = -1
110 write(*,*) "Could not find an atype for ident ", this_ident
111 return
112 end if
113 !! Assign temp pointer to pointer list
114 identPtrList(i)%this => tmpPtr
115 end do
116
117 end subroutine create_identPtrList
118
119 function getListLen(this_list) result(listLen)
120 type( generic_atype ), pointer :: this_list
121 type( generic_atype ), pointer :: tmpPtr
122
123 integer :: listLen
124
125 listLen = 0
126
127 tmpPtr => this_list
128 do while (associated(tmpPtr))
129 listLen = listLen + 1
130 tmpPtr => tmpPtr%next
131 end do
132
133 end function getListLen
134
135 subroutine print_list(head)
136 type( generic_atype ), pointer :: head
137 type( generic_atype ), pointer :: tmpLstPointer
138
139 write(*,*) " Printing atype_list"
140 if (.not. associated(head)) then
141
142 write(*,*) "ERROR: list is not associated"
143 return
144 end if
145 tmpLstPointer => head
146 do while(associated(tmpLstPointer))
147 write(*,*) "Found ident: ", tmpLstPointer%atype_ident
148 tmpLstPointer => tmpLstPointer%next
149
150 end do
151
152
153 end subroutine print_list