Changeset 2122 in ntrip for trunk


Ignore:
Timestamp:
Dec 18, 2009, 9:40:33 AM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bnc.pro

    r2057 r2122  
    3636          bncnetqueryrtp.h bncsettings.h latencychecker.h             \
    3737          bncipport.h bncnetqueryv0.h bncnetqueryudp.h                \
    38           bncnetqueryudp0.h bncudpport.h t_time.h                     \
     38          bncnetqueryudp0.h bncudpport.h bnctime.h                    \
    3939          bncserialport.h bncnetquerys.h bncfigure.h                  \
    4040          bncfigurelate.h bncpppclient.h bncversion.h                 \
     
    6666          bncnetqueryudp0.cpp bncudpport.cpp                          \
    6767          bncserialport.cpp bncnetquerys.cpp bncfigure.cpp            \
    68           bncfigurelate.cpp bncpppclient.cpp t_time.cpp               \
     68          bncfigurelate.cpp bncpppclient.cpp bnctime.cpp              \
    6969          bancroft.cpp bncmodel.cpp                                   \
    7070          RTCM/RTCM2.cpp RTCM/RTCM2Decoder.cpp                        \
  • trunk/BNC/t_time.cpp

    r2027 r2122  
    99using namespace std;
    1010
    11 double t_time::djul(long jj, long mm, double tt) {
    12   long    ii, kk;
    13   double  djul ;
    14   if( mm <= 2 ) {
    15     jj = jj - 1;
    16     mm = mm + 12;
    17   } 
    18   ii   = jj/100;
    19   kk   = 2 - ii + ii/4;
    20   djul = (365.25*jj - fmod( 365.25*jj, 1.0 )) - 679006.0;
    21   djul = djul + floor( 30.6001*(mm + 1) ) + tt + kk;
    22   return djul;
    23 }
    24 
    25 double t_time::gpjd(double second, int nweek) {
    26   double deltat;
    27   deltat = nweek*7.0 + second/86400.0 ;
    28   return( 44244.0 + deltat) ;
    29 }
    30 
    31 void t_time::jdgp(double tjul, double & second, long & nweek) {
    32   double      deltat;
    33   deltat = tjul - 44244.0 ;
    34   nweek = (long) floor(deltat/7.0);
    35   second = (deltat - (nweek)*7.0)*86400.0;
    36 }
    37 
    38 void t_time::jmt(double djul, long& jj, long& mm, double& dd) {
    39   long   ih, ih1, ih2 ;
    40   double t1, t2,  t3, t4;
    41   t1  = 1.0 + djul - fmod( djul, 1.0 ) + 2400000.0;
    42   t4  = fmod( djul, 1.0 );
    43   ih  = long( (t1 - 1867216.25)/36524.25 );
    44   t2  = t1 + 1 + ih - ih/4;
    45   t3  = t2 - 1720995.0;
    46   ih1 = long( (t3 - 122.1)/365.25 );
    47   t1  = 365.25*ih1 - fmod( 365.25*ih1, 1.0 );
    48   ih2 = long( (t3 - t1)/30.6001 );
    49   dd  = t3 - t1 - (int)( 30.6001*ih2 ) + t4;
    50   mm  = ih2 - 1;
    51   if ( ih2 > 13 ) mm = ih2 - 13;
    52   jj  = ih1;
    53   if ( mm <= 2 ) jj = jj + 1;
    54 }
    55 
    56 t_time::t_time(int gpsw, int dow, double daysec) {
    57   this->set(gpsw, dow, daysec);
    58 }
    59 
     11// Constructor
     12//////////////////////////////////////////////////////////////////////////////
    6013t_time::t_time(int gpsw, double gpssec) {
    6114  this->set(gpsw, gpssec);
    6215}
    6316 
    64 t_time::t_time(int hour, int min, double sec,
    65                      int day,  int month, int year) {
    66   double  daysec = hour*3600.0 + min*60.0 + sec;
    67   this->set(daysec, day, month, year);
    68 }
    69 
    70 t_time::t_time(double daysec, int day, int month, int year) {
    71   this->set(daysec, day, month, year);
    72 }
    73 
    74 t_time::t_time(double daysec, int doy, unsigned int year) {
    75   this->set(daysec, doy, year);
    76 }
    77 
    78 t_time& t_time::set(int gpsw, int dow, double daysec) {
    79   int deltad;
    80   while (daysec >= 86400) {
    81     daysec-=86400;
    82     dow++;
    83   }
    84   while (daysec < 0) {
    85     daysec+=86400;
    86     dow--;
    87   }
    88   deltad = gpsw*7 + dow;
    89   _mjd = 44244 + deltad;
    90   _sec = daysec;
    91   return *this;
    92 }
    93 
     17//
     18//////////////////////////////////////////////////////////////////////////////
    9419t_time& t_time::set(int gpsw, double gpssec) {
    9520  int  deltad;
     
    10934}
    11035
    111 t_time& t_time::set(int hour, int min, double sec, int day,  int month, int year) {
    112   return this->set(hour*3600 + min*60 + sec, day, month, year);
    113 }
    114 
    115 t_time& t_time::set(double daysec, int day, int month, int year) {
    116   _sec = daysec;
    117   _mjd = (unsigned int)djul(year, month, day);
    118   while ( _sec >= 86400 ) {
    119     _sec-=86400;
    120     _mjd++;
    121   }
    122   while ( _sec <  0 ) {
    123     _sec+=86400;
    124     _mjd--;
    125   }
    126   return *this;
    127 }
    128 
    129 t_time& t_time::set(double daysec, int doy, int year) {
    130   _mjd = (unsigned int)djul(year, 1, 1) + (doy - 1);
    131   _sec = daysec;
    132   while ( _sec >= 86400 ) {
    133     _sec-=86400;
    134     _mjd++;
    135   }
    136   while ( _sec <  0 ) {
    137     _sec+=86400;
    138     _mjd--;
    139   }
    140   return *this;
    141 }
    142 
     36//
     37//////////////////////////////////////////////////////////////////////////////
    14338t_time& t_time::setmjd(double daysec, int mjd) {
    14439  _sec = daysec;
     
    15449  return *this;
    15550}
    156  
    157 t_time& t_time::setmjd(double mjddec) {
    158   _mjd = static_cast<unsigned int>(mjddec);
    159   _sec = (mjddec - _mjd)*86400.0;
    160   return *this;
     51
     52//
     53//////////////////////////////////////////////////////////////////////////////
     54void t_time::jdgp(double tjul, double & second, long & nweek) {
     55  double      deltat;
     56  deltat = tjul - 44244.0 ;
     57  nweek = (long) floor(deltat/7.0);
     58  second = (deltat - (nweek)*7.0)*86400.0;
    16159}
    16260
    163 t_time& t_time::operator++() { //prefix
    164   return (*this) += 1.0;
     61//
     62//////////////////////////////////////////////////////////////////////////////
     63unsigned int t_time::mjd() const {
     64  return _mjd;
     65}
     66 
     67//
     68//////////////////////////////////////////////////////////////////////////////
     69double t_time::daysec() const {
     70  return _sec;
    16571}
    16672
    167 t_time t_time::operator++(int) { //postfix
    168   t_time tmp = (*this);
    169   (*this) += 1.0;
    170   return tmp;
     73//
     74//////////////////////////////////////////////////////////////////////////////
     75unsigned int t_time::gpsw() const {
     76  double   gsec;
     77  long     gpsw;
     78  jdgp(_mjd, gsec, gpsw);
     79  return (int)gpsw;
    17180}
    17281
    173 t_time& t_time::operator--() { //prefix
    174   return (*this) -= 1.0;
     82//
     83//////////////////////////////////////////////////////////////////////////////
     84double t_time::gpssec() const {
     85  double   gsec;
     86  long     gpsw;
     87  jdgp(_mjd, gsec, gpsw);
     88  return gsec + _sec;
    17589}
    17690
    177 t_time t_time::operator--(int) { //postfix
    178   t_time tmp = *this;
    179   (*this) -= 1.0;
    180   return tmp;
     91//
     92//////////////////////////////////////////////////////////////////////////////
     93bool t_time::operator!=(const t_time &time1) const {
     94  if ( ((*this) - time1) != 0 ) return 1;
     95  return 0;
    18196}
    18297
     98//
     99//////////////////////////////////////////////////////////////////////////////
    183100t_time t_time::operator+(double sec) const {
    184101  int     mjd    = this->mjd();
     
    188105}
    189106
     107//
     108//////////////////////////////////////////////////////////////////////////////
    190109t_time t_time::operator-(double sec) const {
    191110  return (*this) + (-sec);
    192111}
    193112
    194 t_time& t_time::operator+=(double sec) {
    195   _sec+=sec;
    196   while ( _sec >= 86400 ) {
    197     _sec-=86400;
    198     _mjd++;
    199   }
    200   while ( _sec < 0 ) {
    201     _sec+=86400;
    202     _mjd--;
    203   }
    204   return *this;
    205 }
    206 
    207 t_time& t_time::operator-=(double sec) {
    208   return (*this)+=(-sec);
    209 }
    210 
     113//
     114//////////////////////////////////////////////////////////////////////////////
    211115double t_time::operator-(const t_time &time1) const {
    212116  int mjdDiff = this->_mjd - time1._mjd;
     
    219123}
    220124
    221 bool t_time::operator<(const t_time &time1) const {
    222   if ( ((*this) - time1) < 0 ) return 1;
    223   return 0;
    224 }
    225 
    226 bool t_time::operator<=(const t_time &time1) const {
    227   if ( ((*this) - time1) <= 0 ) return 1;
    228   return 0;
    229 }
    230 
    231 bool t_time::operator>(const t_time &time1) const {
    232   if ( ((*this) - time1) > 0 ) return 1;
    233   return 0;
    234 }
    235 
    236 bool t_time::operator>=(const t_time &time1) const {
    237   if ( ((*this) - time1) >= 0 ) return 1;
    238   return 0;
    239 }
    240 
    241 bool t_time::operator==(const t_time &time1) const {
    242   if ( ((*this) - time1) == 0 ) return 1;
    243   return 0;
    244 }
    245 
    246 bool t_time::operator!=(const t_time &time1) const {
    247   if ( ((*this) - time1) != 0 ) return 1;
    248   return 0;
    249 }
    250 
    251 void t_time::civil_datum(unsigned int &year,
    252                             unsigned int &month, unsigned int &day) const {
    253   double day_d;
    254   long int yy, mm;
    255   jmt(_mjd, yy, mm, day_d);
    256   year  = yy;
    257   month = mm;
    258   day   = static_cast<unsigned int>(day_d);
    259 }
    260 
    261 void t_time::civil_datum(int &year, int &month, int &day) const {
    262   unsigned int yy = year;
    263   unsigned int mm = month;
    264   unsigned int dd = day;
    265 
    266   civil_datum(yy, mm, dd);
    267 
    268   year = yy; month = mm; day = dd;
    269 }
    270 
     125//
     126//////////////////////////////////////////////////////////////////////////////
    271127void t_time::civil_time(unsigned int &hour, unsigned int &min,
    272128                          double &sec) const {
     
    284140}
    285141
    286 void t_time::civil_time(int &hour, int &min, double &sec) const {
    287   unsigned int hh, mm;
    288   hh = hour;
    289   mm = min;
    290 
    291   civil_time(hh, mm, sec);
    292 
    293   hour = hh; min = mm;
    294 }
    295 
    296 unsigned int t_time::year() const {
    297   unsigned int year, month, day;
    298   this->civil_datum(year, month, day);
    299   return year;
    300 }
    301 
    302 unsigned int t_time::month() const {
    303   unsigned int year, month, day;
    304   this->civil_datum(year, month, day);
    305   return month;
    306 }
    307 
    308 unsigned int t_time::day() const {
    309   unsigned int year, month, day;
    310   this->civil_datum(year, month, day);
    311   return (unsigned int)day;
    312 }
    313 
    314 unsigned int t_time::hour() const {
    315   unsigned int hour, minute;
    316   double sec;
    317   this->civil_time(hour, minute, sec);
    318   return hour;
    319 }
    320 
    321 unsigned int t_time::minute() const {
    322   unsigned int hour, minute;
    323   double sec;
    324   this->civil_time(hour, minute, sec);
    325   return minute;
    326 }
    327 
    328 double t_time::sec() const {
    329   unsigned int hour, minute;
    330   double sec;
    331   this->civil_time(hour, minute, sec);
    332   return sec;
    333 }
    334 
    335 unsigned int t_time::doy() const {
    336   return  _mjd - (int)djul(this->year(), 1, 1) + 1;
    337 }
    338 
    339 unsigned int t_time::mjd() const {
    340   return _mjd;
    341 }
    342 
    343 double t_time::mjddec() const {
    344   return _mjd + _sec / 86400.0;
    345 }
    346  
    347 double t_time::daysec() const {
    348   return _sec;
    349 }
    350 
    351 unsigned int t_time::gpsw() const {
    352   double   gsec;
    353   long     gpsw;
    354   jdgp(_mjd, gsec, gpsw);
    355   return (int)gpsw;
    356 }
    357 
    358 unsigned int t_time::dow() const {
    359   double   gsec;
    360   long     gpsw;
    361   jdgp(_mjd+_sec/86400.0, gsec, gpsw);
    362   return (unsigned int)(gsec/86400.0);
    363 }
    364 
    365 double t_time::gpssec() const {
    366   double   gsec;
    367   long     gpsw;
    368   jdgp(_mjd, gsec, gpsw);
    369   return gsec + _sec;
    370 }
    371 
    372 t_time::operator string() const {
    373   return datestr() + ' ' + timestr();
    374 }
    375 
     142//
     143//////////////////////////////////////////////////////////////////////////////
    376144string t_time::timestr(unsigned numdec, char sep) const {
    377145  ostringstream str;
     
    406174}
    407175
    408 string t_time::datestr(bool digit2year, char sep) const {
    409   ostringstream str;
    410   str.setf(ios::fixed);
    411   str << setfill('0');
    412   if (digit2year) {
    413     str << setw(2) << (year() % 100);
    414   }
    415   else {
    416     str << setw(4) << year();
    417   }
    418   if (sep) str << sep;
    419   str << setw(2) << month();
    420   if (sep) str << sep;
    421   str << setw(2) << day();
    422   return str.str();
    423 }
  • trunk/BNC/t_time.h

    r2027 r2122  
    77class t_time {
    88 public:
    9   static double djul(long j1, long m1, double tt);
    10   static double gpjd(double second, int nweek) ;
    11   static void   jdgp(double tjul, double & second, long & nweek);
    12   static void   jmt (double djul, long& jj, long& mm, double& dd);
     9  t_time() {this->reset();}
     10  t_time(int gpsw, double gpssec);
    1311
    14   t_time() {this->reset();}
    15   t_time(int gpsw, int dow, double daysec);
    16   t_time(int gpsw, double gpssec);
    17   t_time(int hour, int min, double sec, int day,  int month, int year);
    18   t_time(double daysec, int day, int month, int year);
    19   t_time(double daysec, int doy, unsigned int year);
     12  t_time& set(int gpsw, double gpssec);
    2013
    21   void reset() {_mjd = 0; _sec = 0;}
    22   bool undef() const {return (_mjd==0 && _sec==0);}
    23   bool valid() const {return (_mjd!=0 || _sec!=0);}
     14  unsigned int mjd()    const;
     15  double       daysec() const;
     16  unsigned int gpsw()   const;
     17  double       gpssec() const;
    2418
    25   t_time &  operator++();
    26   t_time    operator++(int);
     19  bool   operator!=(const t_time &time1) const;
     20  double operator-(const t_time &time1) const;
     21  t_time operator-(double sec) const;
     22  t_time operator+(double sec) const;
    2723
    28   t_time &  operator--();
    29   t_time    operator--(int);
    30 
    31   t_time    operator+(double sec) const;
    32   t_time    operator-(double sec) const;
    33 
    34   t_time&   operator+=(double sec);
    35   t_time&   operator-=(double sec);
    36 
    37   double operator-(const t_time &time1) const;
    38 
    39   bool operator< (const t_time &time1) const;
    40   bool operator<=(const t_time &time1) const;
    41   bool operator> (const t_time &time1) const;
    42   bool operator>=(const t_time &time1) const;
    43   bool operator==(const t_time &time1) const;
    44   bool operator!=(const t_time &time1) const;
    45 
    46   unsigned int  gpsw()   const;
    47   unsigned int  dow()    const;
    48   double        daysec() const;
    49   double        gpssec() const;
    50 
    51   unsigned int  doy()    const;
    52   unsigned int  mjd()    const;
    53   double        mjddec() const;
    54 
    55   unsigned int  year()   const;
    56   unsigned int  month()  const;
    57   unsigned int  day()    const;
    58   unsigned int  hour()   const;
    59   unsigned int  minute() const;
    60   double        sec()    const;
    61 
    62   void civil_datum(unsigned int& year,
    63                    unsigned int& month, unsigned int& day) const;
    64   void civil_time (unsigned int& hour, unsigned int& min,   double& sec) const;
    65   void civil_datum(int& year,
    66                    int& month, int& day) const;
    67   void civil_time (int& hour, int& min, double& sec) const;
    68  
    69   t_time& set(int gpsw, int dow, double daysec);
    70   t_time& set(int gpsw, double gpssec);
    71   t_time& set(int hour, int min, double sec, int day,  int month, int year);
    72   t_time& set(double daysec, int day, int month, int year);
    73   t_time& set(double daysec, int doy, int year);
    74   t_time& setmjd(double daysec, int mjd);
    75   t_time& setmjd(double mjddec);
    76 
    77   t_time& setmachinetime(bool gmt = false);
    78 
    79   operator std::string() const;
    80   std::string datestr(bool digit2year = false, char sep = '-') const; 
    8124  std::string timestr(unsigned numdec = 3, char sep = ':') const; 
    8225
    8326 private:
     27  t_time&     setmjd(double daysec, int mjd);
     28  void        reset() {_mjd = 0; _sec = 0;}
     29  void        civil_time (unsigned int& hour, unsigned int& min,   double& sec) const;
     30  static void jdgp(double tjul, double & second, long & nweek);
     31
    8432  unsigned int _mjd;
    8533  double       _sec;
Note: See TracChangeset for help on using the changeset viewer.