User`s manual

4 Calling MATLAB from C and Fortran Programs
4-12
C Other variable declarations here
double precision time(10), dist(10)
integer engPutMatrix, engEvalString, engClose
integer temp, status
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
status = engPutMatrix(ep, T)
C
if (status .ne. 0) then
write(6,*) 'engPutMatrix failed'
stop
endif
C
C
C Evaluate a function of time, distance = (1/2)g.*t.^2
C (g is the acceleration due to gravity)
C
if (engEvalString(ep, 'D = .5.*(-9.8).*T.^2;') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
C