============================================================
 
      This routine injects a 2D beam of "NPARB" particles
      at the longitudinal postition XS [M] (along the ring or
      beam line).
      IOUT is a parameter for saving in the file "injection.data"
      the particle distribution.
      EX, EY, ES [MM*MMRAD] are the emittances of the 2D beam
      at injection.
      These emittances for a KV beam yields are the "edge emittances".
      Rxi,Rpxi,Ryi,Rpy are the 4 coordinates [m], [rad] where
      the center of the beam is injected.
      NDIST is a parameter for choosing the kind of distribution:
 
      ndist = 1  -->  K-V distribution
      ndist = 2  -->  Waterbag distribution
      ndist = 3  -->  Gaussia-Gaussian distribution
      the flag sigmacut sayies at how many sigma the beam is cut
 
      in the file "injection.data" particle coordinates are stored as
 
      particle --> x[mm]  px[mmrad] y[mm] py[mmrad] s[m] v[km/s]
 
 
      In the matrix XPAR(n,6) are stored the particle coordinates as
      follows:
 
      N        = particle index
      XPAR(N,1)= X     [M]
      XPAR(N,2)= PX    [RAD]
      XPAR(N,3)= Y     [M]
      XPAR(N,4)= PY    [RAD]
      XPAR(N,5)= S     [M]
      XPAR(N,6)= DP/P0 [RAD]
 
 
 
      It is possible to use repeatedly this routine to inject
      many 2D beam at different transverse positions.
      The total number of particles "NPAR" will be automatically
      updated.
 
 
 =============================================================
 
subroutine injection3D(XS,IOUT,EX,EY,ES, Rxi,Rpxi,Ryi,Rpyi)
 
COMMONS: 
common-initi.f
common-2Dsc-beam.f
common-2Dsc-simulation.f
 
SUBROUTINES USED:
 y
  beta
  beta_KV_BETA0
  messages_n
  cs_phys_inj
  findelea
 
micromap-index
Mon Jul 17 08:57:38 CEST 2017