*$ 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 '(OPPHST)'
*
      DIMENSION DTQUEN ( MXTRCK, MAXQMG )
*
      CHARACTER*20 FILNAM
      CHARACTER*8 MRGNAM, NRGNAM
      LOGICAL LFCOPE
      SAVE LFCOPE
      DATA LFCOPE / .FALSE. /
*
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )
      IF ( .NOT. LFCOPE ) THEN
         LFCOPE = .TRUE.
         OPEN ( UNIT = 88, FILE = "OPH", STATUS = 'UNKNOWN',
     & FORM ='FORMATTED')
         OPEN ( UNIT = 89, FILE = "Primary", STATUS = 'UNKNOWN',
     & FORM ='FORMATTED')
      WRITE(88,'(1P,6A)')'    XSCO','      YSCO','       ZSCO',
     &'          ETRACK','     WTRACK','       ATRACK'
      WRITE(89,'(1P,6A)')'    XSCO','      YSCO','       ZSCO',
     &'          ETRACK','     WTRACK','       ATRACK'
      END IF
      CALL GEOR2N ( MREG, MRGNAM, IERR1 )
      CALL GEOR2N ( NEWREG, NRGNAM, IERR2 )
      IF(IERR1 .NE. 0 .OR. IERR2 .NE. 0) STOP "Error in name conversion"
      IF(JTRACK .EQ. -1) THEN
      IF(MREG .EQ. 5 .AND. NEWREG .EQ. 6) THEN
      WRITE(88,'(1P,6G12.5)')  XSCO, YSCO, ZSCO, ETRACK, WTRACK, ATRACK  
      END IF      
      END IF
*      IF(LTRACK .EQ. 1) THEN
*      IF(MREG .EQ. 4 .AND. NEWREG .EQ. 5) THEN
*      WRITE(89,'(1P,6G12.5)')  XSCO, YSCO, ZSCO, ETRACK, WTRACK, ATRACK  
*      END IF      
*      END IF
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY EEDRAW ( ICODE )
      RETURN
*                                                                      *
*======================================================================*
*                                                                      *
      ENTRY ENDRAW ( ICODE, MREG, RULL, XSCO, YSCO, ZSCO )
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY SODRAW
      RETURN
*
*======================================================================*
*                                                                      *
      ENTRY USDRAW ( ICODE, MREG, XSCO, YSCO, ZSCO )
      RETURN
*=== End of subrutine Mgdraw ==========================================*
      END