OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
JulianDate.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 #include <otb/CivilDateTime.h>
13 #include <otb/JulianDate.h>
14 #include <otb/JSDDateTime.h>
15 #include <otb/GMSTDateTime.h>
16 
17 
18 #include <cmath>
19 #include <cstring>
20 #include <cstdlib>
21 #include <cstdio>
22 
23 namespace ossimplugins
24 {
25 
26 
28  _julianDate(0.0)
29 {
30 }
31 
33 {
34  rhs.AsJulianDate(this);
35 }
36 
37 JulianDate::JulianDate(double julianDate):
38  _julianDate(julianDate)
39 {
40 }
41 
43 {
44  rhs.AsJulianDate(this);
45 }
46 
48 {
49 }
50 
52  _julianDate(rhs._julianDate)
53 {
54 }
55 
57 {
59  return *this;
60 }
61 
63 {
64  _julianDate += rhs._julianDate;
65  return *this;
66 }
67 
69 {
70  int k ;
71  double r ;
72 
73  k = (int)(_julianDate - 0.5) ;
74  double jJul0hTU = (double)k + 0.5;
75 
76  JSDdate->set_day0hTU (jJul0hTU);
77  r = (_julianDate - jJul0hTU) * CivilDateTime::JOURCIVIL_LENGTH ;
78  JSDdate->set_second(floor (r));
79  JSDdate->set_decimal(r - JSDdate->get_second()) ;
80 
81  return 0 ;
82 }
83 
85 {
86  const double TWOPI = 6.28318530717958647693 ;
87  const double OMEGATERRE = 6.28318530717958647693 / 86164.09054 ;
88 
89  int etat=0 , n ;
90  double j0hTU = 0.0;
91  double tsm0hTU = 0.0;
92  double t = 0.0;
93  double d = 0.0;
94  double tsm = 0.0;
95 
96 
97  n = (int)(_julianDate - 0.5) ;
98  j0hTU = (double)n + 0.5 ;
99  d = _julianDate - j0hTU ;
100 
101  if (etat == 0)
102  {
103  if (GMST->get_origine() == GMSTDateTime::AN1900)
104  {
105  t = (j0hTU - 2415020.0) / 36525.0 ;
106  tsm0hTU = 23925.836 + t * (8640184.542 + t * 0.0929) ;
107  tsm0hTU = tsm0hTU * TWOPI / CivilDateTime::JOURCIVIL_LENGTH ;
108  }
109  else if (GMST->get_origine() == GMSTDateTime::AN1950)
110  {
111  t = j0hTU - 2433281.5 ;
112  tsm0hTU = 1.72944494 + t * 6.3003880987 ;
113  }
114  else if (GMST->get_origine() == GMSTDateTime::AN2000)
115  {
116  t = (j0hTU - 2451545.0) / 36525.0 ;
117  tsm0hTU = 24110.54841 + t * (8640184.812866 + t * (0.093103 - t * 6.210e-6)) ;
118  tsm0hTU = tsm0hTU * TWOPI / CivilDateTime::JOURCIVIL_LENGTH ;
119  }
120  t = tsm0hTU + d * CivilDateTime::JOURCIVIL_LENGTH * OMEGATERRE ;
121  tsm = fmod (t,TWOPI) ;
122  if (tsm < 0.0)
123  {
124  tsm = tsm + TWOPI ;
125  }
126 
127  GMST->set_tms(tsm);
128  }
129 
130  return etat ;
131 }
132 
133 JulianDate::operator JSDDateTime()
134 {
135  JSDDateTime date;
136  AsJSDDateTime(&date);
137  return date;
138 }
139 
140 JulianDate::operator GMSTDateTime()
141 {
142  GMSTDateTime date;
143  AsGMSTDateTime(&date);
144  return date;
145 }
146 }
void set_tms(double tms)
Definition: GMSTDateTime.h:68
This class represents a date.
Definition: GMSTDateTime.h:29
int AsJulianDate(JulianDate *julian)
This function converts the current JSDDateTime into Julian Date.
Definition: JSDDateTime.cpp:97
This class represents a date and time in the civil format.
Definition: CivilDateTime.h:30
~JulianDate()
Destructor.
Definition: JulianDate.cpp:47
int AsJulianDate(JulianDate *julianDate)
This function converts the current CivilDateTime into Julian Date.
void set_day0hTU(JulianDate day)
Definition: JSDDateTime.h:86
static const double JOURCIVIL_LENGTH
int AsGMSTDateTime(GMSTDateTime *GMST)
This function converts the current JulianDate into GMSTDateTime.
Definition: JulianDate.cpp:84
void set_second(double second)
Definition: JSDDateTime.h:91
This class represents a date in the julian referential.
Definition: JulianDate.h:27
os2<< "> n<< " > nendobj n
void set_decimal(double decimal)
Definition: JSDDateTime.h:96
double get_second() const
Definition: JSDDateTime.h:76
int AsJSDDateTime(JSDDateTime *JSDdate)
This function converts the current JulianDate in JSDDateTime.
Definition: JulianDate.cpp:68
JulianDate & operator=(const JulianDate &rhs)
Affectation operator.
Definition: JulianDate.cpp:56
JulianDate & operator+(const JulianDate &rhs)
Summation operator.
Definition: JulianDate.cpp:62
Ori_TSM_Green get_origine()
Definition: GMSTDateTime.h:73
This class represents a date.
Definition: JSDDateTime.h:30
JulianDate()
constructor
Definition: JulianDate.cpp:27