Мне удалось MEX-код, но ошибок слишком много ...
Для подавления предупреждения о largeArrayDims
вы можете выполнить:
warning('Off', 'MATLAB:mex:FortranLargeArrayDimsWarn_link');
Примечание: Ваш код на Фортране применяется MX_HAS_INTERLEAVED_COMPLEX
, поэтому вам нужно добавить флаг -2018a
к команде mex
.Я не смог найти способ избежать предупреждения при использовании флага -2018a
.
В командной строке MEX используется флаг -2018a
:
mex -R2018a points.F
Мне пришлось внести слишком много изменений в ваш код, чтобы пройти компиляцию:
Я добавил пробелыв начало строк.
Я удалил MX_HAS_INTERLEAVED_COMPLEX
.
Я не знал, что делать с totnode
, поэтому я заменил его значением 100
.
Я не сделалзнаю, что делать с y_output
, поэтому я заменил его на coord
.
Вот ваш модифицированный код, который проходит компиляцию:
#include "fintrf.h"
C======================================================================
C points.f
C Computational function that creates a cube of equdistant points
C This is a MEX file for MATLAB.
C======================================================================
C Gateway routine
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C Declarations
implicit none
C mexFunction arguments:
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
C Function declarations:
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
C Pointers to input/output mxArrays:
mwPointer x_ptr, y_ptr
C Array information:
mwPointer mrows, ncols
mwSize size
C Arguments for computational routine:
real*8 dx, r
real*8 coordx, coordy, coordz
C What is totnode???
C real*8 coord(totnode,3)
real*8 coord(100,3)
real*8 ndivx, ndivy, ndivz
integer i, j, k
C Get the size of the input array.
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
C MX_HAS_INTERLEAVED_COMPLEX
x_ptr = mxGetDoubles(prhs(1))
C Create matrix for the return argument.
plhs(1) = mxCreateDoubleMatrix(29791,3,0)
y_ptr = mxGetDoubles(plhs(1))
call points(coord,r,dx,ndivx,ndivy,ndivz)
C Load the data into y_ptr, which is the output to MATLAB.
C call mxCopyReal8ToPtr(y_output,y_ptr,size) What is y_output???
call mxCopyReal8ToPtr(coord,y_ptr,size)
return
end
C-----------------------------------------------------------------------
C Computational routine
subroutine points(coord,r,dx,ndivx,ndivy,ndivz)
C Arguments for computational routine:
real*8 dx, r, coordx, coordy, coordz
C What is totnode???
C real*8 coord(totnode,3), ndivx, ndivy, ndivz
real*8 coord(100,3), ndivx, ndivy, ndivz
integer i, j, k
do i = 1,ndivx
do j = 1,ndivy
do k = 1,ndivz
coordx = -1.0d0 / 2.0d0 * r + (dx / 2.0d0) + (i - 1) * dx
coordy = -1.0d0 / 2.0d0 * r + (dx / 2.0d0) + (j - 1) * dx
coordz = -1.0d0 / 2.0d0 * r + (dx / 2.0d0) + (k - 1) * dx
nnum = nnum + 1
coord(nnum,1) = coordx
coord(nnum,2) = coordy
coord(nnum,3) = coordz
enddo
enddo
enddo
return
end
Надеюсь, это поможет вам продолжить разработку.