lab12



CREATING AND LINKING TO SELECTED LIBRARIES



ATTENTION for f90 to matlab practice!

BRIEF OVERVIEW OF WHAT NEEDS TO BE DONE
create a lab_matlab directory  and in it create
  • src/
  • bin/
  • iof/
Download the following files into the src/ dir

In another shell you will be required to bring up the .bashrc file and insert the function
Start the exercise here

CALLING MATLAB TOOLS FROM a f90 code


Matlab Engine interface examples

Compiling and linking "Matlab Engine" programs


CHECKING WHERE MATLAB IS LOCATED

  • <bash> ls /usr/local will list the directories for all the applications
  • The matlab version 7 is ideal for animation and post processing of time dependent data from languages like C, f77 and f90. When using the f90 compiler ifc the animations are no longer delayed but fast and smooth. For better performance the source codes should be compiled without the debug flag.
    • MATLAB 7 IS THE PREFERRED ONE
  FOR MATLAB 7 THE SETTINGS ARE AS FOLLOWS
In order to interface the f90 part of the code to the matlab animation engine an environment variable needs to be set prior to the link step and the execution step. The environment variable must not be exported on log in! For some reason the kde session manager does not like it. However the Gnome session is fine with exporting it on log in. What one can do is set it up as a function that exports the environment variable when the user wants to use it. When it is set as a function the user executes the function by typing the function name in the shell.  In the .bashrc file insert the following lines:

Steps: Start here

What to do
ATTENTION
Insert the following lines in the .bashrc file as shown. The .bashrc file is located in /home/username.
  • <bash>cd
  • <bash>vi .bashrc
function expmatlib
{
           m7=/usr/local/matlab7/bin/glnx86;
           export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$m7
}
Save and exit the .bashrc file and then source the file
<bash> source .bashrc <enter>
cd into the src/ directory for this exercise
<bash> cd ~/aero361/lab_matlab/src
Before running the Makefile.mk in the src/ dir execute the expmatlib function
<bash> expmatlib  < enter>
Use the Makefile or if you have not been enlightened by  aero361 then use the caveman approach to compiling the files.
<bash> make -f Makefile.mk
<bash> ifc -c -w  main.f90 plot4.f90
link the files (if you do not have a Makefile.mk). For those who are using a Makefile place library and its path in the Makefile. Review the downloaded Makefile it shows the user how to access libraries. Its probably done for you, but review it!
<bash> ifc [file1.o] ...... [filen.o]-o step1 -L/usr/local/matlab7/bin/glnx86/ -leng

cd into the bin dir and run the code
<bash> cd ../bin; ./code.x
open up the main.f90 and plot.f90 and review the code and refer to these pages and the function call list in the next cell
  Using the MATLAB Engine
  The Engine Library
  GUI-Intensive Applications
  Calling MATLAB from a Fortran Application
<bash> vi .............

COMMON MATLAB FUNCTION NAMES FOR THE INTERFACE

engOpen to start the matlab engine
*
engClose to close the matlab engine
*
engGetVariable getting a matlab array from matlab

engPutVariable sending a matlab array to matlab
*
engEvalString executing a matlab expression e.g. plot
*
engOutputBuffer text buffer

mcCreateDoubleMatrix
to create a mXn array space  in matlab
*
mxGetPr


mxGetData

mxCopyReal8ToPtr
mxCopyReal8ToPtr(y,px,n) copies n REAL*8 values from the Fortran REAL*8 array y into the MATLAB array pointed to by mxGetPr *


DO IT YOUR-SELF EXERCISE AND PRESENT IN NEXT LAB

  1. Use this matlab post processing tool and implement it in your panel code. If the panel code has been written in a neat/organized modular way it is just a matter of adding a new subroutine and calling it from the main or output routine once these arrays are available. For this you only require plot4.f90  and the addition of the library into the Makefile.mk file.
    1. cp
    2. pressure
    3. vel
    4. source
    5. xp,yp
    6. xgrid, ygrid