31 class(CellWithNbrsType) :: this
32 integer(I4B) :: index
33 class(VirtualModelType), pointer :: v_model
34
35 integer(I4B) :: nbrCnt, currentSize, i
36 type(CellWithNbrsType), dimension(:), pointer, contiguous :: newNeighbors
37 type(CellWithNbrsType), dimension(:), pointer, contiguous :: oldNeighbors
38
39 if (.not. associated(this%neighbors)) then
40 allocate (this%neighbors(defaultcapacity))
41 this%nrOfNbrs = 0
42 end if
43
44 nbrcnt = this%nrOfNbrs
45 currentsize = size(this%neighbors)
46 if (nbrcnt + 1 > currentsize) then
47
48
49 oldneighbors => this%neighbors
50 allocate (newneighbors(currentsize + defaultcapacity))
51 do i = 1, currentsize
52 newneighbors(i) = oldneighbors(i)
53 end do
54 this%neighbors => newneighbors
55
56
57 deallocate (oldneighbors)
58 nullify (oldneighbors)
59 end if
60
61 this%neighbors(nbrcnt + 1)%cell%index = index
62 this%neighbors(nbrcnt + 1)%cell%v_model => v_model
63
64 this%nrOfNbrs = nbrcnt + 1
65