      Subroutine MFFLD(X,B,ierr)
C =================================
C
C Interface to GUFLD.
C
C +CDE,GCTMED.
C +CDE,GCVOLU.
*KEEP,GCTMED.
c      Integer numed,natmed,isvol,ifield,iupd,istpar,numold
c      Real fieldm,tmaxfd,dmaxms,deemax,epsil,stmin,cfield,cmuls
      COMMON/GCTMED/NUMED,NATMED(5),ISVOL,IFIELD,FIELDM,TMAXFD,DMAXMS
     +      ,DEEMAX,EPSIL,STMIN,CFIELD,CMULS,IUPD,ISTPAR,NUMOLD
C
*KEEP,GCVOLU.
c      Integer names,number,lvolum,lindex,infrom,nlevmx,nldev,linmx
c      Real gtran,grmat,gonly,glx
      COMMON/GCVOLU/NLEVEL,NAMES(15),NUMBER(15),
     +LVOLUM(15),LINDEX(15),INFROM,NLEVMX,NLDEV(15),LINMX(15),
     +GTRAN(3,15),GRMAT(10,15),GONLY(15),GLX(3)
C
*KEND.
C
      CHARACTER*20 NAME
      REAL X(3),B(3),Z,ZFBAC(2)
      DATA ZFBAC   /500.,617.6/
      REAL ZTOR(2,2),XTOR,YTOR
      DATA ZTOR /829.,874.,
     .           904.,949./
      DATA XTOR,YTOR /340.0,380.0/
      REAL ZCTD(2) /-142.5,217.5/
      REAL ABX,ABY
C
      integer ierr
      ierr=0
C
      NUMED=0
C
C Interface to GUFLD
C
C Fields dealed with are: FYOKE, TOROIDS and SOLENOID.
C
C
C---------------------------------------------------------
C--> initialize with `we are not in iron'.
C---------------------------------------------------------
      NAME='    '
      CALL UCTOH(NAME,NAMES(2),4,4)
C---------------------------------------------------------
C
C---------------------------------------------------------
C FORWARD YOKE
C---------------------------------------------------------
      Z = X(3)
      IF(Z.GT.ZFBAC(1).and.Z.LT.ZFBAC(2)) THEN
        R=SQRT(X(1)**2+X(2)**2)
        IF(R.GT.50.) THEN
          NLEVEL=2
          NAME='BFC '
          CALL UCTOH(NAME,NAMES(2),4,4)
          LA=(Z-ZFBAC(1))/11.
          DZ=Z-ZFBAC(1)-LA*11.
          IF(DZ.LT.7.5) THEN
            NUMED=34
          ELSE
            NUMED=33
          ENDIF
        ENDIF
C---------------------------------------------------------
C TOROIDS
C---------------------------------------------------------
      ELSEIF(Z.GT.ZTOR(1,1).and.Z.lt.ZTOR(2,1) .or.
     .       Z.GT.ZTOR(2,1).and.Z.lt.ZTOR(2,2)     ) THEN
        ABX=ABS(X(1))
        ABY=ABS(X(2))
        IF(ABX.LT.XTOR.and.ABY.LT.YTOR) THEN
            NUMED=13
        ELSE
            NUMED=6
        ENDIF
C---------------------------------------------------------
C CTD
C---------------------------------------------------------
      ELSEIF(Z.GT.ZCTD(1).and.Z.lt.ZCTD(2)) THEN
        NUMED=6
        NAME='    '
        CALL UCTOH(NAME,NAMES(2),4,4)
      ENDIF
C
C---------------------------------------------------------
       CALL GUFLD(X,B)
C---------------------------------------------------------
C
C---------------------------------------------------------
C--> reset with `we are not in iron'.
C---------------------------------------------------------
      NAME='    '
      CALL UCTOH(NAME,NAMES(2),4,4)
C---------------------------------------------------------
C
       END
C-----------------------------------------------------------------------

