Mercurial > octave
comparison libinterp/dldfcn/fftw.cc @ 20939:b17fda023ca6
maint: Use new C++ archetype in more files.
Place input validation first in files.
Move declaration of retval down in function to be closer to point of usage.
Eliminate else clause after if () error.
Use "return ovl()" where it makes sense.
* find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc,
graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc,
load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc,
ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc,
rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc,
strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc,
syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc,
__glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc,
symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc,
ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc:
Use new C++ archetype in more files.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 18 Dec 2015 15:37:22 -0800 |
parents | 1142cf6abc0d |
children | e39e05d90788 |
comparison
equal
deleted
inserted
replaced
20938:aac911d8847b | 20939:b17fda023ca6 |
---|---|
130 used per default.\n\ | 130 used per default.\n\ |
131 \n\ | 131 \n\ |
132 @seealso{fft, ifft, fft2, ifft2, fftn, ifftn}\n\ | 132 @seealso{fft, ifft, fft2, ifft2, fftn, ifftn}\n\ |
133 @end deftypefn") | 133 @end deftypefn") |
134 { | 134 { |
135 octave_value retval; | 135 #if defined (HAVE_FFTW) |
136 | 136 |
137 int nargin = args.length (); | 137 int nargin = args.length (); |
138 | 138 |
139 if (nargin < 1 || nargin > 2) | 139 if (nargin < 1 || nargin > 2) |
140 print_usage (); | 140 print_usage (); |
141 | 141 |
142 #if defined (HAVE_FFTW) | 142 octave_value retval; |
143 | |
143 std::string arg0 = args(0).xstring_value ("fftw: first argument must be a string"); | 144 std::string arg0 = args(0).xstring_value ("fftw: first argument must be a string"); |
144 | 145 |
145 if (arg0 == "planner") | 146 if (arg0 == "planner") |
146 { | 147 { |
147 if (nargin == 2) //planner setter | 148 if (nargin == 2) // planner setter |
148 { | 149 { |
149 // Use STL function to convert to lower case | 150 // Use STL function to convert to lower case |
150 std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); | 151 std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); |
151 | 152 |
152 std::string arg1 = args(1).xstring_value ("fftw: METHOD must be a string"); | 153 std::string arg1 = args(1).xstring_value ("fftw: METHOD must be a string"); |
233 else if (! fftw_import_wisdom_from_string (arg1.c_str ())) | 234 else if (! fftw_import_wisdom_from_string (arg1.c_str ())) |
234 error ("fftw: could not import supplied WISDOM"); | 235 error ("fftw: could not import supplied WISDOM"); |
235 | 236 |
236 retval = octave_value (std::string (str)); | 237 retval = octave_value (std::string (str)); |
237 | 238 |
238 // FIXME: need to free string even if there is an | 239 // FIXME: need to free string even if there is an exception. |
239 // exception. | |
240 free (str); | 240 free (str); |
241 } | 241 } |
242 else //dwisdom getter | 242 else //dwisdom getter |
243 { | 243 { |
244 char *str = fftw_export_wisdom_to_string (); | 244 char *str = fftw_export_wisdom_to_string (); |
245 retval = octave_value (std::string (str)); | 245 retval = octave_value (std::string (str)); |
246 | 246 |
247 // FIXME: need to free string even if there is an | 247 // FIXME: need to free string even if there is an exception. |
248 // exception. | |
249 free (str); | 248 free (str); |
250 } | 249 } |
251 } | 250 } |
252 else if (arg0 == "swisdom") | 251 else if (arg0 == "swisdom") |
253 { | 252 { |
267 else if (! fftwf_import_wisdom_from_string (arg1.c_str ())) | 266 else if (! fftwf_import_wisdom_from_string (arg1.c_str ())) |
268 error ("fftw: could not import supplied WISDOM"); | 267 error ("fftw: could not import supplied WISDOM"); |
269 | 268 |
270 retval = octave_value (std::string (str)); | 269 retval = octave_value (std::string (str)); |
271 | 270 |
272 // FIXME: need to free string even if there is an | 271 // FIXME: need to free string even if there is an exception. |
273 // exception. | |
274 free (str); | 272 free (str); |
275 } | 273 } |
276 else //swisdom getter | 274 else //swisdom getter |
277 { | 275 { |
278 char *str = fftwf_export_wisdom_to_string (); | 276 char *str = fftwf_export_wisdom_to_string (); |
279 retval = octave_value (std::string (str)); | 277 retval = octave_value (std::string (str)); |
280 | 278 |
281 // FIXME: need to free string even if there is an | 279 // FIXME: need to free string even if there is an exception. |
282 // exception. | |
283 free (str); | 280 free (str); |
284 } | 281 } |
285 } | 282 } |
286 else if (arg0 == "threads") | 283 else if (arg0 == "threads") |
287 { | 284 { |
288 if (nargin == 2) //threads setter | 285 if (nargin == 2) //threads setter |
289 { | 286 { |
290 if (args(1).is_real_scalar ()) | 287 if (! args(1).is_real_scalar ()) |
291 { | 288 error ("fftw: setting threads needs one integer argument"); |
292 int nthreads = args(1).int_value(); | 289 |
293 if (nthreads >= 1) | 290 int nthreads = args(1).int_value(); |
294 { | 291 if (nthreads < 1) |
292 error ("fftw: number of threads must be >=1"); | |
293 | |
295 #if defined (HAVE_FFTW3_THREADS) | 294 #if defined (HAVE_FFTW3_THREADS) |
296 octave_fftw_planner::threads (nthreads); | 295 octave_fftw_planner::threads (nthreads); |
297 #else | 296 #else |
298 gripe_disabled_feature ("fftw", "multithreaded FFTW"); | 297 gripe_disabled_feature ("fftw", "multithreaded FFTW"); |
299 #endif | 298 #endif |
300 #if defined (HAVE_FFTW3F_THREADS) | 299 #if defined (HAVE_FFTW3F_THREADS) |
301 octave_float_fftw_planner::threads (nthreads); | 300 octave_float_fftw_planner::threads (nthreads); |
302 #else | 301 #else |
303 gripe_disabled_feature ("fftw", "multithreaded FFTW"); | 302 gripe_disabled_feature ("fftw", "multithreaded FFTW"); |
304 #endif | 303 #endif |
305 } | |
306 else | |
307 error ("fftw: number of threads must be >=1"); | |
308 } | |
309 else | |
310 error ("fftw: setting threads needs one integer argument"); | |
311 } | 304 } |
312 else //threads getter | 305 else //threads getter |
313 #if defined (HAVE_FFTW3_THREADS) | 306 #if defined (HAVE_FFTW3_THREADS) |
314 retval = octave_value (octave_fftw_planner::threads()); | 307 retval = octave_value (octave_fftw_planner::threads()); |
315 #else | 308 #else |
316 retval = 1; | 309 retval = 1; |
317 #endif | 310 #endif |
318 } | 311 } |
319 else | 312 else |
320 error ("fftw: unrecognized argument"); | 313 error ("fftw: unrecognized argument"); |
314 | |
315 return retval; | |
316 | |
321 #else | 317 #else |
322 | 318 |
323 gripe_disabled_feature ("fftw", "the FFTW3 planner"); | 319 gripe_disabled_feature ("fftw", "the FFTW3 planner"); |
324 | 320 |
325 #endif | 321 #endif |
326 | |
327 return retval; | |
328 } | 322 } |
329 | 323 |
330 /* | 324 /* |
331 %!testif HAVE_FFTW | 325 %!testif HAVE_FFTW |
332 %! def_method = fftw ("planner"); | 326 %! def_method = fftw ("planner"); |