【问题标题】:Execute a program compiled using intel-fortran from MATLAB on Linux machine在 Linux 机器上从 MATLAB 执行使用 intel-fortran 编译的程序
【发布时间】:2013-08-07 14:07:27
【问题描述】:

我有一个我想从 MATLAB 运行的 fortran 代码的可执行文件。

我尝试使用以下两个选项,但出现错误:

!/home/atrac/code case172.jcl
error:- ls: cannot access ./id: No such file or directory
ls: cannot access ./id: No such file or directory

!gnome-terminal --command "./home/myhome/code case12.jcl"
error: There was an error creating child process for this terminal

有没有办法我可以编写一个 shell 脚本来执行程序并暂停 Matlab 直到执行外部程序然后将控制权传回给 Matlab?

我正在尝试在 Matlab 中运行一个遗传算法,它调用这个外部软件。 非常感谢任何想法或帮助。

谢谢, 亚什

【问题讨论】:

    标签: linux matlab fortran genetic-algorithm


    【解决方案1】:

    好的,看起来这里发生了两件不同的事情。两者都可能与Matlab的当前目录有关。

    !/home/atrac/code case172.jcl
    error:- ls: cannot access ./id: No such file or directory
    ls: cannot access ./id: No such file or directory
    

    在这里,您似乎正在设法运行 code 程序,但 code 或 JCL 脚本正在当前工作目录中查找名为 id 的文件。当您从 Matlab 中取出时,这将是 Matlab 的当前目录。从 Matlab 命令提示符运行 pwd 以找出您所在的位置。您可以通过在 Matlab 中使用cd 移动到实际存在id 文件的目录来解决此问题(我猜它在/home/atrac 中),然后使用相同的命令行运行code。更好的解决方法是重写 code 和/或 JCL 脚本,以便在从任何路径(可能使用绝对路径)运行时工作,因此您的 cwd 无关紧要。

    !gnome-terminal --command "./home/myhome/code case12.jcl"
    error: There was an error creating child process for this terminal
    

    这里,开头的“。”可能把它搞砸了,因为它现在在当前工作目录下寻找home/myhome,而不是在根目录下。尝试改用!gnome-terminal --command "/home/myhome/code case12.jcl"(不带“.”)。

    【讨论】:

      【解决方案2】:

      理想情况下,这应该作为评论,但我没有足够的声誉。

      但是,创建子进程的错误与 MATLAB 无关。外壳出错了。你能从终端运行程序吗?

      其次,你正在使用:

      !/home/atrac/code case172.jcl 
      

      但你应该使用 !./home/atrac/code case172.jcl

      【讨论】:

      • 感谢 Lokesh,即使我认为应该是 '!./home/atrac/code case172.jcl' 但这不起作用我得到一个错误:/bin/bash: ./home/atrac /code:没有这样的文件或目录是的,我可以从终端运行这个程序
      • 你能看到你的linux的shell是什么吗?
      • 另请参阅尝试运行 !ls /home/atrac。这应该列出目录中的所有文件。这至少可以确认目录是可见的。
      • 不,!/home/atrac/code 可能没问题。看起来它实际上正在运行该程序,这是通往主目录的传统路径。 !./home/atrac/code 命令在当前目录下寻找home 子目录。
      【解决方案3】:

      当包含该文件的文件夹不在 MATLAB 可见的 UNIX 系统路径上时,您可以从 MATLAB 运行 UNIX 程序。要确定对 MATLAB 可见的系统路径,请在命令行窗口中键入以下内容:

      getenv('PATH')

      您可以修改为当前 MATLAB 会话或后续 MATLAB 会话持续存在的系统路径,如以下部分所述。

      修改当前 MATLAB 会话的系统路径。执行以下操作之一:

      Change the current folder in MATLAB to the folder that contains the program you want to run.
      
      Issue these commands using the Command Window:
      
      path1 = getenv('PATH')
      path1 = [path1 ':/usr/local/bin']
      setenv('PATH', path1)
      !echo $PATH 
      

      如果您重新启动 MATLAB,该文件夹将不再位于 MATLAB 可见的系统路径上。

      http://www.mathworks.com/help/matlab/matlab_env/creating-opening-changing-and-deleting-files-and-folders.html#f0-38522

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-28
        • 1970-01-01
        • 2012-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多