简体   繁体   English

在Linux机器上执行使用MATLAB从intel-fortran编译的程序

[英]Execute a program compiled using intel-fortran from MATLAB on Linux machine

I have an executable of a fortran code which I want to run from MATLAB. 我有一个要从MATLAB运行的fortran代码的可执行文件。

I tried using following two options but got errors: 我尝试使用以下两个选项,但出现错误:

!/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

Is there a way I can write a shell script to execute the program and pause Matlab till the external program is executed then pass the control back to Matlab? 有没有一种方法可以编写Shell脚本来执行程序并暂停Matlab,直到执行外部程序,然后将控件传递回Matlab?

I am trying to run a genetic algorithm in Matlab, which calls this external software. 我正在尝试在Matlab中运行一种遗传算法,该算法称为外部软件。 Any ideas or help is greatly appreciated. 任何想法或帮助将不胜感激。

Thanks, Yash 谢谢,亚什

Ideally, this should go as a comment, but I dont have enough reputation. 理想情况下,这应该作为评论,但是我没有足够的声誉。

But nonetheless, the error with the creating the child process is unrelated to MATLAB. 但是,尽管如此,创建子进程的错误与MATLAB无关。 The shell is erroring out. 外壳错误。 Are you able to run the program from the terminal? 您可以从终端运行程序吗?

Secondly, you are using: 其次,您正在使用:

!/home/atrac/code case172.jcl 

but you should be using !./home/atrac/code case172.jcl 但您应该使用!./ home / atrac / code case172.jcl

Okay, looks like two different things going on here. 好的,看起来好像发生了两件事。 Both are probably related to Matlab's current directory. 两者都可能与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

Here, it looks like you're managing to run your code program, but code or the JCL script is looking for a file named id in the current working directory. 在这里,您似乎正在设法运行code程序,但是code或JCL脚本正在当前工作目录中查找名为id的文件。 When you shell out from Matlab, that's going to be Matlab's current directory. 当您从Matlab封装时,它将成为Matlab的当前目录。 Run pwd from the Matlab command prompt to find out where you are. 在Matlab命令提示符下运行pwd ,以了解您的位置。 You can probably fix this by using cd in Matlab to move to the directory where the id file actually exists (I'm guessing it's in /home/atrac), and then running code using the same command line. 您可能可以通过以下方法解决此问题:在Matlab中使用cd移至id文件实际存在的目录(我猜它在/ home / atrac中),然后使用同一命令行运行code A better fix would be to rewrite code and/or the JCL script to work when run from any path (maybe by using absolute paths), so your cwd doesn't matter. 更好的解决办法是重写code和/或JCL脚本,使其在从任何路径运行时都可以工作(也许通过使用绝对路径),因此您的cwd无关紧要。

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

Here, the leading "." 在这里,以“。”开头。 is probably messing it up, because it's now looking for home/myhome under the current working directory, instead of under the root directory. 可能搞砸了,因为它现在正在当前工作目录下而不是根目录下寻找home/myhome Try doing !gnome-terminal --command "/home/myhome/code case12.jcl" (without the ".") instead. 尝试执行!gnome-terminal --command "/home/myhome/code case12.jcl" (不带“。”)。

You can run a UNIX program from MATLAB when the folder containing that file is not on the UNIX system path that is visible to MATLAB. 当包含该文件的文件夹不在MATLAB可见的UNIX系统路径上时,您可以从MATLAB运行UNIX程序。 To determine the system path that is visible to MATLAB, type the following in the Command Window: 要确定MATLAB可见的系统路径,请在命令窗口中键入以下内容:

getenv('PATH') GETENV( 'PATH')

You can make modifications to the system path that persist for the current MATLAB session or across subsequent MATLAB sessions, as described in the sections that follow. 您可以对系统路径进行修改,以保留当前MATLAB会话或后续MATLAB会话的持久性,如以下各节所述。

Modify the System Path for the Current MATLAB Session. 修改当前MATLAB会话的系统路径。 Do one of the following: 请执行以下任一操作:

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 

If you restart MATLAB, the folder is no longer on the system path visible to MATLAB. 如果重新启动MATLAB,该文件夹将不再位于MATLAB可见的系统路径上。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM