CDECK  ID>, DOPAT.
      SUBROUTINE DOPAT

C-    Process the current patch
C.    started 27-feb-92

      PARAMETER (KM1=1,KM2=2,KM3=4,KM4=8,KM5=16,KM6=32,KM7=64,KM8=128,
     +  KM9=256, KM10=512, KM11=1024, KM12=2048, KM13=4096, KM14=8192,
     +  KM15=16384, KM16=32768, KM17=65536, KM18=131072, KM19=262144)
      COMMON /QPAGE/ NQLMAX,NQLTOL,NQLTOK,NQCMAX,NQCPGH,NQPAGE
     +,              NQWYLDO,NQWYL,NQNEWH,NQJOIN,NQDKNO,NQDKPG
      PARAMETER  (MCCNIL=1,  MCCKIL=2,  MCCINC=3,  MCCCDE=4,  MCCSEQ=5,
     + MCCXSQ=6,  MCCTRU=7,  MCCFAL=8,  MCCELS=9,  MCCEND=10,
     +            MCCSEL=11, MCCSES=12, MCCFAU=13, MCCSKI=14,
     +            MCCKEE=15, MCCDEL=16, MCCREP=17, MCCADB=18, MCCADD=19,
     + MCCUSE=20, MCCXDI=21, MCCDIV=22, MCCLIS=23, MCCEXE=24, MCCIMI=25,
     + MCCASM=26, MCCUPD=27, MCCNAM=28, MCCGAP=29, MCCMOR=30, MCCONL=31,
     + MCCFOR=32, MCCSUS=33, MCCOPT=34, MCCOP2=35, MCCSHO=36, MCCPAM=37,
     + MCCQUI=38, MCCEOD=39, MCCDEC=40, MCCPAT=41, MCCTIT=42)
      CHARACTER      CCKORG*256, CCKARD*256, CCCOMF*256
      COMMON /CCPARA/NCHCCD,NCHCCT, JCCTYP,JCCLEV,JCCSL,MCCPAR(240)
     +,              NCCPAR,MXCCIF,JCCIFV,JCCBAD,JCCWAR,ICCSUB,JCCWK(4)
     +,              JCCPP,JCCPD,JCCPZ,JCCPT,JCCPIF,JCCPC,JCCPN
     +,              NCCPP,NCCPD,NCCPZ,NCCPT,NCCPIF,NCCPC,NCCPN
     +,              JCCEND, NCHCCC,IXCCC,  CCKORG, CCKARD, CCCOMF
      CHARACTER      CHEXPD*68
      COMMON /CHEXC/ IXEXPAM, IXEXPAT,IXEXDEC,IXEXID, NCHEPD, CHEXPD
      COMMON /MUSEBC/ MX_FORC, MU_GLOB, MU_PAT, MU_DECK, MU_INH, MU_FORG
     +,               MX_TRAN, MX_FORG, MX_SINH, MX_SELF, NVEXDK(6)
      PARAMETER      (NEWLN=10, NCHNEWL=1)
      PARAMETER      (NSIZEQ=100000, NSIZELN=100000)
      PARAMETER      (NSIZETX=40*NSIZELN)
                     CHARACTER    TEXT(NSIZETX)*1
                     DIMENSION    LQ(NSIZEQ), IQ(NSIZEQ), MLIAD(NSIZELN)
                     EQUIVALENCE (LQ,IQ,LQGARB), (MLIAD(1),LQ(NSIZEQ))
                     EQUIVALENCE (TEXT(1), MLIAD(NSIZELN))
      COMMON //      IQUEST(100),LQGARB,LQHOLD,LQARRV,LQKEEP,LQPREP
     +,         LEXP,LLPAST,LQPAST, LQUSER(4), LHASM,LRPAM,LPAM, LQINCL
     +,         LACRAD,LARRV, LPCRA,LDCRAB, LEXD,LDECO, LCRP,LCRD, LSERV
     +, INCRAD, IFLGAR, JANSW, IFMODIF, IFALTN
     +, JDKNEX,JDKTYP, JSLZER,NSLORG,JSLORG
     +, MOPTIO(34), MOPUPD, NCLASH, IFLMERG,IFLDISP, NSLFRE,NTXFRE
     +, NVGAP(4), NVGARB(6), NVIMAT(4), NVUTY(4),  LASTWK
C--------------    End CDE              --------------------------------

      IAND (IZV,IZW) = AND (IZV, IZW)


      IFLGAR = 0
      MUGLOB = MU_GLOB
      JCCBAD = 0
      IF (JDKTYP.EQ.3)             GO TO 26

      JSLF   = IQ(LQHOLD+1)
      JCCTYP = MCCPAT
      JTX = MLIAD(JSLF)
      J   = JPTYPE (TEXT(JTX))
      IF (J.NE.JCCTYP)  THEN
          NTX = MLIAD(JSLF+1) - JTX
          CALL DPLMSG ('Trouble with:',NTX,TEXT(JTX))
          CALL P_CRASH ('trouble in DOPAT')
        ENDIF
      CALL CCKRAK (JSLF)

C--       get the name

      IXEXPAT = MCCPAR(JCCPP+1)
      IF (IXEXPAT.EQ.0)  IXEXPAT= 1

C--       check the patch is already kown, if not it
C-        cannot have been USE selected

      IF (JCCBAD.NE.0)             GO TO 27
      IF (IAND(MU_GLOB,KM5).NE.0)  GO TO 27
      IF (MOPTIO(1).NE.0)          GO TO 27
      IF (LOCPAT(IXEXPAT).NE.0)    GO TO 27

      JDKTYP = 2
      CALL ARRSKP
      RETURN

C--       find/create the patch bank

   26 IF (MOPUPD.GE.0)  MU_GLOB= IAND (MU_GLOB,NOT(KM5))
   27 CALL CREAPD (IXEXPAT,-1,7)
      MU_GLOB = MUGLOB
      IXEXDEC = 0
      IXEXID  = IXEXPAT
      CALL SBYT (NQDKNO, IQ(LEXP+1),13,20)
      MU_PAT = IAND (IQ(LEXP),KM19-1)
      IF (JCCBAD.NE.0)                GO TO 44
      IF (IAND(MU_PAT,KM10).EQ.0)     GO TO 47
      IF (IAND(IQ(LEXP+1),KM2).NE.0)  GO TO 47
      IF (IAND(IQ(LEXP+1),KM4).NE.0)  GO TO 44
      IF (IAND(MU_PAT,KM5).EQ.0)      GO TO 47

   44 CALL DODECK (0)
      GO TO 48

   47 JDKTYP = 2
      CALL ARRSKP
   48 IF (IAND(IQ(LEXP+1),KM5).NE.0)  RETURN
      IF (MOPUPD.LT.0)                RETURN

      IF (LQ(LEXP-2).NE.0)  CALL TOGARB (LEXP-2,7)
      IF (LQ(LEXP-3).NE.0)  CALL TOGARB (LEXP-3,7)
      RETURN
      END
