#include <fintrf.h>
c
c	ENGTEST3
c
c	Simple program that illustrates how to call the Engine Library
c	from a Fortran program.  
c
c	The example starts a MATLAB engine, sends a simple matrix to 
c	the engine, computes its eigenvalues, gets back the vector
c	containing the eigenvalues, and prints the second eigenvalue.
c
      program main
      pointer ep, engOpen 
      integer engClose, engPutFull, engGetFull, engEvalString
      integer m, n, stat
      pointer pr, pi, mxCalloc
      double precision Areal(6), Dreal(3)
      data Areal / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 /
c
      ep = engOpen('matlab ')
c
      if (ep .eq. 0) then
          write(6,*) 'Can''t start MATLAB engine'
          stop
      endif
c
      pr = mxCalloc(6,8)
      call mxCopyReal8ToPtr(Areal, pr, 6)
c
      stat = engPutFull(ep, 'A', 3, 2, pr, 0)
      call mxFree(pr)
      stat = engEvalString(ep, 'd = eig(A*A'')')
      stat = engGetFull(ep, 'd', m, n, pr, pi)
c
      call mxCopyPtrToReal8(pr, Dreal, 3)
c
      write(6,*) 'Eigenval 2: ',Dreal(2)
c
      stat = engClose(ep)
c
      stop
      end
