Forums

Fortran compiler

Started by Unknown December 17, 2003

Hello Kailash Suppose that I have the C routine bellow. This routine
calculate the factorial of n. Suppose that you dont want
translate this routine for Matlab function or script.

So you can use the mex command. In the Matlab prompt you
type (or you can call the command in a Matlab script ou
function):

>>mex -g fact.c (for example there are much more options)

>>mex -g fact.for (if your code is in Fortran)

this creat a file: fact.dll.

Now suppose that you have a Matlab script factorial.m , you
can call the fact C function from factorial.m :

>>factorial

of course the paramater n is necessary.

Can you see this is good if you have several functions
write in C ou Fortran.

---------------
More...

Now suppose that you type in the Matlab prompt:

>>mex -setup [enter]

In Matlab 6.0 (12) the following mensage appear:

Please choose your compiler for building external interface (MEX)
files:

Would you like mex to locate installed compilers [y]/n? n

Select a compiler:
[1] Borland C++Builder version 5.0
[2] Borland C++Builder version 4.0
[3] Borland C++Builder version 3.0
[4] Borland C/C++ version 5.02
[5] Borland C/C++ version 5.0
[6] Borland C/C++ (free command line tools) version 5.5
[7] Compaq Visual Fortran version 6.1
[8] Digital Visual Fortran version 6.0
[9] Digital Visual Fortran version 5.0
[10] Lcc C version 2.4
[11] Microsoft Visual C/C++ version 6.0
[12] Microsoft Visual C/C++ version 5.0
[13] WATCOM C/C++ version 11
[14] WATCOM C/C++ version 10.6

[0] None

Compiler:

Theses are the default Fortran and C compilers in Matlab 6.0 (12).
The Lcc C in provide by Matlab, the other is necessary to install.
I would like to use a different Fortran compiler: The Force.
But I dont have sucess at the moment. I think there is necessary
specify the path but don't know to do this.
I would appreciate any help.

Agostinho

/*
* fact.c - returns the factorial of a non-negative integer.
*
* MATLAB usage: p = fact(n)
*/

#include "mex.h"

void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double n, j, *p;
int i;

n = mxGetScalar(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
p = mxGetPr(plhs[0]);

j = 1.0;
for (i = n; i > 1; i--)
j = j * i;
*p = j;
}
--- In , mailing.list@s... wrote:
> How do we run a fortran written subroutine in matlab? Any example.
>
> --
> Kailash N. Srivastava