home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / f-ifft2.cc < prev    next >
C/C++ Source or Header  |  1995-01-30  |  3KB  |  131 lines

  1. // f-ifft2.cc                                           -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27.  
  28. #include "dMatrix.h"
  29. #include "CMatrix.h"
  30.  
  31. #include "tree-const.h"
  32. #include "user-prefs.h"
  33. #include "gripes.h"
  34. #include "error.h"
  35. #include "utils.h"
  36. #include "help.h"
  37. #include "defun-dld.h"
  38.  
  39. // This function should be merged with Ffft2.
  40.  
  41. DEFUN_DLD_BUILTIN ("ifft2", Fifft2, Sifft2, 3, 1,
  42.   "ifft2 (X [, N] [, M])\n\
  43. \n\
  44. two dimensional inverse fast fourier transform of a vector") 
  45. {
  46.   Octave_object retval;
  47.  
  48.   int nargin = args.length ();
  49.  
  50.   if (nargin < 1 || nargin > 3)
  51.     {
  52.       print_usage ("ifft2");
  53.       return retval;
  54.     }
  55.  
  56.   tree_constant arg = args(0);
  57.  
  58.   int n_rows = arg.rows ();
  59.   if (nargin > 1)
  60.     {
  61.       double dval = args(1).double_value ();
  62.       if (xisnan (dval))
  63.     error ("fft2: NaN is invalid as N_ROWS");
  64.       else
  65.     n_rows = NINT (dval);
  66.     }
  67.  
  68.   if (error_state)
  69.     return retval;
  70.  
  71.   int n_cols = arg.columns ();
  72.   if (nargin > 2)
  73.     {
  74.       double dval = args(2).double_value ();
  75.       if (xisnan (dval))
  76.     error ("fft2: NaN is invalid as N_COLS");
  77.       else
  78.     n_cols = NINT (dval);
  79.     }
  80.  
  81.   if (error_state)
  82.     return retval;
  83.  
  84.   if (n_rows < 0 || n_cols < 0)
  85.     {
  86.       error ("ifft2: number of points must be greater than zero");
  87.       return retval;
  88.     }
  89.  
  90.   int arg_is_empty = empty_arg ("ifft2", arg.rows (), arg.columns ());
  91.  
  92.   if (arg_is_empty < 0)
  93.     return retval;
  94.   else if (arg_is_empty || n_rows == 0 || n_cols == 0)
  95.     return Matrix ();
  96.  
  97.   if (arg.is_real_type ())
  98.     {
  99.       Matrix m = arg.matrix_value ();
  100.  
  101.       if (! error_state)
  102.     {
  103.       m.resize (n_rows, n_cols, 0.0);
  104.       retval = m.ifourier2d ();
  105.     }
  106.     }
  107.   else if (arg.is_complex_type ())
  108.     {
  109.       ComplexMatrix m = arg.complex_matrix_value ();
  110.  
  111.       if (! error_state)
  112.     {
  113.       m.resize (n_rows, n_cols, 0.0);
  114.       retval = m.ifourier2d ();
  115.     }
  116.     }
  117.   else
  118.     {
  119.       gripe_wrong_type_arg ("ifft2", arg);
  120.     }
  121.  
  122.   return retval;
  123. }
  124.  
  125. /*
  126. ;;; Local Variables: ***
  127. ;;; mode: C++ ***
  128. ;;; page-delimiter: "^/\\*" ***
  129. ;;; End: ***
  130. */
  131.