XTime.h
1 |
//----------------------------------------------------------------------
|
---|---|
2 |
//
|
3 |
//RCS: $Id: XTime.h,v 1.2 2007-08-27 21:30:59 aldcroft Exp $
|
4 |
// File Name : XTime.h
|
5 |
// Subsystem : XFF
|
6 |
// Programmer : Arnold Rots, SAO
|
7 |
// Description : XTime, XTimeRange, and XTRList classes
|
8 |
//
|
9 |
// Make manpage:
|
10 |
// genman -h -e -t -oXTime.3 XTime.h
|
11 |
// troff -man XTime.3 | /usr/lib/lp/postscript/dpost -n2 | lpr3dup
|
12 |
//
|
13 |
// .NAME XTime - XTime, XTimeRange, and XTRList classes
|
14 |
// .LIBRARY Util
|
15 |
// .HEADER Time transformations and manipulations
|
16 |
// .INCLUDE XTime.h
|
17 |
// .FILE XTime.C
|
18 |
//
|
19 |
// .SECTION AUTHOR
|
20 |
// Arnold Rots,
|
21 |
// USRA/SAO,
|
22 |
// <arots@head-cfa.harvard.edu>
|
23 |
//
|
24 |
// .SECTION DESCRIPTION
|
25 |
// XTime allows transformations between four time systems in six
|
26 |
// formats. The time systems are MET, TT, TAI, and UTC.
|
27 |
// The formats:
|
28 |
// seconds, MJD, JD (all three: double or long+double),
|
29 |
// date string ("yyyy:ddd:hh:mm:ss.ss..."),
|
30 |
// calendar date string ("yyyyMondd at hh:mm:ss.ss..."),
|
31 |
// and FITS date/time string ("yyyy-mm-ddThh:mm:ss.ss...").
|
32 |
//
|
33 |
// The method getDate allows specifying the number of decimals.
|
34 |
// The time system-specific methods return integer seconds.
|
35 |
// A time correction term is optional. MET is elapsed seconds
|
36 |
// since MJDref (default: 1998-01-01T00:00:00(TT)). Note that if
|
37 |
// MJDref is specified explicitly, it will be assumed to be in
|
38 |
// the time system specified in the constructor or set call.
|
39 |
//
|
40 |
// XTimeRange is an aggregate of two XTime objects and an EMPTY
|
41 |
// indicator. An XTimeRange is considered empty if either the
|
42 |
// start or stop MET is non-positive, or if the start time is
|
43 |
// later than the stop time.
|
44 |
//
|
45 |
// An XTRList is a list of XTimeRanges; it includes methods to
|
46 |
// perform logical AND and OR operations between XTRLists and
|
47 |
// between XTRLists and XTimeRanges.
|
48 |
//
|
49 |
// Note that all instances of XTime will have one private member
|
50 |
// that holds the date strings. It is the user's responsibility
|
51 |
// to copy the string returned by any of the date string methods,
|
52 |
// since the next call will overwrite it. Especially, avoid
|
53 |
// generating more than one date string for the same object in a
|
54 |
// single statement, such as:
|
55 |
//
|
56 |
// cout << "Time : " << t.TTDate() << " or " << t.TTCalDate() << endl ;
|
57 |
//
|
58 |
// Leap seconds are taken from tai-utc.dat. If not available:
|
59 |
// Included leap seconds: 1972 through 1999 (leap seconds 10
|
60 |
// through 32).
|
61 |
//
|
62 |
// .VERSION $Revision: 1.2 $
|
63 |
//
|
64 |
//----------------------------------------------------------------------
|
65 |
//
|
66 |
|
67 |
#ifndef XTIME_H
|
68 |
#define XTIME_H
|
69 |
#include <time.h> |
70 |
|
71 |
|
72 |
//
|
73 |
// ---------
|
74 |
// -- XTime --
|
75 |
// ---------
|
76 |
//
|
77 |
|
78 |
class XTime { |
79 |
|
80 |
//* Private attributes
|
81 |
|
82 |
long MJDint ; // Integer part of time |
83 |
double MJDfr ; // Fractional part of time |
84 |
double timeZero ; // Time correction term in d |
85 |
char tdate[32] ; // Date string |
86 |
long MJDrefint ; // MJDref (integer part) |
87 |
double MJDreffr ; // MJDref (fractional part) |
88 |
int leapflag ; // Indicator whether we are in a leap second |
89 |
double myLeaps ; // Leap seconds at this time |
90 |
double refLeaps ; // Leap seconds at reference epoch |
91 |
|
92 |
//* Static attributes
|
93 |
|
94 |
static const double MJD0 ; // JD - MJD |
95 |
static const long MJD1972 ; // MJD at 1972 |
96 |
static const double DAY2SEC ; // Seconds per day |
97 |
static const double SEC2DAY ; // Inverse seconds per day |
98 |
static const long MJDREFint ; // MJD at 1998.0 (integer part) |
99 |
static const double MJDREFfr ; // MJD at 1998.0 (fractional part) |
100 |
static const double REFLEAPS ; // Leap seconds at default MJDREF (1998.0 TT) |
101 |
static const double TAI2TT ; // TT - TAI |
102 |
static int NUMLEAPSECS ; // Number of leap seconds |
103 |
static long LEAPSMJD[100] ; // Leap second dates |
104 |
static double LEAPSECS[100] ; // Leap seconds |
105 |
static time_t WALLCLOCK0 ; // Wallclock time when leap seconds were read |
106 |
static int NUMOBJECTS ; // Number of XTime objects instantiated |
107 |
|
108 |
public:
|
109 |
|
110 |
//* Enumeration types
|
111 |
|
112 |
enum TimeSys {MET, TT, UTC, TAI} ;
|
113 |
enum TimeFormat {SECS, JD, MJD, DATE, CALDATE, FITS} ;
|
114 |
|
115 |
//* Private methods
|
116 |
|
117 |
private:
|
118 |
|
119 |
const char* monDay (const char* date, TimeFormat tf) ; |
120 |
void setleaps (double dt=5000000.0) ; |
121 |
int setmyleaps (double *leapval, long mjdi, double mjdf) ; |
122 |
|
123 |
//* Public methods
|
124 |
|
125 |
public:
|
126 |
|
127 |
//* Constructors
|
128 |
|
129 |
XTime (void) ;
|
130 |
XTime (double tt) ;
|
131 |
XTime (double tt, TimeSys ts, TimeFormat tf=SECS,
|
132 |
long mjdi=0, double mjdf=0.0) ; |
133 |
XTime (long tti, double ttf, TimeSys ts=TT, TimeFormat tf=MJD, |
134 |
long mjdi=0, double mjdf=0.0) ; |
135 |
XTime (const char* date, TimeSys ts=UTC, TimeFormat tf=DATE, |
136 |
long mjdi=0, double mjdf=0.0) ; |
137 |
|
138 |
//* Destructor
|
139 |
|
140 |
~XTime (void) ;
|
141 |
|
142 |
//* Set methods
|
143 |
|
144 |
void setLeaps (double dt=5000000.0) ; |
145 |
void set (double tt, TimeSys ts=MET, TimeFormat tf=SECS, |
146 |
long mjdi=0, double mjdf=0.0) ; |
147 |
void set (long tti, double ttf, TimeSys ts=TT, TimeFormat tf=MJD, |
148 |
long mjdi=0, double mjdf=0.0) ; |
149 |
void set (const char* date, TimeSys ts=UTC, TimeFormat tf=DATE, |
150 |
long mjdi=0, double mjdf=0.0) ; |
151 |
void setTZero (double tz) ; |
152 |
|
153 |
//* Get methods
|
154 |
|
155 |
double get (TimeSys ts=TT, TimeFormat tf=SECS) const ; |
156 |
double mjd (long *mjdi, double *mjdf, TimeSys ts=TT) const ; |
157 |
double getMET (void) const ; |
158 |
double getTT (void) const ; |
159 |
double getTAI (void) const ; |
160 |
double getUTC (void) const ; |
161 |
double getTZero (void) const ; |
162 |
const char* getDate (TimeSys ts=UTC, TimeFormat tf=DATE, int dec=0) ; |
163 |
const char* UTDate (void) ; |
164 |
const char* TTDate (void) ; |
165 |
const char* TAIDate (void) ; |
166 |
const char* UTCalDate (void) ; |
167 |
const char* TTCalDate (void) ; |
168 |
const char* TAICalDate (void) ; |
169 |
const char* UTFITS (void) ; |
170 |
const char* TTFITS (void) ; |
171 |
const char* TAIFITS (void) ; |
172 |
double UTmjd (void) const ; |
173 |
double TTmjd (void) const ; |
174 |
double TAImjd (void) const ; |
175 |
double UTmjd (long *mjdi, double *mjdf) const ; |
176 |
double TTmjd (long *mjdi, double *mjdf) const ; |
177 |
double TAImjd (long *mjdi, double *mjdf) const ; |
178 |
double UTjd (void) const ; |
179 |
double TTjd (void) const ; |
180 |
double TAIjd (void) const ; |
181 |
int numObjects (void) ; |
182 |
int leapSecs (const double** secs) const ; |
183 |
|
184 |
} ; |
185 |
|
186 |
// Description:
|
187 |
// long MJDint ; // Integer part of time
|
188 |
// double MJDfr ; // Fractional part of time
|
189 |
// double timeZero ; // Time correction term in d
|
190 |
// char tdate[32] ; // Date string
|
191 |
// long MJDrefint ; // MJDref (integer part)
|
192 |
// double MJDreffr ; // MJDref (fractional part)
|
193 |
// int leapflag ; // Indicator whether we are in a leap second
|
194 |
// double myLeaps ; // Leap seconds at this time
|
195 |
// double refLeaps ; // Leap seconds at reference epoch
|
196 |
// Constructor: default constructor; set time to zero.
|
197 |
inline XTime::XTime (void) |
198 |
: MJDint (MJDREFint), MJDfr (MJDREFfr), timeZero (0.0), |
199 |
MJDrefint (MJDREFint), MJDreffr (MJDREFfr), |
200 |
leapflag (0), myLeaps (REFLEAPS), refLeaps (REFLEAPS)
|
201 |
{ setleaps() ; } |
202 |
|
203 |
// Description:
|
204 |
// Constructor: create from MET seconds (tt).
|
205 |
inline XTime::XTime (double tt) |
206 |
: MJDint (MJDREFint), MJDfr (MJDREFfr+tt*SEC2DAY), timeZero (0.0), |
207 |
MJDrefint (MJDREFint), MJDreffr (MJDREFfr), |
208 |
leapflag (0), refLeaps (REFLEAPS)
|
209 |
{ |
210 |
setleaps() ; |
211 |
leapflag = setmyleaps (&myLeaps, MJDint, MJDfr) ; |
212 |
} |
213 |
|
214 |
// Description:
|
215 |
// Constructor: create from seconds, MJD, or JD (tt); specified
|
216 |
// by ts and tf; allows specification of MJDREF (mjdi+mjdf).
|
217 |
// Default for ts is MET; default for tf is SECS; default for
|
218 |
// mjdi is 0 (i.e., default value); default for mjdf is 0.0.
|
219 |
inline XTime::XTime (double tt, TimeSys ts, TimeFormat tf, |
220 |
long mjdi, double mjdf) |
221 |
: timeZero (0.0), MJDrefint (MJDREFint), MJDreffr (MJDREFfr), |
222 |
leapflag (0), refLeaps (REFLEAPS)
|
223 |
{ |
224 |
setleaps() ; |
225 |
set (tt, ts, tf, mjdi, mjdf) ; |
226 |
} |
227 |
|
228 |
// Description:
|
229 |
// Constructor: most general constructor; create from seconds,
|
230 |
// MJD, or JD (tti+ttf); specified by ts and tf; allows
|
231 |
// specification of MJD reference (mjdi+mjdf).
|
232 |
// Default for ts is TT; default for tf is MJD; default for
|
233 |
// mjdi is 0 (i.e., default value); default for mjdf is 0.0.
|
234 |
inline XTime::XTime (long tti, double ttf, TimeSys ts, TimeFormat tf, |
235 |
long mjdi, double mjdf) |
236 |
: timeZero (0.0), MJDrefint (MJDREFint), MJDreffr (MJDREFfr), |
237 |
leapflag (0), refLeaps (REFLEAPS)
|
238 |
{ |
239 |
setleaps() ; |
240 |
set (tti, ttf, ts, tf, mjdi, mjdf) ; |
241 |
} |
242 |
|
243 |
// Description:
|
244 |
// Constructor: create from a date string; create from DATE,
|
245 |
// CALDATE, or FITSDATE (date); specified by ts and tf; allows
|
246 |
// specification of MJD reference (mjdi+mjdf).
|
247 |
// Default for ts is UTC, for tf is DATE; default for mjdi is 0
|
248 |
// (i.e., default value); default for mjdf is 0.0.
|
249 |
inline XTime::XTime (const char* date, TimeSys ts, TimeFormat tf, |
250 |
long mjdi, double mjdf) |
251 |
: timeZero (0.0), MJDrefint (MJDREFint), MJDreffr (MJDREFfr), leapflag (0), refLeaps (31.0) |
252 |
{ |
253 |
setleaps() ; |
254 |
set (date, ts, tf, mjdi, mjdf) ; |
255 |
} |
256 |
|
257 |
// Description:
|
258 |
// Destructor: decrement object counter
|
259 |
inline XTime::~XTime (void) { |
260 |
NUMOBJECTS-- ; |
261 |
} |
262 |
|
263 |
// Description:
|
264 |
// Set the time correction term (in s)
|
265 |
inline void XTime::setTZero (double tz) { |
266 |
timeZero = tz * SEC2DAY ; |
267 |
leapflag = setmyleaps (&myLeaps, MJDint, MJDfr+timeZero) ; |
268 |
} |
269 |
|
270 |
// Description:
|
271 |
// Force refreshing leapseconds table (public method).
|
272 |
// Function to set leap second table
|
273 |
// If it was more than abs(dt) seconds since the
|
274 |
// leap seconds were read, the leap second table
|
275 |
// is refreshed; if dt > 0, only additional leap
|
276 |
// seconds are added; if dt < 0, all leap seconds
|
277 |
// are refreshed. The default is dt=5000000 (about
|
278 |
// two months).
|
279 |
inline void XTime::setLeaps (double dt) { |
280 |
setleaps (dt) ; |
281 |
NUMOBJECTS-- ; |
282 |
} |
283 |
|
284 |
// Description:
|
285 |
// Return MET seconds
|
286 |
inline double XTime::getMET (void) const { |
287 |
return ((MJDint - MJDrefint) + (MJDfr - MJDreffr) + timeZero) * DAY2SEC ;
|
288 |
} |
289 |
|
290 |
// Description:
|
291 |
// Return TT seconds since MJDref
|
292 |
inline double XTime::getTT (void) const { |
293 |
return getMET () ;
|
294 |
} |
295 |
|
296 |
// Description:
|
297 |
// Return TAI seconds since MJDref
|
298 |
inline double XTime::getTAI (void) const { |
299 |
return getMET () ;
|
300 |
} |
301 |
|
302 |
// Description:
|
303 |
// Return UTC seconds since MJDref
|
304 |
inline double XTime::getUTC (void) const { |
305 |
return ((MJDint - MJDrefint) + (MJDfr - MJDreffr) + timeZero) * DAY2SEC
|
306 |
- myLeaps + refLeaps ; |
307 |
} |
308 |
|
309 |
// Description:
|
310 |
// Return time zero point correction
|
311 |
inline double XTime::getTZero (void) const { |
312 |
return timeZero * DAY2SEC ;
|
313 |
} |
314 |
|
315 |
// Description:
|
316 |
// Return time as UTC date string (integer seconds)
|
317 |
inline const char* XTime::UTDate (void) { |
318 |
return ( getDate (UTC, DATE, 0) ) ; |
319 |
} |
320 |
|
321 |
// Description:
|
322 |
// Return time as TT date string (integer seconds)
|
323 |
inline const char* XTime::TTDate (void) { |
324 |
return ( getDate (TT, DATE, 0) ) ; |
325 |
} |
326 |
|
327 |
// Description:
|
328 |
// Return time as TAI date string (integer seconds)
|
329 |
inline const char* XTime::TAIDate (void) { |
330 |
return ( getDate (TAI, DATE, 0) ) ; |
331 |
} |
332 |
|
333 |
// Description:
|
334 |
// Return time as UTC calendar date string (integer seconds)
|
335 |
inline const char* XTime::UTCalDate (void) { |
336 |
return ( getDate (UTC, CALDATE, 0) ) ; |
337 |
} |
338 |
|
339 |
// Description:
|
340 |
// Return time as TT calendar date string (integer seconds)
|
341 |
inline const char* XTime::TTCalDate (void) { |
342 |
return ( getDate (TT, CALDATE, 0) ) ; |
343 |
} |
344 |
|
345 |
// Description:
|
346 |
// Return time as TAI calendar date string (integer seconds)
|
347 |
inline const char* XTime::TAICalDate (void) { |
348 |
return ( getDate (TAI, CALDATE, 0) ) ; |
349 |
} |
350 |
|
351 |
// Description:
|
352 |
// Return time as UTC FITS date string (integer seconds)
|
353 |
inline const char* XTime::UTFITS (void) { |
354 |
return ( getDate (UTC, FITS, 0) ) ; |
355 |
} |
356 |
|
357 |
// Description:
|
358 |
// Return time as TT FITS date string (integer seconds)
|
359 |
inline const char* XTime::TTFITS (void) { |
360 |
return ( getDate (TT, FITS, 0) ) ; |
361 |
} |
362 |
|
363 |
// Description:
|
364 |
// Return time as TAI FITS date string (integer seconds)
|
365 |
inline const char* XTime::TAIFITS (void) { |
366 |
return ( getDate (TAI, FITS, 0) ) ; |
367 |
} |
368 |
|
369 |
// Description:
|
370 |
// Return time as MJD(UTC)
|
371 |
inline double XTime::UTmjd (void) const { |
372 |
long mjdi ;
|
373 |
double mjdf ;
|
374 |
return ( UTmjd (&mjdi, &mjdf) ) ;
|
375 |
} |
376 |
|
377 |
// Description:
|
378 |
// Return time as MJD(TT)
|
379 |
inline double XTime::TTmjd (void) const { |
380 |
return ( MJDint + MJDfr + timeZero ) ;
|
381 |
} |
382 |
|
383 |
// Description:
|
384 |
// Return time as MJD(TAI)
|
385 |
inline double XTime::TAImjd (void) const { |
386 |
return ( TTmjd() - TAI2TT * SEC2DAY ) ;
|
387 |
} |
388 |
|
389 |
// Description:
|
390 |
// Return time as MJD(TT) and fill the arguments
|
391 |
// with the integer and fractional parts.
|
392 |
inline double XTime::TTmjd (long *mjdi, double *mjdf) const { |
393 |
*mjdi = MJDint ; |
394 |
*mjdf = MJDfr ; |
395 |
return ( TTmjd() ) ;
|
396 |
} |
397 |
|
398 |
// Description:
|
399 |
// Return time as MJD(TAI) and fill the arguments
|
400 |
// with the integer and fractional parts.
|
401 |
inline double XTime::TAImjd (long *mjdi, double *mjdf) const { |
402 |
*mjdi = MJDint ; |
403 |
*mjdf = MJDfr - TAI2TT * SEC2DAY ; |
404 |
return ( TAImjd() ) ;
|
405 |
} |
406 |
|
407 |
// Description:
|
408 |
// Return time as JD(UTC)
|
409 |
inline double XTime::UTjd (void) const { |
410 |
return ( UTmjd() + MJD0 ) ;
|
411 |
} |
412 |
|
413 |
// Description:
|
414 |
// Return time as JD(TT)
|
415 |
inline double XTime::TTjd (void) const { |
416 |
return ( TTmjd() + MJD0 ) ;
|
417 |
} |
418 |
|
419 |
// Description:
|
420 |
// Return time as JD(TAI)
|
421 |
inline double XTime::TAIjd (void) const { |
422 |
return ( TAImjd() + MJD0 ) ;
|
423 |
} |
424 |
|
425 |
// Description:
|
426 |
// Return number of existing XTime objects
|
427 |
inline int XTime::numObjects (void) { |
428 |
return NUMOBJECTS ;
|
429 |
} |
430 |
|
431 |
// Description:
|
432 |
// Return number of leapsecond entries.
|
433 |
// Actual times are in array secs.
|
434 |
inline int XTime::leapSecs (const double** secs) const { |
435 |
*secs = LEAPSECS ; |
436 |
return NUMLEAPSECS ;
|
437 |
} |
438 |
|
439 |
//
|
440 |
// --------------
|
441 |
// -- XTimeRange --
|
442 |
// --------------
|
443 |
//
|
444 |
|
445 |
class XTimeRange { |
446 |
|
447 |
//* Private attributes
|
448 |
|
449 |
XTime start ; |
450 |
XTime stop ; |
451 |
int empty ; // Empty defined as: |
452 |
// start or stop <= 0.0, or start >= stop
|
453 |
// start == stop > 0.0 is empty!
|
454 |
|
455 |
//* Private method
|
456 |
|
457 |
void setEmpty (void) ; |
458 |
|
459 |
//* Public methods
|
460 |
|
461 |
public:
|
462 |
|
463 |
//* Constructors
|
464 |
|
465 |
XTimeRange (void) ;
|
466 |
XTimeRange (const XTime &T1, const XTime &T2) ; |
467 |
XTimeRange (double t1, double t2) ; |
468 |
|
469 |
//* Set Methods
|
470 |
|
471 |
void setStart (const XTime &T1) ; // Set start as XTime object |
472 |
void setStop (const XTime &T2) ; // Set stop as XTime object |
473 |
void resetRange (const XTime &T1, const XTime &T2) ; |
474 |
void setStart (double t1) ; // Set start as MET seconds |
475 |
void setStop (double t2) ; // Set stop as MET seconds |
476 |
void resetRange (double t1, double t2) ; |
477 |
|
478 |
//* Get methods
|
479 |
|
480 |
XTime TStart (void) const ; // Return start as XTime object |
481 |
XTime TStop (void) const ; // Return stop as XTime object |
482 |
double METStart (void) const ; // Return start in MET seconds |
483 |
double METStop (void) const ; // Return stop in MET seconds |
484 |
const char* UTStartDate (void) ; // Return start as UTC date string |
485 |
const char* UTStopDate (void) ; // Return stop as UTC date string |
486 |
const char* TTStartDate (void) ; // Return start as TT date string |
487 |
const char* TTStopDate (void) ; // Return stop as TT date string |
488 |
int isInRange (const XTime &T) const ; |
489 |
int isInRange (double t) const ; |
490 |
double totalTime (void) const ; // Return total seconds |
491 |
int isEmpty (void) const ; // Empty range? |
492 |
void printRange (void) ; // A two-liner in UTC date format |
493 |
void printRangeCal (void) ; // A two-liner in UTC calendar format |
494 |
|
495 |
} ; |
496 |
|
497 |
// Description:
|
498 |
// Empty constructor
|
499 |
inline XTimeRange::XTimeRange (void) |
500 |
: start (0.0), stop (0.0), empty (1) { } |
501 |
|
502 |
// Description:
|
503 |
// Constructor using XTime objects
|
504 |
inline XTimeRange::XTimeRange (const XTime &T1, const XTime &T2) |
505 |
: start (T1), stop (T2) { |
506 |
setEmpty () ; |
507 |
} |
508 |
|
509 |
// Description:
|
510 |
// Constructor using MET seconds
|
511 |
inline XTimeRange::XTimeRange (double t1, double t2) |
512 |
: start (t1), stop (t2) { |
513 |
setEmpty () ; |
514 |
} |
515 |
|
516 |
// Description:
|
517 |
// Set start as XTime object
|
518 |
inline void XTimeRange::setStart (const XTime &T1) { |
519 |
start = T1 ; |
520 |
setEmpty () ; |
521 |
} |
522 |
|
523 |
// Description:
|
524 |
// Set stop as XTime object
|
525 |
inline void XTimeRange::setStop (const XTime &T2) { |
526 |
stop = T2 ; |
527 |
setEmpty () ; |
528 |
} |
529 |
|
530 |
// Description:
|
531 |
// Reset range with XTime objects
|
532 |
inline void XTimeRange::resetRange (const XTime &T1, const XTime &T2) { |
533 |
start = T1 ; |
534 |
stop = T2 ; |
535 |
setEmpty () ; |
536 |
} |
537 |
|
538 |
// Description:
|
539 |
// Set start as MET seconds
|
540 |
inline void XTimeRange::setStart (double t1) { |
541 |
start.set (t1) ; |
542 |
setEmpty () ; |
543 |
} |
544 |
|
545 |
// Description:
|
546 |
// Set start as MET seconds
|
547 |
inline void XTimeRange::setStop (double t2) { |
548 |
stop.set (t2) ; |
549 |
setEmpty () ; |
550 |
} |
551 |
|
552 |
// Description:
|
553 |
// Reset range in MET seconds
|
554 |
inline void XTimeRange::resetRange (double t1, double t2) { |
555 |
start.set (t1) ; |
556 |
stop.set (t2) ; |
557 |
setEmpty () ; |
558 |
} |
559 |
|
560 |
// Description:
|
561 |
// Return start as XTime object
|
562 |
inline XTime XTimeRange::TStart (void) const { |
563 |
return start ;
|
564 |
} |
565 |
|
566 |
// Description:
|
567 |
// Return start as XTime object
|
568 |
inline XTime XTimeRange::TStop (void) const { |
569 |
return stop ;
|
570 |
} |
571 |
|
572 |
// Description:
|
573 |
// Return start in MET seconds
|
574 |
inline double XTimeRange::METStart (void) const { |
575 |
return start.getMET () ;
|
576 |
} |
577 |
|
578 |
// Description:
|
579 |
// Return stop in MET seconds
|
580 |
inline double XTimeRange::METStop (void) const { |
581 |
return stop.getMET () ;
|
582 |
} |
583 |
|
584 |
// Description:
|
585 |
// Return start as UTC date string
|
586 |
inline const char* XTimeRange::UTStartDate (void) { |
587 |
return start.UTDate () ;
|
588 |
} |
589 |
|
590 |
// Description:
|
591 |
// Return stop as UTC date string
|
592 |
inline const char* XTimeRange::UTStopDate (void) { |
593 |
return stop.UTDate () ;
|
594 |
} |
595 |
|
596 |
// Description:
|
597 |
// Return start as TT date string
|
598 |
inline const char* XTimeRange::TTStartDate (void) { |
599 |
return start.TTDate () ;
|
600 |
} |
601 |
|
602 |
// Description:
|
603 |
// Return stop as TT date string
|
604 |
inline const char* XTimeRange::TTStopDate (void) { |
605 |
return stop.TTDate () ;
|
606 |
} |
607 |
|
608 |
// Description:
|
609 |
// Return -1 if before, 0 if in range, 1 if after
|
610 |
inline int XTimeRange::isInRange (double t) const { |
611 |
if ( t < start.getMET() )
|
612 |
return -1 ; |
613 |
else if ( t > stop.getMET() ) |
614 |
return 1 ; |
615 |
else if ( empty ) |
616 |
return 1 ; |
617 |
else
|
618 |
return 0 ; |
619 |
} |
620 |
|
621 |
// Description:
|
622 |
// Return -1 if before, 0 if in range, 1 if after
|
623 |
inline int XTimeRange::isInRange (const XTime &T) const { |
624 |
return isInRange (T.getMET()) ;
|
625 |
} |
626 |
|
627 |
// Description:
|
628 |
// Return total seconds
|
629 |
inline double XTimeRange::totalTime (void) const { |
630 |
return ( empty ? 0.0 : ( stop.getMET() - start.getMET() ) ) ; |
631 |
} |
632 |
|
633 |
// Description:
|
634 |
// Empty range?
|
635 |
inline int XTimeRange::isEmpty (void) const { |
636 |
return empty ;
|
637 |
} |
638 |
|
639 |
//
|
640 |
// ---------
|
641 |
// -- XTRList --
|
642 |
// ---------
|
643 |
//
|
644 |
|
645 |
class XTRList { |
646 |
|
647 |
//* Private attributes
|
648 |
|
649 |
XTimeRange listRange ; |
650 |
int numXTRs ;
|
651 |
XTimeRange* tr ; |
652 |
int empty ;
|
653 |
|
654 |
//* Public methods
|
655 |
|
656 |
public:
|
657 |
|
658 |
//* Constructors
|
659 |
|
660 |
XTRList (void) ;
|
661 |
XTRList (const XTimeRange &T) ;
|
662 |
XTRList (const XTRList &trl) ;
|
663 |
XTRList (const XTRList &trl1, const XTRList &trl2) ; |
664 |
|
665 |
//* Destructor
|
666 |
|
667 |
~XTRList () ; |
668 |
|
669 |
//* Operators
|
670 |
|
671 |
XTRList& operator=(const XTRList &trl) ;
|
672 |
|
673 |
//* Processing (modification) methods
|
674 |
|
675 |
void orList (const XTRList &trl) ; |
676 |
void notList (const XTimeRange &T) ; |
677 |
void andRange (const XTimeRange &T) ; |
678 |
void orRange (const XTimeRange &T) ; |
679 |
|
680 |
//* Get methods
|
681 |
|
682 |
int isInRange (const XTime &T) const ; // Return 0 if in range |
683 |
int isInRange (double t) const ; |
684 |
int getNumXTRs (void) const ; |
685 |
const XTimeRange* getRange (int i) const ; |
686 |
const XTimeRange* getRange (const XTime &T) const ; |
687 |
const XTimeRange* getRange (double t) const ; |
688 |
void setListRange (void) ; |
689 |
int isEmpty (void) const ; |
690 |
double totalTime (void) const ; |
691 |
void printList (void) ; |
692 |
void printListCal (void) ; |
693 |
} ; |
694 |
|
695 |
// Description:
|
696 |
// Default constructor for a single XTimeRange List
|
697 |
inline XTRList::XTRList (void) |
698 |
: numXTRs (1), empty(1) { |
699 |
tr = new XTimeRange () ; |
700 |
listRange =* tr ; |
701 |
} |
702 |
|
703 |
// Description:
|
704 |
// Constructor for a single XTimeRange List
|
705 |
inline XTRList::XTRList (const XTimeRange &T) |
706 |
: listRange (T), numXTRs (1) {
|
707 |
tr = new XTimeRange (T) ; |
708 |
empty = T.isEmpty () ; |
709 |
} |
710 |
|
711 |
// Description:
|
712 |
// Destructor
|
713 |
inline XTRList::~XTRList () {
|
714 |
delete [] tr ; |
715 |
} |
716 |
|
717 |
// Description:
|
718 |
// Return number of ranges in list
|
719 |
inline int XTRList::getNumXTRs (void) const { |
720 |
return numXTRs ;
|
721 |
} |
722 |
|
723 |
// Description:
|
724 |
// Return range no. ,i>
|
725 |
inline const XTimeRange* XTRList::getRange (int i) const { |
726 |
if ( ( i >= 0 ) && ( i < numXTRs ) ) |
727 |
return tr+i ;
|
728 |
else
|
729 |
return NULL ; |
730 |
} |
731 |
|
732 |
// Description:
|
733 |
// Empty list?
|
734 |
inline int XTRList::isEmpty (void) const { |
735 |
return empty ;
|
736 |
} |
737 |
|
738 |
#endif // XTIME_H |