*$ 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)'
*
      DIMENSION DTQUEN ( MXTRCK, MAXQMG )
*
      CHARACTER*20 FILNAM
      LOGICAL LFCOPE
      SAVE LFCOPE
      DATA LFCOPE / .FALSE. /

*----------------------------------------------------------------------
*	Unit Numbers of Primary and Secondary Output
	INTEGER :: PRIMARYOUTPUT=55
	INTEGER :: SECONDARYOUTPUT=56
	INTEGER :: JTRACKOUTPUT=99

	CHARACTER*8 DEPARTREGION, ARRIVEREGION
*----------------------------------------------------------------------



      ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )

	IF ( .NOT. LFCOPE ) THEN
		LFCOPE = .TRUE.
		OPEN ( UNIT = PRIMARYOUTPUT, FILE = "PRIMARY", STATUS = 'UNKNOWN')
	END IF

	CALL GEOR2N ( MREG,   DEPARTREGION, IERR1 )
	CALL GEOR2N ( NEWREG, ARRIVEREGION, IERR2 )


	IF(IERR1 .NE. 0 .OR. IERR2 .NE. 0) STOP "Error in name conversion"
	IF(Ptrack .LE. 0.0) STOP "Error in momentum: mgdraw.f"

	IF(DEPARTREGION .EQ. "VAC" .AND. ARRIVEREGION .EQ. "WAT") THEN

		IF((JTRACK .GT. -7) .AND. (JTRACK .LT. 63)) THEN
			WRITE(PRIMARYOUTPUT,*) JTRACK,ICHRGE(JTRACK),
     & IBARCH(JTRACK),ETRACK-AM(JTRACK)
		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

