1
votes

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.

3
How are you executing the program from matlab?IanH
The method used normally within the actual matlab program is as follows: system(['cd "',handles.indir,'";chmod u+x ./qp.exe',... ';./qp.exe']); the program is copied into a directory and then executed. I've also tried navigating to the directory and running !qp.exeScot Halverson
Ok - as long as you have nothing to the left of the system call (no [xxx,yyy] = system(... )IanH

3 Answers

0
votes

I believe Matlab is a single threaded application. When you invoke a multithreaded executive, I have seen various issues with piping the output back to Matlab. Have you considered recompiling into a Fortran mex file?

0
votes

I am not sure a mex file would print to stdout any better than a standalone executable.

There are other options. One is to write(append) all your diagnostics to a file and just look at the file when you want to. Emacs, for example, automatically "revert"s the contents of a file every second or whatever you set the interval to. Another option might be to convert the fortran source into matlab source (see f2matlab) and keep it all in matlab.

bb

0
votes

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'])