Skip to content

Commit bbb0fcb

Browse files
Add files via upload
1 parent 8f56c33 commit bbb0fcb

6 files changed

Lines changed: 919 additions & 40 deletions

File tree

Astime.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ QT += core gui
22

33
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
44

5+
TARGET = astrotime
6+
57
CONFIG += c++11
68

79
# The following define makes your compiler emit warnings if you use

Astime.pro.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.11.1, 2020-03-10T19:32:33. -->
3+
<!-- Written by QtCreator 4.11.1, 2020-03-16T02:43:17. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>

astm.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include <ctime>
33
#include <math.h>
44

5-
double JD(int y, int m, int d, int h, int mi, double s)
5+
// year month day hour minute second
6+
double JD(int y, int m, int d, int h, int mi, float s)
67
{
78

89
double jd, dd ;
@@ -15,7 +16,9 @@ double JD(int y, int m, int d, int h, int mi, double s)
1516

1617
}
1718

18-
double d_d(int y0, int m0, int d0, int h0, int mi0, float s0, int y, int m, int d, int h, int mi, double s)
19+
20+
// year 0 month 0 day 0 hour 0 minute 0 sec 0 year month day hour minute second
21+
double d_d(int y0, int m0, int d0, int h0, int mi0, float s0, int y, int m, int d, int h, int mi, float s)
1922
{
2023

2124
struct std::tm a = { s0, mi0, h0, d0, m0 - 1, y0 - 1900 } ;
@@ -32,7 +35,7 @@ double d_d(int y0, int m0, int d0, int h0, int mi0, float s0, int y, int m, int
3235

3336
}
3437

35-
double GMST(int y, int m, int d, int h, int mi, double s)
38+
double GMST(int y, int m, int d, int h, int mi, float s)
3639
{
3740

3841
double D, T, gmst ;
@@ -51,3 +54,37 @@ double GMST(int y, int m, int d, int h, int mi, double s)
5154

5255
}
5356

57+
58+
59+
double UTC2TAI(int y, int m, int d, int h, int mi, double s)
60+
{
61+
62+
int n = 2020 - 1972 + 1 ; // limit array
63+
double TAI ;
64+
65+
int leap[n][2] = { {1,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,0}, {1,0},
66+
{1,0}, {1,0}, {0,0}, {1,0}, {0,0}, {0,1}, {0,0}, {0,1}, {0,1}, {0,0},
67+
{1,0}, {1,0}, {1,0}, {0,1}, {0,0}, {1,0}, {0,1}, {0,0}, {0,0}, {0,0},
68+
{0,0}, {0,0}, {0,0}, {0,1}, {0,0}, {0,0}, {0,1}, {0,0}, {0,0}, {0,0},
69+
{1,0}, {0,0}, {0,0}, {1,0}, {0,1}, {0,0}, {0,0}, {0,0}, {0,0} } ; // leap seconds each year since 1972.
70+
// Yes, I am masochist
71+
int l = 10 ; // leap seconds
72+
73+
for (int i = 0; i < (y - 1972); i++)
74+
{
75+
76+
if (i == n)
77+
break ;
78+
79+
l += leap[i][0] + leap[i][1] ;
80+
81+
}
82+
83+
if ( ( (y - 1972) < n ) and (m > 6) )
84+
l += leap[y - 1972][0] ;
85+
86+
TAI = h + double(mi) * 0.01666666666666666 + (s + double(l)) * 2.777777777777777777e-4 ;
87+
88+
return TAI ;
89+
90+
}

astm.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#ifndef ASTM_H
22
#define ASTM_H
33

4-
double JD(int, int, int, int, int, double) ; // Julian day for gregorian callendar. Fuck people who don't use it
5-
6-
double d_d(int, int, int, int, int, float, int, int, int, int, int, double) ; // difference between 2 dates (initial: year, month,
7-
// day, hour, minute, second
8-
// final: year, month etc.)
9-
// Also works backwards i.e. first year 2000 final year 1840
10-
11-
double GMST(int, int, int, int, int, double) ; // Greenwich medium siderial time. Input current year, month,
12-
// day, hour, minute, second
4+
double JD(int, int, int, int, int, float) ;
135

6+
double d_d(int, int, int, int, int, float, int, int, int, int, int, float) ;
7+
8+
double GMST(int, int, int, int, int, float) ;
9+
10+
double UTC2TAI(int, int, int, int, int, double) ;
1411

1512
#endif /* ASTM_H */

mainwindow.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ MainWindow::~MainWindow()
3737
void MainWindow::changed_time()
3838
{
3939

40-
int UT_h, UT_m, gm_h, gm_m, LST_h, LST_m ;
41-
double UT_s, seconds, jd, gmst, gm_s, LST, LST_s ;
40+
int UT_h, UT_m, gm_h, gm_m ;
41+
double UT_s, seconds, jd, gmst, gm_s ;
42+
int LST_h, LST_m ;
43+
double LST, LST_s ;
44+
int TAI_h, TAI_m ;
45+
double TAI, TAI_s ;
46+
int GPS_h, GPS_m ;
47+
double GPS, GPS_s ;
4248

4349
UT = hour - tz ;
4450

@@ -119,6 +125,32 @@ void MainWindow::changed_time()
119125
ui -> lst_m -> setText(QString::number(LST_m)) ;
120126
ui -> lst_s -> setText(QString::number(LST_s, 'f', 3)) ;
121127

128+
129+
130+
TAI = UTC2TAI(year_2, month_2, day_2, UT_h, UT_m, UT_s) ;
131+
132+
TAI_h = int(TAI) ;
133+
TAI_m = int( (TAI - TAI_h) * 60) ;
134+
TAI_s = (TAI - TAI_h) * 3600 - TAI_m * 60 ;
135+
136+
ui -> tai_h -> setText(QString::number(TAI_h)) ;
137+
ui -> tai_m -> setText(QString::number(TAI_m)) ;
138+
ui -> tai_s -> setText(QString::number(TAI_s, 'f', 3)) ;
139+
140+
GPS = TAI - 5.27777777777777e-3 ;
141+
142+
if (GPS < 0)
143+
GPS += 24 ;
144+
145+
GPS_h = int(GPS) ;
146+
GPS_m = int( (GPS - GPS_h) * 60) ;
147+
GPS_s = (GPS - GPS_h) * 3600 - GPS_m * 60 ;
148+
149+
ui -> gps_h -> setText(QString::number(GPS_h)) ;
150+
ui -> gps_m -> setText(QString::number(GPS_m)) ;
151+
ui -> gps_s -> setText(QString::number(GPS_s, 'f', 3)) ;
152+
153+
122154
}
123155

124156
void MainWindow::on_time_userTimeChanged(const QTime &time)

0 commit comments

Comments
 (0)