help-octave
[Top][All Lists]
Advanced

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

Passing a "ColumnVector" to a Fortran subroutine


From: Eduardo Gallestey
Subject: Passing a "ColumnVector" to a Fortran subroutine
Date: Thu, 04 Nov 1999 15:16:51 +1100

Hi folks,

I have a fortran program, which I want to call from the "octave"
environment. Say

A=rand(3,1);
B=fort_routine(A);

As far as I understand, the solution is to write a C++ function, which
would then call the Fortran subroutine. I have been able to do that and
it works correctly. 

However, the data transfer to and from FORTRAN is very  inefficient. The
reason is that FORTRAN doesn't understand the structures "Matrix",
"ColumnVector", etc., and I can not pass "ColumnVector" as an argument
to the FORTRAN part. 

Now I am doing loops to copy the data "ColumnVector" into a a C++
"array", acceptable for FORTRAN:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

DEFUN_DLD (Test, args , , "")
{

/* Get data */
ColumnVector data=args(1).vector_value();

int N=data.length();
double x[N], y[N];

/* Horrible loop */

for (int i=0; i<N; i++)
  x[i]=data(i);

/* useful action */

fortr_routine(x,y)       

ColumnVector retval[N];

/* Horrible loop */

for (int i=0; i<N; i++)
  retval(i)=y[i];

and "retval" is returned to "octave" in the usual way.

}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I wonder if there is a way to avoid the "horrible loops" above. For
example, do I have access to the pointer, which "points" to the
numerical values contained in "ColumnVector"? It must be somewhere,
isn't it?

Sorry for the long formulation of the question.

Thanks in advance,
Eduardo



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

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