Mercurial > hg > octave-nkf
annotate examples/embedded.cc @ 11919:66881d20101d release-3-0-x
grid.m: handle minor grid option
author | Doug Stewart <dastew@sympatico.ca> |
---|---|
date | Fri, 16 Jan 2009 07:27:19 +0100 |
parents | 3f15a11ec417 |
children | 4295d634797d |
rev | line source |
---|---|
11835
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 #include <iostream> |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 #include <octave/oct.h> |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 #include <octave/octave.h> |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 #include <octave/parse.h> |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 int |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 main (void) |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 { |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 string_vector argv (2); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 argv(0) = "embedded"; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 argv(1) = "-q"; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 octave_main (2, argv.c_str_vec(), 1); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 octave_idx_type n = 2; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 Matrix a_matrix = Matrix (1, 2); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 std::cout << "GCD of ["; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 for (octave_idx_type i = 0; i < n; i++) |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 { |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 a_matrix (i) = 5 * (i + 1); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 if (i != 0) |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 std::cout << ", " << 5 * (i + 2); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 else |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 std::cout << 5 * (i + 2); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 } |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 std::cout << "] is "; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 octave_value_list in = octave_value (a_matrix); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 octave_value_list out = feval ("gcd", in, 1); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 if (!error_state && out.length () > 0) |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 { |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 a_matrix = out(0).matrix_value (); |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 if (a_matrix.numel () == 1) |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 std::cout << a_matrix(0) << "\n"; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 else |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 std::cout << "invalid\n"; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 } |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 else |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 std::cout << "invalid\n"; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 return 0; |
3f15a11ec417
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 } |