[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size
From: |
Marco2008 |
Subject: |
Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size |
Date: |
Wed, 8 Oct 2008 14:01:46 -0700 (PDT) |
John W. Eaton wrote:
>
> I think we need to know more details about precisely how your function
> does what you claim it does. Perhaps you could post a simple example
> that has all the relevant features (i.e., some Fortran function that
> allocates a matrix and returns it as a parameter). Exactly how does
> your Fortran function allocate the data? How would you call your
> fucntion in a program written purely in Fortran?
>
> jwe
>
So here is the example that works:
c++-wrapper (fun_cpp.cc):
#include <octave/oct.h>
#include "f77-fcn.h"
extern "C"
{
F77_RET_T
F77_FUNC (funfortran, FUNFORTRAN) (double* matrix1);
}
DEFUN_DLD (fun_cpp, args, ,"...")
{
octave_value_list retval;
Matrix M1 = Matrix(2,2);
F77_XFCN (funfortran, FUNFORTRAN,
( M1.fortran_vec() ) );
if (f77_exception_encountered)
{
error ("Error!");
return retval;
}
retval(0) = M1;
return retval;
}
Fortran-Subroutine (funfortran.f90):
subroutine funfortran(matrix1)
implicit none
real(8), intent(out) :: matrix1(2,2)
matrix1(1,:) = (/1,2/)
matrix1(2,:) = (/3,4/)
end subroutine funfortran
Call in octave:
octave:1> fun_cpp
ans =
1 2
3 4
octave:2>
My problem is the following fortran code:
subroutine funfortrantwo(vector1)
implicit none
integer :: size1
real(8), allocatable :: vector1(:)
size1 = 3
! size1 here is defined by a fixed number only to make the
! example clear. Normally, it is computed inside this fortran
! subroutine and not known before a call of funfortrantwo.
allocate( vector1(size1) )
vector1 = 2
end subroutine funfortrantwo
I do not know how to write the c++-wrapper for this subroutine. In the first
example the size of the matrix is known before the fortran subroutine is
called. But this is not the case in the second example.
Marco
--
View this message in context:
http://www.nabble.com/Include-Fortran-Code-which-Returns-Arrays-of-Dynamic-Unknown-Size-tp19845758p19887509.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Marco2008, 2008/10/08
- Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, John W. Eaton, 2008/10/08
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size,
Marco2008 <=
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Jaroslav Hajek, 2008/10/09
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Marco2008, 2008/10/10
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, David Bateman, 2008/10/10
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Marco2008, 2008/10/13
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, David Bateman, 2008/10/13
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Jaroslav Hajek, 2008/10/13
- Re: Include Fortran Code which Returns Arrays of Dynamic/Unknown Size, Jaroslav Hajek, 2008/10/13