annotate libinterp/octave-value/ov-fcn-inline.cc @ 19731:4197fc428c7d

maint: Update copyright notices for 2015.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Feb 2015 14:19:08 -0500
parents 76478d2da117
children 09ed6f7538dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1 /*
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19632
diff changeset
3 Copyright (C) 2004-2015 David Bateman
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
4
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
5 This file is part of Octave.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
6
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 under the terms of the GNU General Public License as published by the
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
15 for more details.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
16
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 <http://www.gnu.org/licenses/>.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
20
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
21 In addition to the terms of the GPL, you are permitted to link
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
22 this program with any Open Source program, as defined by the
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
23 Open Source Initiative (www.opensource.org)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
24
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
25 */
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
26
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
27 #ifdef HAVE_CONFIG_H
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
28 #include <config.h>
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
29 #endif
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
30
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
31 #include <istream>
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
32 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
33 #include <sstream>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5105
diff changeset
34 #include <vector>
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
35
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8045
diff changeset
36 #include "oct-locbuf.h"
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8045
diff changeset
37
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
38 #include "defun.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
39 #include "error.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
40 #include "gripes.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
41 #include "oct-map.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
42 #include "ov-base.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
43 #include "ov-fcn-inline.h"
8032
2fd4a5ef6b59 stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents: 7908
diff changeset
44 #include "ov-usr-fcn.h"
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
45 #include "pr-output.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
46 #include "variables.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
47 #include "parse.h"
8032
2fd4a5ef6b59 stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents: 7908
diff changeset
48 #include "toplev.h"
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
49
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
50 #include "byte-swap.h"
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
51 #include "ls-ascii-helper.h"
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
52 #include "ls-oct-ascii.h"
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
53 #include "ls-hdf5.h"
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
54 #include "ls-utils.h"
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
55
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
56
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_inline,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
58 "inline function",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
59 "function_handle");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
60
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
61 octave_fcn_inline::octave_fcn_inline (const std::string& f,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
62 const string_vector& a,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
63 const std::string& n)
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
64 : octave_fcn_handle (n), iftext (f), ifargs (a)
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
65 {
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
66 // Form a string representing the function.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
67
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
68 std::ostringstream buf;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
69
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
70 buf << "@(";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
71
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
72 for (int i = 0; i < ifargs.length (); i++)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
73 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
74 if (i > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
75 buf << ", ";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
76
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
77 buf << ifargs(i);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
78 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
79
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
80 buf << ") " << iftext;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
81
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
82 int parse_status;
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
83 octave_value anon_fcn_handle = eval_string (buf.str (), true, parse_status);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
84
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
85 if (parse_status == 0)
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
86 {
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
87 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
88
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
89 if (fh)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
90 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
91 fcn = fh->fcn_val ();
8032
2fd4a5ef6b59 stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents: 7908
diff changeset
92
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
93 octave_user_function *uf = fcn.user_function_value ();
8032
2fd4a5ef6b59 stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents: 7908
diff changeset
94
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
95 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
96 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
97 octave_function *curr_fcn = octave_call_stack::current ();
8045
24701aa75ecb scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents: 8032
diff changeset
98
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
99 if (curr_fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
100 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
101 symbol_table::scope_id parent_scope
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
102 = curr_fcn->parent_fcn_scope ();
8045
24701aa75ecb scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents: 8032
diff changeset
103
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
104 if (parent_scope < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
105 parent_scope = curr_fcn->scope ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
106
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
107 uf->stash_parent_fcn_scope (parent_scope);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
108 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
109 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
110 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
111 }
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
112
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
113 if (fcn.is_undefined ())
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
114 error ("inline: unable to define function");
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
115 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
116
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
117 // This function is supplied to allow a Matlab style class structure
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
118 // to be returned..
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
119 octave_map
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
120 octave_fcn_inline::map_value (void) const
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
121 {
11070
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
122 octave_scalar_map m;
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
123
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
124 m.assign ("version", 1.0);
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
125 m.assign ("isEmpty", 0.0);
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
126 m.assign ("expr", fcn_text ());
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
127
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
128 string_vector args = fcn_arg_names ();
11070
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
129
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
130 m.assign ("numArgs", args.length ());
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
131 m.assign ("args", args);
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
132
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
133 std::ostringstream buf;
11070
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
134
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
135 for (int i = 0; i < args.length (); i++)
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
136 buf << args(i) << " = INLINE_INPUTS_{" << i + 1 << "}; ";
11070
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
137
686d5bd22132 ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
138 m.assign ("inputExpr", buf.str ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
139
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
140 return m;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
141 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
142
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
143 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6973
diff changeset
144 octave_fcn_inline::save_ascii (std::ostream& os)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
145 {
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
146 os << "# nargs: " << ifargs.length () << "\n";
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
147 for (int i = 0; i < ifargs.length (); i++)
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
148 os << ifargs(i) << "\n";
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
149 if (nm.length () < 1)
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
150 // Write an invalid value to flag empty fcn handle name.
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
151 os << "0\n";
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
152 else
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
153 os << nm << "\n";
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
154 os << iftext << "\n";
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
155 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
156 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
157
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
158 bool
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
159 octave_fcn_inline::load_ascii (std::istream& is)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
160 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
161 int nargs;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
162 if (extract_keyword (is, "nargs", nargs, true))
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
163 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
164 ifargs.resize (nargs);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
165 for (int i = 0; i < nargs; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
166 is >> ifargs(i);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
167 is >> nm;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
168 if (nm == "0")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
169 nm = "";
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
170
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
171 skip_preceeding_newline (is);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
172
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
173 std::string buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
174
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
175 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 {
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
177
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
178 // Get a line of text whitespace characters included,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 // leaving newline in the stream.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
180 buf = read_until_newline (is, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
181 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
182
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
183 iftext = buf;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
184
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
185 octave_fcn_inline tmp (iftext, ifargs, nm);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
186 fcn = tmp.fcn;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
187
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
188 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
189 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
190 else
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
191 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
192 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
193
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
194 bool
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
195 octave_fcn_inline::save_binary (std::ostream& os, bool&)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
196 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
197 int32_t tmp = ifargs.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
198 os.write (reinterpret_cast<char *> (&tmp), 4);
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
199 for (int i = 0; i < ifargs.length (); i++)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
200 {
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
201 tmp = ifargs(i).length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
202 os.write (reinterpret_cast<char *> (&tmp), 4);
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
203 os.write (ifargs(i).c_str (), ifargs(i).length ());
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
204 }
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
205 tmp = nm.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
206 os.write (reinterpret_cast<char *> (&tmp), 4);
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
207 os.write (nm.c_str (), nm.length ());
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
208 tmp = iftext.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
209 os.write (reinterpret_cast<char *> (&tmp), 4);
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
210 os.write (iftext.c_str (), iftext.length ());
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
211 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
212 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
213
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
214 bool
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
215 octave_fcn_inline::load_binary (std::istream& is, bool swap,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
216 oct_mach_info::float_format)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
217 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
218 int32_t nargs;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
219 if (! is.read (reinterpret_cast<char *> (&nargs), 4))
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
220 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
221 if (swap)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
222 swap_bytes<4> (&nargs);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
223
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
224 if (nargs < 1)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
225 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
226 else
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
227 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
228 int32_t tmp;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
229 ifargs.resize (nargs);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
230 for (int i = 0; i < nargs; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
231 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
232 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
233 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 if (swap)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
235 swap_bytes<4> (&tmp);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
236
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
237 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
238 is.read (ctmp, tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
239 ifargs(i) = std::string (ctmp);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
240
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
241 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
242 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
243 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
244
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
245 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
246 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
247 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
248 swap_bytes<4> (&tmp);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
249
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
250 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
251 is.read (ctmp1, tmp);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
252 nm = std::string (ctmp1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
253
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
254 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
255 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
256
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
257 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
258 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
259 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
260 swap_bytes<4> (&tmp);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
261
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
262 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
263 is.read (ctmp2, tmp);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
264 iftext = std::string (ctmp2);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
265
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
266 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
267 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
268
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
269 octave_fcn_inline ftmp (iftext, ifargs, nm);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
270 fcn = ftmp.fcn;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
271 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
272 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
273 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
274
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
275 #if defined (HAVE_HDF5)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
276 bool
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
277 octave_fcn_inline::save_hdf5 (hid_t loc_id, const char *name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
278 bool /* save_as_floats */)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
279 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
280 hid_t group_hid = -1;
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
281 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
282 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
283 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
284 group_hid = H5Gcreate (loc_id, name, 0);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
285 #endif
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18537
diff changeset
286 if (group_hid < 0) return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
287
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
288 size_t len = 0;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
289 for (int i = 0; i < ifargs.length (); i++)
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
290 if (len < ifargs(i).length ())
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
291 len = ifargs(i).length ();
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
292
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17861
diff changeset
293 hid_t space_hid, data_hid, type_hid;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17861
diff changeset
294 space_hid = data_hid = type_hid = -1;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
295 bool retval = true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
296
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
297 // FIXME: Is there a better way of saving string vectors,
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
298 // than a null padded matrix?
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
299
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
300 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
301
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
302 // Octave uses column-major, while HDF5 uses row-major ordering
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
303 hdims[1] = ifargs.length ();
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
304 hdims[0] = len + 1;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
305
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
306 space_hid = H5Screate_simple (2, hdims, 0);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
307 if (space_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
308 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
309 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
310 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
311 }
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
312 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
313 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
315 #else
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
316 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
318 #endif
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
319 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
320 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
321 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
322 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
323 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
324 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
325
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
326 OCTAVE_LOCAL_BUFFER (char, s, ifargs.length () * (len + 1));
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
327
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
328 // Save the args as a null teminated list
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
329 for (int i = 0; i < ifargs.length (); i++)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
330 {
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
331 const char * cptr = ifargs(i).c_str ();
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
332 for (size_t j = 0; j < ifargs(i).length (); j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
333 s[i*(len+1)+j] = *cptr++;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
334 s[ifargs(i).length ()] = '\0';
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
335 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
336
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
337 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
338 H5P_DEFAULT, s) >= 0;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
339
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
340 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
341 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
342
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
343 if (!retval)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
344 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
345 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
346 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
347 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
348
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
349 // attach the type of the variable
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
350 type_hid = H5Tcopy (H5T_C_S1);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
351 H5Tset_size (type_hid, nm.length () + 1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
352 if (type_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
353 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
354 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
355 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
356 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
357
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
358 hdims[0] = 0;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
359 space_hid = H5Screate_simple (0 , hdims, 0);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
360 if (space_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
361 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
362 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
363 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
364 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
365 }
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
366 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
367 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
368 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
369 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
370 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
371 #endif
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
372 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
373 H5P_DEFAULT, nm.c_str ()) < 0)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
374 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
375 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
376 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
377 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
378 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
379 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
380 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
381
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
382 // attach the type of the variable
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
383 H5Tset_size (type_hid, iftext.length () + 1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
384 if (type_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
385 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
386 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
387 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
388 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
389
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
390 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
391 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
392 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
393 #else
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
394 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
395 H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
396 #endif
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
397 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
398 H5P_DEFAULT, iftext.c_str ()) < 0)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
399 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
400 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
401 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
402 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
403 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
404 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
405
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
406 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
407 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
408 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
409 H5Gclose (group_hid);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
410
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
411 return retval;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
412 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
413
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
414 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9038
diff changeset
415 octave_fcn_inline::load_hdf5 (hid_t loc_id, const char *name)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
416 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
417 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
418 hsize_t rank;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
419 int slen;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
420
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
421 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
422 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
423 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
424 group_hid = H5Gopen (loc_id, name);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
425 #endif
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18537
diff changeset
426 if (group_hid < 0) return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
427
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
428 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
429 data_hid = H5Dopen (group_hid, "args", H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
430 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
431 data_hid = H5Dopen (group_hid, "args");
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
432 #endif
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
433 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
434 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
435
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
436 if (rank != 2)
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
437 {
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
438 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
439 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
440 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
441 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
442 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
443
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
444 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
445 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
446
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
447 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
448
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
449 ifargs.resize (hdims[1]);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
450
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
451 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
452
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
453 if (H5Dread (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
454 H5P_DEFAULT, s1) < 0)
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
455 {
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
456 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
457 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
458 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
459 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
460 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
461
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
462 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
463 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
464
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
465 for (size_t i = 0; i < hdims[1]; i++)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
466 ifargs(i) = std::string (s1 + i*hdims[0]);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
467
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
468 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
469 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
470 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
471 data_hid = H5Dopen (group_hid, "nm");
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
472 #endif
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
473
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
474 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
475 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
476 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
477 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
478 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
479
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
480 type_hid = H5Dget_type (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
481 type_class_hid = H5Tget_class (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
482
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
483 if (type_class_hid != H5T_STRING)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
484 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
485 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
486 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
487 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
488 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
489 }
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
490
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
491 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
492 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
493
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
494 if (rank != 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
495 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
496 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
497 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
498 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
499 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
500 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
501 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
502
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
503 slen = H5Tget_size (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
504 if (slen < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
505 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
506 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
507 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
508 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
509 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
510 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
511 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
512
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
513 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
514
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
515 // create datatype for (null-terminated) string to read into:
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
516 st_id = H5Tcopy (H5T_C_S1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
517 H5Tset_size (st_id, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
518
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
519 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
520 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
521 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
522 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
523 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
524 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
525 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
526 H5Tclose (st_id);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
527 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
528 nm = nm_tmp;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
529
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
530 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
531 data_hid = H5Dopen (group_hid, "iftext", H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
532 #else
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
533 data_hid = H5Dopen (group_hid, "iftext");
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
534 #endif
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
535
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
536 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
537 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
538 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
539 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
540 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
541
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
542 type_hid = H5Dget_type (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
543 type_class_hid = H5Tget_class (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
544
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
545 if (type_class_hid != H5T_STRING)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
546 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
547 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
548 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
549 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
550 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
551 }
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
552
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
553 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
554 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
555
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
556 if (rank != 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
557 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
558 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
559 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
560 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
561 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
562 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
563 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
564
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
565 slen = H5Tget_size (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
566 if (slen < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
567 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
568 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
569 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
570 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
571 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
572 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
573 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
574
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
575 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
576
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
577 // create datatype for (null-terminated) string to read into:
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
578 st_id = H5Tcopy (H5T_C_S1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
579 H5Tset_size (st_id, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
580
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
581 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, iftext_tmp) < 0)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
582 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
583 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
584 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
585 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
586 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
587 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
588 H5Tclose (st_id);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
589 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
590 iftext = iftext_tmp;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
591
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
592 octave_fcn_inline ftmp (iftext, ifargs, nm);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
593 fcn = ftmp.fcn;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
594
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
595 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
596 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
597 #endif
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
598
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
599 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18099
diff changeset
600 octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax)
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
601 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
602 print_raw (os, pr_as_read_syntax);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
603 newline (os);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
604 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
605
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
606 void
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
607 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
608 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
609 std::ostringstream buf;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
610
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
611 if (nm.empty ())
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
612 buf << "f(";
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
613 else
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
614 buf << nm << "(";
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
615
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
616 for (int i = 0; i < ifargs.length (); i++)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
617 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
618 if (i)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
619 buf << ", ";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
620
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
621 buf << ifargs(i);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
622 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
623
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
624 buf << ") = " << iftext;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
625
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
626 octave_print_internal (os, buf.str (), pr_as_read_syntax,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
627 current_print_indent_level ());
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
628 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
629
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
630 octave_value
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5164
diff changeset
631 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
632 {
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5164
diff changeset
633 return octave_value (fcn_text (), type);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
634 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
635
6973
6fcc2f5b2c7d [project @ 2007-10-08 10:22:17 by jwe]
jwe
parents: 6635
diff changeset
636 DEFUNX ("inline", Finline, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
637 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10742
diff changeset
638 @deftypefn {Built-in Function} {} inline (@var{str})\n\
6547
4fb053f24fd6 [project @ 2007-04-19 21:47:40 by jwe]
jwe
parents: 6529
diff changeset
639 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{arg1}, @dots{})\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
640 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{n})\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
641 Create an inline function from the character string @var{str}.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
642 \n\
5034
49827f6892f4 [project @ 2004-09-24 13:28:56 by jwe]
jwe
parents: 5025
diff changeset
643 If called with a single argument, the arguments of the generated\n\
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8946
diff changeset
644 function are extracted from the function itself. The generated\n\
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8946
diff changeset
645 function arguments will then be in alphabetical order. It should\n\
5034
49827f6892f4 [project @ 2004-09-24 13:28:56 by jwe]
jwe
parents: 5025
diff changeset
646 be noted that i, and j are ignored as arguments due to the\n\
49827f6892f4 [project @ 2004-09-24 13:28:56 by jwe]
jwe
parents: 5025
diff changeset
647 ambiguity between their use as a variable or their use as an inbuilt\n\
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8946
diff changeset
648 constant. All arguments followed by a parenthesis are considered\n\
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 15978
diff changeset
649 to be functions. If no arguments are found, a function taking a single\n\
15977
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
650 argument named @code{x} will be created.\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
651 \n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
652 If the second and subsequent arguments are character strings,\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
653 they are the names of the arguments of the function.\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
654 \n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
655 If the second argument is an integer @var{n}, the arguments are\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16816
diff changeset
656 @qcode{\"x\"}, @qcode{\"P1\"}, @dots{}, @qcode{\"P@var{N}\"}.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
657 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
658 Programming Note: The use of @code{inline} is discouraged and it may be\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
659 removed from a future version of Octave. The preferred way to create\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
660 functions from strings is through the use of anonymous functions\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
661 (@pxref{Anonymous Functions}) or @code{str2func}.\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17861
diff changeset
662 @seealso{argnames, formula, vectorize, str2func}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5409
diff changeset
663 @end deftypefn")
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
664 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
665 octave_value retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
666
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
667 int nargin = args.length ();
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
668
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
669 if (nargin > 0)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
670 {
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
671 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
672 {
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
673 std::string fun = args(0).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
674 string_vector fargs;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
675
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
676 if (nargin == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
677 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
678 bool is_arg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
679 bool in_string = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
680 std::string tmp_arg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
681 size_t i = 0;
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
682 size_t fun_length = fun.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
683
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
684 while (i < fun_length)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
685 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
686 bool terminate_arg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
687 char c = fun[i++];
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
688
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
689 if (in_string)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
690 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
691 if (c == '\'' || c == '\"')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
692 in_string = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
693 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
694 else if (c == '\'' || c == '\"')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
695 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
696 in_string = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
697 if (is_arg)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
698 terminate_arg = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
699 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
700 else if (! isalpha (c) && c != '_')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
701 if (! is_arg)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
702 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
703 else if (isdigit (c))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
704 tmp_arg.append (1, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
705 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
706 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
707 // Before we do anything remove trailing whitespaces.
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
708 while (i < fun_length && isspace (c))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
709 c = fun[i++];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
710
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
711 // Do we have a variable or a function?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
712 if (c != '(')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
713 terminate_arg = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
714 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
715 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
716 tmp_arg = std::string ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
717 is_arg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
718 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
719 }
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
720 else if (! is_arg)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
721 {
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
722 if (c == 'e' || c == 'E')
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
723 {
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
724 // possible number in exponent form, not arg
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
725 if (isdigit (fun[i])
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
726 || fun[i] == '-' || fun[i] == '+')
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
727 continue;
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
728 }
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
729 is_arg = true;
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
730 tmp_arg.append (1, c);
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
731 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
732 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
733 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
734 tmp_arg.append (1, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
735 }
5034
49827f6892f4 [project @ 2004-09-24 13:28:56 by jwe]
jwe
parents: 5025
diff changeset
736
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
737 if (terminate_arg || (i == fun_length && is_arg))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
738 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
739 bool have_arg = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
740
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
741 for (int j = 0; j < fargs.length (); j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
742 if (tmp_arg == fargs (j))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
743 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
744 have_arg = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
745 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
746 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
747
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
748 if (! have_arg && tmp_arg != "i" && tmp_arg != "j" &&
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
749 tmp_arg != "NaN" && tmp_arg != "nan" &&
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
750 tmp_arg != "Inf" && tmp_arg != "inf" &&
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
751 tmp_arg != "NA" && tmp_arg != "pi" &&
14145
5a25a51146a1 ov-fcn-inline.cc (Vinline): Add "e" to the built-in variables (bug #35236)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
752 tmp_arg != "e" && tmp_arg != "eps")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
753 fargs.append (tmp_arg);
5037
70be065b8201 [project @ 2004-09-24 14:59:24 by jwe]
jwe
parents: 5034
diff changeset
754
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
755 tmp_arg = std::string ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
756 is_arg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
757 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
758 }
5034
49827f6892f4 [project @ 2004-09-24 13:28:56 by jwe]
jwe
parents: 5025
diff changeset
759
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
760 // Sort the arguments into ascii order.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
761 fargs.sort ();
15977
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
762
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
763 if (fargs.length () == 0)
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
764 fargs.append (std::string ("x"));
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
765
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
766 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
767 else if (nargin == 2 && args(1).is_numeric_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
768 {
15978
dc5d42399e89 maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15977
diff changeset
769 if (! args(1).is_scalar_type ())
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
770 {
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
771 error ("inline: N must be an integer");
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
772 return retval;
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
773 }
15978
dc5d42399e89 maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15977
diff changeset
774
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
775 int n = args(1).int_value ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
776
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
777 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
778 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
779 if (n >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
780 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
781 fargs.resize (n+1);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
782
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
783 fargs(0) = "x";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
784
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
785 for (int i = 1; i < n+1; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
787 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
788 buf << "P" << i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
789 fargs(i) = buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
790 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
791 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
792 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
793 {
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
794 error ("inline: N must be a positive integer or zero");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
795 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
796 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
797 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
798 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
799 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
800 error ("inline: N must be an integer");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
801 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
802 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
803 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
804 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
805 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
806 fargs.resize (nargin - 1);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
807
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
808 for (int i = 1; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
809 {
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
810 if (args(i).is_string ())
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
811 {
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
812 std::string s = args(i).string_value ();
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
813 fargs(i-1) = s;
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
814 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
815 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
816 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
817 error ("inline: expecting string arguments");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
818 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
819 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
820 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
821 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
822
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
823 retval = octave_value (new octave_fcn_inline (fun, fargs));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
824 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
825 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
826 error ("inline: STR argument must be a string");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
827 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
828 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
829 print_usage ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
830
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
831 return retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
832 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
833
7394
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
834 /*
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
835 %!shared fn
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
836 %! fn = inline ("x.^2 + 1");
7394
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
837 %!assert (feval (fn, 6), 37)
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
838 %!assert (fn (6), 37)
15977
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
839 %!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10)
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
840 %!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5)
6535f92350ec Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
841 %!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5)
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
842
15978
dc5d42399e89 maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15977
diff changeset
843 ## Test input validation
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
844 %!error inline ()
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
845 %!error <STR argument must be a string> inline (1)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
846 %!error <N must be an integer> inline ("2", ones (2,2))
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
847 %!error <N must be a positive integer> inline ("2", -1)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
848 %!error <expecting string arguments> inline ("2", "x", -1, "y")
7394
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
849 */
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
850
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
851 DEFUN (formula, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
852 "-*- texinfo -*-\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
853 @deftypefn {Built-in Function} {} formula (@var{fun})\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
854 Return a character string representing the inline function @var{fun}.\n\
19156
c43223245085 doc: Add warnings about eventual removal of inline functions.
Rik <rik@octave.org>
parents: 18712
diff changeset
855 \n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
856 Note that @code{char (@var{fun})} is equivalent to\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
857 @code{formula (@var{fun})}.\n\
19156
c43223245085 doc: Add warnings about eventual removal of inline functions.
Rik <rik@octave.org>
parents: 18712
diff changeset
858 @seealso{char, argnames, inline, vectorize}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5409
diff changeset
859 @end deftypefn")
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
860 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
861 octave_value retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
862
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
863 int nargin = args.length ();
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
864
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
865 if (nargin == 1)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
866 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
867 octave_fcn_inline* fn = args(0).fcn_inline_value (true);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
868
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
869 if (fn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
870 retval = octave_value (fn->fcn_text ());
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
871 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
872 error ("formula: FUN must be an inline function");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
873 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
874 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
875 print_usage ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
876
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
877 return retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
878 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
879
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
880 /*
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
881 %!assert (formula (fn), "x.^2 + 1")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
882 %!assert (formula (fn), char (fn))
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
883
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14145
diff changeset
884 ## Test input validation
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
885 %!error formula ()
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
886 %!error formula (1, 2)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
887 %!error <FUN must be an inline function> formula (1)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
888 */
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
889
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
890 DEFUN (argnames, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
891 "-*- texinfo -*-\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
892 @deftypefn {Built-in Function} {} argnames (@var{fun})\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
893 Return a cell array of character strings containing the names of\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
894 the arguments of the inline function @var{fun}.\n\
6529
853f99e292ec [project @ 2007-04-16 21:29:03 by jwe]
jwe
parents: 6220
diff changeset
895 @seealso{inline, formula, vectorize}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5409
diff changeset
896 @end deftypefn")
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
897 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
898 octave_value retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
899
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
900 int nargin = args.length ();
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
901
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
902 if (nargin == 1)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
903 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
904 octave_fcn_inline *fn = args(0).fcn_inline_value (true);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
905
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
906 if (fn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
907 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
908 string_vector t1 = fn->fcn_arg_names ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
909
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
910 Cell t2 (dim_vector (t1.length (), 1));
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
911
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
912 for (int i = 0; i < t1.length (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
913 t2(i) = t1(i);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
914
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
915 retval = t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
916 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
917 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
918 error ("argnames: FUN must be an inline function");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
919 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
920 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
921 print_usage ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
922
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
923 return retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
924 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
925
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
926 /*
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
927 %!assert (argnames (fn), {"x"})
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
928 %!assert (argnames (inline ("1e-3*y + 2e4*z")), {"y"; "z"})
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
929 %!assert (argnames (inline ("2", 2)), {"x"; "P1"; "P2"})
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
930
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14145
diff changeset
931 ## Test input validation
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
932 %!error argnames ()
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
933 %!error argnames (1, 2)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
934 %!error <FUN must be an inline function> argnames (1)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
935 */
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
936
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
937 DEFUN (vectorize, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
938 "-*- texinfo -*-\n\
6635
c9c504d939c5 [project @ 2007-05-19 10:36:56 by dbateman]
dbateman
parents: 6625
diff changeset
939 @deftypefn {Built-in Function} {} vectorize (@var{fun})\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
940 Create a vectorized version of the inline function @var{fun}\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
941 by replacing all occurrences of @code{*}, @code{/}, etc., with\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
942 @code{.*}, @code{./}, etc.\n\
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
943 \n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
944 This may be useful, for example, when using inline functions with\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
945 numerical integration or optimization where a vector-valued function\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
946 is expected.\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
947 \n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
948 @example\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12632
diff changeset
949 @group\n\
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
950 fcn = vectorize (inline (\"x^2 - 1\"))\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
951 @result{} fcn = f(x) = x.^2 - 1\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
952 quadv (fcn, 0, 3)\n\
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
953 @result{} 6\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12632
diff changeset
954 @end group\n\
12632
2dbac27e0e40 doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
955 @end example\n\
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
956 @seealso{inline, formula, argnames}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5409
diff changeset
957 @end deftypefn")
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
958 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
959 octave_value retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
960
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
961 int nargin = args.length ();
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
962
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
963 if (nargin == 1)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
964 {
5409
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
965 std::string old_func;
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
966 octave_fcn_inline* old = 0;
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
967 bool func_is_string = true;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
968
5409
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
969 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
970 old_func = args(0).string_value ();
5409
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
971 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
972 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
973 old = args(0).fcn_inline_value (true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
974 func_is_string = false;
5409
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
975
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
976 if (old)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
977 old_func = old->fcn_text ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
978 else
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
979 error ("vectorize: FUN must be a string or inline function");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
980 }
5409
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
981
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
982 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
983 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
984 std::string new_func;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
985 size_t i = 0;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
986
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
987 while (i < old_func.length ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
988 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
989 std::string t1 = old_func.substr (i, 1);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
990
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
991 if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
992 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
993 if (i && old_func.substr (i-1, 1) != ".")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
994 new_func.append (".");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
995
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
996 // Special case for ** operator.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
997 if (t1 == "*" && i < (old_func.length () - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
998 && old_func.substr (i+1, 1) == "*")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
999 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1000 new_func.append ("*");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1001 i++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1002 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1003 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1004 new_func.append (t1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1005 i++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1006 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1007
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1008 if (func_is_string)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1009 retval = octave_value (new_func);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1010 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1011 retval = octave_value (new octave_fcn_inline
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1012 (new_func, old->fcn_arg_names ()));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1013 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1014 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1015 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1016 print_usage ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1017
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1018 return retval;
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1019 }
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1020
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1021 /*
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1022 %!assert (char (vectorize (fn)), "x.^2 + 1")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1023 %!assert (char (vectorize (inline ("1e-3*y + 2e4*z"))), "1e-3.*y + 2e4.*z")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1024 %!assert (char (vectorize (inline ("2**x^5"))), "2.**x.^5")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1025 %!assert (vectorize ("x.^2 + 1"), "x.^2 + 1")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1026 %!assert (vectorize ("1e-3*y + 2e4*z"), "1e-3.*y + 2e4.*z")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1027 %!assert (vectorize ("2**x^5"), "2.**x.^5")
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1028
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14145
diff changeset
1029 ## Test input validation
14098
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1030 %!error vectorize ()
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1031 %!error vectorize (1, 2)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1032 %!error <FUN must be a string or inline function> vectorize (1)
ebf41239e47e Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
1033 */