anchor.diff:        integer, intent(in)                   :: min, dim
         real*8, intent(in)                    :: gamma
   
  -      pos(1,min) = (1 - gamma) * pos(1,dim - 2) + gamma * pos(1, min)
  -      pos(2,min) = (1 - gamma) * pos(2,dim - 2) + gamma * pos(2, min)
  +      pos(1,min) = (1 - gamma) * pos(1,dim) + gamma * pos(1, min)
  +      pos(2,min) = (1 - gamma) * pos(2,dim) + gamma * pos(2, min)
   
   
   end subroutine
  
positive.code: !  DEFINITIONS
  !!----------------------------------------------------------------------------!!
  
        integer, parameter :: dim = 6
        integer :: min, max, i
        real*8, dimension(2, dim)  :: pos
        real*8, dimension(dim)     :: value
        real*8  :: x, y, alpha, beta, gamma
  
        call downhill
  
negative.code:           call reflect(pos, min, dim, alpha)
            call findval(pos, value, dim)
            call minmax(value, min, max)
            call centroid(pos, min, max, dim)
  
            !! Expansion if the minimum value becomes the maximum
            if (minsave.EQ.max) then
                write(*,*) "expanding...", dist
               
                maxsave = max
                xsave = pos(1, max)
                ysave = pos(2, max)
                call expand(pos, max, dim, gamma)
                call findval(pos, value, dim)
                call minmax(value, min, max)
                call centroid(pos, min, max, dim)
  
                !! Setting things back, if expansion is worse than 
                !! standard reflection
                if (maxsave.NE.max) then
                    pos(1, maxsave) = xsave
                    pos(2, maxsave) = ysave
                    call findval(pos, value, dim)
                    call minmax(value, min, max)
                end if
  
            !! Contract from old position if minima value is still minima value
            else if (minsave.EQ.min) then
                !write(*,*) "contracting...", dist
                xsave = pos(1, min)
                ysave = pos(2, min)
  
                pos(1, min) = xsave
                pos(2, min) = ysave
                call contract(pos, min, dim, beta)
                call findval(pos, value, dim)
                call minmax(value, min, max)
                call centroid(pos, min, max, dim)
  
                !! if minima is still minima, contract everything towards max
                if (minsave.EQ.min) then
                    !write(*,*) "Contract all...", dist, min, max
                    !write(*,*) pos(1,1), pos(1,2), pos(1,3), pos(1,4)
                    !write(*,*) pos(2,:)
                    !write(*,*) pos
                    call contractall(pos, max, dim)
                    call findval(pos, value, dim)
                    call minmax(value, min, max)
                    call centroid(pos, min, max, dim)
  
                end if
  
            end if
            i = i + 1
            dist = sqrt((pos(1,min)-pos(1,max)) * (pos(1,min)-pos(1,max)) &
                        + (pos(2,min)-pos(2,max)) * (pos(2,min)-pos(2,max)))
  
        end do
  
        write(*,*) pos(1,1), pos(1,2), pos(1,3), pos(1,4)
        write(*,*) pos(2,1), pos(2,2), pos(2,3), pos(2,4)
        write(*,*) min, max, dim
  
  end subroutine
  
  