*$ 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 '(EMFSTK)'
      INCLUDE '(MGDDCM)'
      INCLUDE '(PAPROP)'
      INCLUDE '(QUEMGD)'
      INCLUDE '(SUMCOU)'
      INCLUDE '(TRACKR)'
*
      DIMENSION DTQUEN ( MXTRCK, MAXQMG )
*
      CHARACTER*20 FILNAM
      CHARACTER*8 MRGNAM, NRGNAM
      LOGICAL LFCOPE
      SAVE LFCOPE
      DATA LFCOPE / .FALSE. /
*
      LOGICAL UDFIRST
      DATA UDFIRST / .TRUE. /
      SAVE UDFIRST
*
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )

      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY EEDRAW ( ICODE )
      RETURN
*                                                                      *
*======================================================================*
*                                                                      *
      ENTRY ENDRAW ( ICODE, MREG, RULL, XSCO, YSCO, ZSCO )
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY SODRAW
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY USDRAW ( ICODE, MREG, XSCO, YSCO, ZSCO )
      IF ( UDFIRST ) THEN
         UDFIRST = .FALSE.
         OPEN ( UNIT = 80, FILE = "filejuju_usd", STATUS = 'UNKNOWN')
      ENDIF
      IF (NPHEAV/=0) THEN
         WRITE(80,'(1P,12G25.15)') 'c1 ',NCASE,JTRACK,NPFLKA,ICODE,
     & NP,NPHEAV,ETRACK-AM(JTRACK),XSCO,YSCO,ZSCO,WTRACK
      ENDIF
*
* Boucle sur particules secondaires
*      do 10 ip = 1, NP
*         IF (ZPART/=0) THEN
*            WRITE( 80,'(1P,12G25.15)')'c2 ',NCASE,JTRACK,
*     & ip,ICODE,ZPART,APART,TKI(ip)
*     ,CXR(ip),CYR(ip),
*     & CZR(ip),WEI(ip)
*         ENDIF
*10    continue
*
      do 20 ip=1,NPHEAV
         WRITE(80,'(1P,12G25.15)') 'c4', NCASE, JTRACK,
     & ip,ICODE,KHEAVY(ip),ICHEAV(KHEAVY(ip)),
     & IBHEAV(KHEAVY(ip)),TKHEAV(ip)
20    continue
      DO 1 IZ = 1, MAXZ
        DO 2 NMZMK = MINNMZ-K, MAXNMZ-K
          WRITE(80,'(2I4,1P,G15.6)') 'cres',IZ, NMZMK+K+2*IZ,
     & ARRAY(IZ,NMZMK)
2     CONTINUE
1     CONTINUE
      RETURN
*=== End of subrutine Mgdraw ==========================================*
      END
