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 /* SgMJD inline members: */
377 /* */
378 /*=====================================================================================================*/
379 //
380 //
381 // CONSTRUCTORS:
382 //
383 // An empty constructor:
384 inline SgMJD::SgMJD()
385 {
386  date_ = 0;
387  time_ = 0.0;
388 };
389 
390 
391 
392 // A regular constructor:
393 inline SgMJD::SgMJD(double epoch)
394 {
395  date_ = (int)floor(epoch);
396  time_ = epoch - (double) date_;
397 };
398 
399 
400 
401 // Another constructor:
402 inline SgMJD::SgMJD(int nDay, double dTime)
403 {
404  date_ = nDay + (int)trunc(dTime);
405  time_ = dTime>=1.0? dTime-trunc(dTime) : dTime;
406 };
407 
408 
409 
410 // A copying constructor:
411 inline SgMJD::SgMJD(const SgMJD& T)
412 {
413  date_ = T.date_;
414  time_ = T.time_;
415 };
416 
417 
418 
419 // Constructor too:
420 inline SgMJD::SgMJD(int nYear, int nMonth, int nDay, int nHour, int nMin, double dSec)
421 {
422  setUpEpoch(nYear, nMonth, nDay, nHour, nMin, dSec);
423 };
424 
425 
426 
427 inline SgMJD::SgMJD(const QDateTime& d)
428 {
429  setUpEpoch(d.date().year(), d.date().month(), d.date().day(),
430  d.time().hour(), d.time().minute(), d.time().second() + d.time().msec()/1000.0);
431 };
432 
433 
434 
435 // A destructor:
437 {
438  // nothing to do
439 };
440 
441 
442 
443 //
444 // INTERFACES:
445 //
446 // returns number of MJDays
447 inline int SgMJD::getDate() const
448 {
449  return date_;
450 };
451 
452 
453 
454 // returns fractional part of a day:
455 inline double SgMJD::getTime() const
456 {
457  return time_;
458 };
459 
460 
461 
462 //
463 inline void SgMJD::setDate(int nDays)
464 {
465  date_ = nDays;
466 };
467 
468 
469 
470 //
471 inline SgMJD& SgMJD::operator=(const SgMJD& T)
472 {
473  date_ = T.date_;
474  time_ = T.time_;
475  return *this;
476 };
477 
478 
479 
480 
481 //
482 // FUNCTIONS:
483 //
484 //
485 //
486 inline QString SgMJD::className() const
487 {
488  return "SgMJD";
489 };
490 
491 
492 //
493 inline int SgMJD::calcHour() const
494 {
495  return (int)(time_*DAY2SEC/3600.0);
496 };
497 
498 
499 //
500 inline int SgMJD::calcMin() const
501 {
502  return (int)((time_*DAY2SEC - 3600.0*calcHour())/60.0);
503 };
504 
505 
506 //
507 inline double SgMJD::calcSec() const
508 {
509  return time_*DAY2SEC - 3600.0*calcHour() - 60.0*calcMin();
510 };
511 
512 
513 
514 //
515 inline bool SgMJD::operator==(const SgMJD& T) const
516 {
517  return T.date_==date_ && T.time_==time_;
518 };
519 
520 
521 
522 //
523 inline bool SgMJD::operator!=(const SgMJD& T) const
524 {
525  return T.date_!=date_ || T.time_!=time_;
526 };
527 
528 
529 
530 // explicit type conversion:
531 inline double SgMJD::toDouble() const
532 {
533  return date_ + time_;
534 };
535 
536 
537 
538 
539 //
540 // FRIENDS:
541 //
542 //
543 //
544 inline double operator-(const SgMJD& T1, const SgMJD& T2)
545 {
546  return (T1.date_-T2.date_) + (T1.time_-T2.time_);
547 };
548 
549 
550 
551 //
552 inline bool operator<(const SgMJD& T1, const SgMJD& T2)
553 {
554  if (T1.date_ < T2.date_)
555  return true;
556  return T1.date_==T2.date_? T1.time_<T2.time_ : false;
557 };
558 
559 
560 
561 //
562 inline bool operator<=(const SgMJD& T1, const SgMJD& T2)
563 {
564  if (T1.date_ < T2.date_)
565  return true;
566  return T1.date_==T2.date_? T1.time_<=T2.time_ : false;
567 };
568 
569 
570 
571 //
572 inline bool operator>(const SgMJD& T1, const SgMJD& T2)
573 {
574  if (T1.date_ > T2.date_)
575  return true;
576  return T1.date_==T2.date_? T1.time_>T2.time_ : false;
577 };
578 
579 
580 
581 //
582 inline bool operator>=(const SgMJD& T1, const SgMJD& T2)
583 {
584  if (T1.date_ > T2.date_)
585  return true;
586  return T1.date_==T2.date_? T1.time_>=T2.time_ : false;
587 };
588 
589 
590 
591 //
592 inline SgMJD operator+(const SgMJD& T, double dT)
593 {
594  return SgMJD(T)+=dT;
595 };
596 
597 
598 
599 //
600 inline SgMJD operator-(const SgMJD& T, double dT)
601 {
602  return SgMJD(T)-=dT;
603 };
604 
605 
606 /*=====================================================================================================*/
607 
608 
609 
610 
611 
612 /*=====================================================================================================*/
613 //
614 // aux functions:
615 //
619 QString interval2Str(double days);
620 
621 
622 /*=====================================================================================================*/
623 #endif //SG_MJD_H
QString interval2Str(double days)
Definition: SgMJD.cpp:1371
bool operator<(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:552
bool operator>=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:582
const SgMJD tZero
SgMJD operator+(const SgMJD &T, double dT)
Definition: SgMJD.h:592
const SgMJD tInf
const SgMJD tEphem
const SgMJD tUnix0
double operator-(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:544
bool operator>(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:572
bool operator<=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:562
#define DAY2SEC
radians to mas:
Definition: SgMathSupport.h:69
Definition: SgMJD.h:59
friend bool operator<(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:552
SgMJD & operator=(const SgMJD &T)
Definition: SgMJD.h:471
friend bool operator>=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:582
QString dayOfWeek2LongStr() const
Definition: SgMJD.cpp:1213
bool fromString(Format format, const QString &str, bool isReset=true)
Definition: SgMJD.cpp:268
int date_
Definition: SgMJD.h:354
double getTime() const
Definition: SgMJD.h:455
friend SgMJD operator+(const SgMJD &T, double dT)
Definition: SgMJD.h:592
void setTime(double dTime)
Definition: SgMJD.cpp:166
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:486
SgMJD toUtc() const
Definition: SgMJD.cpp:1230
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1008
double toDouble() const
Definition: SgMJD.h:531
static const char * shortMonthNames_[]
Definition: SgMJD.h:362
static const char * longWeekdayNames_[]
Definition: SgMJD.h:365
bool saveIntermediateResults(QDataStream &) const
Definition: SgMJD.cpp:1315
void toYMDHMS_tr(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec) const
Definition: SgMJD.cpp:1306
static const char * shortWeekdayNames_[]
Definition: SgMJD.h:364
bool operator!=(const SgMJD &T) const
Definition: SgMJD.h:523
double time_
integer part of the epoch;
Definition: SgMJD.h:355
bool loadIntermediateResults(QDataStream &)
Definition: SgMJD.cpp:1330
static int calcDayNumber(int year, int month, int day)
Definition: SgMJD.cpp:52
int getDate() const
Definition: SgMJD.h:447
void normalize()
part of the day, in days.
Definition: SgMJD.cpp:135
double gmst() const
Definition: SgMJD.cpp:1264
bool operator==(const SgMJD &T) const
Definition: SgMJD.h:515
int calcHour() const
Definition: SgMJD.h:493
int calcDayOfYear() const
Definition: SgMJD.cpp:238
~SgMJD()
Definition: SgMJD.h:436
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
int calcDay() const
Definition: SgMJD.cpp:227
SgMJD & operator-=(double days)
Definition: SgMJD.cpp:190
static double calcPartOfDay(int hour, int min, double sec)
Definition: SgMJD.cpp:42
int calcDayOfWeek() const
Definition: SgMJD.cpp:246
void setUpEpoch(int year, int month, int day, int hour, int min, double sec)
Definition: SgMJD.cpp:255
SgMJD()
Definition: SgMJD.h:384
int calcMin() const
Definition: SgMJD.h:500
static void MJD_reverse(int date, double time, int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec)
Definition: SgMJD.cpp:75
friend double operator-(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:544
static const char * longMonthNames_[]
Definition: SgMJD.h:363
SgMJD & operator+=(double days)
Definition: SgMJD.cpp:175
void setDate(int nDays)
Definition: SgMJD.h:463
friend bool operator>(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:572
SgMJD toLocal() const
Definition: SgMJD.cpp:1247
QDateTime toQDateTime() const
Definition: SgMJD.cpp:152
friend bool operator<=(const SgMJD &T1, const SgMJD &T2)
Definition: SgMJD.h:562
double calcSec() const
Definition: SgMJD.h:507
QString dayOfWeek2Str() const
Definition: SgMJD.cpp:1196
int calcMonth() const
Definition: SgMJD.cpp:216
int calcYear() const
Definition: SgMJD.cpp:205