# HG changeset patch # User jwe # Date 821189925 0 # Node ID a744f4d0ba5927b80bfacdc64e69471a5b3f0000 # Parent 227706b05144702b59c0b35fdd05c57d7d3ebffd [project @ 1996-01-09 12:16:29 by jwe] diff --git a/liboctave/CmplxAEPBAL.cc b/liboctave/CmplxAEPBAL.cc --- a/liboctave/CmplxAEPBAL.cc +++ b/liboctave/CmplxAEPBAL.cc @@ -29,6 +29,8 @@ #include #endif +#include + #include "CmplxAEPBAL.h" #include "dMatrix.h" #include "f77-uscore.h" @@ -46,10 +48,17 @@ } int -ComplexAEPBALANCE::init (const ComplexMatrix& a, const char *balance_job) +ComplexAEPBALANCE::init (const ComplexMatrix& a, const string& balance_job) { + int a_nc = a.cols (); - int n = a.cols (); + if (a.rows () != a_nc) + { + (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); + return -1; + } + + int n = a_nc; // Parameters for balance call. @@ -62,7 +71,9 @@ balanced_mat = a; - F77_FCN (zgebal, ZGEBAL) (balance_job, n, + char bal_job = balance_job[0]; + + F77_FCN (zgebal, ZGEBAL) (&bal_job, n, balanced_mat.fortran_vec (), n, ilo, ihi, scale, info, 1L, 1L); @@ -72,7 +83,7 @@ for (int i = 0; i < n; i++) balancing_mat (i, i) = 1.0; - F77_FCN (zgebak, ZGEBAK) (balance_job, "R", n, ilo, ihi, scale, n, + F77_FCN (zgebak, ZGEBAK) (&bal_job, "R", n, ilo, ihi, scale, n, balancing_mat.fortran_vec (), n, info, 1L, 1L); diff --git a/liboctave/CmplxAEPBAL.h b/liboctave/CmplxAEPBAL.h --- a/liboctave/CmplxAEPBAL.h +++ b/liboctave/CmplxAEPBAL.h @@ -30,6 +30,8 @@ class ostream; +#include + #include "CMatrix.h" class ComplexAEPBALANCE @@ -40,7 +42,7 @@ ComplexAEPBALANCE (void) { } - ComplexAEPBALANCE (const ComplexMatrix& a, const char * balance_job) + ComplexAEPBALANCE (const ComplexMatrix& a, const string& balance_job) { init (a, balance_job); } @@ -67,7 +69,7 @@ private: - int init (const ComplexMatrix& a, const char * balance_job); + int init (const ComplexMatrix& a, const string& balance_job); ComplexMatrix balanced_mat; ComplexMatrix balancing_mat; diff --git a/liboctave/dbleAEPBAL.cc b/liboctave/dbleAEPBAL.cc --- a/liboctave/dbleAEPBAL.cc +++ b/liboctave/dbleAEPBAL.cc @@ -29,6 +29,8 @@ #include #endif +#include + #include "dbleAEPBAL.h" #include "f77-uscore.h" @@ -45,9 +47,10 @@ } int -AEPBALANCE::init (const Matrix& a, const char *balance_job) +AEPBALANCE::init (const Matrix& a, const string& balance_job) { int a_nc = a.cols (); + if (a.rows () != a_nc) { (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); @@ -67,7 +70,9 @@ balanced_mat = a; - F77_FCN (dgebal, DGEBAL) (balance_job, n, + char bal_job = balance_job[0]; + + F77_FCN (dgebal, DGEBAL) (&bal_job, n, balanced_mat.fortran_vec (), n, ilo, ihi, scale, info, 1L, 1L); @@ -77,7 +82,7 @@ for (int i = 0; i < n; i++) balancing_mat.elem (i ,i) = 1.0; - F77_FCN (dgebak, DGEBAK) (balance_job, "R", n, ilo, ihi, scale, n, + F77_FCN (dgebak, DGEBAK) (&bal_job, "R", n, ilo, ihi, scale, n, balancing_mat.fortran_vec (), n, info, 1L, 1L); diff --git a/liboctave/dbleAEPBAL.h b/liboctave/dbleAEPBAL.h --- a/liboctave/dbleAEPBAL.h +++ b/liboctave/dbleAEPBAL.h @@ -30,6 +30,8 @@ class ostream; +#include + #include "dMatrix.h" class AEPBALANCE @@ -40,7 +42,7 @@ AEPBALANCE (void) { } - AEPBALANCE (const Matrix& a,const char * balance_job) + AEPBALANCE (const Matrix& a,const string& balance_job) { init (a, balance_job); } @@ -67,7 +69,7 @@ private: - int init (const Matrix& a, const char * balance_job); + int init (const Matrix& a, const string& balance_job); Matrix balanced_mat; Matrix balancing_mat; diff --git a/liboctave/dbleGEPBAL.cc b/liboctave/dbleGEPBAL.cc --- a/liboctave/dbleGEPBAL.cc +++ b/liboctave/dbleGEPBAL.cc @@ -31,6 +31,8 @@ #include +#include + #include "dbleGEPBAL.h" #include "f77-uscore.h" @@ -56,11 +58,12 @@ } int -GEPBALANCE::init (const Matrix& a, const Matrix& b, const char *balance_job) +GEPBALANCE::init (const Matrix& a, const Matrix& b, const string& balance_job) { int a_nr = a.rows (); int a_nc = a.cols (); int b_nr = b.rows (); + if (a_nr != a_nc || a_nr != b_nr || b_nr != b.cols ()) { (*current_liboctave_error_handler) @@ -109,7 +112,9 @@ // Check for permutation option. - if (*balance_job == 'P' || *balance_job == 'B') + char bal_job = balance_job[0]; + + if (bal_job == 'P' || bal_job == 'B') { F77_FCN (reduce, REDUCE) (n, n, balanced_a_mat.fortran_vec (), n, balanced_b_mat.fortran_vec (), ilo, @@ -125,7 +130,7 @@ // Check for scaling option. - if ((*balance_job == 'S' || *balance_job == 'B') && ilo != ihi) + if ((bal_job == 'S' || bal_job == 'B') && ilo != ihi) { F77_FCN (scaleg, SCALEG) (n, n, balanced_a_mat.fortran_vec (), n, balanced_b_mat.fortran_vec (), ilo, @@ -152,13 +157,13 @@ // Column permutations/scaling. - F77_FCN (dgebak, DGEBAK) (balance_job, "R", n, ilo, ihi, cscale, n, + F77_FCN (dgebak, DGEBAK) (&bal_job, "R", n, ilo, ihi, cscale, n, right_balancing_mat.fortran_vec (), n, info, 1L, 1L); // Row permutations/scaling. - F77_FCN (dgebak, DGEBAK) (balance_job, "L", n, ilo, ihi, + F77_FCN (dgebak, DGEBAK) (&bal_job, "L", n, ilo, ihi, wk.fortran_vec (), n, left_balancing_mat.fortran_vec (), n, info, 1L, 1L); @@ -168,7 +173,7 @@ // here they are. #if 0 - if ((*balance_job == 'P' || *balance_job == 'B') && ilo != ihi) + if ((bal_job == 'P' || bal_job == 'B') && ilo != ihi) { F77_FCN (gradeq, GRADEQ) (n, n, balanced_a_mat.fortran_vec (), n, balanced_b_mat.fortran_vec (), ilo, diff --git a/liboctave/dbleGEPBAL.h b/liboctave/dbleGEPBAL.h --- a/liboctave/dbleGEPBAL.h +++ b/liboctave/dbleGEPBAL.h @@ -30,6 +30,8 @@ class ostream; +#include + #include "dMatrix.h" class GEPBALANCE @@ -40,7 +42,7 @@ GEPBALANCE (void) { } - GEPBALANCE (const Matrix& a, const Matrix& b, const char * balance_job) + GEPBALANCE (const Matrix& a, const Matrix& b, const string& balance_job) { init (a, b, balance_job); } @@ -73,7 +75,7 @@ private: - int init (const Matrix& a, const Matrix& b, const char * balance_job); + int init (const Matrix& a, const Matrix& b, const string& balance_job); Matrix balanced_a_mat; Matrix balanced_b_mat; diff --git a/src/balance.cc b/src/balance.cc --- a/src/balance.cc +++ b/src/balance.cc @@ -74,8 +74,7 @@ return retval; } - const char *bal_job; - string tstr; + string bal_job; int my_nargin; // # args w/o optional string arg // Determine if balancing option is listed. Set my_nargin to the @@ -83,8 +82,7 @@ if (args(nargin-1).is_string ()) { - tstr = args(nargin-1).string_value (); - bal_job = tstr.c_str (); + bal_job = args(nargin-1).string_value (); my_nargin = nargin-1; } else