help-octave
[Top][All Lists]
Advanced

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

issue calling external fortran subroutines that have the 'bind' statemen


From: wim van hoydonck
Subject: issue calling external fortran subroutines that have the 'bind' statement (fortran 2003 related)
Date: Sun, 4 Nov 2007 20:28:41 +0100

Hi all,

I am experimenting a little bit with interfacing octave with Fortran
(90/95/2003) code. In general, this works really well, but there are
some things where I have some strange results (could be entirely due
to my lack of c-programming skills).

Setup:
- octave 2.9.16 on fedora 7 x86_64 (had to compile this myself using a
modified rpm spec file, as fedora 7 only ships with 2.9.9)
- octave is compiled with standard compilers (gcc, gfortran)
- my external shared library is compiled using the intel fortran compiler 10.
- interface files are oct c++ files that are linked to that shared library

In general, I have not encountered any problems mixing fortran
compilers in this way.

Problems/issues:

1) fortran subroutines that have the BIND attribute (to define the
name when accessing it from c) only work if the name attribute of BIND
ends with an underscore.

-> subroutine times_two ( x , y ) bind(c, name="f90_mod_mp_times_two")
 does not work
-> subroutine times_two ( x , y ) bind(c,
name="f90_mod_mp_times_two_") does work

if in the oct-file, i use:
F77_FUNC (f90_mod_mp_div_two, F90_MOD_MP_DIV_TWO) ( double& x, double& y);

does the macro F77_FUNC

2) logicals/booleans returned from a fortran subroutine that are true,
have the value 255 inside the oct file. I have to divide them by 255
so that true booleans have the value 1. Is this normal behaviour?
The opposite way does work correctly, booleans that are input in a
fortran subroutine from c++ are recognized correctly. At the moment, I
cannot provide an example that compiles fine with gfortran, as I am
having trouble accessing module procedures with that compiler.

3) there seems to be something wrong with the isreal and isinteger
built-in functions  (at least, both isreal and isinteger return 1 with
the following oct file, that returns an integer array):

=pass_int_arr.cc=================================
#include <octave/oct.h>

DEFUN_DLD (pass_int_arr , args , , "return integer array, whose size
is determined by the input\n")
{
  octave_value_list retval;
  // check amount of input arguments
  int nargin = args.length();
  if (nargin != 1)
    print_usage ();
  else
    {
      octave_idx_type i;
      i = args(0).int_value();

      dim_vector dv (i);
      int32NDArray test(dv);
      //NDArray test(dv);

      for (int j=0;j<i;j++) {
        test(j) = j+1;
      }

      retval(0) = test;
      //retval(0) = octave_value(test);

    }
  return retval;
}
=======================================
then:
============
$ mkoctfile pass_int_arr.cc
$ octave --quiet
octave:1> isreal(pass_int_arr(3))
ans = 1
octave:2> isinteger(pass_int_arr(3))
ans = 1
============


I suppose one of them should return 0.


Greetings,

Wim


reply via email to

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