source: ntrip/trunk/BNS/newmat/newmatex.cpp@ 8198

Last change on this file since 8198 was 810, checked in by mervart, 17 years ago

* empty log message *

File size: 8.7 KB
Line 
1/// \file newmatex.cpp
2/// \brief Exceptions thrown by matrix library.
3
4// Copyright (C) 1992,3,4,7: R B Davies
5
6#define WANT_STREAM // include.h will get stream fns
7
8#include "include.h" // include standard files
9#include "newmat.h"
10
11#ifdef use_namespace
12namespace NEWMAT {
13#endif
14
15unsigned long OverflowException::Select;
16unsigned long SingularException::Select;
17unsigned long NPDException::Select;
18unsigned long ConvergenceException::Select;
19unsigned long ProgramException::Select;
20unsigned long IndexException::Select;
21unsigned long VectorException::Select;
22unsigned long NotSquareException::Select;
23unsigned long SubMatrixDimensionException::Select;
24unsigned long IncompatibleDimensionsException::Select;
25unsigned long NotDefinedException::Select;
26unsigned long CannotBuildException::Select;
27unsigned long InternalException::Select;
28
29
30
31static void MatrixDetails(const GeneralMatrix& A)
32// write matrix details to Exception buffer
33{
34 MatrixBandWidth bw = A.bandwidth();
35 int ubw = bw.upper_val; int lbw = bw.lower_val;
36 BaseException::AddMessage("MatrixType = ");
37 BaseException::AddMessage(A.Type().Value());
38 BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows());
39 BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols());
40 if (lbw >=0)
41 {
42 BaseException::AddMessage("; lower BW = ");
43 BaseException::AddInt(lbw);
44 }
45 if (ubw >=0)
46 {
47 BaseException::AddMessage("; upper BW = ");
48 BaseException::AddInt(ubw);
49 }
50 BaseException::AddMessage("\n");
51}
52
53NPDException::NPDException(const GeneralMatrix& A)
54 : Runtime_error()
55{
56 Select = BaseException::Select;
57 AddMessage("detected by Newmat: matrix not positive definite\n\n");
58 MatrixDetails(A);
59 Tracer::AddTrace();
60}
61
62SingularException::SingularException(const GeneralMatrix& A)
63 : Runtime_error()
64{
65 Select = BaseException::Select;
66 AddMessage("detected by Newmat: matrix is singular\n\n");
67 MatrixDetails(A);
68 Tracer::AddTrace();
69}
70
71ConvergenceException::ConvergenceException(const GeneralMatrix& A)
72 : Runtime_error()
73{
74 Select = BaseException::Select;
75 AddMessage("detected by Newmat: process fails to converge\n\n");
76 MatrixDetails(A);
77 Tracer::AddTrace();
78}
79
80ConvergenceException::ConvergenceException(const char* c) : Runtime_error()
81{
82 Select = BaseException::Select;
83 AddMessage("detected by Newmat: ");
84 AddMessage(c); AddMessage("\n\n");
85 if (c) Tracer::AddTrace();
86}
87
88OverflowException::OverflowException(const char* c) : Runtime_error()
89{
90 Select = BaseException::Select;
91 AddMessage("detected by Newmat: ");
92 AddMessage(c); AddMessage("\n\n");
93 if (c) Tracer::AddTrace();
94}
95
96ProgramException::ProgramException(const char* c) : Logic_error()
97{
98 Select = BaseException::Select;
99 AddMessage("detected by Newmat: ");
100 AddMessage(c); AddMessage("\n\n");
101 if (c) Tracer::AddTrace();
102}
103
104ProgramException::ProgramException(const char* c, const GeneralMatrix& A)
105 : Logic_error()
106{
107 Select = BaseException::Select;
108 AddMessage("detected by Newmat: ");
109 AddMessage(c); AddMessage("\n\n");
110 MatrixDetails(A);
111 if (c) Tracer::AddTrace();
112}
113
114ProgramException::ProgramException(const char* c, const GeneralMatrix& A,
115 const GeneralMatrix& B) : Logic_error()
116{
117 Select = BaseException::Select;
118 AddMessage("detected by Newmat: ");
119 AddMessage(c); AddMessage("\n\n");
120 MatrixDetails(A); MatrixDetails(B);
121 if (c) Tracer::AddTrace();
122}
123
124ProgramException::ProgramException(const char* c, MatrixType a, MatrixType b)
125 : Logic_error()
126{
127 Select = BaseException::Select;
128 AddMessage("detected by Newmat: ");
129 AddMessage(c); AddMessage("\nMatrixTypes = ");
130 AddMessage(a.Value()); AddMessage("; ");
131 AddMessage(b.Value()); AddMessage("\n\n");
132 if (c) Tracer::AddTrace();
133}
134
135VectorException::VectorException() : Logic_error()
136{
137 Select = BaseException::Select;
138 AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
139 Tracer::AddTrace();
140}
141
142VectorException::VectorException(const GeneralMatrix& A)
143 : Logic_error()
144{
145 Select = BaseException::Select;
146 AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
147 MatrixDetails(A);
148 Tracer::AddTrace();
149}
150
151NotSquareException::NotSquareException(const GeneralMatrix& A)
152 : Logic_error()
153{
154 Select = BaseException::Select;
155 AddMessage("detected by Newmat: matrix is not square\n\n");
156 MatrixDetails(A);
157 Tracer::AddTrace();
158}
159
160NotSquareException::NotSquareException()
161 : Logic_error()
162{
163 Select = BaseException::Select;
164 AddMessage("detected by Newmat: matrix is not square\n\n");
165 Tracer::AddTrace();
166}
167
168SubMatrixDimensionException::SubMatrixDimensionException()
169 : Logic_error()
170{
171 Select = BaseException::Select;
172 AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
173 Tracer::AddTrace();
174}
175
176IncompatibleDimensionsException::IncompatibleDimensionsException()
177 : Logic_error()
178{
179 Select = BaseException::Select;
180 AddMessage("detected by Newmat: incompatible dimensions\n\n");
181 Tracer::AddTrace();
182}
183
184IncompatibleDimensionsException::IncompatibleDimensionsException
185 (const GeneralMatrix& A, const GeneralMatrix& B)
186 : Logic_error()
187{
188 Select = BaseException::Select;
189 AddMessage("detected by Newmat: incompatible dimensions\n\n");
190 MatrixDetails(A); MatrixDetails(B);
191 Tracer::AddTrace();
192}
193
194IncompatibleDimensionsException::IncompatibleDimensionsException
195 (const GeneralMatrix& A)
196 : Logic_error()
197{
198 Select = BaseException::Select;
199 AddMessage("detected by Newmat: incompatible dimensions\n\n");
200 MatrixDetails(A);
201 Tracer::AddTrace();
202}
203
204NotDefinedException::NotDefinedException(const char* op, const char* matrix)
205 : Logic_error()
206{
207 Select = BaseException::Select;
208 AddMessage("detected by Newmat: ");
209 AddMessage(op);
210 AddMessage(" not defined for ");
211 AddMessage(matrix);
212 AddMessage("\n\n");
213 Tracer::AddTrace();
214}
215
216CannotBuildException::CannotBuildException(const char* matrix)
217 : Logic_error()
218{
219 Select = BaseException::Select;
220 AddMessage("detected by Newmat: cannot build matrix type ");
221 AddMessage(matrix); AddMessage("\n\n");
222 Tracer::AddTrace();
223}
224
225IndexException::IndexException(int i, const GeneralMatrix& A)
226 : Logic_error()
227{
228 Select = BaseException::Select;
229 AddMessage("detected by Newmat: index error: requested index = ");
230 AddInt(i); AddMessage("\n\n");
231 MatrixDetails(A);
232 Tracer::AddTrace();
233}
234
235IndexException::IndexException(int i, int j, const GeneralMatrix& A)
236 : Logic_error()
237{
238 Select = BaseException::Select;
239 AddMessage("detected by Newmat: index error: requested indices = ");
240 AddInt(i); AddMessage(", "); AddInt(j);
241 AddMessage("\n\n");
242 MatrixDetails(A);
243 Tracer::AddTrace();
244}
245
246
247IndexException::IndexException(int i, const GeneralMatrix& A, bool)
248 : Logic_error()
249{
250 Select = BaseException::Select;
251 AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
252 AddInt(i);
253 AddMessage("\n\n");
254 MatrixDetails(A);
255 Tracer::AddTrace();
256}
257
258IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
259 : Logic_error()
260{
261 Select = BaseException::Select;
262 AddMessage(
263 "detected by Newmat: element error: requested indices (wrt 0) = ");
264 AddInt(i); AddMessage(", "); AddInt(j);
265 AddMessage("\n\n");
266 MatrixDetails(A);
267 Tracer::AddTrace();
268}
269
270InternalException::InternalException(const char* c) : Logic_error()
271{
272 Select = BaseException::Select;
273 AddMessage("internal error detected by Newmat: please inform author\n");
274 AddMessage(c); AddMessage("\n\n");
275 Tracer::AddTrace();
276}
277
278
279
280
281/************************* ExeCounter functions *****************************/
282
283#ifdef DO_REPORT
284
285int ExeCounter::nreports; // will be set to zero
286
287ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
288
289ExeCounter::~ExeCounter()
290{
291 nreports++;
292 cout << "REPORT " << setw(6) << nreports << " "
293 << setw(6) << fileid << " " << setw(6) << line
294 << " " << setw(6) << nexe << "\n";
295}
296
297#endif
298
299/**************************** error handler *******************************/
300
301void MatrixErrorNoSpace(const void* v) { if (!v) Throw(Bad_alloc()); }
302// throw exception if v is null
303
304
305
306
307/************************* miscellanous errors ***************************/
308
309
310void CroutMatrix::GetRow(MatrixRowCol&)
311 { Throw(NotDefinedException("GetRow","Crout")); }
312void CroutMatrix::GetCol(MatrixRowCol&)
313 { Throw(NotDefinedException("GetCol","Crout")); }
314void BandLUMatrix::GetRow(MatrixRowCol&)
315 { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
316void BandLUMatrix::GetCol(MatrixRowCol&)
317 { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
318void BaseMatrix::IEQND() const
319 { Throw(NotDefinedException("inequalities", "matrices")); }
320
321
322#ifdef use_namespace
323}
324#endif
325
Note: See TracBrowser for help on using the repository browser.