Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

Pengfei_S_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
10:41 AM

1 View

Fortran-Matlab interface

Hello,

I am very new to Fortran. I am building some Fortran codes to run some post-processing of data acquired by an ultrasound system that is controlled by Matlab. I cannot get away with Matlab because it is where the data is coming from. So far my solution is to use Matlab's "fopen" and "fwrite" functions to write the data into a file on the hard drive, and then read in the file using my Fortran codes. I have two questions:

1. I am running Matlab 2014a on a Mac OS (10.10) with Intel Fortran 2016 (compilers and libraries 2016.3.170). Under terminal window, I could run the Unix executable fine. But in Matlab's command window, when I run "./myfunction", it gives me the error below:

** **dyld: Library not loaded: @rpath/libmkl_intel_lp64.dylib

Referenced from: /Volumes/...

Reason: image not found

I know that under the terminal window, I have to always call "source bin/compilervars.sh intel64". I did this in Matlab's command window. It would run but would still gives me the error above when I tried executing my function. Any ideas on how to do this?

2. The Matlab "fopen" and "fwrite" solution is not optimal. I was thinking about building my Fortran codes with Matlab's mex function, but mex doesn't seem to support Fortran 2016 on a Mac OS X. Any suggestions on how to efficiently run a Fortran executable that is interacting with Matlab? The main interaction between the two is data input and data output: Matlab raw data -> my Fortran function for processing -> output to Matlab.

Thank you!

5 Replies

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
02:49 PM

1 View

I have no experience with

I have no experience with running Matlab on OSX, so my remarks may not apply.

Are you running a 32-bit version of Matlab, or a 64-bit version? How do you launch Matlab?

On Linux, I would suggest opening up a shell window, sourcing the Intel startup script, adding the Matlab BIN directory to PATH, adding the directory containing the Matlab shared libraries to LD_LIBRARY_PATH and then running the Matlab application from the same command window.

Please expand on why you think it is bad to have your Fortran application run as a post-processor. Are the data files being exchanged of very large size? How many times do you run the post-processor?

Highlighted
##

Pengfei_S_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
03:45 PM

1 View

Quote:mecej4 wrote:

mecej4 wrote:

I have no experience with running Matlab on OSX, so my remarks may not apply.

Are you running a 32-bit version of Matlab, or a 64-bit version? How do you launch Matlab?

On Linux, I would suggest opening up a shell window, sourcing the Intel startup script, adding the Matlab BIN directory to PATH, adding the directory containing the Matlab shared libraries to LD_LIBRARY_PATH and then running the Matlab application from the same command window.

Please expand on why you think it is bad to have your Fortran application run as a post-processor. Are the data files being exchanged of very large size? How many times do you run the post-processor?

I am running a 64-bit version of Matlab on OSX. I just click the Matlab icon on the dashboard to launch it. Thank you for the shell window idea, I am going to give it a try.

Sorry maybe I was not clear: I don't think having Fortran application run as a post-processor is a bad idea. It is much faster than Matlab. The Matlab is controlling an ultrasound system which is collecting data with dimensions of about 200 x 200 x 100 in complex double format at a rate of about 20 times per second. So I have to transfer such 200 x 200 x 100 complex double matrix about 20 times a second between Matlab and Fortran. Ideally a gateway that supports fast data transfer between the two would be great. The data is in Matlab's workspace memory on the same Mac that runs the Fortran codes.

Thanks!

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
04:06 PM

1 View

Good; one more question: what

Good; one more question: what do you do with the results from the post-processing? In particular, do you pass them back to Matlab?

I think that you can slightly modify your Fortran code to produce a Mex file that can be called from Matlab with your 200 X 200 X 100 array as input.

Highlighted
##

Pengfei_S_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
04:11 PM

1 View

Yes I have to pass them back

Yes I have to pass them back to Matlab for display, specifically overlaying the result on an existing Matlab figure.

Do you have an example of how to modify Fortran code to produce a mex file? So far what I could find is in this link: http://www.mathworks.com/help/matlab/matlab_external/create-fortran-source-mex-file.html.

Thanks!

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2016
07:48 PM

1 View

The example in the link that

The example in the link that you provided, and several examples in the Matlab "extern" subdirectory on your computer, can be consulted.

You have to modify your Fortran source code such that the entry point is a subroutine called mexFunction, with input and output arguments in the way specified in the Matlab documentation.

For more complete information about compiler optimizations, see our Optimization Notice.