home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / octave-2.1.23 / liboctave / CmplxSCHUR.cc < prev    next >
C/C++ Source or Header  |  2000-01-15  |  3KB  |  131 lines

  1. /*
  2.  
  3. Copyright (C) 1996, 1997 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "CmplxSCHUR.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34.  
  35. extern "C"
  36. {
  37.   int F77_FCN (zgeesx, ZGEESX) (const char*, const char*,
  38.                 ComplexSCHUR::select_function,
  39.                 const char*, const int&, Complex*,
  40.                 const int&, int&, Complex*, Complex*,
  41.                 const int&, double&, double&,
  42.                 Complex*, const int&, double*, int*,
  43.                 int&, long, long, long);
  44. }
  45.  
  46. static int
  47. select_ana (const Complex& a)
  48. {
  49.   return a.real () < 0.0;
  50. }
  51.  
  52. static int
  53. select_dig (const Complex& a)
  54. {
  55.   return (abs (a) < 1.0);
  56. }
  57.  
  58. int
  59. ComplexSCHUR::init (const ComplexMatrix& a, const string& ord)
  60. {
  61.   int a_nr = a.rows ();
  62.   int a_nc = a.cols ();
  63.  
  64.   if (a_nr != a_nc)
  65.     {
  66.       (*current_liboctave_error_handler)
  67.     ("ComplexSCHUR requires square matrix");
  68.       return -1;
  69.     }
  70.  
  71.   // Workspace requirements may need to be fixed if any of the
  72.   // following change.
  73.  
  74.   char jobvs = 'V';
  75.   char sense = 'N';
  76.   char sort = 'N';
  77.  
  78.   char ord_char = ord.empty () ? 'U' : ord[0];
  79.  
  80.   if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
  81.     sort = 'S';
  82.  
  83.   if (ord_char == 'A' || ord_char == 'a')
  84.     selector = select_ana;
  85.   else if (ord_char == 'D' || ord_char == 'd')
  86.     selector = select_dig;
  87.   else
  88.     selector = 0;
  89.  
  90.   int n = a_nc;
  91.   int lwork = 8 * n;
  92.   int info;
  93.   int sdim;
  94.   double rconde;
  95.   double rcondv;
  96.  
  97.   schur_mat = a;
  98.   unitary_mat.resize (n, n);
  99.  
  100.   Complex *s = schur_mat.fortran_vec ();
  101.   Complex *q = unitary_mat.fortran_vec ();
  102.  
  103.   Array<double> rwork (n);
  104.   double *prwork = rwork.fortran_vec ();
  105.  
  106.   Array<Complex> w (n);
  107.   Complex *pw = w.fortran_vec ();
  108.  
  109.   Array<Complex> work (lwork);
  110.   Complex *pwork = work.fortran_vec ();
  111.  
  112.   // BWORK is not referenced for non-ordered Schur.
  113.   Array<int> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n);
  114.   int *pbwork = bwork.fortran_vec ();
  115.  
  116.   F77_XFCN (zgeesx, ZGEESX, (&jobvs, &sort, selector, &sense, n, s, n,
  117.                  sdim, pw, q, n, rconde, rcondv, pwork,
  118.                  lwork, prwork, pbwork, info, 1L, 1L, 1L));
  119.  
  120.   if (f77_exception_encountered)
  121.     (*current_liboctave_error_handler) ("unrecoverable error in zgeesx");
  122.  
  123.   return info;
  124. }
  125.  
  126. /*
  127. ;;; Local Variables: ***
  128. ;;; mode: C++ ***
  129. ;;; End: ***
  130. */
  131.