Mercurial > hg > octave-nkf
annotate examples/embedded.cc @ 12385:c468c5b902b3 release-3-4-x ss-3-3-92
version is now 3.3.92
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 06 Feb 2011 06:27:19 -0500 |
parents | 23385f2c90b7 |
children | 3c5e6971064c 27a6bb1a2f74 |
rev | line source |
---|---|
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 #include <iostream> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 #include <octave/oct.h> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 #include <octave/octave.h> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 #include <octave/parse.h> |
9053
4295d634797d
remove copyright notices from example files
John W. Eaton <jwe@octave.org>
parents:
8097
diff
changeset
|
5 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 int |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 main (void) |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 { |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 string_vector argv (2); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 argv(0) = "embedded"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 argv(1) = "-q"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 octave_main (2, argv.c_str_vec(), 1); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 octave_idx_type n = 2; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 Matrix a_matrix = Matrix (1, 2); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 std::cout << "GCD of ["; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 for (octave_idx_type i = 0; i < n; i++) |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 { |
12254 | 21 a_matrix (i) = 5 * (i + 1); |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 if (i != 0) |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
23 std::cout << ", " << 5 * (i + 2); |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 else |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
25 std::cout << 5 * (i + 2); |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 } |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 std::cout << "] is "; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 octave_value_list in = octave_value (a_matrix); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 octave_value_list out = feval ("gcd", in, 1); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 if (!error_state && out.length () > 0) |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 { |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 a_matrix = out(0).matrix_value (); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 if (a_matrix.numel () == 1) |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
36 std::cout << a_matrix(0) << "\n"; |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 else |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
38 std::cout << "invalid\n"; |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 } |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 else |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 std::cout << "invalid\n"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 return 0; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 } |