User`s manual

Examples of Fortran MEX-Files
3-13
Below is the gateway routine that calls the computational routine.
C The gateway routine
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 mxCreateString, mxGetString
C--------------------------------------------------------------
C
integer mxGetM, mxGetN, mxIsString
integer status, strlen
character*100 input_buf, output_buf
C Check for proper number of arguments.
if (nrhs .ne. 1) then
call mexErrMsgTxt('One input required.')
elseif (nlhs .gt. 1) then
call mexErrMsgTxt('Too many output arguments.')
C The input must be a string.
elseif(mxIsString(prhs(1)) .ne. 1) then
call mexErrMsgTxt('Input must be a string.')
C The input must be a row vector.
elseif (mxGetM(prhs(1)) .ne. 1) then
call mexErrMsgTxt('Input must be a row vector.')
endif
C Get the length of the input string.
strlen = mxGetM(prhs(1))*mxGetN(prhs(1))
C Get the string contents (dereference the input integer).
status = mxGetString(prhs(1), input_buf, 100)
C Check if mxGetString is successful.
if (status .ne. 0) then
call mexErrMsgTxt('String length must be less than 100.')
endif