comparison libinterp/dldfcn/fftw.cc @ 20614:10ec79b47808

use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 18:15:56 -0400
parents f90c8372b7ba
children
comparison
equal deleted inserted replaced
20613:647db46ad754 20614:10ec79b47808
141 print_usage (); 141 print_usage ();
142 return retval; 142 return retval;
143 } 143 }
144 144
145 #if defined (HAVE_FFTW) 145 #if defined (HAVE_FFTW)
146 if (args(0).is_string ()) 146 std::string arg0 = args(0).string_value ("fftw: first argument must be a string");
147 { 147
148 std::string arg0 = args(0).string_value (); 148 if (arg0 == "planner")
149 149 {
150 if (arg0 == "planner") 150 if (nargin == 2) //planner setter
151 { 151 {
152 if (nargin == 2) //planner setter 152 // Use STL function to convert to lower case
153 { 153 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
154 if (args(1).is_string ()) 154 tolower);
155
156 std::string arg1 = args(1).string_value ("fftw: planner expects a string value as METHOD");
157
158 std::transform (arg1.begin (), arg1.end (),
159 arg1.begin (), tolower);
160 octave_fftw_planner::FftwMethod meth
161 = octave_fftw_planner::UNKNOWN;
162 octave_float_fftw_planner::FftwMethod methf
163 = octave_float_fftw_planner::UNKNOWN;
164
165 if (arg1 == "estimate")
166 {
167 meth = octave_fftw_planner::ESTIMATE;
168 methf = octave_float_fftw_planner::ESTIMATE;
169 }
170 else if (arg1 == "measure")
171 {
172 meth = octave_fftw_planner::MEASURE;
173 methf = octave_float_fftw_planner::MEASURE;
174 }
175 else if (arg1 == "patient")
176 {
177 meth = octave_fftw_planner::PATIENT;
178 methf = octave_float_fftw_planner::PATIENT;
179 }
180 else if (arg1 == "exhaustive")
181 {
182 meth = octave_fftw_planner::EXHAUSTIVE;
183 methf = octave_float_fftw_planner::EXHAUSTIVE;
184 }
185 else if (arg1 == "hybrid")
186 {
187 meth = octave_fftw_planner::HYBRID;
188 methf = octave_float_fftw_planner::HYBRID;
189 }
190 else
191 error ("fftw: unrecognized planner METHOD");
192
193 meth = octave_fftw_planner::method (meth);
194 octave_float_fftw_planner::method (methf);
195
196 if (meth == octave_fftw_planner::MEASURE)
197 retval = octave_value ("measure");
198 else if (meth == octave_fftw_planner::PATIENT)
199 retval = octave_value ("patient");
200 else if (meth == octave_fftw_planner::EXHAUSTIVE)
201 retval = octave_value ("exhaustive");
202 else if (meth == octave_fftw_planner::HYBRID)
203 retval = octave_value ("hybrid");
204 else
205 retval = octave_value ("estimate");
206 }
207 else //planner getter
208 {
209 octave_fftw_planner::FftwMethod meth =
210 octave_fftw_planner::method ();
211
212 if (meth == octave_fftw_planner::MEASURE)
213 retval = octave_value ("measure");
214 else if (meth == octave_fftw_planner::PATIENT)
215 retval = octave_value ("patient");
216 else if (meth == octave_fftw_planner::EXHAUSTIVE)
217 retval = octave_value ("exhaustive");
218 else if (meth == octave_fftw_planner::HYBRID)
219 retval = octave_value ("hybrid");
220 else
221 retval = octave_value ("estimate");
222 }
223 }
224 else if (arg0 == "dwisdom")
225 {
226 if (nargin == 2) //dwisdom setter
227 {
228 // Use STL function to convert to lower case
229 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
230 tolower);
231
232 std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string");
233
234 char *str = fftw_export_wisdom_to_string ();
235
236 if (arg1.length () < 1)
237 fftw_forget_wisdom ();
238 else if (! fftw_import_wisdom_from_string (arg1.c_str ()))
239 error ("fftw: could not import supplied WISDOM");
240
241 retval = octave_value (std::string (str));
242
243 // FIXME: need to free string even if there is an
244 // exception.
245 free (str);
246 }
247 else //dwisdom getter
248 {
249 char *str = fftw_export_wisdom_to_string ();
250 retval = octave_value (std::string (str));
251
252 // FIXME: need to free string even if there is an
253 // exception.
254 free (str);
255 }
256 }
257 else if (arg0 == "swisdom")
258 {
259 //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real)
260 if (nargin == 2) //swisdom setter
261 {
262 // Use STL function to convert to lower case
263 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
264 tolower);
265
266 std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string");
267
268 char *str = fftwf_export_wisdom_to_string ();
269
270 if (arg1.length () < 1)
271 fftwf_forget_wisdom ();
272 else if (! fftwf_import_wisdom_from_string (arg1.c_str ()))
273 error ("fftw: could not import supplied WISDOM");
274
275 retval = octave_value (std::string (str));
276
277 // FIXME: need to free string even if there is an
278 // exception.
279 free (str);
280 }
281 else //swisdom getter
282 {
283 char *str = fftwf_export_wisdom_to_string ();
284 retval = octave_value (std::string (str));
285
286 // FIXME: need to free string even if there is an
287 // exception.
288 free (str);
289 }
290 }
291 else if (arg0 == "threads")
292 {
293 if (nargin == 2) //threads setter
294 {
295 if (args(1).is_real_scalar ())
296 {
297 int nthreads = args(1).int_value();
298 if (nthreads >= 1)
155 { 299 {
156 // Use STL function to convert to lower case 300 #if defined (HAVE_FFTW3_THREADS)
157 std::transform (arg0.begin (), arg0.end (), arg0.begin (), 301 octave_fftw_planner::threads (nthreads);
158 tolower); 302 #else
159 std::string arg1 = args(1).string_value (); 303 gripe_disabled_feature ("fftw", "multithreaded FFTW");
160 304 #endif
161 std::transform (arg1.begin (), arg1.end (), 305 #if defined (HAVE_FFTW3F_THREADS)
162 arg1.begin (), tolower); 306 octave_float_fftw_planner::threads (nthreads);
163 octave_fftw_planner::FftwMethod meth 307 #else
164 = octave_fftw_planner::UNKNOWN; 308 gripe_disabled_feature ("fftw", "multithreaded FFTW");
165 octave_float_fftw_planner::FftwMethod methf 309 #endif
166 = octave_float_fftw_planner::UNKNOWN;
167
168 if (arg1 == "estimate")
169 {
170 meth = octave_fftw_planner::ESTIMATE;
171 methf = octave_float_fftw_planner::ESTIMATE;
172 }
173 else if (arg1 == "measure")
174 {
175 meth = octave_fftw_planner::MEASURE;
176 methf = octave_float_fftw_planner::MEASURE;
177 }
178 else if (arg1 == "patient")
179 {
180 meth = octave_fftw_planner::PATIENT;
181 methf = octave_float_fftw_planner::PATIENT;
182 }
183 else if (arg1 == "exhaustive")
184 {
185 meth = octave_fftw_planner::EXHAUSTIVE;
186 methf = octave_float_fftw_planner::EXHAUSTIVE;
187 }
188 else if (arg1 == "hybrid")
189 {
190 meth = octave_fftw_planner::HYBRID;
191 methf = octave_float_fftw_planner::HYBRID;
192 }
193 else
194 error ("fftw: unrecognized planner METHOD");
195
196 meth = octave_fftw_planner::method (meth);
197 octave_float_fftw_planner::method (methf);
198
199 if (meth == octave_fftw_planner::MEASURE)
200 retval = octave_value ("measure");
201 else if (meth == octave_fftw_planner::PATIENT)
202 retval = octave_value ("patient");
203 else if (meth == octave_fftw_planner::EXHAUSTIVE)
204 retval = octave_value ("exhaustive");
205 else if (meth == octave_fftw_planner::HYBRID)
206 retval = octave_value ("hybrid");
207 else
208 retval = octave_value ("estimate");
209 } 310 }
210 else 311 else
211 error ("fftw: planner expects a string value as METHOD"); 312 error ("fftw: number of threads must be >=1");
212 } 313 }
213 else //planner getter 314 else
214 { 315 error ("fftw: setting threads needs one integer argument");
215 octave_fftw_planner::FftwMethod meth = 316 }
216 octave_fftw_planner::method (); 317 else //threads getter
217
218 if (meth == octave_fftw_planner::MEASURE)
219 retval = octave_value ("measure");
220 else if (meth == octave_fftw_planner::PATIENT)
221 retval = octave_value ("patient");
222 else if (meth == octave_fftw_planner::EXHAUSTIVE)
223 retval = octave_value ("exhaustive");
224 else if (meth == octave_fftw_planner::HYBRID)
225 retval = octave_value ("hybrid");
226 else
227 retval = octave_value ("estimate");
228 }
229 }
230 else if (arg0 == "dwisdom")
231 {
232 if (nargin == 2) //dwisdom setter
233 {
234 if (args(1).is_string ())
235 {
236 // Use STL function to convert to lower case
237 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
238 tolower);
239 std::string arg1 = args(1).string_value ();
240
241 char *str = fftw_export_wisdom_to_string ();
242
243 if (arg1.length () < 1)
244 fftw_forget_wisdom ();
245 else if (! fftw_import_wisdom_from_string (arg1.c_str ()))
246 error ("fftw: could not import supplied WISDOM");
247
248 retval = octave_value (std::string (str));
249
250 // FIXME: need to free string even if there is an
251 // exception.
252 free (str);
253 }
254 }
255 else //dwisdom getter
256 {
257 char *str = fftw_export_wisdom_to_string ();
258 retval = octave_value (std::string (str));
259
260 // FIXME: need to free string even if there is an
261 // exception.
262 free (str);
263 }
264 }
265 else if (arg0 == "swisdom")
266 {
267 //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real)
268 if (nargin == 2) //swisdom setter
269 {
270 if (args(1).is_string ())
271 {
272 // Use STL function to convert to lower case
273 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
274 tolower);
275 std::string arg1 = args(1).string_value ();
276
277 char *str = fftwf_export_wisdom_to_string ();
278
279 if (arg1.length () < 1)
280 fftwf_forget_wisdom ();
281 else if (! fftwf_import_wisdom_from_string (arg1.c_str ()))
282 error ("fftw: could not import supplied WISDOM");
283
284 retval = octave_value (std::string (str));
285
286 // FIXME: need to free string even if there is an
287 // exception.
288 free (str);
289 }
290 }
291 else //swisdom getter
292 {
293 char *str = fftwf_export_wisdom_to_string ();
294 retval = octave_value (std::string (str));
295
296 // FIXME: need to free string even if there is an
297 // exception.
298 free (str);
299 }
300 }
301 else if (arg0 == "threads")
302 {
303 if (nargin == 2) //threads setter
304 {
305 if (args(1).is_real_scalar ())
306 {
307 int nthreads = args(1).int_value();
308 if (nthreads >= 1)
309 {
310 #if defined (HAVE_FFTW3_THREADS) 318 #if defined (HAVE_FFTW3_THREADS)
311 octave_fftw_planner::threads (nthreads); 319 retval = octave_value (octave_fftw_planner::threads());
312 #else 320 #else
313 gripe_disabled_feature ("fftw", "multithreaded FFTW"); 321 retval = 1;
314 #endif 322 #endif
315 #if defined (HAVE_FFTW3F_THREADS)
316 octave_float_fftw_planner::threads (nthreads);
317 #else
318 gripe_disabled_feature ("fftw", "multithreaded FFTW");
319 #endif
320 }
321 else
322 error ("fftw: number of threads must be >=1");
323 }
324 else
325 error ("fftw: setting threads needs one integer argument");
326 }
327 else //threads getter
328 #if defined (HAVE_FFTW3_THREADS)
329 retval = octave_value (octave_fftw_planner::threads());
330 #else
331 retval = 1;
332 #endif
333 }
334 else
335 error ("fftw: unrecognized argument");
336 } 323 }
337 else 324 else
338 error ("fftw: unrecognized argument"); 325 error ("fftw: unrecognized argument");
339 #else 326 #else
340 327