      subroutine korbit(irpt,iud) ! Bernd Berg Feb 16 2009.
C Prepare data for gnuplot of the orbit.
C Circle, Ellips, Parabola, or Hyperbola all in one.
C Orbit parameters p and e are in common_kepler.f.
      include 'implicit.sta'
      character crpt*3
      include 'constants.par'
      include 'kepler.par'
C Parameters of kepler.par used here:
C ngnu       Number of data in gnuplot file.
      include 'common_kepler.f'
C Common block elements used here:
C p parameter,  e eccentricity,
C r12(4) initial radius, phi0 initial azimuth.
      if(irpt.gt.200) stop "korbit: irpt max value exceeded (change!)."
      if(irpt.lt.0) stop "k_orbit: irpt.lt.0."
      write(crpt,'(i3.3)') irpt ! Initial positions:
      open(iud,file="ki"//crpt//".d",form='formatted',status='unknown')
        x=r12(4)*cos(phi0)
        y=r12(4)*sin(phi0)
        angle=180*phi0/pi
        write(iud,'(4G15.6)') x,y,phi0,angle
      close(iud) ! Data for orbits:
      open(iud,file="k"//crpt//".d",form='formatted',status='unknown')
      do ignu=0,ngnu ! Circle, Ellipse, Parabola, Hyperbola:
        phi=-pi+(tpi*ignu)/ngnu
        cosphi=cos(phi)
        if((one+e*cosphi).gt.zero) then ! Exclusions for hyperbola.
          r=p/(one+e*cosphi)
          x=r*cosphi
          y=r*sin(phi)
          write(iud,'(2G15.6)') x,y
        endif
      enddo
      close(iud)
      return
      end
