| 1 |
chuckv |
247 |
!! 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 |
chuckv |
254 |
|
| 50 |
chuckv |
247 |
do while (associated(temp)) |
| 51 |
|
|
if (temp%atype_ident == ident) then |
| 52 |
|
|
atype => temp |
| 53 |
|
|
exit |
| 54 |
|
|
endif |
| 55 |
chuckv |
254 |
|
| 56 |
chuckv |
247 |
temp => temp%next |
| 57 |
|
|
end do |
| 58 |
|
|
|
| 59 |
|
|
end subroutine find_atype |
| 60 |
|
|
|
| 61 |
|
|
subroutine create_identPtrList(ident,this_list,identPtrList,status) |
| 62 |
chuckv |
254 |
use definitions |
| 63 |
chuckv |
247 |
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 |
chuckv |
252 |
|
| 77 |
chuckv |
247 |
!! Allocate space for pointer list. |
| 78 |
|
|
if (.not. associated(identPtrList)) then |
| 79 |
|
|
allocate(identPtrList(list_size),stat=alloc_stat) |
| 80 |
|
|
if (alloc_stat /= 0) then |
| 81 |
|
|
status = -1 |
| 82 |
|
|
return |
| 83 |
|
|
end if |
| 84 |
chuckv |
252 |
|
| 85 |
chuckv |
247 |
else if ( list_size > size(identPtrList)) then |
| 86 |
|
|
!! We've already allocated this list and need to make it bigger |
| 87 |
chuckv |
252 |
|
| 88 |
chuckv |
247 |
deallocate(identPtrList) |
| 89 |
|
|
allocate(identPtrList(list_size),stat=alloc_stat) |
| 90 |
|
|
if (alloc_stat /= 0) then |
| 91 |
|
|
status = -1 |
| 92 |
|
|
return |
| 93 |
|
|
end if |
| 94 |
|
|
else |
| 95 |
|
|
!! nullify entire list.... |
| 96 |
|
|
do i = 1, list_size |
| 97 |
|
|
identPtrList(i)%this => null() |
| 98 |
|
|
end do |
| 99 |
|
|
end if |
| 100 |
|
|
|
| 101 |
|
|
|
| 102 |
|
|
do i = 1, list_size |
| 103 |
|
|
this_ident = ident(i) |
| 104 |
chuckv |
252 |
|
| 105 |
chuckv |
247 |
call find_atype(this_ident,this_list,tmpPtr) |
| 106 |
|
|
!! If we can't find the atype corresponding to the ident, return w/ error. |
| 107 |
|
|
if (.not. associated(tmpPtr)) then |
| 108 |
|
|
status = -1 |
| 109 |
|
|
write(*,*) "Could not find an atype for ident ", this_ident |
| 110 |
|
|
return |
| 111 |
|
|
end if |
| 112 |
|
|
!! Assign temp pointer to pointer list |
| 113 |
|
|
identPtrList(i)%this => tmpPtr |
| 114 |
|
|
end do |
| 115 |
|
|
|
| 116 |
|
|
end subroutine create_identPtrList |
| 117 |
|
|
|
| 118 |
|
|
function getListLen(this_list) result(listLen) |
| 119 |
|
|
type( generic_atype ), pointer :: this_list |
| 120 |
|
|
type( generic_atype ), pointer :: tmpPtr |
| 121 |
|
|
|
| 122 |
|
|
integer :: listLen |
| 123 |
|
|
|
| 124 |
|
|
listLen = 0 |
| 125 |
|
|
|
| 126 |
|
|
tmpPtr => this_list |
| 127 |
|
|
do while (associated(tmpPtr)) |
| 128 |
|
|
listLen = listLen + 1 |
| 129 |
|
|
tmpPtr => tmpPtr%next |
| 130 |
|
|
end do |
| 131 |
|
|
|
| 132 |
|
|
end function getListLen |
| 133 |
|
|
|
| 134 |
|
|
subroutine print_list(head) |
| 135 |
|
|
type( generic_atype ), pointer :: head |
| 136 |
|
|
type( generic_atype ), pointer :: tmpLstPointer |
| 137 |
|
|
|
| 138 |
|
|
write(*,*) " Printing atype_list" |
| 139 |
|
|
if (.not. associated(head)) then |
| 140 |
|
|
|
| 141 |
|
|
write(*,*) "ERROR: list is not associated" |
| 142 |
|
|
return |
| 143 |
|
|
end if |
| 144 |
|
|
tmpLstPointer => head |
| 145 |
|
|
do while(associated(tmpLstPointer)) |
| 146 |
|
|
write(*,*) "Found ident: ", tmpLstPointer%atype_ident |
| 147 |
|
|
tmpLstPointer => tmpLstPointer%next |
| 148 |
|
|
|
| 149 |
|
|
end do |
| 150 |
|
|
|
| 151 |
|
|
|
| 152 |
|
|
end subroutine print_list |