anchor.diff:  !  write(*,*) "r", r
   
     ! MISCUT third step: F coordinates on crystal exit face
  -  A_F = tan_mb(cry_bend)**2 + one
  -  B_F = -two*tan_mb(cry_bend)**2*c_rcurv + two*tan_mb(cry_bend)*s_P -two*x_P
  -  C_F = tan_mb(cry_bend)**2*c_rcurv**2 - two*tan_mb(cry_bend)*s_P*c_rcurv + s_P**2 + x_P**2 - r**2
  +!  A_F = tan_mb(cry_bend)**2 + one
  +!  B_F = -two*tan_mb(cry_bend)**2*c_rcurv + two*tan_mb(cry_bend)*s_P -two*x_P
  +!  C_F = tan_mb(cry_bend)**2*c_rcurv**2 - two*tan_mb(cry_bend)*s_P*c_rcurv + s_P**2 + x_P**2 - r**2
  +  A_F = tan_mb(length/c_rcurv)**2 + one
  +  B_F = -two*tan_mb(length/c_rcurv)**2*c_rcurv + two*tan_mb(length/c_rcurv)*s_P -two*x_P
  +  C_F = tan_mb(length/c_rcurv)**2*c_rcurv**2 - two*tan_mb(length/c_rcurv)*s_P*c_rcurv + s_P**2 + x_P**2 - r**2
   
     x_F = (-B_F-sqrt(B_F**2-four*A_F*C_F))/(two*A_F)
  -  s_F = -tan_mb(cry_bend)*(x_F-c_rcurv)
  +!  s_F = -tan_mb(cry_bend)*(x_F-c_rcurv)
  +  s_F = -tan_mb(length/c_rcurv)*(x_F-c_rcurv)
   !  write(*,*) "F", s_F, x_F
  +!  write(*,*) "F-K", s_F-s_K, x_F-x_K
  +!  write(*,*) "F-M", s_F-s_M, x_F-x_M
   
     if(x_F >= x_K .and. x_F <= x_M .and. s_F >= s_M .and. s_F <= s_K) then
   !    write(*,*) "F on exit face"
       ! MISCUT No additional steps required
  +  else if (c_miscut == 0 .and. abs(x_F-x_K) <= c1m13 .and. abs(s_F-s_K) <= c1m13) then
  +    ! no miscut, entrance from below: exit point is K
  +!    write(*,*) "F on exit face"
  +    x_F = x_K
  +    s_F = s_K
  +  else if (c_miscut == 0 .and. abs(x_F-x_M) <= c1m13 .and. abs(s_F-s_M) <= c1m13) then
  +    ! no miscut, entrance from above: exit point is M
  +!    write(*,*) "F on exit face"
  +    x_F = x_M
  +    s_F = s_M
     else
   !    write(*,*) "F NOT on exit face"
   
  
positive.code: 
      else
  
  !      write(*,*) "not actually hit"
        s = c_rcurv*sin_mb(cry_length/c_rcurv)
        x = x + s*xp
        z = z + s*zp
  
negative.code:     ! If the hit is below, the angle must be greater or equal than the tangent,
      ! or if the hit is above, the angle must be smaller or equal than the tangent
      if((x < zero .and. xp >= xp_tangent) .or. (x >= zero .and. xp <= xp_tangent)) then
  
  !      write(*,*) 'Crystal actually hit from above/below'
  
        ! If it hits the crystal, calculate in which point and apply the transformation and drift to that point
        a_eq  = one + xp**2
  