anchor.diff:    else
   
       if(x < zero) then ! Crystal hit from below
  -!      write(*,*) 'Crystal hit from below'
  +!      write(*,*) 'Crystal potentially hit from below'
   !      write(*,*) 'CHECK', x
         xp_tangent = sqrt((-(two*x)*c_rcurv + x**2)/c_rcurv**2)
   !      write(*,*) 'tangent', xp_tangent, xp
       else ! Crystal hit from above
  +!      write(*,*) 'Crystal potentially hit from above'
   !      write(*,*) 'CHECK', x
         xp_tangent = asin_mb((c_rcurv*(one - c_cBend) - x)/sqrt(((two*c_rcurv)*(c_rcurv - x))*(one - c_cBend) + x**2))
   !      write(*,*) 'tangent', xp_tangent, xp
  
positive.code:   L_chan   = length
  
    ! MISCUT second step: fundamental coordinates
    s_K = c_rcurv*sin_mb(cry_bend)
    x_K = c_rcurv*(1-cos_mb(cry_bend))
    s_M = (c_rcurv-c_xmax)*sin_mb(cry_bend)
    x_M = c_xmax + (c_rcurv-c_xmax)*(1-cos_mb(cry_bend))
    r   = sqrt(s_P**2 + (x-x_P)**2)
  !  write(*,*) "bending", length/c_rcurv
  !  write(*,*) "Rcurv", c_rcurv
  !  write(*,*) "P", s_P, x_P
  !  write(*,*) "I", s, x
  
negative.code: 
      else
  
  !      write(*,*) 'Crystal NOT actually hit'
        s = c_rcurv*sin_mb(cry_length/c_rcurv)
        x = x + s*xp
        z = z + s*zp
  