Fortran Logical mex functions

버전 1.0.0.0 (6.79 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 (2026). Fortran Logical mex functions (https://kr.mathworks.com/matlabcentral/fileexchange/18635-fortran-logical-mex-functions), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2007a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Fortran with MATLAB에 대해 자세히 알아보기
버전 게시됨 릴리스 정보
1.0.0.0