*$ CREATE MGDRAW.FOR
*COPY MGDRAW
*                                                                      *
*=== mgdraw ===========================================================*
*                                                                      *
      SUBROUTINE MGDRAW ( ICODE, MREG )

      INCLUDE '(DBLPRC)'
      INCLUDE '(DIMPAR)'
      INCLUDE '(IOUNIT)'
*
*----------------------------------------------------------------------*
*                                                                      *
*     Copyright (C) 1990-2006      by        Alfredo Ferrari           *
*     All Rights Reserved.                                             *
*                                                                      *
*                                                                      *
*     MaGnetic field trajectory DRAWing: actually this entry manages   *
*                                        all trajectory dumping for    *
*                                        drawing                       *
*                                                                      *
*     Created on   01 march 1990   by        Alfredo Ferrari           *
*                                              INFN - Milan            *
*     Last change  05-may-06       by        Alfredo Ferrari           *
*                                              INFN - Milan            *
*                                                                      *
*----------------------------------------------------------------------*
*
      INCLUDE '(CASLIM)'
      INCLUDE '(COMPUT)'
      INCLUDE '(SOURCM)'
      INCLUDE '(FHEAVY)'
      INCLUDE '(FLKSTK)'
      INCLUDE '(GENSTK)'
      INCLUDE '(MGDDCM)'
      INCLUDE '(PAPROP)'
      INCLUDE '(QUEMGD)'
      INCLUDE '(SUMCOU)'
      INCLUDE '(TRACKR)'
      INCLUDE '(EMFSTK)'
      INCLUDE '(RESNUC)'

*
      DIMENSION DTQUEN ( MXTRCK, MAXQMG )
*
      CHARACTER*8 MRGNAM, NRGNAM
      LOGICAL LFCOPE
      SAVE LFCOPE
      DATA LFCOPE / .FALSE. /
      LOGICAL UDFIRST
      DATA UDFIRST / .TRUE. /
      SAVE UDFIRST
*                                                                      *
      ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )
      RETURN
*
*======================================================================*
*                                                                      *
*     Event End DRAWing:                                               *
*                                                                      *
*======================================================================*
*                                                                      *
      ENTRY EEDRAW ( ICODE )
      RETURN
*
*                                                                      *
      ENTRY ENDRAW ( ICODE, MREG, RULL, XSCO, YSCO, ZSCO )
      RETURN
*
*======================================================================*
*                                                                      *
*     SOurce particle DRAWing:                                         *
*                                                                      *
*======================================================================*
*
      ENTRY SODRAW
      RETURN
*
      ENTRY USDRAW ( ICODE, MREG, XSCO, YSCO, ZSCO )
      IF ( UDFIRST ) THEN
        UDFIRST = .FALSE.
      ENDIF
      do 20 ip = 1, NP
         IF (KPART(ip) .EQ. -6) THEN
         WRITE(IODRAW,*) XSCO,YSCO,ZSCO,
     & TKI(ip),CXR(ip),CYR(ip),CZR(ip),ETRACK-AM(JTRACK),WEI(IP)
         ENDIF
20      continue
      do 30 ip=1,NPHEAV
        IF (KHEAVY(ip) .EQ. 6) THEN
         WRITE (IODRAW,*) XSCO,YSCO,ZSCO,
     & TKHEAV(ip),CXHEAV(ip),CYHEAV(ip),
     & CZHEAV(ip),ETRACK-AM(JTRACK), WHEAVY(ip)
        ENDIF
30      continue
      RETURN
*==== end of subrutine Mgdraw =========================================*
      END
