Fortran Coder

查看: 7242|回复: 8
打印 上一主题 下一主题

matlab与fortran混合编程mex文件编译

[复制链接]

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
跳转到指定楼层
楼主
发表于 2018-8-9 14:38:55 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
在vs2013中编译用于Matlab调用的mex文件,出现以下错误,是什么原因呢?代码格式基本是按标准mex框架写的
错误        2         error #5082: Syntax error, found ',' when expecting one of: ( % [ . = =>       

错误        5         error #5082: Syntax error, found ',' when expecting one of: ( % [ : . = =>       

错误        6         error #5082: Syntax error, found ',' when expecting one of: ( % [ : . = =>       

错误        7         error #5082: Syntax error, found ',' when expecting one of: ( % [ : . = =>       

错误        8         error #5082: Syntax error, found ',' when expecting one of: ( % [ : . = =>       

错误        3         error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ : . = =>       

错误        4         error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ : . = =>       

错误        9         error #6218: This statement is positioned incorrectly and/or has syntax errors.       

错误        12         error #6236: A specification statement cannot appear in the executable section.       

错误        13         error #6236: A specification statement cannot appear in the executable section.       

错误        14         error #6236: A specification statement cannot appear in the executable section.       

错误        15         error #6236: A specification statement cannot appear in the executable section.       

错误        20         error #6404: This name does not have a type, and must have an explicit type.   [MROWS1]       

错误        24         error #6404: This name does not have a type, and must have an explicit type.   [MROWS2]       

错误        16         error #6404: This name does not have a type, and must have an explicit type.   [MWPOINTERMXGETM]

错误        10         error #6404: This name does not have a type, and must have an explicit type.   [MWPOINTERPLHS]

错误        18         error #6404: This name does not have a type, and must have an explicit type.   [MWSIZESIZE1]       

错误        21         error #6404: This name does not have a type, and must have an explicit type.  

错误        17         error #6404: This name does not have a type, and must have an explicit type.   

错误        27         error #6404: This name does not have a type, and must have an explicit type.

错误        22         error #6404: This name does not have a type, and must have an explicit type.  

错误        25         error #6404: This name does not have a type, and must have an explicit type.   

错误        11         error #6404: This name does not have a type, and must have an explicit type.  

错误        23         error #6404: This name does not have a type, and must have an explicit type.  

错误        19         error #6404: This name does not have a type, and must have an explicit type.   

错误        28         error #6404: This name does not have a type, and must have an explicit type.   

错误        30         error #6404: This name does not have a type, and must have an explicit type.  

错误        26         error #6404: This name does not have a type, and must have an explicit type.   

错误        29         error #6404: This name does not have a type, and must have an explicit type.

错误        31         error #6410: This name has not been declared as an array or a function.   [PLHS]       

警告        1         warning #5117: Bad # preprocessor line       

错误        32        Compilation Aborted (code 1)       



微信图片_20180809143215.png (70.79 KB, 下载次数: 161)

微信图片_20180809143215.png
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

沙发
发表于 2018-8-9 14:47:14 | 只看该作者
请给出必要的代码。
“输出窗口”的内容,复制粘贴。(不要看“错误列表”窗口)

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
板凳
 楼主| 发表于 2018-8-9 14:59:14 | 只看该作者
fcode 发表于 2018-8-9 14:47
请给出必要的代码。
“输出窗口”的内容,复制粘贴。(不要看“错误列表”窗口) ...

提示错误的代码区域如下:
#include <fintrf.h>
C
C
C This subroutine is the main gateway to MATLAB.  When a MEX function
C  is executed MATLAB calls the MEXFUNCTION subroutine in the corresponding
C  MEX file.  
C
C
C     Gateway routine
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)
      
C     Declarations
      implicit none
      
C-----------------------------------------------------------------------
C     mexFunction arguments:
      mwPointer plhs(*), prhs(*)
      integer nlhs, nrhs
      
C-----------------------------------------------------------------------
C     Function declarations:
      mwPointer mxGetPr
      mwPointer mxCreateDoubleMatrix
      integer mxIsNumeric
      mwPointer mxGetM, mxGetN
      
C-----------------------------------------------------------------------      
C     Pointers to input/output mxArrays:
      mwPointer x_ptr_LLH, x_ptr_YMDH, y_ptr

C-----------------------------------------------------------------------
C     Array information:
      mwPointer mrows1, ncols1,  mrows2, ncols2
      mwSize size1, size2

C-----------------------------------------------------------------------
C     Arguments for computational routine:
      integer*4  x_input_YMDH  !TIME
      real*8  x_input_LLH, y_output  !LATITUDE  LONGITUDE  HEIGHT   OTUPUT
C-----------------------------------------------------------------------
C     Get the size of the input array.
      mrows1 = mxGetM(prhs(1))
      ncols1 = mxGetN(prhs(1))
      size1 = mrows1*ncols1
      
      mrows2 = mxGetM(prhs(2))
      ncols2 = mxGetN(prhs(2))
      size2 = mrows2*ncols2

C     Create Fortran array from the input argument.
      x_ptr_LLH = mxGetPr(prhs(1))
      call mxCopyPtrToReal8(x_ptr_LLH,x_input_LLH,size1)
      x_ptr_YMDH = mxGetPr(prhs(2))
      call mxCopyPtrToInteger4(x_ptr_YMDH,x_input_YMDH,size2)
      
C     Create matrix for the return argument.
      plhs(1) = mxCreateDoubleMatrix(1,20,0)
      y_ptr = mxGetPr(plhs(1))
      
C     Call the computational subroutine.
      call Ionosphere(y_output, x_input_LLH, x_input_YMDH)

C     Load the data into y_ptr, which is the output to MATLAB.
      call mxCopyReal8ToPtr(y_output,y_ptr,20)     

      return
      end
计算子程序名称为:
C-----------------------------------------------------------------------
C     Computational routine

      subroutine Ionosphere(y_output, x_input_LLH, x_input_YMDH)

输出窗口重要提示为:
remark #8290: Recommended relationship between field width 'W' and the number of fractional digits 'D' in this edit descriptor is 'W>=D+3'.

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

地板
发表于 2018-8-9 21:56:38 | 只看该作者
输出窗口提示请给更多一些。

注意 <fintrf.h> 文件是什么格式?如果是自由格式,则源代码也要是自由格式。如果是固定格式,则源代码也要是固定格式。

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
5#
 楼主| 发表于 2018-8-10 10:02:40 | 只看该作者
fcode 发表于 2018-8-9 21:56
输出窗口提示请给更多一些。

注意  文件是什么格式?如果是自由格式,则源代码也要是自由格式。如果是固定 ...

我不是特别清楚自由格式是咋回事。。就是把matlab里的文件复制到工程里。。
输出窗口显示如图:

假如我格式对的,在matlab里编译mex文件是不是就可以了?我试了一下,但还是提示错误太多。。



微信图片_20180810095903.png (56.19 KB, 下载次数: 166)

微信图片_20180810095903.png

微信图片_20180810100315.png (40.3 KB, 下载次数: 169)

微信图片_20180810100315.png

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

6#
发表于 2018-8-10 10:29:25 | 只看该作者
第一个错误是 #Bad preprocessor line
这说明你需要开启 预处理。
项目(工程,Project)菜单,属性,Fortran(展开),Preprocessor,Preprocessor Source File,Yes

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
7#
 楼主| 发表于 2018-8-10 21:01:09 | 只看该作者
fcode 发表于 2018-8-10 10:29
第一个错误是 #Bad preprocessor line
这说明你需要开启 预处理。
项目(工程,Project)菜单,属性,Fortr ...

嗯嗯,谢谢您!少了很多错误,还剩下点我再调调

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
8#
 楼主| 发表于 2018-8-10 21:23:25 | 只看该作者
fcode 发表于 2018-8-10 10:29
第一个错误是 #Bad preprocessor line
这说明你需要开启 预处理。
项目(工程,Project)菜单,属性,Fortr ...

您好,我在matlab中编译mex文件时出现以下错误,其中READ_IG_RZ、 READAPF107、IRI_WEB是我计算子程序中调用的子函数

微信图片_20180810212231.png (23.4 KB, 下载次数: 180)

微信图片_20180810212231.png

22

帖子

3

主题

0

精华

入门

F 币
90 元
贡献
48 点
9#
 楼主| 发表于 2018-8-10 21:37:03 | 只看该作者
fcode 发表于 2018-8-10 10:29
第一个错误是 #Bad preprocessor line
这说明你需要开启 预处理。
项目(工程,Project)菜单,属性,Fortr ...

如果在VS中编译,提示的错误如下:

微信图片_20180810213708.png (38.48 KB, 下载次数: 166)

微信图片_20180810213708.png

微信图片_20180810213711.png (27.02 KB, 下载次数: 181)

微信图片_20180810213711.png
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-8 07:42

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表