User`s manual
Examples of Fortran MEX-Files
3-33
C
C NOTE: The subfunction fill() is in the file called fill.f.
C
C This is a MEX-file for MATLAB.
C Copyright (c) 1984-2000 The MathWorks, Inc.
C
C ==============================================================
C Gateway subroutine
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer nlhs, nrhs
C---------------------------------------------------------------
C (pointer) Replace integer by integer*8 on the DEC Alpha
C platform.
C
integer plhs(*), prhs(*)
integer rhs(1), lhs(1)
integer mxGetPr, mxCreateFull
C---------------------------------------------------------------
C
integer m, n, max
C initializition
m=1
n=1
max=1000
rhs(1) = mxCreateFull(max, 1, 0)
C Pass the pointer and variable and let fill() fill up data.
call fill(%val(mxGetPr(rhs(1))), m, n, max)
call mxSetM(rhs(1), m)
call mxSetN(rhs(1), n)
call mexCallMATLAB(1, lhs, 1, rhs, 'sin')
call mexCallMATLAB(0, NULL, 1, lhs, 'plot')
C Clean up the unfreed memory after calling mexCallMATLAB.
call mxFreeMatrix(rhs(1))