[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamically loaded Fortran, how?

From: Paul Kienzle
Subject: Re: Dynamically loaded Fortran, how?
Date: Tue, 17 Dec 2002 20:40:42 -0500

----- Original Message -----
From: "John W. Eaton" <address@hidden>
To: "Albert F. Niessner" <address@hidden>
Cc: "Octave Help" <address@hidden>
Sent: Tuesday, December 17, 2002 6:00 PM
Subject: Dynamically loaded Fortran, how?

> On 17-Dec-2002, Albert F. Niessner <address@hidden> wrote:
> | I have a C++ wrapper around a Fortran subroutine (mostly) and need some
> | help getting it working with octave -- it works with g++/g77.
> |
> | First, what is the recommend way to go from Matrix to reference to the
> | matrix for passing into the fortran subroutine?
> There are a number of examples of calling Fortran from C++ in the
> Octave sources.  Search for F77_XFCN or F77_FUNC.

Particularly in octave/src/DLD_FUNCTIONS.  Please note that all fortran
variables are pass by reference.

Something like the following should work:

    extern "C" F77_FUNC (f,F) (const double *, int&, int&);
    const Matrix A(args(i).matrix_value());
    const int nr=A.rows(), nc=A.columns();
    F77_FUNC (f,F) (, nr, nc);

If you need to operate on a matrix in fortran, use the following:

    Matrix A(args(i).matrix_value());

If the operation is not in place, or if you need a working vector, allocate
it beforehand:

    octave_value_list retval;
    const Matrix A(args(0).matrix_value());
    const Matrix B(args(1).matrix_value());
    Matrix C(A.rows(),B.columns());
    retval(0) = C;
    return retval;

> | Second, what is the recommend way to use mkoctfile to produce the
> | desired results -- a dynamically loadable function?
> A starting point:

Please do update this with info about calling Fortran.  The document source
is in CVS in octave-forge/doc/coda (

Paul Kienzle

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]