#include <fintrf.h>
c
c	ENGTEST1
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 process,
c	sends a 3-by-2 real matrix to it, computes the eigen values of
c	the matrix multiplied by its transpose, gets the matrix back 
c	to the Fortran program, and prints out the second eigenvalue.
c
      program main
      pointer mxCreateFull, engOpen, engGetMatrix
      pointer ep, a, d
      integer engPutMatrix, engEvalString, engClose
      integer stat
      double precision Areal(6), darray(3)
      data Areal / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 /
c
      a = mxCreateFull(3, 2, 0)
      call mxCopyReal8ToPtr(Areal, mxGetPr(a), 6)
      call mxSetName(a, 'A')
c
      ep = engOpen('matlab ')
c
      if (ep .eq. 0) then
          write(6,*) 'Can''t start MATLAB engine'
          stop
      endif
c
      stat = engPutMatrix(ep, a)
      stat = engEvalString(ep, 'd = eig(A*A'')')
      d = engGetMatrix(ep, 'd')
c
      call mxCopyPtrToReal8(mxGetPr(d), darray, 3)
c
      write(6,*) 'Eigenval 2: ',darray(2)
c
      stat = engClose(ep)
c
      stop
      end
