#include "fintrf.h" C #if 0 C C fengdemo.F C .F file need to be preprocessed to generate .for equivalent C #endif C C fengdemo.f C C This is a simple program that illustrates how to call the MATLAB C Engine functions from a FORTRAN program. C C Copyright (c) 1996-1998 by The MathWorks, Inc. C All Rights Reserved. C====================================================================== C $Revision: 1.3 $ program main C----------------------------------------------------------------------- C (pointer) Replace integer by integer*8 on the DEC Alpha and the C SGI 64 platforms C mwpointer engOpen, engGetMatrix, mxCreateFull, mxGetPr mwpointer ep, T, D, result C---------------------------------------------------------------------- C C Other variable declarations here double precision time(10), dist(10) integer stat, temp data time / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 / C ep = engOpen('matlab ') C if (ep .eq. 0) then write(6,*) 'Can''t start MATLAB engine' stop endif C T = mxCreateFull(1, 10, 0) call mxSetName(T, 'T') call mxCopyReal8ToPtr(time, mxGetPr(T), 10) C C C Place the variable T into the MATLAB workspace C call engPutMatrix(ep, T) C C C Evaluate a function of time, distance = (1/2)g.*t.^2 C (g is the acceleration due to gravity) C call engEvalString(ep, 'D = .5.*(-9.8).*T.^2;') C C C Plot the result C call engEvalString(ep, 'plot(T,D);') call engEvalString(ep, 'title(''Position vs. Time'')') call engEvalString(ep, 'xlabel(''Time (seconds)'')') call engEvalString(ep, 'ylabel(''Position (meters)'')') C C C read from console to make sure that we pause long enough to be C able to see the plot C print *, 'Type 0 to Exit' print *, 'Type 1 to continue' read(*,*) temp if (temp.eq.0) then print *, 'EXIT!' stop end if C call engEvalString(ep, 'close;') C D = engGetMatrix(ep, 'D') call mxCopyPtrToReal8(mxGetPr(D), dist, 10) print *, 'MATLAB computed the following distances:' print *, ' time(s) distance(m)' do 10 i=1,10 print 20, time(i), dist(i) 20 format(' ', G10.3, G10.3) 10 continue C C call mxFreeMatrix(T) call mxFreeMatrix(result) stat = engClose(ep) C stop end