Can I change Matlab libraries in a program
Show older comments
I am trying to run a FORTRAN program (FVCOM) from Matlab. I ran into the error similar to what these folks had:
My FORTRAN program uses a library called libnetcdf.so.7. Matlab has a built in version of this library, but it is missing a symbol that my FORTRAN program needs. So in order for me to successfully execute my program from MATLAB I need to start up Matlab using the following command from the terminal:
LD_PRELOAD=/usr/local/lib/libnetcdf.so.7 matlab
However, before I run my FORTRAN program I want to use Matlab's netdcf abilities to create some input files needed for the program. Unfortunately, since I changed where Matlab is looking for the libnetcdf.so.7, Matlab's netcdf functions don't work because they need a symbol that is in the built in Matlab library and not in the library that is in my /user/local/lib/ directory.
Is there a way for me to set the library path after matlab has started? Ideally I would start up matlab normally (without changing the library path) and do something like:
%%%execute matlab code using matlab's netcdf functions such as...%%%
t=ncread(file, 'time');
nc=netcdf.create(WindFile,'clobber'); % etc
%%%then, in the same instance of Matlab run my Fortran program %%%
% change my library path, but note that this doesn't work
LD_LIBRARY_PATH=/usr/local/lib/libnetcdf.so.7
% run my FORTRAN program
system(sprintf('sh run_FVCOM.sh'))
I am running Matlab R2014a on Ubunto 14.04.1
It seems like I can either startup Matlab to run my Fortran program or I can startup Matlab normally to create my netcdf files, but not both. The only work-around I can think of is to call matlab from matlab (which just seems really kludgy):
%%%code to create my netcdf files %%%
nc=netcdf.create(WindFile,'clobber'); % etc
%%%code to create a new instance of matlab that calls a program to run my fortran program %%
system(LD_PRELOAD=/usr/local/lib/libnetcdf.so.7 matlab -nodisplay -r "runfvcom")
Is there a more ellegant solution that I am not aware of?
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Mobile 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!