User`s manual

3 Creating Fortran MEX-Files
3-12
To compile and link this example source file, at the MATLAB prompt type
mex timestwo.f
This carries out the necessary steps to create the MEX-file called timestwo
with an extension corresponding to the machine type on which you’re running.
You can now call
timestwo as if it were an M-function.
x = 2;
y = timestwo(x)
y =
4
Passing Strings
Passing strings from MATLAB to a Fortran MEX-file is straightforward. This
program accepts a string and returns the characters in reverse order.
C $Revision: 1.14 $
C==============================================================
C
C revord.f
C Example for illustrating how to copy string data from
C MATLAB to a Fortran-style string and back again.
C
C Takes a string and returns a string in reverse order.
C
C This is a MEX-file for MATLAB.
C Copyright (c) 1984-2000 The MathWorks, Inc.
C==============================================================
subroutine revord(input_buf, strlen, output_buf)
character input_buf(*), output_buf(*)
integer i, strlen
do 10 i=1,strlen
output_buf(i) = input_buf(strlen-i+1)
10 continue
return
end