Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linux上从Intel Fortran调用Matlab_Linux_Matlab_Fortran_Intel Fortran - Fatal编程技术网

在Linux上从Intel Fortran调用Matlab

在Linux上从Intel Fortran调用Matlab,linux,matlab,fortran,intel-fortran,Linux,Matlab,Fortran,Intel Fortran,编辑: 这是建立在我以前的基础上的 有了答案,我可以用gfortran编译和运行,但是我仍然不能用ifort运行。我在tcsh中编译时使用的命令有: set PATH=${PATH}:${matlabroot}/bin/glnxa64/:${matlabroot}/bin set LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${matlabroot}/bin/glnxa64/:${matlabroot}/sys/os/glnxa64/ ${FC} ${matlabroo

编辑:

这是建立在我以前的基础上的

有了答案,我可以用gfortran编译和运行,但是我仍然不能用ifort运行。我在tcsh中编译时使用的命令有:

set PATH=${PATH}:${matlabroot}/bin/glnxa64/:${matlabroot}/bin
set LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${matlabroot}/bin/glnxa64/:${matlabroot}/sys/os/glnxa64/
${FC} ${matlabroot}/extern/examples/eng_mat/fengdemo.F -I${matlabroot}/extern/include/ -L${matlabroot}/bin/glnxa64/ -leng -lmx -cpp -o FEngDemo
我是否需要更改我使用的库?到Fortran代码?还是到Matlab代码

任何帮助都将不胜感激

Fortran代码是:

#include "fintrf.h"
C
#if 0
C
C     fengdemo.F
C     .F file need to be preprocessed to generate .for equivalent
C
#endif
C
C     fengdemo.f
C
C     This is a simple program that illustrates how to call the MATLAB
C     Engine functions from a FORTRAN program.
C
C Copyright 1984-2011 The MathWorks, Inc.
C======================================================================
C 

      program main

C     Declarations
      implicit none

      mwPointer engOpen, engGetVariable, mxCreateDoubleMatrix
      mwPointer mxGetPr
      mwPointer ep, T, D 
      double precision time(10), dist(10)
      integer engPutVariable, engEvalString, engClose
      integer temp, status
      mwSize i
      data time / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 /

      mwSize M, N
      parameter(M=1) 
      parameter(N=10) 

C
      ep = engOpen('matlab ')
C
      if (ep .eq. 0) then
         write(6,*) 'Can''t start MATLAB engine'
         stop
      endif
C
      T = mxCreateDoubleMatrix(M, N, 0)
      call mxCopyReal8ToPtr(time, mxGetPr(T), N)
C
C
C     Place the variable T into the MATLAB workspace
C
      status = engPutVariable(ep, 'T', T)
C
      if (status .ne. 0) then 
         write(6,*) 'engPutVariable failed'
         stop
      endif
C
C
C     Evaluate a function of time, distance = (1/2)g.*t.^2
C     (g is the acceleration due to gravity)
C     
      if (engEvalString(ep, 'D = .5.*(-9.8).*T.^2;') .ne. 0) then
         write(6,*) 'engEvalString failed'
         stop
      endif
C
C
C     Plot the result
C
      if (engEvalString(ep, 'plot(T,D);') .ne. 0) then 
       write(6,*) 'engEvalString failed'
         stop
      endif

      if (engEvalString(ep, 'title(''Position vs. Time'')') .ne. 0) then
          write(6,*) 'engEvalString failed'
          stop
      endif

      if (engEvalString(ep, 'xlabel(''Time (seconds)'')') .ne. 0) then
          write(6,*) 'engEvalString failed'
          stop
      endif
      if (engEvalString(ep, 'ylabel(''Position (meters)'')') .ne. 0)then
          write(6,*) 'engEvalString failed'
          stop
      endif
C     
C     
C     read from console to make sure that we pause long enough to be
C     able to see the plot
C     
      print *, 'Type 0 <return> to Exit'
      print *, 'Type 1 <return> to continue'

      read(*,*) temp
C
      if (temp.eq.0) then
         print *, 'EXIT!'
         status = engClose(ep)

         if (status .ne. 0) then 
            write(6,*) 'engClose failed'
         endif

         stop
      end if
C
      if (engEvalString(ep, 'close;') .ne. 0) then
         write(6,*) 'engEvalString failed'
         stop
      endif 
C      
      D = engGetVariable(ep, 'D')
      call mxCopyPtrToReal8(mxGetPr(D), dist, N)
      print *, 'MATLAB computed the following distances:'
      print *, '  time(s)  distance(m)'
      do 10 i=1,10
         print 20, time(i), dist(i)
 20      format(' ', G10.3, G10.3)
 10   continue
C   
C     
      call mxDestroyArray(T)
      call mxDestroyArray(D)
      status = engClose(ep)
C      
      if (status .ne. 0) then 
         write(6,*) 'engClose failed'
         stop
      endif
C
      stop
      end

它在第46行执行segFaults,
调用mxCopyReal8ToPtr(time,mxGetPr(T),N)
。如果执行segFaults,则执行编译。Mex是一件棘手的事情,通常需要一段时间才能正确地对所有内容进行尺寸化,并为
mx*
函数的输入参数使用正确的类型。为此,您将需要实际的fortran代码…您已经达到了目标。现在发布编译错误或运行时错误,具体取决于您得到的结果。有了你的名声,你应该意识到“这行不通”本身不是一个恰当的问题。哪一行是46?您是否也尝试了
-检查
选项?第46行是
调用mxCopyReal8ToPtr(时间,mxGetPr(T),N)
。我从未听说过
-check
标志,但它没有改变输出。
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source                                                                 
FEngDemo           0000000000477619  Unknown               Unknown  Unknown
FEngDemo           0000000000475EEE  Unknown               Unknown  Unknown
FEngDemo           000000000044D8F2  Unknown               Unknown  Unknown
FEngDemo           0000000000431573  Unknown               Unknown  Unknown
FEngDemo           00000000004041FB  Unknown               Unknown  Unknown
libpthread.so.0    0000003E1D80F790  Unknown               Unknown  Unknown
libmx.so           00007F5F077FCED7  Unknown               Unknown  Unknown
FEngDemo           00000000004032ED  MAIN__                     46  fengdemo.F
FEngDemo           0000000000403186  Unknown               Unknown  Unknown
libc.so.6          0000003E1D01ED5D  Unknown               Unknown  Unknown
FEngDemo           0000000000403009  Unknown               Unknown  Unknown