Need help on DLFs (dynamically linked functions)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need help on DLFs (dynamically linked functions)

wkim+
I'm using Octave 2.0.13 for OS/2.
First of all, thanks for answers to my previous query on DLF.
Though I could successfully run a small examples and I've spend
some time on DLFs, but I'm not yet familiar enough with DLFs to
adapt my C codes to Octave.  So, I'd like to see some more
example codes.

Suppose I want an Octave function:  

 [mat_x, vec_y, string_z] = func (mat_a, vec_b, int_c, string_d)

and suppose I have my own C code that does the same job as
func(), with variables double a[][], b[], int c, char *d, etc.
However, my problem is that I don't know how to connect Octave
function arguments (or return values) to the variables of my code.
Would you please show me short examples?  (Or, point me a site.)

I write C codes, but not C++ codes.  So, if I want to keep the most
part of my C functions untouched, how do I wrap C codes for Octave
DLFs?  (However, I'm willing to modify my C codes for C++ Octave
DLFs.)

Thanks.

//--------------------------------------------------------------------
// Wonkoo Kim ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: Need help on DLFs (dynamically linked functions)

Joao Cardoso-8
Wonkoo Kim wrote:

>
> I'm using Octave 2.0.13 for OS/2.
> First of all, thanks for answers to my previous query on DLF.
> Though I could successfully run a small examples and I've spend
> some time on DLFs, but I'm not yet familiar enough with DLFs to
> adapt my C codes to Octave.  So, I'd like to see some more
> example codes.
>
> Suppose I want an Octave function:
>
>  [mat_x, vec_y, string_z] = func (mat_a, vec_b, int_c, string_d)
>
> and suppose I have my own C code that does the same job as
> func(), with variables double a[][], b[], int c, char *d, etc.
> However, my problem is that I don't know how to connect Octave
> function arguments (or return values) to the variables of my code.
> Would you please show me short examples?  (Or, point me a site.)

Matwrap was created for this purpose, making foreign functions
available to octave. You only need to provide the function
prototype (and the function). You can find it at

        http://www.klab.caltech.edu/~holt/matwrap/

>
> I write C codes, but not C++ codes.  So, if I want to keep the most
> part of my C functions untouched, how do I wrap C codes for Octave
> DLFs?  (However, I'm willing to modify my C codes for C++ Octave
> DLFs.)
>
> Thanks.
>
> //--------------------------------------------------------------------
> // Wonkoo Kim ([hidden email])

--
Joao Cardoso                |   e-mail: [hidden email]
INESC, R. Jose Falcao 110   |   tel: + 351 2 2094322
4050 Porto, Portugal        |   fax: + 351 2 2008487


Reply | Threaded
Open this post in threaded view
|

Re: Need help on DLFs (dynamically linked functions)

wkim+
In reply to this post by wkim+
> Date: Thu, 18 Jun 98 14:35:08 +0200
> From: "Michael Hanke" <[hidden email]>
>
> Have a look at my recently uploaded sample drivers for ode's in
> octaves source repository.
> Michael

This helped me quite a lot!  I successfully managed to convert my C
function to Octave DLF.  (Matwrap package was too complex for my
needs.)

Some quick questions:

(1) Should I define only one DLF (to be called from Octave) in a file?
    (I noticed that Octave failed to load a DLF if the DLF name was
     not matched with its .oct file name, like with .m files.)

(2) What's the difference between x(1,1) and x.elem(1,1)?
    Just additional bound checking for .elem?

(3) If I want to detect input vector type of either row or column
    vector, should I treat the input arg as matrix?  (I want to
    return a vector of the same type as an input vector.)

(4) In Hanke's code (RADAU5.cc), I see lines:
        octave_value_list retval;
    but retval was not assigned anywhere before "return retval;"
    lines.  Could you explain why?

Thanks.

//--------------------------------------------------------------------
// Wonkoo Kim ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: Need help on DLFs (dynamically linked functions)

John W. Eaton-6
On 20-Jun-1998, Wonkoo Kim <[hidden email]> wrote:

| > Date: Thu, 18 Jun 98 14:35:08 +0200
| > From: "Michael Hanke" <[hidden email]>
| >
| > Have a look at my recently uploaded sample drivers for ode's in
| > octaves source repository.
| > Michael
|
| This helped me quite a lot!  I successfully managed to convert my C
| function to Octave DLF.  (Matwrap package was too complex for my
| needs.)
|
| Some quick questions:
|
| (1) Should I define only one DLF (to be called from Octave) in a file?
|     (I noticed that Octave failed to load a DLF if the DLF name was
|      not matched with its .oct file name, like with .m files.)

Some of Octave's .oct files define more than one function.  Multiple
links in the filesystem are then used to refer to the same .oct file
using more than one name.

| (2) What's the difference between x(1,1) and x.elem(1,1)?
|     Just additional bound checking for .elem?

The operator() version does bounds checking if Octave was compiled
with BOUNDS_CHECKING defined.  The elem() member function never does
bounds checking.  See Array.h for more details.

| (3) If I want to detect input vector type of either row or column
|     vector, should I treat the input arg as matrix?

Seems reasonable.

| (4) In Hanke's code (RADAU5.cc), I see lines:
|         octave_value_list retval;
|     but retval was not assigned anywhere before "return retval;"
|     lines.  Could you explain why?

I'm not sure exactly what function(s) you mean, but it has the effect
of returning an empty list.  If error_state has been set, the return
value doesn't much matter.

jwe