fCmplxGEPBAL.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 #include "fCmplxGEPBAL.h"
00031 #include "Array-util.h"
00032 #include "f77-fcn.h"
00033 #include "oct-locbuf.h"
00034 
00035 extern "C"
00036 {
00037   F77_RET_T
00038   F77_FUNC (cggbal, CGGBAL) (F77_CONST_CHAR_ARG_DECL,
00039                              const octave_idx_type& N,
00040                              FloatComplex* A, const octave_idx_type& LDA,
00041                              FloatComplex* B, const octave_idx_type& LDB,
00042                              octave_idx_type& ILO, octave_idx_type& IHI,
00043                              float* LSCALE, float* RSCALE,
00044                              float* WORK, octave_idx_type& INFO
00045                              F77_CHAR_ARG_LEN_DECL);
00046 
00047   F77_RET_T
00048   F77_FUNC (sggbak, SGGBAK) (F77_CONST_CHAR_ARG_DECL,
00049                              F77_CONST_CHAR_ARG_DECL,
00050                              const octave_idx_type& N,
00051                              const octave_idx_type& ILO,
00052                              const octave_idx_type& IHI, const float* LSCALE,
00053                              const float* RSCALE, octave_idx_type& M, float* V,
00054                              const octave_idx_type& LDV, octave_idx_type& INFO
00055                              F77_CHAR_ARG_LEN_DECL
00056                              F77_CHAR_ARG_LEN_DECL);
00057 
00058 }
00059 
00060 octave_idx_type
00061 FloatComplexGEPBALANCE::init (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
00062                   const std::string& balance_job)
00063 {
00064   octave_idx_type n = a.cols ();
00065 
00066   if (a.rows () != n)
00067     {
00068       (*current_liboctave_error_handler) ("FloatComplexGEPBALANCE requires square matrix");
00069       return -1;
00070     }
00071 
00072   if (a.dims() != b.dims ())
00073     {
00074       gripe_nonconformant ("FloatComplexGEPBALANCE", n, n, b.rows(), b.cols());
00075       return -1;
00076     }
00077 
00078   octave_idx_type info;
00079   octave_idx_type ilo;
00080   octave_idx_type ihi;
00081 
00082   OCTAVE_LOCAL_BUFFER (float, plscale, n);
00083   OCTAVE_LOCAL_BUFFER (float, prscale, n);
00084   OCTAVE_LOCAL_BUFFER (float, pwork, 6 * n);
00085 
00086   balanced_mat = a;
00087   FloatComplex *p_balanced_mat = balanced_mat.fortran_vec ();
00088   balanced_mat2 = b;
00089   FloatComplex *p_balanced_mat2 = balanced_mat2.fortran_vec ();
00090 
00091   char job = balance_job[0];
00092 
00093   F77_XFCN (cggbal, CGGBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
00094                              n, p_balanced_mat, n, p_balanced_mat2,
00095                              n, ilo, ihi, plscale,prscale, pwork, info
00096                              F77_CHAR_ARG_LEN (1)));
00097 
00098   balancing_mat = FloatMatrix (n, n, 0.0);
00099   balancing_mat2 = FloatMatrix (n, n, 0.0);
00100   for (octave_idx_type i = 0; i < n; i++)
00101     {
00102       octave_quit ();
00103       balancing_mat.elem (i ,i) = 1.0;
00104       balancing_mat2.elem (i ,i) = 1.0;
00105     }
00106 
00107   float *p_balancing_mat = balancing_mat.fortran_vec ();
00108   float *p_balancing_mat2 = balancing_mat2.fortran_vec ();
00109 
00110   // first left
00111   F77_XFCN (sggbak, SGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00112                              F77_CONST_CHAR_ARG2 ("L", 1),
00113                              n, ilo, ihi, plscale, prscale,
00114                              n, p_balancing_mat, n, info
00115                              F77_CHAR_ARG_LEN (1)
00116                              F77_CHAR_ARG_LEN (1)));
00117 
00118   // then right
00119   F77_XFCN (sggbak, SGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00120                              F77_CONST_CHAR_ARG2 ("R", 1),
00121                              n, ilo, ihi, plscale, prscale,
00122                              n, p_balancing_mat2, n, info
00123                              F77_CHAR_ARG_LEN (1)
00124                              F77_CHAR_ARG_LEN (1)));
00125 
00126   return info;
00127 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines