【发布时间】:2019-06-25 08:48:42
【问题描述】:
当我尝试在 matlab 上编译 fortran 代码时收到一些错误消息。
>> mex points.f
Warning: MATLAB FORTRAN MEX Files are now defaulting to -largeArrayDims and 8 byte integers.
If you are building a FORTRAN S-Function, please recompile using the -compatibleArrayDims flag.
You can find more about adapting code to use 64-bit array dimensions at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
Building with 'Intel Parallel Studio XE 2019 for Fortran with Microsoft Visual Studio 2017'.
Error using mex
C:\Users\Kinan\Desktop\Strathshare\Personal Folders\PhD\MATLABPERIDYNAMICS\points.f(44): error #5149: Illegal character in statement
label field [r]
re*8 dx, ral
----^
C:\Users\Kinan\Desktop\Strathshare\Personal Folders\PhD\MATLABPERIDYNAMICS\points.f(45): error #5149: Illegal character in statement
label field [r]
re*8 coordx, coordy, coordz
----^
>C:\Users\Kinan\Desktop\Strathshare\Personal Folders\PhD\MATLABPERIDYNAMICS\points.f(46): error #5149: Illegal character in statement
label field [r]
real*8 coord(totnode,3)
----^
实际代码是
#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
real*8 coord(totnode,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
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.
call mxCopyReal8ToPtr(y_output,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
real*8 coord(totnode,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
我有几个 for 循环我需要这样做,所以如果我能得到一个工作模板,那会很有帮助。
对不起,我尝试添加更多错误消息,但它说我有太多代码
【问题讨论】:
-
是的,我知道这很奇怪。是的,这是我遵守的代码。我想知道它是否与一开始的这个版本警告有关,但我真的不明白这是否有影响。
-
MX_HAS_INTERLEAVED_COMPLEX是什么?是stackoverflow复制错误吗? -
MX_HAS_INTERLEAVED_COMPLEX 是一个错误,它的前面应该有一个注释。今晚我会上传更多错误信息和更正代码
-
为什么有些行不在第 8 列开始?是stackoverflow复制错误还是实际的源文件?
-
我同意 PTRK ...您有固定格式的源代码,但您在第 1-6 列中有代码,这些代码是为标签和延续保留的,因此会出现错误。您需要修复源代码并缩进所有代码,使其超出第 6 列。(也许这有制表符而不是空格?)