GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Quad-opts.cc
Go to the documentation of this file.
1 // DO NOT EDIT!
2 // Generated automatically from ../liboctave/numeric/Quad-opts.in.
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iomanip>
9 #include <iostream>
10 
11 #include "Quad-opts.h"
12 
13 #include "defun.h"
14 #include "pr-output.h"
15 
16 #include "oct-obj.h"
17 #include "utils.h"
18 #include "pager.h"
19 
21 
22 #define MAX_TOKENS 4
23 
25 {
26  const char *keyword;
27  const char *kw_tok[MAX_TOKENS + 1];
28  int min_len[MAX_TOKENS + 1];
30 };
31 
32 #define NUM_OPTIONS 4
33 
35 {
36  { "absolute tolerance",
37  { "absolute", "tolerance", 0, 0, 0, },
38  { 1, 0, 0, 0, 0, }, 1, },
39 
40  { "relative tolerance",
41  { "relative", "tolerance", 0, 0, 0, },
42  { 1, 0, 0, 0, 0, }, 1, },
43 
44  { "single precision absolute tolerance",
45  { "single", "precision", "absolute", "tolerance", 0, },
46  { 1, 1, 1, 0, 0, }, 3, },
47 
48  { "single precision relative tolerance",
49  { "single", "precision", "relative", "tolerance", 0, },
50  { 1, 1, 1, 0, 0, }, 3, },
51 };
52 
53 static void
54 print_Quad_options (std::ostream& os)
55 {
56  std::ostringstream buf;
57 
58  os << "\n"
59  << "Options for Quad include:\n\n"
60  << " keyword value\n"
61  << " ------- -----\n";
62 
64 
65  {
66  os << " "
67  << std::setiosflags (std::ios::left) << std::setw (50)
68  << list[0].keyword
69  << std::resetiosflags (std::ios::left)
70  << " ";
71 
72  double val = quad_opts.absolute_tolerance ();
73 
74  os << val << "\n";
75  }
76 
77  {
78  os << " "
79  << std::setiosflags (std::ios::left) << std::setw (50)
80  << list[1].keyword
81  << std::resetiosflags (std::ios::left)
82  << " ";
83 
84  double val = quad_opts.relative_tolerance ();
85 
86  os << val << "\n";
87  }
88 
89  {
90  os << " "
91  << std::setiosflags (std::ios::left) << std::setw (50)
92  << list[2].keyword
93  << std::resetiosflags (std::ios::left)
94  << " ";
95 
96  float val = quad_opts.single_precision_absolute_tolerance ();
97 
98  os << val << "\n";
99  }
100 
101  {
102  os << " "
103  << std::setiosflags (std::ios::left) << std::setw (50)
104  << list[3].keyword
105  << std::resetiosflags (std::ios::left)
106  << " ";
107 
108  float val = quad_opts.single_precision_relative_tolerance ();
109 
110  os << val << "\n";
111  }
112 
113  os << "\n";
114 }
115 
116 static void
117 set_Quad_options (const std::string& keyword, const octave_value& val)
118 {
120 
121  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
122  keyword, list[0].min_toks_to_match, MAX_TOKENS))
123  {
124  double tmp = val.double_value ();
125 
126  if (! error_state)
127  quad_opts.set_absolute_tolerance (tmp);
128  }
129  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
130  keyword, list[1].min_toks_to_match, MAX_TOKENS))
131  {
132  double tmp = val.double_value ();
133 
134  if (! error_state)
135  quad_opts.set_relative_tolerance (tmp);
136  }
137  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
138  keyword, list[2].min_toks_to_match, MAX_TOKENS))
139  {
140  float tmp = val.float_value ();
141 
142  if (! error_state)
144  }
145  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
146  keyword, list[3].min_toks_to_match, MAX_TOKENS))
147  {
148  float tmp = val.float_value ();
149 
150  if (! error_state)
152  }
153  else
154  {
155  warning ("quad_options: no match for `%s'", keyword.c_str ());
156  }
157 }
158 
159 static octave_value_list
160 show_Quad_options (const std::string& keyword)
161 {
162  octave_value retval;
163 
165 
166  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
167  keyword, list[0].min_toks_to_match, MAX_TOKENS))
168  {
169  double val = quad_opts.absolute_tolerance ();
170 
171  retval = val;
172  }
173  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
174  keyword, list[1].min_toks_to_match, MAX_TOKENS))
175  {
176  double val = quad_opts.relative_tolerance ();
177 
178  retval = val;
179  }
180  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
181  keyword, list[2].min_toks_to_match, MAX_TOKENS))
182  {
183  float val = quad_opts.single_precision_absolute_tolerance ();
184 
185  retval = val;
186  }
187  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
188  keyword, list[3].min_toks_to_match, MAX_TOKENS))
189  {
190  float val = quad_opts.single_precision_relative_tolerance ();
191 
192  retval = val;
193  }
194  else
195  {
196  warning ("quad_options: no match for `%s'", keyword.c_str ());
197  }
198 
199  return retval;
200 }
201 
202 DEFUN (quad_options, args, ,
203  "-*- texinfo -*-\n\
204 @deftypefn {Built-in Function} {} quad_options ()\n\
205 @deftypefnx {Built-in Function} {val =} quad_options (@var{opt})\n\
206 @deftypefnx {Built-in Function} {} quad_options (@var{opt}, @var{val})\n\
207 Query or set options for the function @code{quad}.\n\
208 When called with no arguments, the names of all available options and\n\
209 their current values are displayed.\n\
210 Given one argument, return the value of the corresponding option.\n\
211 When called with two arguments, @code{quad_options} set the option\n\
212 @var{opt} to value @var{val}.\n\
213 \n\
214 Options include\n\
215 \n\
216 @table @code\n\
217 @item @qcode{\"absolute tolerance\"}\n\
218 Absolute tolerance; may be zero for pure relative error test.\n\
219 \n\
220 @item @qcode{\"relative tolerance\"}\n\
221 Non-negative relative tolerance. If the absolute tolerance is zero,\n\
222 the relative tolerance must be greater than or equal to\n\
223 @w{@code{max (50*eps, 0.5e-28)}}.\n\
224 \n\
225 @item @qcode{\"single precision absolute tolerance\"}\n\
226 Absolute tolerance for single precision; may be zero for pure relative\n\
227 error test.\n\
228 \n\
229 @item @qcode{\"single precision relative tolerance\"}\n\
230 Non-negative relative tolerance for single precision. If the absolute\n\
231 tolerance is zero, the relative tolerance must be greater than or equal to\n\
232 @w{@code{max (50*eps, 0.5e-28)}}.\n\
233 @end table\n\
234 @end deftypefn")
235 {
236  octave_value_list retval;
237 
238  int nargin = args.length ();
239 
240  if (nargin == 0)
241  {
243  }
244  else if (nargin == 1 || nargin == 2)
245  {
246  std::string keyword = args(0).string_value ();
247 
248  if (! error_state)
249  {
250  if (nargin == 1)
251  retval = show_Quad_options (keyword);
252  else
253  set_Quad_options (keyword, args(1));
254  }
255  else
256  error ("quad_options: expecting keyword as first argument");
257  }
258  else
259  print_usage ();
260 
261  return retval;
262 }