Fortran应用程序的输出没有在Matlab中显示 [英] Output from fortran application not showing up in Matlab

查看:256
本文介绍了Fortran应用程序的输出没有在Matlab中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些Fortran应用程序输出的问题,这些应用程序是在Matlab中执行的。我们使用Matlab来调用一些Fortran应用程序并显示输出和结果。

我在OSX上使用gfortran来构建这些程序中的一个,它执行大量文件输出并向stdout输出一些信息以跟踪进度。 stdout输出主要通过print *语句完成,但我也尝试写(*,*)。该程序使用OpenMP,但在OpenMP并行部分内没有执行print *或write(*,*)语句。从终端执行程序时,一切正常。但是,当程序从matlab内部执行时,标准输出没有输出。文件输出工作正常。

另外,使用英特尔ifort编译的相同代码在matlab中显示其输出没有问题。不幸的是,我没有经常访问英特尔编译器。



我肯定输出是stdout(不是stderr),我试过冲洗(从调用flush(6)& call flush(0)),但是这似乎没有什么区别。



我不确定可能会造成这种情况。任何想法?

一些相关信息:
操作系统:OSX 10.6.8(64位模式)



Matlab:R2012b

gfortran:4.7.2(通过fink获得)

编译标志:-cpp - fopenmp -ffree-line-length-0 -fno-range-check -m64 -static-libgfortran -fconvert = little-endian -fstrict-aliasing

编辑:

我做了一些更多的测试,创建了一个简单的'hello'程序:

程序printTest 
写(*,*)'hello'
结束程序

用...编译...

  gfortran test.f90 -o测试

表现出相同的行为。

我也尝试使用gfortran(4.2.1)的早期版本进行编译,从而产生了一些有趣的结果。它在终端执行罚款,但在matlab中,我得到以下内容:

lockquote


!./测试
dyld:懒惰符号绑定失败:找不到符号:__gfortran_set_std
引用自:/Users/sah/Desktop/./test
预计位置:/Applications/MATLAB_R2012b.app/sys/os/maci64/ libgfortran.2.dylib


dyld:找不到符号:__gfortran_set_std
引用自:/Users/sah/Desktop/./test
预计:/Applications/MATLAB_R2012b.app/sys/os/maci64/libgfortran.2.dylib

./ test:跟踪/断点陷阱


这让我相信它是一个图书馆问题。在这种情况下使用-static-libgfortran会产生相同的结果。 根据 www.mathworks.se/help/matlab/ref/system.htmlrel =nofollow>系统功能文档 $ b



[status,result] = system('command')将状态变量的完成状态返回给状态变量,并将命令的结果返回给结果变量。

[status,result] = system('command',' - echo')也会强制输出到命令窗口。


因此,您应该在系统调用中使用'-echo'参数直接在命令窗口中查看输出

  system(['cd'',handles.indir,'; chmod u + x ./qp.exe',...'; ./ qp.exe'],'-echo' )

或者您可以将stdout分配给一个变量:

  [ret txt] = system(['cd ',handles.indir,'; chmod u + x ./qp.exe',...'; ./ qp.exe'])


I'm having some issues with output from a fortran application being executed from within Matlab. We use Matlab to call a number of fortran applications and to display output and results.

I'm using gfortran on OSX to build one of these programs, which does a large amount of file output and a little output to stdout to track progress. stdout output is accomplished mainly through print * statements, but I've tried write( * , * ) as well. The program uses OpenMP, but none of the print * or write( * , * ) statements are performed within OpenMP parallel sections.Everything works fine when the program is executed from a terminal. However, when the program is executed from within matlab, there is no output from stdout. The file output works fine though.

Additionally, the same code, when compiled with Intel's ifort, displays its output in matlab without issue. Unfortunately I don't have regular access to the Intel compiler.

I'm positive that the output is going to stdout (not stderr), and I've tried flushing both from within the code (call flush(6) & call flush(0)), but this doesn't seem to make a difference.

I'm not sure what could be causing this. Any thoughts?

some relevant information: OS: OSX 10.6.8 (64bit mode)

Matlab: R2012b

gfortran: 4.7.2 (obtained via fink)

compile flags: -cpp -fopenmp -ffree-line-length-0 -fno-range-check -m64 -static-libgfortran -fconvert=little-endian -fstrict-aliasing

EDIT:

I've done some more testing, creating a simple 'hello' program:

program printTest
write (*,*) 'hello'
end program

compiled with...

gfortran test.f90 -o test

which exhibits the same behavior.

I've also tried compiling with an earlier version of gfortran (4.2.1), which produced some interesting results. it executes fine in terminal, but in matlab I get the following:

!./test dyld: lazy symbol binding failed: Symbol not found: __gfortran_set_std Referenced from: /Users/sah/Desktop/./test Expected in: /Applications/MATLAB_R2012b.app/sys/os/maci64/libgfortran.2.dylib

dyld: Symbol not found: __gfortran_set_std Referenced from: /Users/sah/Desktop/./test Expected in: /Applications/MATLAB_R2012b.app/sys/os/maci64/libgfortran.2.dylib

./test: Trace/breakpoint trap

This leads me to believe its a library issue. using -static-libgfortran produces the same result in this case.

解决方案

According to the system function documentation

[status, result] = system('command') returns completion status to the status variable and returns the result of the command to the result variable.

[status,result] = system('command','-echo') also forces the output to the Command Window.

So you should use '-echo' parameter to the system call to see the output directly in the command window

system(['cd "',handles.indir,'";chmod u+x ./qp.exe',... ';./qp.exe'], '-echo')

or you can assign the stdout to a variable:

[ret txt] = system(['cd "',handles.indir,'";chmod u+x ./qp.exe',... ';./qp.exe'])

这篇关于Fortran应用程序的输出没有在Matlab中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆