help-octave
[Top][All Lists]
Advanced

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

Re: Building Standalone Executables


From: David Grundberg
Subject: Re: Building Standalone Executables
Date: Mon, 15 Feb 2010 12:27:30 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

Tim Felty wrote:
Everyone,
I am trying to build a standalone executable that makes use of Octave's computational routines. I have looked at the manual and have built the simple example and had it work fine. However, I haven't been able to find any guide that describes anything more complex than creating matrices within a standalone app. My code currently looks like this: #include <iostream>
#include <octave/oct.h>
using namespace std; int
main(void)
{
    cout << "Hello Octave world! This is a test\n";
    int size;
    cin >> size;
 Matrix a_matrix = Matrix(1,size);
 Matrix b_matrix = Matrix(1,size);
 Matrix c_matrix = Matrix(1,size);
 for (int column = 0; column < size; ++column)
 {
  a_matrix(column) = (column + 1);
  b_matrix(column) = column*3 + 2;
 }
 c_matrix = a_matrix + b_matrix;
 cout << a_matrix;
 cout << b_matrix;
 cout << c_matrix;
// could not find infomration on how to use the Octave griddata function
 // or any Octave function from within C++
 double zi = griddata(a_matrix, b_matrix, c_matrix, 1, 3);
cout<<zi<<endl; return 0;
}
Any links to guides or just direct help would be appreciated.

Here is something in the right direction.

Compile with mkoctfile --link-stand-alone standalone.cc

David
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h> 
 
using namespace std;
 
int
main(void)
{
  char *argv[] = {"octave", NULL};
  octave_main (1, argv, true);
  cout << "Hello Octave world! This is a test\n";
  int size;
  cin >> size;
  Matrix a_matrix = Matrix (1,size);
  Matrix b_matrix = Matrix (1,size);
  Matrix c_matrix = Matrix (1,size);
  for (int column = 0; column < size; ++column)
    {
      a_matrix(column) = column + 1;
      b_matrix(column) = column * 3 + 2;
    }
  c_matrix = a_matrix + b_matrix;
  cout << a_matrix;
  cout << b_matrix;
  cout << c_matrix;

  octave_value_list args;
  args(0) = a_matrix;
  args(1) = b_matrix;
  args(2) = c_matrix;
  args(3) = 1;
  args(4) = 3;
 
  octave_value_list result = feval ("griddata", args);
  if (! error_state && result.length () > 0)
    {
      double zi = result(0).double_value ();
      cout << zi << endl;
    }
  else
    {
      error ("while executing griddata");
      return 1;
    }
 
  return 0;
}

reply via email to

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