Simplest Fortran example (Add Two numbers)

Code Generation using MathCode/Fortran

Simplest example

Load the MathCode system into Mathematica

Needs["MathCode`"]

Set Working Directory

SetDirectory[$MCRoot<>"/DemosF90/SimplestExample"];

Define a simple function

Typed definition

addtwo[Real a_,Real b_] -> Real := Module[{},a+b]

Evaluation in Mathematica

addtwo[2.,2.]

Generate Fortran90 code and Build Executables

BuildCode[]

Install the Mathlink Executable

InstallCode[];

Run some examples

addtwo[2.,2.]

Uninstall the code

UninstallCode[];

which will clean up things and terminate the MathLink process.

A glance at the Generated Code

!! Global.f90

CleanMathCodeFiles[Confirm -> False, CleanAllBut -> {}];