OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
JSDDateTime.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/JSDDateTime.h>
13 #include <otb/CivilDateTime.h>
14 #include <otb/JulianDate.h>
15 #include <otb/GMSTDateTime.h>
16 
17 #include <otb/Arithmetic.h>
18 
19 #include <cmath>
20 #include <cstring>
21 #include <cstdlib>
22 #include <cstdio>
23 
24 namespace ossimplugins
25 {
26 
27 
29  _day0hTU(0),
30  _second(0.0),
31  _decimal(0.0)
32 {
33 }
34 
36 {
37 }
38 
40  _day0hTU(rhs._day0hTU),
41  _second(rhs._second),
42  _decimal(rhs._decimal)
43 {
44 }
45 
46 JSDDateTime::JSDDateTime(JulianDate day0hTU, double second, double decimal):
47  _day0hTU(day0hTU),
48  _second(second),
49  _decimal(decimal)
50 {
51 }
52 
54 {
55  rhs.AsJSDDateTime(this);
56 }
57 
59 {
60  rhs.AsJSDDateTime(this);
61 }
62 
63 
65 {
66  CivilDateTime referenceCiv;
67 
68  /* Initialisation of the MJD reference day (01/01/2000, 0h00) */
69  referenceCiv.set_year(2000);
70  referenceCiv.set_month(01);
71  referenceCiv.set_day(01);
72  referenceCiv.set_second(0);
73  referenceCiv.set_decimal(0.0);
74 
75  /* JSD day of the ref. MJD date */
76  JSDDateTime referenceJSD(referenceCiv);
77 
78  /* JSD day computation */
79  JulianDate JD((double) rhs.get_day());
80 
81  _day0hTU = referenceJSD.get_day0hTU() + JD;
82  _second = referenceJSD.get_second() + (double) rhs.get_second();
83  _decimal = referenceJSD.get_decimal() + 0.000001 * (double) rhs.get_microsecond();
84 
85  this->NormDate();
86 }
87 
89 {
90  _day0hTU = rhs._day0hTU;
91  _second = rhs._second;
92  _decimal = rhs._decimal;
93 
94  return *this;
95 }
96 
98 {
100  julian->set_julianDate(jourJulien);
101 
102  return 0 ;
103 }
104 
106 {
107  const double TWOPI = 6.28318530717958647693 ;
108  const double OMEGATERRE = 6.28318530717958647693 / 86164.09054 ;
109 
110  int etat ;
111  JulianDate jourJulien;
112  double t = 0.0;
113  double tsm0hTU = 0.0;
114  double tsm = 0.0;
115  JSDDateTime date0hTU ;
116 
117 
118  date0hTU = *this ;
119  date0hTU.set_second(0);
120  date0hTU.set_decimal(0.0);
121 
122  etat = date0hTU.AsJulianDate(&jourJulien ) ;
123 
124  if (etat == 0)
125  {
126  if (GMST->get_origine() == GMSTDateTime::AN1900)
127  {
128  t = (jourJulien.get_julianDate() - 2415020.0) / 36525.0 ;
129  tsm0hTU = 23925.836 + t * (8640184.542 + t * 0.0929) ;
130  tsm0hTU = tsm0hTU * TWOPI / CivilDateTime::JOURCIVIL_LENGTH ;
131  }
132  else if (GMST->get_origine() == GMSTDateTime::AN1950)
133  {
134  t = jourJulien.get_julianDate() - 2433281.5 ;
135  tsm0hTU = 1.72944494 + t * 6.3003880987 ;
136  }
137  else if (GMST->get_origine() == GMSTDateTime::AN2000)
138  {
139  t = (jourJulien.get_julianDate() - 2451545.0) / 36525.0 ;
140  tsm0hTU = 24110.54841 + t * (8640184.812866
141  + t * (0.093103 - t * 6.210e-6)) ;
142  tsm0hTU = tsm0hTU * TWOPI / CivilDateTime::JOURCIVIL_LENGTH ;
143  }
144  t = tsm0hTU + (_second + _decimal) * OMEGATERRE ;
145  tsm = fmod (t,TWOPI) ;
146  if (tsm < 0.0)
147  {
148  tsm = tsm + TWOPI ;
149  }
150 
151  GMST->set_tms(tsm);
152  }
153 
154  return etat ;
155 }
156 
158 {
159  const double epsilon = 1.0e-12 ;
160 
161  int k, iu, iv, iw ;
162  double u, v, w, ru, rv, rw ;
163 
164 
165  w = _day0hTU.get_julianDate() - 0.5 ;
166  if (fabs (w - fnint (w)) < epsilon)
167  {
168  iw = (int)inint(w) ;
169  rw = 0.0 ;
170  }
171  else
172  {
173  iw = (int)w ;
174  rw = w - (double)iw ;
175  if ((iw < 0) && (rw != 0.0))
176  {
177  iw = iw - 1 ;
178  rw = rw + 1.0 ;
179  }
180  }
181 
183  if (fabs(v - fnint (v)) < epsilon)
184  {
185  iv = (int)inint (v) ;
186  rv = 0.0 ;
187  }
188  else
189  {
190  iv = (int)v ;
191  rv = v - (double)iv ;
192  if ((iv < 0) && (rv != 0.0))
193  {
194  iv = iv - 1 ;
195  rv = rv + 1.0 ;
196  }
197  }
198 
199  u = _decimal + rv ;
200  iu = (int)u ;
201  ru = u - (double)iu ;
202  if ((iu < 0) && (ru != 0.0))
203  {
204  iu = iu - 1 ;
205  ru = ru + 1.0 ;
206  }
207 
208  iv = iv + iu ;
209  k = iv / ((int)inint(CivilDateTime::JOURCIVIL_LENGTH)) ;
210  iw = iw + k ;
211  iv = iv - k * ((int)inint(CivilDateTime::JOURCIVIL_LENGTH)) ;
212  if (iv < 0)
213  {
214  iw = iw - 1 ;
215  iv = iv + (int)inint(CivilDateTime::JOURCIVIL_LENGTH) ;
216  }
217 
218  _decimal = ru ;
219  _second = (double)iv ;
220  _day0hTU = (double)iw + 0.5 ;
221 }
222 
223 JSDDateTime::operator JulianDate()
224 {
225  JulianDate date;
226  this->AsJulianDate(&date);
227  return date;
228 }
229 
230 JSDDateTime::operator GMSTDateTime()
231 {
232  GMSTDateTime date;
233  this->AsGMSTDateTime(&date);
234  return date;
235 }
236 }
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
double get_julianDate() const
Definition: JulianDate.h:70
unsigned long get_second()
Definition: MJDDateTime.h:56
static const double JOURCIVIL_LENGTH
This class represents an MJD date (Modified Julian date)
Definition: MJDDateTime.h:25
void set_second(int second)
~JSDDateTime()
Destructor.
Definition: JSDDateTime.cpp:35
JulianDate _day0hTU
Julian day at 0h00 UT.
Definition: JSDDateTime.h:125
int AsJSDDateTime(JSDDateTime *JSDdate)
This function converts the current CivilDateTime into JSDDateTime.
int AsGMSTDateTime(GMSTDateTime *GMST)
This function converts the current JSDDateTime into GMST Date.
void set_second(double second)
Definition: JSDDateTime.h:91
This class represents a date in the julian referential.
Definition: JulianDate.h:27
double fnint(double x)
Definition: Arithmetic.h:35
void set_decimal(double decimal)
JulianDate get_day0hTU() const
Definition: JSDDateTime.h:71
long inint(double x)
Definition: Arithmetic.h:26
void set_decimal(double decimal)
Definition: JSDDateTime.h:96
double get_second() const
Definition: JSDDateTime.h:76
unsigned long get_microsecond()
Definition: MJDDateTime.h:61
void set_julianDate(double julianDate)
Definition: JulianDate.h:65
int AsJSDDateTime(JSDDateTime *JSDdate)
This function converts the current JulianDate in JSDDateTime.
Definition: JulianDate.cpp:68
double get_decimal() const
Definition: JSDDateTime.h:81
Ori_TSM_Green get_origine()
Definition: GMSTDateTime.h:73
This class represents a date.
Definition: JSDDateTime.h:30
JSDDateTime & operator=(const JSDDateTime &rhs)
Affectation operator.
Definition: JSDDateTime.cpp:88