! GeReallocTree.f90 ! ! Allows us to change the size of an allocated array. Contents of old ! array are copied into new array in mutual overlap. Frees old array. ! Array must be declared as pointer (not allocatable) in calling routine. ! ! Detlef Irmscher, Thomas Ullrich, Uni Heidelberg, September 1993 ! Last update: 16.3.95 tu - bug corrected ! subroutine GeReallocTree(newup, istat) use genesis_m, self=>GeReallocTree implicit none integer, intent (in) :: newup integer, intent (out) :: istat integer :: i type(tree), pointer :: pnew(:) if (.not.associated(treeList)) then ! check if allocated call GeErrorMessage ("realloc_tree", & "can only reallocate allocated treeList", & fatal=.true.) endif allocate (pnew(newup),stat=istat) ! allocate and zero new array if (istat /= 0) then call GeErrorMessage("GeReallocTree", "can't allocate new array") return endif do i = 1, size(treeList) ! copy old to new array if (i <= newup) then pnew(i) = treeList(i) endif enddo deallocate(treeList) treeList => pnew ! copy new to old pointer end subroutine GeReallocTree