!******************** start file orbpre.for ; group orbpre *************
!---------------------------------------------------------------------
!  created dmc apr 1985 - interface to bob's orbit codes
!
subroutine orbpre
  !
  !   ******
  !   define the common variables used by orbc, orbs, orbg, orbxy, and orbxit
  !   ******
  !
  !  rga oct00 - removed levgb = 1,2
  !
  ! mg, 12/19/2013 , i restore (-nsnccw) switch as it is important
  ! for promt losses due to [b x grad b] drift,
  ! i accomplished this by assigning a sign to q while using v_parallel .gt. 0 if it is in
  ! the "co" direction (v_phi*j_phi.gt.0), see gintrp.for
  ! also v_parallel, xksid for motion eq. are in b_tor direction (not j_tor as it is
  ! used to be in transp). changes are made in gintrp.for, orbout.for, orbpre.for

  !      rtm: 24 nov 87 - i have removed the sign of q from bsub85. now
  !   the orbit equations are always in a right handed coordinate system
  !   even though the rest of the beam code may be in a left handed
  !   system.  i have been told (mike z.) that bt has a sign (nsnccw).
  !
  !      rtm: 14 aug 87 -
  !	the (-nsnccw) hack has been removed because only the v_parallel
  !   drift term in the theta and v_parallel equations depends upon the
  !   handedness of the poloidal magnetic field.  this can be accomplished
  !   by assigning a sign to q while using v_parallel .gt. 0 if it is in
  !   the "co" direction (v_phi*j_phi.gt.0). note that psi_t_limiter
  !   is defined to be always positive, and b_toroidal is always positive.
  !   so the (psi_p, theta, phi) coordinate system is either right or
  !   left handed as needed, even though the (xi, theta, phi) system is
  !   always right handed.
  !
  use nbi_com
  !
  !------------------------------------
  !
  implicit none
  bixi(1) = xion
  bithst(1) = th            !rtm 24 nov 87 we don't care about handedness
  !restored by mg dec.2 2013 we do care about handedness
  biv(1) = vion
  !
  !mg, 12/19/2013      bivpar(1) = vpll
  !mg, 12/19/2013      biksid(1) = xksid
  bivpar(1) = vpll*(-nsnccw)  !mg, 12/19/2013
  biksid(1) = xksid*(-nsnccw) !mg, 12/19/2013
  bivprp(1) = vperp
  !
  bia(1)=abeam
  biz(1)=xzbeami
  !
  !   time step control  *** dt_adjust applied here ***
  !
  bidtnv = dt_adjust*dtnv
  !
  return
end subroutine orbpre
!******************** end file orbpre.for ; group orbpre ***************
