找回密码
 注册
Simdroid-非首页
查看: 82|回复: 3

matlab调用fortran中,变量传递问题

[复制链接]
发表于 2010-8-30 10:35:21 | 显示全部楼层 |阅读模式 来自 陕西西安
最近在搞matlab调用fortran,其中变量传递出现了问题,调用程序中用到了module,其中的变量大小是由传递的变量定义的,程序如下,mex就出错,请帮忙看一下,谢谢!
#include "fintrf.h"
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)
      mwpointer plhs(*), prhs(*)
      mwpointer mxCreateDoubleMatrix
      mwpointer mxGetPr
      mwpointer x_pr, y_pr, z_pr
      integer nlhs, nrhs, mxIsNumeric
      mwsize m, n, size, row
      mwsize mxGetM, mxGetN
      real*8  x, y(100), z(100)
      if (nrhs .ne. 2) then
         call mexErrMsgTxt('Two inputs required.')
      elseif (nlhs .ne. 1) then
         call mexErrMsgTxt('One output required.')
      endif
      if (mxIsNumeric(prhs(1)) .ne. 1) then
         call mexErrMsgTxt('Input # 1 is not a numeric.')
      elseif (mxIsNumeric(prhs(2)) .ne. 1) then
         call mexErrMsgTxt('Input #2 is not a numeric array.')
      endif
      m = mxGetM(prhs(1))
      n = mxGetN(prhs(1))
      if(n .ne. 1 .or. m .ne. 1) then
         call mexErrMsgTxt('Input #1 is not a scalar.')
      endif
      m = mxGetM(prhs(2))
      n = mxGetN(prhs(2))
      size = m*n
      if(size .gt. 100) then
         call mexErrMsgTxt('Input #2 number of elements exceeds buffer')
      endif
      plhs(1) = mxCreateDoubleMatrix(m,n,0)
      x_pr = mxGetPr(prhs(1))
      y_pr = mxGetPr(prhs(2))
      z_pr = mxGetPr(plhs(1))
      row = 1
      call mxCopyPtrToReal8(x_pr,x,row)
      call mxCopyPtrToReal8(y_pr,y,size)
      call xtimesy(x,y,z,m,n)
      call mxCopyReal8ToPtr(z,z_pr,size)  !ddddadfa
        !!dddd
      return
      end

    module zzz
    integer :: mm
    integer aa(m)
    end module
      
      subroutine xtimesy(x,y,z,m,n)
      use zzz
      real*8  x, y(m,n), z(m,n),zz(m,n)
      integer i, j
      do  i=1,m
         do  j=1,n
          z(i,j)=x*y(i,j)                                                
        end do
       end do
      return
      end
 楼主| 发表于 2010-8-30 10:35:34 | 显示全部楼层 来自 陕西西安
Simdroid开发平台
mex错误提示如下:
xtimesy.F90(68): error #6841: An automatic object must not appear in the specification part of a module.   [AA]
    integer aa(m)
------------^
xtimesy.F90(68): error #6219: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association   [M]
    integer aa(m)
---------------^
compilation aborted for xtimesy.F90 (code 1)
回复 不支持

使用道具 举报

 楼主| 发表于 2010-8-30 12:22:23 | 显示全部楼层 来自 陕西西安
本帖最后由 jojocleo 于 2010-8-30 16:55 编辑

单从语法上我没找到什么问题,由于自己的程序中有好多module,所以这个问题必须解决,希望mex经验比较丰富的高手前来解疑,谢谢

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2010-8-30 22:22:42 | 显示全部楼层 来自 陕西西安
请版主们帮忙检查以下,谢谢!
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-6 21:32 , Processed in 0.046960 second(s), 17 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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