Как исправить ошибку недопустимого символа в mex файлах - PullRequest
2 голосов
/ 25 июня 2019

Я получаю сообщение об ошибке, когда пытаюсь скомпилировать код fortran на matlab.

>> 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, для которых мне нужно это сделать, поэтому, если я смогу получить рабочий шаблон, это очень поможет.

Извините, я пытался добавить больше сообщения об ошибке, но в нем говорилось, что у меня слишком много кода

1 Ответ

0 голосов
/ 25 июня 2019

Мне удалось 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

Надеюсь, это поможет вам продолжить разработку.

...