From help-octave-request at bevo dot che dot wisc dot edu Tue Dec 17 19:41:42 2002 Subject: Re: Dynamically loaded Fortran, how? From: Paul Kienzle To: "\"Albert F. Niessner\"" Cc: "\"Octave Help\"" Date: Tue, 17 Dec 2002 20:40:42 -0500 ----- Original Message ----- From: "John W. Eaton" To: "Albert F. Niessner" Cc: "Octave Help" Sent: Tuesday, December 17, 2002 6:00 PM Subject: Dynamically loaded Fortran, how? > On 17-Dec-2002, Albert F. Niessner 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) (A.data(), nr, nc); If you need to operate on a matrix in fortran, use the following: Matrix A(args(i).matrix_value()); F77_FUNC(f,F)(A.fortran_vec(),nr,nc); 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()); F77_FUNC(f,F)(A.data(),B.data(),C.fortran_vec()); 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: http://octave.sourceforge.net/coda/coda.html Please do update this with info about calling Fortran. The document source is in CVS in octave-forge/doc/coda (http://octave.sf.net). Paul Kienzle pkienzle at users dot sf dot net ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------