FAST MEXing with Eclipse, Photran and G95 Compiler PDF Print E-mail

FAST is a very useful software for the simulation of Wind Turbine Generator systems, developed at the National Renewable Energy Laboratory (NREL); the program core consists of a non-linear multi-body model written in FORTRAN that can be also implemented in MATLAB/Simulink® as a S-Function.

The FAST software package can be downloaded from NWTC Design Codes page and already contains a good set of example WTG; along with the command line Windows version of the program, a couple of Simulink model, based on a MEXed version of FAST (that is a .dll or mexw32/mexw64 depending on new/old releases), is also available.

FAST is "ready to go" but can happen that you want to change some parts of the code to satisfy certain requirements; the complete source code is available and the following steps can be used to build an executable file or a dynamic library.

 

INDEX


REQUIREMENTS

First of all the methods described here are intended for Windows users, but I didn't spent time to figure out compatibilities on other OS that however could exist.

Compiling FORTRAN code means that at least one FORTRAN compiler is set on your system; two free compilers, GFortran and G95 are available and I've choosen the second. These compilers need a UNIX-like C development environment, provided on Windows by Cygwin or MinGW. The latter will be used for this purpose.

Install first MinGW (MSYS is recomended too) and then G95. Instructions, how-to, installers and other resources are available from the respective web pages and are frequently updated (that's why not directly linked from here).

The Mathworks grants compatibility with most commercial FORTRAN compilers like Compaq/HP and Intel; there is no supporting documentation for the free G95 compiler(GNU) but has been succesfully tested too.

Last thing we need to speed up coding/debugging phase is a full featured FORTRAN IDE; Eclipse + Photran plugin will do the job. If it is your first time using Eclipse download Eclipse IDE for C/C++ Developers otherwise you can simply downloand/install the Photran plugin.

 

REFERENCES

I found some very helpful pages on the net and here they go as a reference for you too:


BUILD FAST

A. Standard MAKEFILE

How to compile Matlab-compatible (or Simulink-compatible) MEX files? Assuming you have downloaded FAST and AeroDyn packages from the NWTC repository, create a new FORTRAN project in Eclipse with whatever name you want (FAST602c for me)and import the source files (this creates a copy, not affecting your original). This is done by right-clicking within the Project Explorer and selecting Import->General->File System and browsing to the correct file/folder. A destination subfolder can be specified in Into folder textfield (for the purpose AeroDyn will be copied to FAST602c/AeroDyn, and FAST source to FAST602c/Source, FASTDynamics.f90 and FASTGateway.f90, used for the S-Function only, will be copied to FAST602c).

Then we need to prepare the output folder, by right-clicking on the Project Explorer then New->Folder and name it SFunc; create also two SFunc subfolders named Modules and Objects (just to keep the workspace clean)

Next, we create the makefile by right-clicking on the SFunc folder inside the Project Explorer then New->File and choosing makefile (no extension) as filename and finally copying the following lines, or simply downloading (from DOWNLOAD section) and importing the makefile into SFunc dir.

 

# FAST MEX - Stefano Cottafavi 07/2008 - Manual makefile
# for Eclipse + Photran + G95 FORTRAN compiler
 
# Folders
ROOT = ..
SRCF = ${ROOT}/Source
SRCA = ${ROOT}/AeroDyn
 
# Configuration options
NAME = FAST602c_SFunc.mexw32
OUT = Objects
 
# Commands
FC = g95
DEBUG =
OPTIM = -O0
WARNING = -Wno-line-truncation
INCLUDE = -I"D:\Program Files (x86)\MATLAB\R2007b\extern\include"
LIBRARY = -L"D:\Program Files (x86)\MATLAB\R2007b\bin\win32" -lmex -lmat -lmx
MACRO = -DMATLAB_MEX_FILE
OPTIONS = -fmod=Modules -fcase-upper -fno-underscoring -r8
MACHINE =
OUTPUT = -o $(NAME)
 
# Compiler flags (CFLAGS), Linker flags (LFLAGS)
CFLAGS = -c ${DEBUG} ${OPTIM} ${WARNING} ${INCLUDE} ${OPTIONS}
LFLAGS = -shared ${MACRO} ${LIBRARY} ${MACHINE} ${OUTPUT}
 
# Targets: S-Function
fasts: ModG95.o SysG95.o \
fftpack.o \
AeroModsS.o FFTMod.o NoiseMods.o FastMods.o \
AeroSubs.o GenSubsS.o NoiseSubs.o UserSubs.o \
GenUse.o SetVersion.o \
AeroCalc.o HydroCalc.o FastIO.o FAST2ADAMS.o FAST_Lin.o \
PitchControl.o SpeedControl.o UserWind.o \
Fast.o FastDynamics.o FastGateway.o makefile
 
${FC} ${LFLAGS} ${OUTPUT} \
$(OUT)/ModG95.o $(OUT)/SysG95.o \
$(OUT)/fftpack.o \
$(OUT)/AeroModsS.o $(OUT)/FFTMod.o $(OUT)/NoiseMods.o $(OUT)/FastMods.o \
$(OUT)/GenSubsS.o $(OUT)/AeroSubs.o $(OUT)/NoiseSubs.o $(OUT)/UserSubs.o \
$(OUT)/GenUse.o $(OUT)/SetVersion.o \
$(OUT)/HydroCalc.o $(OUT)/AeroCalc.o $(OUT)/FastIO.o $(OUT)/FAST2ADAMS.o $(OUT)/FAST_Lin.o \
$(OUT)/PitchControl.o $(OUT)/SpeedControl.o $(OUT)/UserWind.o \
$(OUT)/Fast.o $(OUT)/FastDynamics.o $(OUT)/FastGateway.o
 
#clean:
# rm -f *.mod *.o
 
# -- COMPILE
FastDynamics.o: ${ROOT}/FASTDynamics.f90 makefile
${FC} ${CFLAGS} ${ROOT}/FASTDynamics.f90 -o ${OUT}/$@
FastGateway.o: ${ROOT}/FastGateway.f90 makefile
${FC} ${CFLAGS} ${ROOT}/FastGateway.f90 -o ${OUT}/$@
 
fftpack.o: $(SRCF)/fftpack.f makefile
${FC} ${CFLAGS} $(OPT) $(SRCF)/fftpack.f -o $(OUT)/$@
FFTMod.o: $(SRCF)/FFTMod.f90 makefile
${FC} ${CFLAGS} $(OPT) $(SRCF)/FFTMod.f90 -o $(OUT)/$@
 
ModG95.o: $(SRCF)/ModG95.f90 makefile
${FC} ${CFLAGS} $(SRCF)/ModG95.f90 -o $(OUT)/$@
SysG95.o: $(SRCF)/SysG95.f90 makefile
${FC} ${CFLAGS} $(SRCF)/SysG95.f90 -o $(OUT)/$@
AeroMods.o: $(SRCA)/AeroMods.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroMods.f90 -o $(OUT)/$@
AeroModsS.o: $(SRCA)/AeroMods_SFunc.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroMods_SFunc.f90 -o $(OUT)/$@
NoiseMods.o: $(SRCF)/NoiseMods.f90 makefile
${FC} ${CFLAGS} $(SRCF)/NoiseMods.f90 -o $(OUT)/$@
FastMods.o: $(SRCF)/FAST_Mods.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Mods.f90 -o $(OUT)/$@
GenSubs.o: $(SRCA)/GenSubs.f90 makefile
${FC} ${CFLAGS} $(SRCA)/GenSubs.f90 -o $(OUT)/$@
GenSubsS.o: $(SRCA)/GenSubs_SFunc.f90 makefile
${FC} ${CFLAGS} $(SRCA)/GenSubs_SFunc.f90 -o $(OUT)/$@
AeroSubs.o: $(SRCA)/AeroSubs.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroSubs.f90 -o $(OUT)/$@
NoiseSubs.o: $(SRCF)/NoiseSubs.f90 makefile
${FC} ${CFLAGS} $(SRCF)/NoiseSubs.f90 -o $(OUT)/$@
UserSubs.o: $(SRCF)/UserSubs.f90 makefile
${FC} ${CFLAGS} $(SRCF)/UserSubs.f90 -o $(OUT)/$@
 
SetVersion.o: $(SRCF)/SetVersion.f90 makefile
${FC} ${CFLAGS} $(SRCF)/SetVersion.f90 -o $(OUT)/$@
GenUse.o: $(SRCF)/GenUse.f90 makefile
${FC} ${CFLAGS} $(SRCF)/GenUse.f90 -o $(OUT)/$@
 
FastIO.o: $(SRCF)/Fast_IO.f90 makefile
${FC} ${CFLAGS} $(SRCF)/Fast_IO.f90 -o $(OUT)/$@
AeroCalc.o: $(SRCF)/AeroCalc.f90 makefile
${FC} ${CFLAGS} $(SRCF)/AeroCalc.f90 -o $(OUT)/$@
HydroCalc.o: $(SRCF)/HydroCalc.f90 makefile
${FC} ${CFLAGS} $(SRCF)/HydroCalc.f90 -o $(OUT)/$@
FAST2ADAMS.o: $(SRCF)/FAST2ADAMS.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST2ADAMS.f90 -o $(OUT)/$@
FAST_Lin.o: $(SRCF)/FAST_Lin.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Lin.f90 -o $(OUT)/$@
 
UserWind.o: $(SRCA)/UserWind.f90 makefile
${FC} ${CFLAGS} $(SRCA)/UserWind.f90 -o $(OUT)/$@
PitchControl.o: $(SRCF)/PitchCntrl_ACH.f90 makefile
${FC} ${CFLAGS} $(SRCF)/PitchCntrl_ACH.f90 -o $(OUT)/$@
SpeedControl.o: $(SRCF)/UserVSCont_KP.f90 makefile
${FC} ${CFLAGS} $(SRCF)/UserVSCont_KP.f90 -o $(OUT)/$@
 
Fast.o: $(SRCF)/FAST.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST.f90 -o $(OUT)/$@
FastProg.o: $(SRCF)/FAST_Prog.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Prog.f90 -o $(OUT)/$@
 

 

IMPORTANT: the makefile contains two variables, INLCUDE and LIBRARY: those are additional path to let compiler and linker know where your additional headers (.h) and lib files are stored (in this case we MUST add MATLAB header and lib files).

Change those variables to

INCLUDE = -I"yourdrive:\yourmatlab\extern\include"
LIBRARY = -L"yourdrive:\yourmatlab\bin\win32" -lmex -lmat -lmx

 

IMPORTANT: the proposed makefile has no optimization; to force hard optimization or customize the process a bit more follow G95 Manual instructions.

 

Finally, Photran has a view called Make targets in which you can link all targets from a makefile; once you have your makefile inside the SFunc folder just right-click on it then go to Make targets->Create and fill in with a name of your choice (FAST SFunc for me) and fasts for the target.

Double clicking on the target hopefully should build FAST602c_SFunc.mexw32 and put it inside SFunc folder.


fast_fortran

 

B. Autotools MAKEFILE

TODO

 

C. Managed MAKEFILE

This option creates a makefile starting from project dependent settings (toolchain, compiler, linker, etc...). At the time of writing, this is unusable feature for projects with multiple source files (so with FAST too) due to an error on compile/link dependencies order.

 

DOWNLOAD

MAKEFILE

FAST G95 Helpers (SysG95.f90, ModG95.f90)

 

Comments

avatar Scott Larwood
0
 
 
Hi Steffano, thank you for posting this information. I'm just trying to get a FAST executable compiled with G95. I got your make file for this from Jason's folder, but I don't understand what to do with it in Photran. I'll try to use your information here, but is there any other specific information I need?

Thanks,
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar air max 360
0
 
 
Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
This article is way over my mind. Very complicated topics to think about.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar SteeleJune
0
 
 
Different people in every country receive the business loans from different banks, because it is fast and easy.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar buy term papers
0
 
 
All the college students have to be aimed to result. That's achievable to get A+ with a support of college research paper service, I can tell you.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Scott Larwood
0
 
 
Hi Steffano,

With some effort I have my version of FAST compiled with G95 through Eclipse. My new problem is getting turbulent wind files read. Would you please let me know if you have problems reading full-field wind files.

Thanks,
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Scott Larwood
0
 
 
Found that I can read the binary wind files in G95 with ACCESS='STREAM' in the open command
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Too bad this one is for windows only...
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
I hope it can also work with ViSTA.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar web development
0
 
 
Really this was the very helpful information for me......
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Acai Berry Diet
0
 
 
This is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Thanks for giving me an amazing post, its great time to read your post. I’ve got some more interesting topic for discussion. So keep it up.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Medifast
0
 
 
Too bad this one is for windows only...
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Nutrisystem
0
 
 
This is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar p90x
0
 
 
All the methods described here are intended for Windows users...
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
I'm just trying to get a FAST executable compiled with G95.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Me and my friend were arguing about an issue similar to this! Now I know that I was right. lol! Thanks for the information you post.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Hanger
0
 
 
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar r9 irons
0
 
 
Great info.I like all your post.I will keep visiting this blog very often.It is

good to see you verbalise from the heart and your clarity on this important subject

can be easily observed. Thanks again!
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar nike air force
0
 
 
I am glad to talk with you and you give me great help! Thanks for that, I am

wonderring if i can contact you via email when i meet problems?
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
i am happy to be a part of this website and share my experience with everyone.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar air jordan 12
0
 
 
It looks good,I have learn a recruit!Recently,I found an excellent online store, the XX are completely various, good quality and cheap price,[url=http://www.prada-outlet-
store.com]prada store[/url] it's worth buying!
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
its really nice, that you guys are giving us an opportunity to share our views and opinions.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel

Talk about [URL=http://www.hotsalewatch.com]discount watches[/URL] .My mum goto buy
[URL=http://www.myceramicwatch.org]ceramic watch[/URL].But I like
[URL=http://www.mydiscounthandb ags.com]discount handbags[/URL] more.
Where do I could buy
[URL=http://www.mydiscountwatch es.org]discount watch[/URL].
Let's go to buy
[URL=http://www.thedesignerwatc hes.org]Designer Watches[/URL].
Find the
[URL=http://www.theledmanufactu rer.org]led manufacturer[/URL] from China.
Do you want to purchase for low price
[URL=http://www.wholesalejewelr ywatches.net]wholesale jewelry[/URL]
that is what I want.
I want to be [URL=http://www.benwon.com]led strip lights[/URL] designer.
My father want to find [URL=http://chinaelectrade.com]China Electronics[/URL] supplier.

[URL=http://www.themarcjacobsha ndbags.org]Marc Jacobs Handbags[/URL] This is the one I want to

buy.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar LED vs LCD
0
 
 
Wow, a lot of very good information in this article. I want to learn more about MEXing.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Last Updated on Tuesday, 31 March 2009 12:32