source: ntrip/trunk/BNS/timeutils.cpp@ 10415

Last change on this file since 10415 was 2258, checked in by mervart, 15 years ago

* empty log message *

File size: 3.1 KB
Line 
1/* -----------------------------------------------------------------------------
2 *
3 * Function : djul
4 *
5 * Purpose : computes the modified julian date (mjd) from
6 * year, month and day
7 *
8 * Author : Z. Lukes
9 *
10 * Created : 13-OCT-2001
11 *
12 * Changes :
13 *
14 * ---------------------------------------------------------------------------*/
15
16#include <math.h>
17
18#ifndef NO_CVS_HEADER
19static const char *const cvsid = "$Header: /usr/local/cvsroot/BNC/RTCM3/timeutils.cpp,v 1.1 2008/08/07 14:05:11 zdenek Exp $";
20#endif
21
22double djul(long jj, long mm, double tt) {
23 long ii, kk;
24 double djul ;
25
26 if( mm <= 2 ) {
27 jj = jj - 1;
28 mm = mm + 12;
29 }
30
31 ii = jj/100;
32 kk = 2 - ii + ii/4;
33 djul = (365.25*jj - fmod( 365.25*jj, 1.0 )) - 679006.0;
34 djul = djul + floor( 30.6001*(mm + 1) ) + tt + kk;
35 return djul;
36}
37
38/* -----------------------------------------------------------------------------
39 *
40 * Function : gpjd
41 *
42 * Purpose : computes the modified julian date (mjd) from
43 * gpsweek number and number of seconds past last
44 * saturday/sunday midnight
45 *
46 * Author : Z. Lukes
47 *
48 * Created : 13-OCT-2001
49 *
50 * Changes :
51 *
52 * ---------------------------------------------------------------------------*/
53
54double gpjd(double second, int nweek) {
55 double deltat;
56
57 // days since starting epoch of gps weeks (sunday 06-jan-80)
58
59 deltat = nweek*7.0 + second/86400.0 ;
60
61 // mod. julian date
62
63 return( 44244.0 + deltat) ;
64}
65
66/* -----------------------------------------------------------------------------
67 *
68 * Function : jdgp
69 *
70 * Purpose : compute number of seconds past midnight of last
71 * saturday/sunday and gps week number of current
72 * date given in modified julian date
73 *
74 * Author : Z. Lukes
75 *
76 * Created : 13-OCT-2001
77 *
78 * Changes :
79 *
80 * ---------------------------------------------------------------------------*/
81
82void jdgp(double tjul, double & second, long & nweek) {
83 double deltat;
84
85 deltat = tjul - 44244.0 ;
86
87 // current gps week
88
89 nweek = (long) floor(deltat/7.0);
90
91 // seconds past midnight of last weekend
92
93 second = (deltat - (nweek)*7.0)*86400.0;
94
95}
96
97/* -----------------------------------------------------------------------------
98 *
99 * Function : djul
100 *
101 * Purpose : compute year,month,day of month from
102 * modified julian date (mjd=jul. date-2400000.5)
103 *
104 * Author : Z. Lukes
105 *
106 * Created : 13-OCT-2001
107 *
108 * Changes :
109 *
110 * ---------------------------------------------------------------------------*/
111
112void jmt(double djul, long& jj, long& mm, double& dd) {
113 long ih, ih1, ih2 ;
114 double t1, t2, t3, t4;
115
116 t1 = 1.0 + djul - fmod( djul, 1.0 ) + 2400000.0;
117 t4 = fmod( djul, 1.0 );
118 ih = long( (t1 - 1867216.25)/36524.25 );
119 t2 = t1 + 1 + ih - ih/4;
120 t3 = t2 - 1720995.0;
121 ih1 = long( (t3 - 122.1)/365.25 );
122 t1 = 365.25*ih1 - fmod( 365.25*ih1, 1.0 );
123 ih2 = long( (t3 - t1)/30.6001 );
124 dd = t3 - t1 - (int)( 30.6001*ih2 ) + t4;
125 mm = ih2 - 1;
126
127 if ( ih2 > 13 ) mm = ih2 - 13;
128
129 jj = ih1;
130
131 if ( mm <= 2 ) jj = jj + 1;
132
133}
Note: See TracBrowser for help on using the repository browser.