General Purpose Geodetic Library
SgMJD.h
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SG_MJD_H
24 #define SG_MJD_H
25 
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 
32 #include <math.h>
33 
34 #include <QtCore/QString>
35 #include <QtCore/QDateTime>
36 
37 class QDataStream;
38 
39 
40 #include <SgMathSupport.h>
41 
42 
43 
44 class SgMJD;
45 extern const SgMJD tEphem;
46 extern const SgMJD tZero;
47 extern const SgMJD tInf;
48 extern const SgMJD tUnix0;
49 
50 
51 
52 /***===================================================================================================*/
58 class SgMJD
59 {
60 public:
61  enum Format
62  {
63  // date and time:
64  // for humans:
69  // for cylons:
85  // date only:
94  // time only:
98  };
99 
100 
101  // Statics:
107  static int calcDayNumber(int year, int month, int day);
108 
114  static double calcPartOfDay(int hour, int min, double sec);
115 
126  static void MJD_reverse(int date, double time,
127  int& nYear, int& nMonth, int& nDay, int& nHour, int& nMin, double& dSec);
128 
131  static SgMJD currentMJD();
132 
133 
134 
135  //
136  // constructors/destructors:
137  //
141  inline SgMJD();
142 
147  inline SgMJD(double epoch);
148 
153  inline SgMJD(const SgMJD& MJD);
154 
160  inline SgMJD(int nDay, double dTime);
161 
171  inline SgMJD(int nYear, int nMonth, int nDay, int nHour=0, int nMin=0, double dSec=0.0);
172 
173  inline SgMJD(const QDateTime&);
174 
178  inline ~SgMJD();
179 
180 
181 
182  //
183  // Interfaces:
184  //
187  inline SgMJD& operator=(const SgMJD& T);
188 
191  inline int getDate() const;
192 
195  inline double getTime() const;
196 
200  inline void setDate(int nDays);
201 
205  void setTime(double dTime);
206 
207  QDateTime toQDateTime() const;
208 
209 
210  //
211  // Functions:
212  //
215  inline QString className() const;
216 
219  int calcYear() const;
220 
223  int calcMonth() const;
224 
227  int calcDay() const;
228 
231  int calcDayOfYear() const;
232 
235  int calcDayOfWeek() const;
236 
239  inline int calcHour() const;
240 
243  inline int calcMin() const;
244 
247  inline double calcSec() const;
248 
249  void toYMDHMS_tr(int& nYear, int& nMonth, int& nDay, int& nHour, int& nMin, double& dSec) const;
250 
251 
252 // QString month2Str() const;
253 
256  QString dayOfWeek2Str() const;
257 
260  QString dayOfWeek2LongStr() const;
261 
270  void setUpEpoch(int year, int month, int day, int hour, int min, double sec);
271 
276  QString toString(Format format=F_Verbose) const;
277 
284  bool fromString(Format format, const QString& str, bool isReset=true);
285 
286 
287 
290  inline bool operator==(const SgMJD& T) const;
291 
294  inline bool operator!=(const SgMJD& T) const;
295 
298  SgMJD& operator+=(double days);
299 
302  SgMJD& operator-=(double days);
303 
306  inline double toDouble() const;
307 
308  SgMJD toUtc() const;
309  SgMJD toLocal() const;
310 
311  double gmst() const;
312 
313 
314  //
315  // Friends:
316  //
319  inline friend double operator-(const SgMJD& T1, const SgMJD& T2);
320 
323  inline friend bool operator<(const SgMJD& T1, const SgMJD& T2);
324 
327  inline friend bool operator>(const SgMJD& T1, const SgMJD& T2);
328 
331  inline friend bool operator<=(const SgMJD& T1, const SgMJD& T2);
332 
335  inline friend bool operator>=(const SgMJD& T1, const SgMJD& T2);
336 
339  inline friend SgMJD operator+(const SgMJD& T, double dT);
340 
343  inline friend SgMJD operator-(const SgMJD& T, double dT);
344 
345  //
346  // I/O:
347  //
349 
351 
352 
353 private:
354  int date_;
355  double time_;
356 
359  void normalize();
360 
361 protected:
362  static const char *shortMonthNames_[];
363  static const char *longMonthNames_[];
364  static const char *shortWeekdayNames_[];
365  static const char *longWeekdayNames_[];
366 };
367 /*=====================================================================================================*/
368 
369 
370 
371 
372 
373 
374 
375 
376 /*=====================================================================================================*/
377 /* */
378 /* SgMJD inline members: */
379 /* */
380 /*=====================================================================================================*/
381 //
382 //
383 // CONSTRUCTORS:
384 //
385 // An empty constructor:
386 inline SgMJD::SgMJD()
387 {
388  date_ = 0;
389  time_ = 0.0;
390 };
391 
392 
393 
394 // A regular constructor:
395 inline SgMJD::SgMJD(double epoch)
396 {
397  date_ = (int)floor(epoch);
398  time_ = epoch - (double) date_;
399 };
400 
401 
402 
403 // Another constructor:
404 inline SgMJD::SgMJD(int nDay, double dTime)
405 {
406  date_ = nDay + (int)trunc(dTime);
407  time_ = dTime>=1.0? dTime-trunc(dTime) : dTime;
408 };
409 
410 
411 
412 // A copying constructor:
413 inline SgMJD::SgMJD(const SgMJD& T)
414 {
415  date_ = T.date_;
416  time_ = T.time_;
417 };
418 
419 
420 
421 // Constructor too:
422 inline SgMJD::SgMJD(int nYear, int nMonth, int nDay, int nHour, int nMin, double dSec)
423 {
424  setUpEpoch(nYear, nMonth, nDay, nHour, nMin, dSec);
425 };
426 
427 
428 
429 inline SgMJD::SgMJD(const QDateTime& d)
430 {
431  setUpEpoch(d.date().year(), d.date().month(), d.date().day(),
432  d.time().hour(), d.time().minute(), d.time().second() + d.time().msec()/1000.0);
433 };
434 
435 
436 
437 // A destructor:
439 {
440  // nothing to do
441 };
442 
443 
444 
445 //
446 // INTERFACES:
447 //
448 // returns number of MJDays
449 inline int SgMJD::getDate() const
450 {
451  return date_;
452 };
453 
454 
455 
456 // returns fractional part of a day:
457 inline double SgMJD::getTime() const
458 {
459  return time_;
460 };
461 
462 
463 
464 //
465 inline void SgMJD::setDate(int nDays)
466 {
467  date_ = nDays;
468 };
469 
470 
471 
472 //
473 inline SgMJD& SgMJD::operator=(const SgMJD& T)
474 {
475  date_ = T.date_;
476  time_ = T.time_;
477  return *this;
478 };
479 
480 
481 
482 
483 //
484 // FUNCTIONS:
485 //
486 //
487 //
488 inline QString SgMJD::className() const
489 {
490  return "SgMJD";
491 };
492 
493 
494 //
495 inline int SgMJD::calcHour() const
496 {
497  return (int)(time_*DAY2SEC/3600.0);
498 };
499 
500 
501 //
502 inline int SgMJD::calcMin() const
503 {
504  return (int)((time_*DAY2SEC - 3600.0*calcHour())/60.0);
505 };
506 
507 
508 //
509 inline double SgMJD::calcSec() const
510 {
511  return time_*DAY2SEC - 3600.0*calcHour() - 60.0*calcMin();
512 };
513 
514 
515 
516 //
517 inline bool SgMJD::operator==(const SgMJD& T) const
518 {
519  return T.date_==date_ && T.time_==time_;
520 };
521 
522 
523 
524 //
525 inline bool SgMJD::operator!=(const SgMJD& T) const
526 {
527  return T.date_!=date_ || T.time_!=time_;
528 };
529 
530 
531 
532 // explicit type conversion:
533 inline double SgMJD::toDouble() const
534 {
535  return date_ + time_;
536 };
537 
538 
539 
540 
541 //
542 // FRIENDS:
543 //
544 //
545 //
546 inline double operator-(const SgMJD& T1, const SgMJD& T2)
547 {
548  return (T1.date_-T2.date_) + (T1.time_-T2.time_);
549 };
550 
551 
552 
553 //
554 inline bool operator<(const SgMJD& T1, const SgMJD& T2)
555 {
556  if (T1.date_ < T2.date_)
557  return true;
558  return T1.date_==T2.date_? T1.time_<T2.time_ : false;
559 };
560 
561 
562 
563 //
564 inline bool operator<=(const SgMJD& T1, const SgMJD& T2)
565 {
566  if (T1.date_ < T2.date_)
567  return true;
568  return T1.date_==T2.date_? T1.time_<=T2.time_ : false;
569 };
570 
571 
572 
573 //
574 inline bool operator>(const SgMJD& T1, const SgMJD& T2)
575 {
576  if (T1.date_ > T2.date_)
577  return true;
578  return T1.date_==T2.date_? T1.time_>T2.time_ : false;
579 };
580 
581 
582 
583 //
584 inline bool operator>=(const SgMJD& T1, const SgMJD& T2)
585 {
586  if (T1.date_ > T2.date_)
587  return true;
588  return T1.date_==T2.date_? T1.time_>=T2.time_ : false;
589 };
590 
591 
592 
593 //
594 inline SgMJD operator+(const SgMJD& T, double dT)
595 {
596  return SgMJD(T)+=dT;
597 };
598 
599 
600 
601 //
602 inline SgMJD operator-(const SgMJD& T, double dT)
603 {
604  return SgMJD(T)-=dT;
605 };
606 
607 
608 /*=====================================================================================================*/
609 
610 
611 
612 
613 
614 /*=====================================================================================================*/
615 //
616 // aux functions:
617 //
621 QString interval2Str(double days);
622 
623 
624 /*=====================================================================================================*/
625 #endif //SG_MJD_H
QString interval2Str(double days)
Definition: SgMJD.cpp:1370
bool operator<(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:554
bool operator>=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:584
const SgMJD tZero
SgMJD operator+(const SgMJD &T, double dT)
Definition: SgMJD.h:594
const SgMJD tInf
const SgMJD tEphem
const SgMJD tUnix0
double operator-(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:546
bool operator>(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:574
bool operator<=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:564
#define DAY2SEC
radians to mas:
Definition: SgMathSupport.h:56
Definition: SgMJD.h:59
friend bool operator<(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:554
SgMJD & operator=(const SgMJD &T)
Definition: SgMJD.h:473
friend bool operator>=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:584
QString dayOfWeek2LongStr() const
Definition: SgMJD.cpp:1212
bool fromString(Format format, const QString &str, bool isReset=true)
Definition: SgMJD.cpp:267
int date_
Definition: SgMJD.h:354
double getTime() const
Definition: SgMJD.h:457
friend SgMJD operator+(const SgMJD &T, double dT)
Definition: SgMJD.h:594
void setTime(double dTime)
Definition: SgMJD.cpp:165
Format
Definition: SgMJD.h:62
@ F_Verbose
Definition: SgMJD.h:65
@ F_FS_LOG
Another version from spoolfile format: 2012.01.20-09:32:00.960.
Definition: SgMJD.h:79
@ F_SOLVE_SPLFL_LONG
Another version from spoolfile format: 12/01/20 00:02.
Definition: SgMJD.h:78
@ F_YYYYMMDD
Another format for a date: 02 Apr, 2010.
Definition: SgMJD.h:88
@ F_yyyymmdd
Date in digits: 2010 04 02.
Definition: SgMJD.h:89
@ F_YYYYMMDDHHMMSSSS
Long verbose: Fri, the 2nd of Apr, 2010; 17hr 02min 43.6400sec.
Definition: SgMJD.h:67
@ F_SOLVE_SPLFL_SHORT
Another spoolfile represenation of epoch: 2012.01.20-09:14:28.05.
Definition: SgMJD.h:77
@ F_DDMonYYYY
Date: 2010 Apr 02.
Definition: SgMJD.h:87
@ F_ECCDAT
Digits, MJD and seconds : 055288:61363.6400.
Definition: SgMJD.h:73
@ F_YYYYMMDDDD
Digits, date and seconds: 20100402613636.
Definition: SgMJD.h:71
@ F_RFC2822
ISO date format realized by Qt (Qt::ISODate)
Definition: SgMJD.h:84
@ F_SINEX
UNUX seconds: 1270227763.6400.
Definition: SgMJD.h:82
@ F_VerboseLong
Verbose output: 02 Apr, 2010; 17:02:43.6400.
Definition: SgMJD.h:66
@ F_SINEX_S
Year: 2010.25.
Definition: SgMJD.h:93
@ F_YYYYMonDD
Date in digits: 2010.04.02.
Definition: SgMJD.h:90
@ F_UNIX
Just MJD: 55288.7102.
Definition: SgMJD.h:81
@ F_YYMonDD
Date, short: 2016Mar01.
Definition: SgMJD.h:91
@ F_MJD
Field System logs: 2020.195.11:15:34.11.
Definition: SgMJD.h:80
@ F_YYYYMMDDSSSSSS
Digits: 2010/04/02 17:02:43.
Definition: SgMJD.h:70
@ F_ISO
SINEX format: 10:092:61364.
Definition: SgMJD.h:83
@ F_HHMMSS
Just time: 17:02:43.6.
Definition: SgMJD.h:96
@ F_SOLVE_SPLFL_V2
A spoolfile represenation of epoch: 2012.01.20-09:14:28.
Definition: SgMJD.h:75
@ F_Simple
Digits: 2010/04/02 17:02:43.6.
Definition: SgMJD.h:68
@ F_Date
RFC2822 date format realized by Qt (Qt::RFC2822Date)
Definition: SgMJD.h:86
@ F_SOLVE_SPLFL_V3
Another spoolfile represenation of epoch: 2012.01.20-09:14:28.0.
Definition: SgMJD.h:76
@ F_SOLVE_SPLFL
That was used in ECC.dat files: 2010.04.02-17.02.
Definition: SgMJD.h:74
@ F_Year
Date, more shortly: 10Apr02.
Definition: SgMJD.h:92
@ F_Time
SINEX, short version: 10:092.
Definition: SgMJD.h:95
@ F_TimeShort
Time, seconds are integer: 17:02:43.
Definition: SgMJD.h:97
@ F_INTERNAL
Digits, date and time: 20100402.71.
Definition: SgMJD.h:72
QString className() const
Definition: SgMJD.h:488
SgMJD toUtc() const
Definition: SgMJD.cpp:1229
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1007
double toDouble() const
Definition: SgMJD.h:533
static const char * shortMonthNames_[]
Definition: SgMJD.h:362
static const char * longWeekdayNames_[]
Definition: SgMJD.h:365
bool saveIntermediateResults(QDataStream &) const
Definition: SgMJD.cpp:1314
void toYMDHMS_tr(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec) const
Definition: SgMJD.cpp:1305
static const char * shortWeekdayNames_[]
Definition: SgMJD.h:364
bool operator!=(const SgMJD &T) const
Definition: SgMJD.h:525
double time_
integer part of the epoch;
Definition: SgMJD.h:355
bool loadIntermediateResults(QDataStream &)
Definition: SgMJD.cpp:1329
static int calcDayNumber(int year, int month, int day)
Definition: SgMJD.cpp:51
int getDate() const
Definition: SgMJD.h:449
void normalize()
part of the day, in days.
Definition: SgMJD.cpp:134
double gmst() const
Definition: SgMJD.cpp:1263
bool operator==(const SgMJD &T) const
Definition: SgMJD.h:517
int calcHour() const
Definition: SgMJD.h:495
int calcDayOfYear() const
Definition: SgMJD.cpp:237
~SgMJD()
Definition: SgMJD.h:438
static SgMJD currentMJD()
Definition: SgMJD.cpp:118
int calcDay() const
Definition: SgMJD.cpp:226
SgMJD & operator-=(double days)
Definition: SgMJD.cpp:189
static double calcPartOfDay(int hour, int min, double sec)
Definition: SgMJD.cpp:41
int calcDayOfWeek() const
Definition: SgMJD.cpp:245
void setUpEpoch(int year, int month, int day, int hour, int min, double sec)
Definition: SgMJD.cpp:254
SgMJD()
Definition: SgMJD.h:386
int calcMin() const
Definition: SgMJD.h:502
static void MJD_reverse(int date, double time, int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec)
Definition: SgMJD.cpp:74
friend double operator-(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:546
static const char * longMonthNames_[]
Definition: SgMJD.h:363
SgMJD & operator+=(double days)
Definition: SgMJD.cpp:174
void setDate(int nDays)
Definition: SgMJD.h:465
friend bool operator>(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:574
SgMJD toLocal() const
Definition: SgMJD.cpp:1246
QDateTime toQDateTime() const
Definition: SgMJD.cpp:151
friend bool operator<=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:564
double calcSec() const
Definition: SgMJD.h:509
QString dayOfWeek2Str() const
Definition: SgMJD.cpp:1195
int calcMonth() const
Definition: SgMJD.cpp:215
int calcYear() const
Definition: SgMJD.cpp:204