help-octave
[Top][All Lists]
Advanced

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

.oct-files


From: Stef Pillaert
Subject: .oct-files
Date: Tue, 30 Sep 1997 10:57:07 +0200

Hello,

Situation: I managed to turn one of my octave-functions ("optel")
succesfully into a working .oct file (i.e. I wrote some code in the file
optel.cc, and then  I used "mkoctfile"...). Indeed, it works a lot faster
then my old script in optel.m !

Now, I'm trying to translate another function ("kader") to an .oct-file,
but in kader I need to call optel. Is there a way to do this? My file
optel.cc looks like this (just the sum of 2 variables...):

#include <octave/oct.h>

DEFUN_DLD (optel, args, nargout,
  "optel(a,b)\n\
\n\
sum of a and b .")
{
  int nargin = args.length();
  if (nargin != 2 || nargout > 1)
    {print_usage ("optel");
    }
  Matrix a = args(0).matrix_value();
  Matrix b = args(1).matrix_value();
  Matrix c=a+b;
  return octave_value(c);
}


I tried to write kader.cc like this:

#include <octave/oct.h>

DEFUN_DLD (kader, args, nargout,
  "kader(c,d)\n\
\n\
sum of c and d (via optel).")
{ octave_value optel(octave_value a,octave_value b);
  int nargin = args.length();
  if (nargin != 2 || nargout > 1)
    {print_usage ("kader");
    }
  octave_value c = args(0);
  octave_value d = args(1);
  octave_value e = optel(c,d);
  return e;
}


But this doesn't work (I tried "mkoctfile kader.cc optel.cc")

What does work however is changing my optel.cc file into:

#include <octave/oct.h>

Matrix optel(Matrix a,Matrix b)
{
  Matrix som=a+b;
  return som;
}

and changing my kader.cc file into:

#include <octave/oct.h>

DEFUN_DLD (kader, args, nargout,
  "kader(a,b)\n\
\n\
telt a en b op (via optel).")
{ Matrix optel(Matrix a, Matrix b);
  int nargin = args.length();
  if (nargin != 2 || nargout > 1)
    {print_usage ("kader");
    }
  Matrix c = args(0).matrix_value();
  Matrix d = args(1).matrix_value();
  Matrix e = optel(c,d);
  return octave_value(e);
}

(and: "mkoctfile kader.cc optel.cc")

But, this would mean I have to use two versions for my optel-function: one
for using directly in octave, and one for using in other .oct-files.

Is there a solution?

Thanks,

Stef.

P.S. I suppose calling a function defined in a .m-file from a .oct file is
completely out of the question?
P.S. You might suggest that I just write my complete program in C++, but
then I won't be able to take advantage of all the good things octave offers
me... (besides, C++ isn't quite my cup of tea).





reply via email to

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