help-octave
[Top][All Lists]
Advanced

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

Re: information about standalone programs ?


From: Jaroslav Hajek
Subject: Re: information about standalone programs ?
Date: Fri, 9 Apr 2010 08:31:44 +0200

On Thu, Apr 1, 2010 at 3:44 PM, mallet <address@hidden> wrote:
> Dear all,
>
> I tried to get information about making standalone programs but didn’ t
> find a lot so i try here.
>
> I have to coupling programs, ones in Fortran others in Matlab with data
> exchange between them. I can use C or C++ but it have to be standalone
> programs.
>
> So that’ s my purpose: receive a matrix in an array, send it to a
> function.m which returns another matrix that y send in an array.
>
> I made it and it works well but i want to understand some things.
> Below a simplified example with my questions commented (I made it from
> the example of the documentation):
>
> /*
> Which includes are really needed in the example below?
> */
> #include <octave/oct.h>
> #include <octave/octave.h>
> #include <octave/parse.h>
> #include <octave/toplev.h> /* do_octave_atexit */
>
> #define IP_DIM_X 2
> #define IP_DIM_Y 3
>
> int main (const int argc, char ** argv) {
>
> const char * argvv [] = {"" /* name of program, not relevant */,
> "--silent"};
> /*
> Why the line below doesn’ t work?
>
> const char * argvv [] = {"",""};
>
> What would be the name of program if I would one?
> */
> int il_size[2];
> int t=12;
>
> il_size[0] = IP_DIM_X;
> il_size[1] = IP_DIM_Y;
>
> double fla_transport [ il_size[0] * il_size[1] ];
> double fla_rent [ il_size[0] * il_size[1] ];
>
> octave_main (2, (char **) argvv, true /* embedded */);
> /*
> Is that calling octave? I have a new line in my «~/.octave_hist» each
> time in run the program.
> Does that mean if octave is not installed I cannot use this program?
> If it does we can’t talk about a standalone program.
>
> What does the «2» and the «true» mean?
>
> */
>
> Matrix inMatrix (il_size[0], il_size[1]);
>
> octave_value_list functionArguments;
> /*
> Do I HAVE to use this to call functions?
> */
>
>
> //Reception of transport
>
> //Copy fla_transport in inMatrix to give it to Octave.
> for (int i=0 ; i<il_size[0]; i++){
> for (int j=0 ; j<il_size[1]; j++){
> int index = i*il_size[1] + j;
> inMatrix (i,j) = fla_transport[index];
> }
> }
>
> functionArguments (0) = inMatrix;
> functionArguments (1) = t;
>
> const octave_value_list result = feval ("multiplication",
> functionArguments,1);
> /*
> I found somewhere that the «1» was because I expect one argument,
> but if I have to use functionArguments it will allways be 1?
>
> Is there another way to use a function than «feval»?
> */
> inMatrix = result (0).matrix_value ();
> /*
> Where can i found the list of the «octave_value_list» methods?
> I thought it was in «oct-obj.cc» but i didn’t find it.
> */
>
> //Copy of inMatrix for send
> for (int i=0 ; i<il_size[0]; i++){
> for (int j=0 ; j<il_size[1]; j++){
> int index = i*il_size[1] + j;
> fla_rent [index] = inMatrix (i,j);
> }
> }
>
> //Send of rent
>
> do_octave_atexit ();
> /*
> What is the difference with:
> clean_up_and_exit(0);
> ?
> */
>
> return 0;
>
> }
>
>

yes, octave_main is calling octave. Without Octave installed, this
program won't work. If you avoid calling the interpreter, you will
actually only need the libraries. But if you want to call any m-file
function, Octave is required.

The best way to call a function from C++ depends on where you get the
function from.

Methods for each class are declared in header files, as is normal in C++.

In newer versions, use clean_up_and_exit.

hth

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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