       SUBROUTINE MAGFLD (X,Y,Z,BTX,BTY,BTZ,B,NREG,IDISC)
       INCLUDE '(DBLPRC)'
       INCLUDE '(DIMPAR)'
       INCLUDE '(IOUNIT)'
       INCLUDE '(LTCLCM)'
       LOGICAL ISFIRST
        INTEGER NAMEP(350 )
        INTEGER NAMEL(350 )
       DATA ISFIRST /.TRUE./
            SAVE ISFIRST,NAMEP,NAMEL
       IDISC=0
                                         IF (ISFIRST) THEN
        CALL GEON2L("B3TaEL  ",NAMEL(  1 ),IERR)
        CALL GEON2L("B3TbEL  ",NAMEL(  2 ),IERR)
        CALL GEON2L("B1EL    ",NAMEL(  3 ),IERR)
        CALL GEON2L("B11EL   ",NAMEL(  4 ),IERR)
        CALL GEON2L("Q2EL    ",NAMEL(  5 ),IERR)
        CALL GEON2L("Q1EL    ",NAMEL(  6 ),IERR)
        CALL GEON2L("Q3EL    ",NAMEL(  9 ),IERR)
        CALL GEON2L("B2aEL   ",NAMEL( 10 ),IERR)
        CALL GEON2L("B2bEL   ",NAMEL( 11 ),IERR)
        CALL GEON2L("B2cEL   ",NAMEL( 12 ),IERR)
        CALL GEON2L("B3aEL   ",NAMEL( 14 ),IERR)
        CALL GEON2L("B3bEL   ",NAMEL( 15 ),IERR)
        CALL GEON2L("B3cEL   ",NAMEL( 16 ),IERR)
        CALL GEON2L("Q4EL    ",NAMEL( 17 ),IERR)
        CALL GEON2L("Q5EL    ",NAMEL( 18 ),IERR)
        CALL GEON2L("Q6aEL   ",NAMEL( 20 ),IERR)
        CALL GEON2L("Q7aEL   ",NAMEL( 21 ),IERR)
        CALL GEON2L("Q8aEL   ",NAMEL( 22 ),IERR)
        CALL GEON2L("Q8bEL   ",NAMEL( 26 ),IERR)
        CALL GEON2L("Q7bEL   ",NAMEL( 27 ),IERR)
        CALL GEON2L("Q6bEL   ",NAMEL( 28 ),IERR)
        CALL GEON2L("Q9aEL   ",NAMEL( 29 ),IERR)
        CALL GEON2L("Q10aEL  ",NAMEL( 30 ),IERR)
        CALL GEON2L("B4aEL   ",NAMEL( 31 ),IERR)
        CALL GEON2L("B4bEL   ",NAMEL( 32 ),IERR)
        CALL GEON2L("B4cEL   ",NAMEL( 33 ),IERR)
        CALL GEON2L("B5aEL   ",NAMEL( 34 ),IERR)
        CALL GEON2L("B5bEL   ",NAMEL( 35 ),IERR)
        CALL GEON2L("B5cEL   ",NAMEL( 36 ),IERR)
        CALL GEON2L("Q10bEL  ",NAMEL( 37 ),IERR)
        CALL GEON2L("Q9bEL   ",NAMEL( 38 ),IERR)
        CALL GEON2L("Q11EL   ",NAMEL( 40 ),IERR)
        CALL GEON2L("B6EL    ",NAMEL( 41 ),IERR)
        CALL GEON2L("Q13EL   ",NAMEL( 43 ),IERR)
        CALL GEON2L("Q14EL   ",NAMEL( 44 ),IERR)
        CALL GEON2L("Q15EL   ",NAMEL( 45 ),IERR)
        CALL GEON2L("Q16EL   ",NAMEL( 46 ),IERR)
        CALL GEON2L("Q17EL   ",NAMEL( 47 ),IERR)
        CALL GEON2L("Q18EL   ",NAMEL( 48 ),IERR)
        CALL GEON2R("MTNH0VA ",NAMEP( 1),IERR)
        CALL GEON2R("MSNH0VA ",NAMEP( 2),IERR)
        CALL GEON2R("MBNH0VA ",NAMEP( 3),IERR)
        CALL GEON2R("MBNV0VA ",NAMEP( 4),IERR)
        CALL GEON2R("QNLQ0VA ",NAMEP( 5),IERR)
        CALL GEON2R("QWLQ0VA ",NAMEP( 6),IERR)
        CALL GEON2R("QSLQ0VA ",NAMEP( 7),IERR)
         ISFIRST = .FALSE.
      END IF
      IF((MLATTC.EQ.NAMEL( 1)).AND.(NREG.EQ.NAMEP( 1))) THEN
        B= 0.103775493E+1
        BTX= 0.00000000000000E+0
        BTY=-0.10000000000000E+1
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 2)).AND.(NREG.EQ.NAMEP( 1))) THEN
        B= 0.103775493E+1
        BTX= 0.00000000000000E+0
        BTY=-0.10000000000000E+1
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 3)).AND.(NREG.EQ.NAMEP( 2))) THEN
        B= 0.583737146E+0
        BTX= 0.00000000000000E+0
        BTY=-0.10000000000000E+1
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 4)).AND.(NREG.EQ.NAMEP( 2))) THEN
        B= 0.000000000E+0
        BTX= 0.00000000000000E+0
        BTY=-0.10000000000000E+1
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 5)).AND.(NREG.EQ.NAMEP( 5))) THEN
        B= 0.000000000E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 6)).AND.(NREG.EQ.NAMEP( 7))) THEN
        B= 0.000000000E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL( 9)).AND.(NREG.EQ.NAMEP( 5))) THEN
        B= 0.000000000E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(10)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(11)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(12)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(14)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(15)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(16)).AND.(NREG.EQ.NAMEP( 4))) THEN
        B= 0.912097630E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(17)).AND.(NREG.EQ.NAMEP( 5))) THEN
        B= 0.000000000E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
      IF((MLATTC.EQ.NAMEL(18)).AND.(NREG.EQ.NAMEP( 5))) THEN
        B= 0.000000000E+0
        BTX= 0.10000000000000E+1
        BTY= 0.00000000000000E+0
        BTZ= 0.00000000000000E+0
       ENDIF
C      IF((MLATTC.EQ.NAMEL(20)).AND.(NREG.EQ.NAMEP( 6))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(21)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(22)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(26)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(27)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(28)).AND.(NREG.EQ.NAMEP( 6))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(29)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(30)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B= 0.000000000E+0
C        BTX= 0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C     IF((MLATTC.EQ.NAMEL(31)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B= 0.912097630E+0
C        BTX=-0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C       BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(32)).AND.(NREG.EQ.NAMEP( 4))) THEN
C       B= 0.912097630E+0
C        BTX=-0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(33)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B= 0.912097630E+0
C        BTX=-0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(34)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B= 0.912097630E+0
C        BTX=-0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(35)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B= 0.912097630E+0
C        BTX=-0.10000000000000E+1
C        BTY= 0.00000000000000E+0
C        BTZ= 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(36)).AND.(NREG.EQ.NAMEP( 4))) THEN
C         B= 0.912097630E+0
C         BTX=-0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(37)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(38)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(40)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(41)).AND.(NREG.EQ.NAMEP( 3))) THEN
C         B= 0.800553800E+0
C         BTX= 0.00000000000000E+0
C         BTY=-0.10000000000000E+1
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(43)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(44)).AND.(NREG.EQ.NAMEP( 6))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(45)).AND.(NREG.EQ.NAMEP( 6))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(46)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(47)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(48)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B= 0.000000000E+0
C         BTX= 0.10000000000000E+1
C         BTY= 0.00000000000000E+0
C         BTZ= 0.00000000000000E+0
C        ENDIF
      RETURN
         END
