C
      include 'tab0d.f'
      include 'tab1d.f'
      include 'tab2d.f'
      include 'taba0d.f'
      include 'taba1d.f'
      include 'taba2d.f'
      include 'taba6d.f'
      include 'taba8d.f'
      include 'tabaxd.f'
      include 'tabszd.f'
      include 'ab0d.f'
      include 'ab1d.f'
      include 'ab4d.f'
      include 'ab5d.f'
      include 'hookax.f'
      include 'plmasd.f'
      include 'plonad.f'
C
      include 'etr3p1d.f'
      include 'etm3p1d.f'
      include 'ets3p1d.f'
      include 'etc3p1d.f'
C
      include 'etr3q1d.f'
      include 'etm3q1d.f'
      include 'ets3q1d.f'
      include 'etc3q1d.f'
C
      include 'etm3q2c.f'
      include 'etr3q2c.f'
      include 'ets3q2c.f'
      include 'ec3c2c.f'
      include 'etc3q2c.f'
C              xxx probleme de nom
C
      include 'etr3r1d.f'
      include 'etm3r1d.f'
      include 'ets3r1d.f'
      include 'etc3r1d.f'
C
      include 'er3c2c.f'
      include 'em3c2c.f'
      include 'es3d2c.f'
      include 'es3c2c.f'
C
      include 'emaq2c.f'
      include 'dpaq2c.f'
C
      include 'etr3r2c.f'
      include 'etm3r2c.f'
      include 'ets3r2c.f'
      include 'etc3r2c.f'
C
      include 'etr3p2c.f'
      include 'etm3p2c.f'
      include 'ets3p2c.f'
      include 'etc3p2c.f'
C
      include 'fobase.f'
      include 'dcopy.f'
C
      include 'etm2p1d.f'
      include 'etr2p1d.f'
      include 'ets2p1d.f'
      include 'etc2p1d.f'
C
      include 'etm2p2c.f'
      include 'etr2p2c.f'
      include 'ets2p2c.f'
      include 'etc2p2c.f'
C
      include 'etm2q1d.f'
      include 'etr2q1d.f'
      include 'ets2q1d.f'
      include 'etc2q1d.f'
C
      include 'etm2q2c.f'
      include 'etr2q2c.f'
      include 'ets2q2c.f'
      include 'etc2q2c.f'
C
      include 'e1ap1d.f'
      include 'etrap1d.f'
      include 'etmap1d.f'
      include 'etsap1d.f'
      include 'etcap1d.f'
C
      include 'e2ap2c.f'
      include 'etrap2c.f'
      include 'etmap2c.f'
      include 'etsap2c.f'
      include 'etcap2c.f'
C
      include 'e1aq1c.f'
      include 'etmaq1d.f'
      include 'etraq1d.f'
      include 'etsaq1d.f'
      include 'etcaq1d.f'
C
      include 'e2aq2c.f'
      include 'etmaq2c.f'
      include 'etraq2c.f'
      include 'eraq2c.f'
      include 'etsaq2c.f'
      include 'etcaq2c.f'
C
      include 'etmdktp.f'
      include 'etrdktp.f'
      include 'etsdktp.f'
      include 'etcdktp.f'
C
      include 'etm5noe.f'
      include 'etr5noe.f'
      include 'ets5noe.f'
      include 'etc5noe.f'
C
      include 'etrmit4.f'
      include 'etsmit4.f'
C
      include 'bremit.f'
      include 'etsmitx.f' 
      include 'inmit4.f'
      include 'mitlin.f'   
C      include 'edemit4.f' INCLUDED AT THE END : PASS BY VALUE XXX
      include 'fonmit.f' 
      include 'melmit.f'   
      include 'replo1.f'   
      include 'pcq12d.f'   
      include 'canoq1.f'   
      include 'chan56.f'
      include 'ddot.f'   
      
      include 'of_mk_subs.f'

C
C GATEWAY FUNCTION FOR CONNECTION WITH MODULEF
C
C
      SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
C-----------------------------------------------------------------------
C     (pointer) Replace integer by integer*8 on the DEC Alpha
C     64-bit platform
C
      INTEGER PLHS(*), PRHS(*)
      INTEGER*4 MXCREATEFULL, MXGETPR, INTEG, CONSTIT, NODE,
     + ESTATE,DEFE,ELTCONST,InfoAtNode, OUT, OUT1, OUT2
C-----------------------------------------------------------------------
C
      INTEGER NLHS, NRHS
      INTEGER MXGETM, MXGETN

C-----------------------------------------------------------------------
C
      integer*4     status, i1, j1, Pointers(10)
      real*8        r1, FOUT(10)
      character*100 CAM, IERR

C-----------------------------------------------------------------------
C      INIT used by all

      IF (nrhs .eq. 0) THEN 
        PLHS(1) = MXCREATEFULL(1,1,0)
        out = MXGETPR(PLHS(1))
        r1=5.0003
        CALL mxCopyReal8ToPtr(r1,out,1)     
        RETURN
      ENDIF

      i1 = mxGetM(prhs(1))*mxGetN(prhs(1))
      status = mxGetString(prhs(1), CAM, i1)
      IF (status .ne. 0) THEN 
         CALL mexErrMsgTxt('CAM length must be less than 100.')
      ENDIF

C-------------------------------------------------------------- MITC4 INIT
      IF  (CAM(1:8) .EQ. 'mitcinit')  THEN 
        PLHS(1) = MXCREATEFULL(96,1,0)
        OUT = MXGETPR(PLHS(1))
        CALL EDEMIT4(%val(OUT))     
        RETURN
      ENDIF
C-----------------------------------------------------------------------
C     of_mk(ElemF,point,integ,constit,nodeE,estate,
C                         defe,EltConst,InfoAtNode)

      if (mxIsInt32(PRHS(3)) .NE. 1) THEN
        CALL mexErrMsgTxt('integ must be int32')
      endif
      if (mxIsInt32(PRHS(2)) .NE. 1) THEN
        CALL mexErrMsgTxt('point must be int32')
      endif
      INTEG   = MXGETPR(PRHS(3))
      CONSTIT = MXGETPR(PRHS(4))
      NODE  = MXGETPR(PRHS(5))
     
      if (nrhs .gt. 5) then
         ESTATE  = MXGETPR(PRHS(6))
      else
         ESTATE  = INTEG
      endif

      if (nrhs .gt. 6) then
          DEFE = MXGETPR(PRHS(7))
      else
          DEFE = INTEG
      endif
      if (nrhs .gt. 7) then
          ELTCONST  = MXGETPR(PRHS(8))
      else
          ELTCONST  = INTEG
      endif
      if (nrhs .gt. 8) then
          InfoAtNode  = MXGETPR(PRHS(9))
      else
          InfoAtNode = INTEG
      endif

      CALL GETPOINTERS(%val(MXGETPR(prhs(2))),Pointers,%val(INTEG))

      PLHS(1) = MXCREATEDOUBLEMATRIX(Pointers(1),1,0)
      OUT = MXGETPR(PLHS(1))

      if (nlhs .gt. 1) then
          PLHS(2) = MXCREATEDOUBLEMATRIX(Pointers(2),1,0)
          OUT1  = MXGETPR(PLHS(2))
      else
          OUT1  = OUT
      endif
      OUT2=OUT
C                                      iopt     constit   node      vol
      CALL io_switch(CAM,IERR,%val(MXGETPR(prhs(2))),%val(INTEG),
     +          %val(CONSTIT),%val(NODE),%val(ESTATE),%val(DEFE),
     +          %val(ELTCONST),%val(OUT),%val(OUT1),%val(OUT2),
     +          %val(InfoAtNode))

      IF (IERR.NE.' ') THEN
           CALL mexPrintf(IERR)
      ENDIF

      RETURN
      END
C-----------------------------------------------------------------------


