1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Encoding: UTF-8
#include "calendar.h"
double pi=3.14159265358979323846;
double delta=5e-9;
void Plus(Date &date)
{
if(date.tm_mday<10)
{
date.tm_mday=20;
}
else
{
date.tm_mday=6;
date.tm_mon++;
}
return;
}
double fuck(double a,double b)
{
while(b<0)
b+=360;
while(b>=360)
b-=360;
if(b==0)
{
return min(fabs(b),fabs(360-b));
}
else
{
return fabs(a-b);
}
}
int main()
{
Date* date=new Date;
cout<<"Please input the year: "<<endl;
//时间确认
cin>>date->tm_year;
date->tm_year-=1900;//年份减去1900
//当年元旦零时
date->tm_mon=0;
date->tm_mday=1;
date->tm_hour=0;
date->tm_min=0;
date->tm_sec=0;
//输出年份
cout<<"Year: "<<date->tm_year+1900<<endl;
//计算当年二十四节气准确时刻
parameter p;
Julian julian;
time_t time;
//double dL;//dL为L对t导数
double t,t_end,t_middle;
double target;
char JieQi[24][10]={"小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"};
//date->tm_mday=6;
for(int i=0;date->tm_mon<12;Plus(*date),i++)
{
//转换为时间戳
time=mktime(date);
//暂时放弃牛顿迭代法
//t=julian.getJulianKiloYear(time);
//while(fuck(p.longitude(t),(double)i*15-75)>=1e-8)
//{
// dL=(p.longitude(t+delta)-p.longitude(t-delta))/(2*delta);
// t=t-p.longitude(t)/dL;
//}
//计算儒略千年数
t=julian.getJulianKiloYear(time);
t_end=julian.getJulianKiloYear(time+86400);
target=i*15-75;
if(target<0)
{
target+=360;
}
//二分法
while(p.sun_longitude(t)>target)
{
time-=86400;
t_end=t;
t=julian.getJulianKiloYear(time);
}
while(p.sun_longitude(t_end)<=target)
{
time+=86400;
t=t_end;
t_end=julian.getJulianKiloYear(time);
}
while(t_end-t>=1e-10)
{
t_middle=(t+t_end)/2;
if(p.sun_longitude(t_middle)>target)
{
t_end=t_middle;
}
else
{
t=t_middle;
}
}
//double t转为时间戳
time=julian.kiloYearToTime(t,date->tm_year+1900);
//date换新
date=localtime(&time);
printf("%d-%02d-%02d %02d:%02d:%02d %s\n",date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,JieQi[i]);
}
printf("\n\n");
return 0;
}
|