GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dbleGEPBAL.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <string>
28 #include <vector>
29 
30 #include "dbleGEPBAL.h"
31 #include "Array-util.h"
32 #include "f77-fcn.h"
33 #include "oct-locbuf.h"
34 
35 extern "C"
36 {
37  F77_RET_T
38  F77_FUNC (dggbal, DGGBAL) (F77_CONST_CHAR_ARG_DECL,
40  double* A, const octave_idx_type& LDA,
41  double* B, const octave_idx_type& LDB,
43  double* LSCALE, double* RSCALE,
44  double* WORK, octave_idx_type& INFO
46 
47  F77_RET_T
48  F77_FUNC (dggbak, DGGBAK) (F77_CONST_CHAR_ARG_DECL,
50  const octave_idx_type& N,
51  const octave_idx_type& ILO,
52  const octave_idx_type& IHI,
53  const double* LSCALE, const double* RSCALE,
54  octave_idx_type& M, double* V,
55  const octave_idx_type& LDV, octave_idx_type& INFO
58 
59 }
60 
62 GEPBALANCE::init (const Matrix& a, const Matrix& b,
63  const std::string& balance_job)
64 {
65  octave_idx_type n = a.cols ();
66 
67  if (a.rows () != n)
68  {
69  (*current_liboctave_error_handler) ("GEPBALANCE requires square matrix");
70  return -1;
71  }
72 
73  if (a.dims () != b.dims ())
74  {
75  gripe_nonconformant ("GEPBALANCE", n, n, b.rows(), b.cols());
76  return -1;
77  }
78 
79  octave_idx_type info;
80  octave_idx_type ilo;
81  octave_idx_type ihi;
82 
83  OCTAVE_LOCAL_BUFFER (double, plscale, n);
84  OCTAVE_LOCAL_BUFFER (double, prscale, n);
85  OCTAVE_LOCAL_BUFFER (double, pwork, 6 * n);
86 
87  balanced_mat = a;
88  double *p_balanced_mat = balanced_mat.fortran_vec ();
89  balanced_mat2 = b;
90  double *p_balanced_mat2 = balanced_mat2.fortran_vec ();
91 
92  char job = balance_job[0];
93 
94  F77_XFCN (dggbal, DGGBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
95  n, p_balanced_mat, n, p_balanced_mat2,
96  n, ilo, ihi, plscale, prscale, pwork, info
97  F77_CHAR_ARG_LEN (1)));
98 
99  balancing_mat = Matrix (n, n, 0.0);
100  balancing_mat2 = Matrix (n, n, 0.0);
101  for (octave_idx_type i = 0; i < n; i++)
102  {
103  octave_quit ();
104  balancing_mat.elem (i ,i) = 1.0;
105  balancing_mat2.elem (i ,i) = 1.0;
106  }
107 
108  double *p_balancing_mat = balancing_mat.fortran_vec ();
109  double *p_balancing_mat2 = balancing_mat2.fortran_vec ();
110 
111  // first left
112  F77_XFCN (dggbak, DGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
113  F77_CONST_CHAR_ARG2 ("L", 1),
114  n, ilo, ihi, plscale, prscale,
115  n, p_balancing_mat, n, info
116  F77_CHAR_ARG_LEN (1)
117  F77_CHAR_ARG_LEN (1)));
118 
119  // then right
120  F77_XFCN (dggbak, DGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
121  F77_CONST_CHAR_ARG2 ("R", 1),
122  n, ilo, ihi, plscale, prscale,
123  n, p_balancing_mat2, n, info
124  F77_CHAR_ARG_LEN (1)
125  F77_CHAR_ARG_LEN (1)));
126 
127  return info;
128 }