About .oct file

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

About .oct file

Shiou-Jhy Ja
Hi:

        I saw a old post in 1997 about recompile .oct file, then calling it
without restart octave will cause segmentation fault.  It still happened
for octave2.0.11 on linux with gcc 2.7.2, libc.so.5 .  Is ther a cure?

        Also I'm trying to compile some known C routin to .oct file and having
some question:

1) how to extrat data(string, double, ..) from octave command line?
What I mean is something like:
  char *str;
  str=strcpy(arg(0).string_value(),' ');

and it didn't work.

for matrix, I use a silly way to do it:

   Matrix oct_x=arg(0).matrix_value();

   int n=oct_x.column();  //assume it's a row vector

   double *x=new double[n];

   for (int i=0; i<n; i++)
       x[i]=oct_x(0,i);

   then I can call other routin with x


It works, however, I would like to know a better way to do it.


        Last question, is there any easy code that can help me learn about
writing .oct code?

Thanks for help


Puck
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: About .oct file

Gary Holt-2
           Also I'm trying to compile some known C routin to .oct file and having
   some question:

   1) how to extrat data(string, double, ..) from octave command line?
        ... [sample code snippet deleted]

   It works, however, I would like to know a better way to do it.

Have a look at http://www.klab.caltech.edu/~holt/matwrap/.  It generates
all this code for you automatically.  It also automatically vectorizes
your functions for you and does some other nice things too.

You can just enter function prototypes for the functions you have into
the demonstration, and it will spit out octave (or matlab) code to call
those functions.  You can also download the program that generates those
functions from that web page.

--
Gary Holt (213)-740-3397
[hidden email] http://www.klab.caltech.edu/~holt/


Reply | Threaded
Open this post in threaded view
|

About .oct file

John W. Eaton-6
In reply to this post by Shiou-Jhy Ja
On 19-Mar-1998, Shiou-Jhy Ja <[hidden email]> wrote:

| I saw a old post in 1997 about recompile .oct file, then calling it
| without restart octave will cause segmentation fault.  It still happened
| for octave2.0.11 on linux with gcc 2.7.2, libc.so.5 .  Is ther a cure?
|
| Also I'm trying to compile some known C routin to .oct file and having
| some question:
|
| 1) how to extrat data(string, double, ..) from octave command line?
| What I mean is something like:
|   char *str;
|   str=strcpy(arg(0).string_value(),' ');

This doesn't work for a couple of reasons.  First, string_value()
returns a C++ string, not a C string.  If you want to convert it to a
NUL-terminated C string, you need to use

  arg(0).string_value().c_str()

but that returns `const char *', so you can't use that as the first
argument to strcpy.  If you are trying to assing a character string to
an Octave object, just do it:

  octave_value val = "foobar";

There are lots of constructors defined to make things like this
relatively convenient.

| for matrix, I use a silly way to do it:
|
|    Matrix oct_x=arg(0).matrix_value();
|
|    int n=oct_x.column();  //assume it's a row vector
|
|    double *x=new double[n];
|
|    for (int i=0; i<n; i++)
|        x[i]=oct_x(0,i);
|
|    then I can call other routin with x

You can extract the data from an Octave Matrix object using

  const double *d = val.matrix_value().data()

This returns all the elements in column-major order.

| Last question, is there any easy code that can help me learn about
| writing .oct code?

The Octave sources themselves contain lots of examples.  A good place
to start would be the files like src/svd.cc and liboctve/dbleSVD.cc.

jwe