Fortran Logical mex functions

版本 1.0.0.0 (6.8 KB) 作者: James Tursa
Fortran mex routines for converting logicals to/from MATLAB mxArray variables
1.2K 次下载
更新时间 2008/2/6

无许可证

mxLogicalFunctions.for provides a suite of functions to support conversion of Fortran logical variables to/from MATLAB style mxArray variables in mex routines or engine applications. Assumes that the MATLAB logical class uses 1 byte for storage of each logical element. When testing a MATLAB logical class variable element for a true value my routines simply look for a non-zero value. When setting a MATLAB logical class element to a true value my routines set the 1-byte MATLAB logical elements to 1. False values are simply set to 0. Instructions for use of each routine are given in the header of each routine. A quick summary is presented below.

subroutine mxCopyPtrToLogical( Ptr, fortran, n )
- Copies MATLAB mxArray logical data to fortran logical variable

subroutine mxCopyLogicalToPtr( fortran, Ptr, n )
- Copies fortran logical variable to MATLAB mxArray logical data

mwPointer function mxCreateLogicalArray( ndim, dims )
- Creates MATLAB mxArray logical array

mwPointer function mxCreateLogicalMatrix( m, n )
- Creates MATLAB mxArray logical matrix

mwPointer function mxCreateLogicalScalar( fortran )
- Creates MATLAB mxArray logical scalar from Fortran logical scalar

logical mxGetLogicalScalar( mxarray )
- Returns Fortran logical scalar from the MATLAB mxArray logical scalar

mwPointer function mxGetLogicals( mxarray )
- Returns the address of the first logical in the mxArray.
Returns 0 if the specified array is not a logical array.

integer*4 mxIsLogicalScalar( mxarray )
- Returns 1 if mxarray is logical class with size 1 x 1
Returns 0 otherwise

integer*4 mxIsLogicalScalarTrue( mxarray )
- Returns 1 if mxarray is logical class with size 1 x 1 and is non-zero
Returns 0 otherwise
(Note: This is very similar to mxGetLogicalScalar)

There are also similar functions specific for logical*1, logical*2, and logical*4 data types supplied with this suite.

Special Note:

Several of the routines use MATLAB supplied functions such as mxGetData and mxCreateNumericMatrix and mxCreateNumericArray with logical class variables. Although the MATLAB doc does not specifically mention that these functions can be used with logical class variables, it does seem to work ok. The only alternative to using these functions would be to call mexCallMATLAB or engCallMATLAB to convert the logical class variables to/from an int8 class. This would slow up the code and force me to make two versions of the code, one for mex files and another for engine applications, so I opted not to do it this way. I use F77 style %VAL constructs instead.

引用格式

James Tursa (2024). Fortran Logical mex functions (https://www.mathworks.com/matlabcentral/fileexchange/18635-fortran-logical-mex-functions), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2007a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0