OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
newmatex.cpp
Go to the documentation of this file.
1 //$$ newmatex.cpp Exception handler
2 
3 // Copyright (C) 1992,3,4,7: R B Davies
4 
5 #define WANT_STREAM // include.h will get stream fns
6 
7 #include <iostream>
8 #include <iomanip>
9 
10 #include <ossim/matrix/include.h>
11 #include <ossim/matrix/newmat.h>
12 
13 #ifdef use_namespace
14 namespace NEWMAT {
15 #endif
16 
17 unsigned long OverflowException::Select;
18 unsigned long SingularException::Select;
19 unsigned long NPDException::Select;
20 unsigned long ConvergenceException::Select;
21 unsigned long ProgramException::Select;
22 unsigned long IndexException::Select;
23 unsigned long VectorException::Select;
24 unsigned long NotSquareException::Select;
27 unsigned long NotDefinedException::Select;
28 unsigned long CannotBuildException::Select;
29 unsigned long InternalException::Select;
30 
31 
32 
33 static void MatrixDetails(const GeneralMatrix& A)
34 // write matrix details to Exception buffer
35 {
36  MatrixBandWidth bw = A.BandWidth(); int ubw = bw.upper; int lbw = bw.lower;
37  BaseException::AddMessage("MatrixType = ");
38  BaseException::AddMessage(A.Type().Value());
39  BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows());
40  BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols());
41  if (lbw >=0)
42  {
43  BaseException::AddMessage("; lower BW = ");
45  }
46  if (ubw >=0)
47  {
48  BaseException::AddMessage("; upper BW = ");
50  }
52 }
53 
55  : Runtime_error()
56 {
58  AddMessage("detected by Newmat: matrix not positive definite\n\n");
59  MatrixDetails(A);
61 }
62 
64  : Runtime_error()
65 {
67  AddMessage("detected by Newmat: matrix is singular\n\n");
68  MatrixDetails(A);
70 }
71 
73  : Runtime_error()
74 {
76  AddMessage("detected by Newmat: process fails to converge\n\n");
77  MatrixDetails(A);
79 }
80 
82 {
84  AddMessage("detected by Newmat: ");
85  AddMessage(c); AddMessage("\n\n");
86  if (c) Tracer::AddTrace();
87 }
88 
90 {
92  AddMessage("detected by Newmat: ");
93  AddMessage(c); AddMessage("\n\n");
94  if (c) Tracer::AddTrace();
95 }
96 
98 {
100  AddMessage("detected by Newmat: ");
101  AddMessage(c); AddMessage("\n\n");
102  if (c) Tracer::AddTrace();
103 }
104 
106  : Logic_error()
107 {
109  AddMessage("detected by Newmat: ");
110  AddMessage(c); AddMessage("\n\n");
111  MatrixDetails(A);
112  if (c) Tracer::AddTrace();
113 }
114 
116  const GeneralMatrix& B) : Logic_error()
117 {
119  AddMessage("detected by Newmat: ");
120  AddMessage(c); AddMessage("\n\n");
121  MatrixDetails(A); MatrixDetails(B);
122  if (c) Tracer::AddTrace();
123 }
124 
126  : Logic_error()
127 {
129  AddMessage("detected by Newmat: ");
130  AddMessage(c); AddMessage("\nMatrixTypes = ");
131  AddMessage(a.Value()); AddMessage("; ");
132  AddMessage(b.Value()); AddMessage("\n\n");
133  if (c) Tracer::AddTrace();
134 }
135 
137 {
139  AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
141 }
142 
144  : Logic_error()
145 {
147  AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
148  MatrixDetails(A);
150 }
151 
153  : Logic_error()
154 {
156  AddMessage("detected by Newmat: matrix is not square\n\n");
157  MatrixDetails(A);
159 }
160 
162  : Logic_error()
163 {
165  AddMessage("detected by Newmat: matrix is not square\n\n");
167 }
168 
170  : Logic_error()
171 {
173  AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
175 }
176 
178  : Logic_error()
179 {
181  AddMessage("detected by Newmat: incompatible dimensions\n\n");
183 }
184 
186  (const GeneralMatrix& A, const GeneralMatrix& B)
187  : Logic_error()
188 {
189  Select = BaseException::Select;
190  AddMessage("detected by Newmat: incompatible dimensions\n\n");
191  MatrixDetails(A); MatrixDetails(B);
193 }
194 
195 NotDefinedException::NotDefinedException(const char* op, const char* matrix)
196  : Logic_error()
197 {
199  AddMessage("detected by Newmat: ");
200  AddMessage(op);
201  AddMessage(" not defined for ");
202  AddMessage(matrix);
203  AddMessage("\n\n");
205 }
206 
208  : Logic_error()
209 {
211  AddMessage("detected by Newmat: cannot build matrix type ");
212  AddMessage(matrix); AddMessage("\n\n");
214 }
215 
217  : Logic_error()
218 {
220  AddMessage("detected by Newmat: index error: requested index = ");
221  AddInt(i); AddMessage("\n\n");
222  MatrixDetails(A);
224 }
225 
227  : Logic_error()
228 {
230  AddMessage("detected by Newmat: index error: requested indices = ");
231  AddInt(i); AddMessage(", "); AddInt(j);
232  AddMessage("\n\n");
233  MatrixDetails(A);
235 }
236 
237 
239  : Logic_error()
240 {
242  AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
243  AddInt(i);
244  AddMessage("\n\n");
245  MatrixDetails(A);
247 }
248 
249 IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
250  : Logic_error()
251 {
253  AddMessage(
254  "detected by Newmat: element error: requested indices (wrt 0) = ");
255  AddInt(i); AddMessage(", "); AddInt(j);
256  AddMessage("\n\n");
257  MatrixDetails(A);
259 }
260 
262 {
264  AddMessage("internal error detected by Newmat: please inform author\n");
265  AddMessage(c); AddMessage("\n\n");
267 }
268 
269 
270 
271 
272 /************************* ExeCounter functions *****************************/
273 
274 #ifdef DO_REPORT
275 
276 int ExeCounter::nreports; // will be set to zero
277 
278 ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
279 
280 ExeCounter::~ExeCounter()
281 {
282  nreports++;
283  std::cout << "REPORT " << std::setw(6) << nreports << " "
284  << std::setw(6) << fileid << " " << std::setw(6) << line
285  << " " << std::setw(6) << nexe << "\n";
286 }
287 
288 #endif
289 
290 /**************************** error handler *******************************/
291 
292 void MatrixErrorNoSpace(const void* v) { if (!v) Throw(Bad_alloc()); }
293 // throw exception if v is null
294 
295 
296 
297 
298 /************************* miscellanous errors ***************************/
299 
300 
302  { Throw(NotDefinedException("GetRow","Crout")); }
304  { Throw(NotDefinedException("GetCol","Crout")); }
306  { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
308  { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
309 void BaseMatrix::IEQND() const
310  { Throw(NotDefinedException("inequalities", "matrices")); }
311 
312 
313 #ifdef use_namespace
314 }
315 #endif
316 
static unsigned long Select
Definition: newmat.h:1617
IndexException(int i, const GeneralMatrix &A)
Definition: newmatex.cpp:216
static void AddMessage(const char *a_what)
Definition: myexcept.cpp:67
void GetRow(MatrixRowCol &)
Definition: newmatex.cpp:305
void IEQND() const
Definition: newmatex.cpp:309
void GetCol(MatrixRowCol &)
Definition: newmatex.cpp:303
static unsigned long Select
Definition: newmat.h:1658
static unsigned long Select
Definition: newmat.h:1707
#define A(r, c)
static void AddTrace()
Definition: myexcept.cpp:110
NPDException(const GeneralMatrix &)
Definition: newmatex.cpp:54
OverflowException(const char *c)
Definition: newmatex.cpp:89
SingularException(const GeneralMatrix &A)
Definition: newmatex.cpp:63
NotDefinedException(const char *op, const char *matrix)
Definition: newmatex.cpp:195
void MatrixErrorNoSpace(const void *v)
Definition: newmatex.cpp:292
CannotBuildException(const char *matrix)
Definition: newmatex.cpp:207
static unsigned long Select
Definition: newmat.h:1648
static unsigned long Select
Definition: newmat.h:1677
static unsigned long Select
Definition: newmat.h:1669
const char * Value() const
Definition: newmat1.cpp:111
static unsigned long Select
Definition: newmat.h:1624
ConvergenceException(const GeneralMatrix &A)
Definition: newmatex.cpp:72
void GetRow(MatrixRowCol &)
Definition: newmatex.cpp:301
static unsigned long Select
Definition: newmat.h:1700
static void AddInt(int value)
Definition: myexcept.cpp:82
void GetCol(MatrixRowCol &)
Definition: newmatex.cpp:307
static unsigned long Select
Definition: myexcept.h:79
static unsigned long Select
Definition: newmat.h:1632
static unsigned long Select
Definition: newmat.h:1715
static unsigned long Select
Definition: newmat.h:1685
static unsigned long Select
Definition: newmat.h:1639
static unsigned long Select
Definition: newmat.h:1692
InternalException(const char *c)
Definition: newmatex.cpp:261