system or unix command run compiled fortran binary fails, but it runs fine from a terminal

3 views (last 30 days)
Hi, I'm trying to get matlab to start up a compiled fortran program with the unix or system commands. To do this, I fill "str" with the required information, and then call unix(str). However, the fortran program won't run when I call it from matlab, but works just fine when I call it from a terminal window.
This is the string I am sending:
/home/derek/Research/2Layer_new/src/seis-spread-response-sameani /home/derek/Data/tables/GSN_SKS_Nov_2011_best/1_Layer_flat/model.synthetics /home/derek/Data/tables/GSN_SKS_Nov_2011_best/1_Layer_flat/geometry /home/derek/Data/tables/GSN_SKS_Nov_2011_best/1_Layer_flat/phasefile /home/derek/Data/tables/GSN_SKS_Nov_2011_best/1_Layer_flat/arrivalfile /home/derek/Data/tables/GSN_SKS_Nov_2011_best/1_Layer_flat/traces.out SV
and this is the output:
/home/derek/Research/2Layer_new/src/seis-spread-response-sameani: /usr/local/MATLAB/R2012a/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /home/derek/Research/2Layer_new/src/seis-spread-response-sameani)
Like I said above, I can take the value in str and cut and paste it to a terminal window, and the fortran code runs fine. I've tried both the system and unix commands, and also confirmed that the MATLAB_SHELL environmental variable is set to the shell I I am using. Apparently there is something I don't understand about how matlab does a system command, but I can't seem to find any useful information. Does anyone have a clue? Thanks.

Accepted Answer

Walter Roberson
Walter Roberson on 16 May 2012
compare
getenv('LD_LIBRARY_PATH')
!ldd /home/derek/Research/2Layer_new/src/seis-spread-response-sameani
inside MATLAB, to
echo $LD_LIBRARY_PATH
ldd /home/derek/Research/2Layer_new/src/seis-spread-response-sameani
from the terminal window. You might need some options to ldd.

More Answers (2)

Derek
Derek on 17 May 2012
Thanks Walter, that led to the correct answer. I didn't know this, but it looks like matlab provides it's own fortran libraries, which I gather are somewhat out of date with respect to the libraries I have on my Fedora 16 computer. The matlab fortran library that was being called was:
libgfortran.so.3 => /usr/local/MATLAB/R2012a/sys/os/glnxa64/libgfortran.so.3
Wheras from the command linel, I was using this library:
libgfortran.so.3 => /usr/lib64/libgfortran.so.3.
Hence, as suggested by this website <http://judsonsnotes.com/notes/index.php?option=com_content&view=article&id=611:matlab-running-external-programs&catid=57:programming&Itemid=81> , I changed the link in matlab to point to my system linux library. In other words, I did this:
$ sudo mv libgfortran.so.3.0.0 libgfortran.so.3.0.0.old
$ sudo ln -sf /usr/lib64/libgfortran.so.3 /usr/local/MATLAB/R2012a/sys/os/glnxa64/libgfortran.so.3

Shan Dou
Shan Dou on 4 Mar 2014
After our matlab gets updated to R2013b, I still have the same issue with gfortran, even though the version of gfortran is supposed to be compatible with R2013b. The temporary solution that works for me is to use g77 instead of gfortran.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!