User`s manual

3 Creating Fortran MEX-Files
3-14
C Initialize outbuf_buf to blanks. This is necessary on some
C compilers.
output_buf = ' '
C Call the computational subroutine.
call revord(input_buf, strlen, output_buf)
C Set output_buf to MATLAB mexFunction output.
plhs(1) = mxCreateString(output_buf)
return
end
After checking for the correct number of inputs, this MEX-file gateway routine
verifies that the input was either a row or column vector string. It then finds
the size of the string and places the string into a Fortran character array. Note
that in the case of character strings, it is not necessary to copy the data into a
Fortran character array by using
mxCopyPtrToCharacter. In fact,
mxCopyPtrToCharacter works only with MAT-files. For more information
about MAT-files, see Chapter 6, “Importing and Exporting Data.”
For an input string
x = 'hello world';
typing
y = revord(x)
produces
y =
dlrow olleh
Passing Arrays of Strings
Passing arrays of strings adds a slight complication to the example in the
previous section, “Passing Strings”. Because MATLAB stores elements of a
matrix by column instead of by row, it is essential that the size of the string
array be correctly defined in the Fortran MEX-file. The key point is that the
row and column sizes as defined in MATLAB must be reversed in the Fortran