Changeset 10791 in ntrip for trunk/BNC/newmat


Ignore:
Timestamp:
Dec 3, 2025, 5:37:16 PM (4 months ago)
Author:
mervart
Message:

BNC Multifrequency and PPPAR Client (initial version)

Location:
trunk/BNC/newmat
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/newmat/bandmat.cpp

    r9434 r10791  
    2929#endif
    3030
    31 static inline int my_min(int x, int y) { return x < y ? x : y; }
    32 static inline int my_max(int x, int y) { return x > y ? x : y; }
     31////static inline int my_min(int x, int y) { return x < y ? x : y; }
     32////static inline int my_max(int x, int y) { return x > y ? x : y; }
    3333
    3434
     
    360360   // while (i--) { sum *= *a; a += w; }
    361361   if (i) for (;;) { sum *= *a; if (!(--i)) break; a += w; }
    362    if (!d) sum.ChangeSign(); return sum;
     362   if (!d) sum.ChangeSign();
     363   return sum;
    363364}
    364365
  • trunk/BNC/newmat/myexcept.cpp

    r9434 r10791  
    2121
    2222#include "myexcept.h"                  // for exception handling
     23#include "newmat.h"                  // for exception handling
    2324
    2425#ifdef use_namespace
     
    5152
    5253
    53 unsigned long BaseException::Select;
    54 char* BaseException::what_error;
    55 int BaseException::SoFar;
    56 int BaseException::LastOne;
    57 
    58 BaseException::BaseException(const char* a_what)
    59 {
    60    Select++; SoFar = 0;
    61    if (!what_error)                   // make space for exception message
    62    {
    63       LastOne = 511;
    64       what_error = new char[512];
    65       if (!what_error)                // fail to make space
    66       {
    67          LastOne = 0;
    68          what_error = (char *)"No heap space for exception message\n";
    69       }
    70    }
    71    AddMessage("\n\nAn exception has been thrown\n");
    72    AddMessage(a_what);
    73    if (a_what) Tracer::AddTrace();
    74 }
    75 
    76 void BaseException::AddMessage(const char* a_what)
    77 {
    78    if (a_what)
    79    {
    80       int l = strlen(a_what); int r = LastOne - SoFar;
    81       if (l < r) { strcpy(what_error+SoFar, a_what); SoFar += l; }
    82       else if (r > 0)
    83       {
    84          strncpy(what_error+SoFar, a_what, r);
    85          what_error[LastOne] = 0;
    86          SoFar = LastOne;
    87       }
    88    }
    89 }
    90 
    91 void BaseException::AddInt(int value)
    92 {
    93    bool negative;
    94    if (value == 0) { AddMessage("0"); return; }
    95    else if (value < 0) { value = -value; negative = true; }
    96    else negative = false;
    97    int n = 0; int v = value;        // how many digits will we need?
    98    while (v > 0) { v /= 10; n++; }
    99    if (negative) n++;
    100    if (LastOne-SoFar < n) { AddMessage("***"); return; }
    101 
    102    SoFar += n; n = SoFar; what_error[n] = 0;
    103    while (value > 0)
    104    {
     54BaseException::BaseException(const char* a_what) {
     55  _what = new char[MAXSIZE];
     56  if (!_what) {                // fail to make space
     57    _what = (char *)"No heap space for exception message\n";
     58    _deleteMe = false;
     59  }
     60  else {
     61    _deleteMe = true;
     62  }
     63  AddMessage("\n\nAn exception has been thrown\n");
     64  AddMessage(a_what);
     65}
     66
     67BaseException::BaseException(const BaseException& oth) {
     68  _what = new char[MAXSIZE];
     69  if (!_what) {                // fail to make space
     70    _what = (char *)"No heap space for exception message\n";
     71    _deleteMe = false;
     72  }
     73  else {
     74    _deleteMe = true;
     75    strcpy(_what, oth._what);
     76  }
     77}
     78 
     79BaseException& BaseException::operator=(const BaseException& oth) {
     80  if (this == &oth) return *this;
     81  _what = new char[MAXSIZE];
     82  if (!_what) {                // fail to make space
     83    _what = (char *)"No heap space for exception message\n";
     84    _deleteMe = false;
     85  }
     86  else {
     87    _deleteMe = true;
     88    strcpy(_what, oth._what);
     89  }
     90  return *this;
     91}
     92 
     93BaseException::~BaseException() {
     94  if (_deleteMe) delete[] _what;
     95}
     96
     97void BaseException::AddMessage(const char* a_what) {
     98  if (a_what) {
     99    size_t nn = MAXSIZE - strlen(_what) - 1;
     100    strncat(_what, a_what, nn);
     101  }
     102}
     103
     104void BaseException::AddInt(int value) {
     105  bool negative = false;
     106   if (value == 0) {
     107     AddMessage("0");
     108     return;
     109   }
     110   else if (value < 0) {
     111     value = -value;
     112     negative = true;
     113   }
     114   int nn = (negative ? 1 : 0); // how many digits will we need?
     115   int vv = value;       
     116   while (vv > 0) { vv /= 10; ++nn; }
     117   if ((int)(MAXSIZE - strlen(_what)) < nn) {
     118     AddMessage("***");
     119     return;
     120   }
     121
     122   nn += strlen(_what);
     123   _what[nn] = 0;
     124   while (value > 0) {
    105125      int nv = value / 10; int rm = value - nv * 10;  value = nv;
    106       what_error[--n] = (char)(rm + '0');
    107    }
    108    if (negative) what_error[--n] = '-';
    109    return;
    110 }
    111 
    112 void Tracer::PrintTrace()
    113 {
    114    cout << "\n";
    115    for (Tracer* et = last; et; et=et->previous)
    116       cout << "  * " << et->entry << "\n";
    117 }
    118 
    119 void Tracer::AddTrace()
    120 {
    121    if (last)
    122    {
    123       BaseException::AddMessage("Trace: ");
    124       BaseException::AddMessage(last->entry);
    125       for (Tracer* et = last->previous; et; et=et->previous)
    126       {
    127          BaseException::AddMessage("; ");
    128          BaseException::AddMessage(et->entry);
    129       }
    130       BaseException::AddMessage(".\n");
    131    }
    132 }
     126      _what[--nn] = (char)(rm + '0');
     127   }
     128   if (negative) _what[--nn] = '-';
     129}
     130
     131 
     132void BaseException::MatrixDetails(const GeneralMatrix& A)
     133{
     134   MatrixBandWidth bw = A.bandwidth();
     135   int ubw = bw.upper_val; int lbw = bw.lower_val;
     136   AddMessage("MatrixType = ");
     137   AddMessage(A.Type().Value());
     138   AddMessage("  # Rows = "); BaseException::AddInt(A.Nrows());
     139   AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols());
     140   if (lbw >=0)
     141   {
     142      AddMessage("; lower BW = ");
     143      AddInt(lbw);
     144   }
     145   if (ubw >=0)
     146   {
     147      AddMessage("; upper BW = ");
     148      AddInt(ubw);
     149   }
     150   AddMessage("\n");
     151}
     152
    133153
    134154#ifdef SimulateExceptions
     
    230250{
    231251   cout << "\n\nThere has been an exception with no handler - exiting";
    232    const char* what = BaseException::what();
    233    if (what) cout << what << "\n";
    234252   exit(1);
    235253}
     
    479497
    480498
     499unsigned long BaseException::Select;
    481500unsigned long Logic_error::Select;
    482501unsigned long Runtime_error::Select;
  • trunk/BNC/newmat/myexcept.h

    r9434 r10791  
    6363
    6464class BaseException;
     65class GeneralMatrix;
    6566
    6667class Tracer                             // linked list showing how
    6768{                                        // we got here
    68    const char* entry;
    69    Tracer* previous;
    70 public:
    71    Tracer(const char*);
    72    ~Tracer();
    73    void ReName(const char*);
    74    static void PrintTrace();             // for printing trace
    75    static void AddTrace();               // insert trace in exception record
    76    static Tracer* last;                  // points to Tracer list
    77    friend class BaseException;
    78 };
    79 
    80 
    81 class BaseException                          // The base exception class
    82 {
    83 protected:
    84    static char* what_error;              // error message
    85    static int SoFar;                     // no. characters already entered
    86    static int LastOne;                   // last location in error buffer
    87 public:
    88    static void AddMessage(const char* a_what);
    89                                          // messages about exception
    90    static void AddInt(int value);        // integer to error message
    91    static unsigned long Select;          // for identifying exception
    92    BaseException(const char* a_what = 0);
    93    static const char* what() { return what_error; }
    94                                          // for getting error message
    95 };
    96 
     69public:
     70  Tracer(const char*) {};
     71  ~Tracer() {}
     72  void ReName(const char*) {}
     73  static void PrintTrace() {};             // for printing trace
     74  static void AddTrace() {};               // insert trace in exception record
     75  static Tracer* last;                  // points to Tracer list
     76};
     77
     78
     79class BaseException {                     // The base exception class
     80 protected:
     81  int    MAXSIZE = 512;
     82  char*  _what;                            // error message
     83  bool   _deleteMe;
     84 public:
     85  static unsigned long Select;
     86  BaseException(const char* a_what = 0);
     87  BaseException(const BaseException& oth);
     88  BaseException& operator=(const BaseException& oth);
     89  ~BaseException();
     90  void AddMessage(const char* a_what);
     91  void AddInt(int value);
     92  void MatrixDetails(const GeneralMatrix& A);
     93  const char* what() { return _what; }
     94};
     95
     96 
    9797#ifdef TypeDefException
    9898typedef BaseException Exception;        // for compatibility with my older libraries
    9999#endif
    100 
    101 inline Tracer::Tracer(const char* e)
    102    : entry(e), previous(last) { last = this; }
    103 
    104 inline Tracer::~Tracer() { last = previous; }
    105 
    106 inline void Tracer::ReName(const char* e) { entry=e; }
    107100
    108101#ifdef SimulateExceptions                // SimulateExceptions
  • trunk/BNC/newmat/newmat.h

    r9434 r10791  
    18341834   MatrixInput(const MatrixInput& mi) : n(mi.n), r(mi.r) {}
    18351835   MatrixInput(int nx, Real* rx) : n(nx), r(rx) {}
    1836    ~MatrixInput();
     1836  ~MatrixInput() noexcept(false);
    18371837   MatrixInput operator<<(double);
    18381838   MatrixInput operator<<(float);
  • trunk/BNC/newmat/newmat2.cpp

    r9434 r10791  
    3939   REPORT
    4040   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
    41    if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
     41   if (f < skip) f = skip;
     42   if (l > lx) l = lx;
     43   l -= f;
    4244   if (l<=0) return;
    4345   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
     
    5052   // THIS += (mrc * x)
    5153   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
    52    if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
     54   if (f < skip) f = skip;
     55   if (l > lx) l = lx;
     56   l -= f;
    5357   if (l<=0) return;
    5458   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
     
    6165   // THIS -= mrc
    6266   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
    63    if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
     67   if (f < skip) f = skip;
     68   if (l > lx) l = lx;
     69   l -= f;
    6470   if (l<=0) return;
    6571   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
     
    7278   REPORT
    7379   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
    74    if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
     80   if (f < skip) f = skip;
     81   if (l > lx) l = lx;
     82   l -= f;
    7583   if (l<=0) return;
    7684   Real* elx=data+(f-skip); Real* ely=mrc.data+(f-mrc.skip);
     
    8391   int f = mrc1.skip; int f2 = mrc2.skip;
    8492   int l = f + mrc1.storage; int l2 = f2 + mrc2.storage;
    85    if (f < f2) f = f2; if (l > l2) l = l2; l -= f;
     93   if (f < f2) f = f2;
     94   if (l > l2) l = l2;
     95   l -= f;
    8696   if (l<=0) return 0.0;
    8797
     
    97107   int f = skip; int l = skip + storage;
    98108   int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
    99    if (f1<f) f1=f; if (l1>l) l1=l;
     109   if (f1<f) f1=f;
     110   if (l1>l) l1=l;
    100111   int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
    101    if (f2<f) f2=f; if (l2>l) l2=l;
     112   if (f2<f) f2=f;
     113   if (l2>l) l2=l;
    102114   Real* el = data + (f-skip);
    103115   Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);
     
    169181   int f = skip; int l = skip + storage;
    170182   int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
    171    if (f1<f) f1=f; if (l1>l) l1=l;
     183   if (f1<f) f1=f;
     184   if (l1>l) l1=l;
    172185   int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
    173    if (f2<f) f2=f; if (l2>l) l2=l;
     186   if (f2<f) f2=f;
     187   if (l2>l) l2=l;
    174188   Real* el = data + (f-skip);
    175189   Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);
     
    333347   int f = skip; int l = skip + storage;
    334348   int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
    335    if (f1<f) f1=f; if (l1>l) l1=l;
     349   if (f1<f) f1=f;
     350   if (l1>l) l1=l;
    336351   int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
    337    if (f2<f) f2=f; if (l2>l) l2=l;
     352   if (f2<f) f2=f;
     353   if (l2>l) l2=l;
    338354   Real* el = data + (f-skip); int i;
    339    if (f1<f2) f1 = f2; if (l1>l2) l1 = l2;
     355   if (f1<f2) f1 = f2;
     356   if (l1>l2) l1 = l2;
    340357   if (l1<=f1) { REPORT i = l-f; while (i--) *el++ = 0.0; }  // disjoint
    341358   else
  • trunk/BNC/newmat/newmat3.cpp

    r9434 r10791  
    668668         Throw(InternalException("SymmetricBandMatrix::GetRow(MatrixRowCol&)"));
    669669      int w = w1+lower_val; s += w-ncols_val; Real* RowCopy;
    670       if (s>0) w -= s; mrc.storage = w; int w2 = w-w1;
     670      if (s>0) w -= s;
     671      mrc.storage = w;
     672      int w2 = w-w1;
    671673      if (!(mrc.cw*HaveStore))
    672674      {
     
    709711         Throw(InternalException("SymmetricBandMatrix::GetCol(MatrixRowCol&)"));
    710712      int w = w1+lower_val; s += w-ncols_val; Real* ColCopy;
    711       if (s>0) w -= s; mrc.storage = w; int w2 = w-w1;
     713      if (s>0) w -= s;
     714      mrc.storage = w;
     715      int w2 = w-w1;
    712716
    713717      if ( +(mrc.cw*HaveStore) ) { REPORT ColCopy = mrc.data; }
     
    759763
    760764      int w = w1+lower_val; s += w-ncols_val;
    761       if (s>0) w -= s; mrc.storage = w; int w2 = w-w1;
     765      if (s>0) w -= s;
     766      mrc.storage = w;
     767      int w2 = w-w1;
    762768
    763769      Real* ColCopy = mrc.data = mrc.store+mrc.skip;
  • trunk/BNC/newmat/newmat5.cpp

    r9434 r10791  
    488488   return MatrixInput(n, r+1);
    489489}
    490 MatrixInput::~MatrixInput()
     490MatrixInput::~MatrixInput() noexcept(false)
    491491{
    492492   REPORT
  • trunk/BNC/newmat/newmat6.cpp

    r9470 r10791  
    352352   // MatrixConversionCheck mcc;
    353353   Eq(X,MatrixType::Rt);
    354 }
     354} 
    355355
    356356void SquareMatrix::operator=(const BaseMatrix& X)
     
    429429   if (&gm == this) { REPORT tag_val = -1; return; }
    430430   REPORT
    431    if (indx) { delete [] indx; indx = 0; }
     431   if (indx != 0) { delete [] indx; indx = 0; }
    432432   ((CroutMatrix&)gm).get_aux(*this);
    433433   Eq(gm);
    434434}
    435 
     435   
    436436
    437437
  • trunk/BNC/newmat/newmat7.cpp

    r9434 r10791  
    545545         { REPORT AddDS(gm1,gm2); gm2->tDelete(); gmx = gm1; }
    546546      else if (c2 && gm2->reuse() )
    547          { REPORT AddDS(gm2,gm1); if (!c1) gm1->tDelete(); gmx = gm2; }
     547        { REPORT AddDS(gm2,gm1);
     548           if (!c1) gm1->tDelete();
     549           gmx = gm2;
     550        }
    548551      else
    549552      {
     
    552555         CatchAll
    553556         {
    554             if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     557            if (!c1) gm1->tDelete();
     558            if (!c2) gm2->tDelete();
    555559            ReThrow;
    556560         }
    557561         AddDS(gmx,gm1,gm2);
    558          if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     562         if (!c1) gm1->tDelete();
     563         if (!c2) gm2->tDelete();
    559564         gmx->ReleaseAndDelete();
    560565      }
     
    616621      {
    617622         REPORT ReverseSubtractDS(gm2,gm1);
    618          if (!c1) gm1->tDelete(); gmx = gm2;
     623         if (!c1) gm1->tDelete();
     624         gmx = gm2;
    619625      }
    620626      else
     
    625631         CatchAll
    626632         {
    627             if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     633            if (!c1) gm1->tDelete();
     634            if (!c2) gm2->tDelete();
    628635            ReThrow;
    629636         }
    630637         SubtractDS(gmx,gm1,gm2);
    631          if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     638         if (!c1) gm1->tDelete();
     639         if (!c2) gm2->tDelete();
    632640         gmx->ReleaseAndDelete();
    633641      }
     
    695703         CatchAll
    696704         {
    697             if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     705            if (!c1) gm1->tDelete();
     706            if (!c2) gm2->tDelete();
    698707            ReThrow;
    699708         }
    700709         SPDS(gmx,gm1,gm2);
    701          if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
     710         if (!c1) gm1->tDelete();
     711         if (!c2) gm2->tDelete();
    702712         gmx->ReleaseAndDelete();
    703713      }
     
    779789   while (i--)
    780790   {
    781       if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false;
    782       if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false;
     791      if (*s1++ != *s2++) return false;
     792      if (*s1++ != *s2++) return false;
     793      if (*s1++ != *s2++) return false;
     794      if (*s1++ != *s2++) return false;
    783795   }
    784796   i = n & 3; while (i--) if (*s1++ != *s2++) return false;
     
    791803   while (i--)
    792804   {
    793       if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false;
    794       if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false;
     805      if (*s1++ != *s2++) return false;
     806      if (*s1++ != *s2++) return false;
     807      if (*s1++ != *s2++) return false;
     808      if (*s1++ != *s2++) return false;
    795809   }
    796810   i = n & 3; while (i--) if (*s1++ != *s2++) return false;
     
    869883   while (i--)
    870884   {
    871       if (*s++) return false; if (*s++) return false;
    872       if (*s++) return false; if (*s++) return false;
     885      if (*s++) return false;
     886      if (*s++) return false;
     887      if (*s++) return false;
     888      if (*s++) return false;
    873889   }
    874890   i = storage & 3; while (i--) if (*s++) return false;
  • trunk/BNC/newmat/newmat8.cpp

    r9434 r10791  
    713713      s += dd;
    714714   }
    715    if (!d) sum.ChangeSign(); return sum;
     715   if (!d) sum.ChangeSign();
     716   return sum;
    716717
    717718}
  • trunk/BNC/newmat/newmat9.cpp

    r9434 r10791  
    1515#include "newmatio.h"
    1616#include "newmatrc.h"
     17
     18#ifdef USE_STD_NAMESPACE
     19using namespace std;
     20#endif
    1721
    1822#ifdef use_namespace
     
    4448   MatrixRow mr((GeneralMatrix*)&X, LoadOnEntry);
    4549   int w = s.width();  int nr = X.Nrows();  ios_format_flags f = s.flags();
    46    s.setf(ios::fixed, ios::floatfield);
     50   /////s.setf(ios::fixed, ios::floatfield);
    4751   for (int i=1; i<=nr; i++)
    4852   {
  • trunk/BNC/newmat/newmatex.cpp

    r9434 r10791  
    2929
    3030
    31 static 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 }
     31////static 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////}
    5252
    5353NPDException::NPDException(const GeneralMatrix& A)
  • trunk/BNC/newmat/newmatio.h

    r9434 r10791  
    1515
    1616#include "newmat.h"
     17#include <iostream>
    1718
    18 #ifdef USE_STD_NAMESPACE
    19 using namespace std;
     19#ifdef use_namespace
     20namespace NEWMAT {
    2021#endif
     22
     23
    2124
    2225// **************************** input/output *****************************/
    2326
    24 ostream& operator<<(ostream&, const BaseMatrix&);
     27std::ostream& operator<<(std::ostream&, const BaseMatrix&);
    2528
    26 ostream& operator<<(ostream&, const GeneralMatrix&);
     29std::ostream& operator<<(std::ostream&, const GeneralMatrix&);
    2730
    2831
Note: See TracChangeset for help on using the changeset viewer.