summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-01-04 17:14:26 +0800
committerWe-unite <3205135446@qq.com>2024-01-05 18:02:20 +0800
commit644f678387cd81a87bd0c73ea0123c825bc99e59 (patch)
treeb0896bbcd223ce4e5894612e99c4a1fad104bb73
parentb6ea7502c67af360b309c6c296fe487fa3bf5d96 (diff)
downloadcalendar-644f678387cd81a87bd0c73ea0123c825bc99e59.tar.gz
calendar-644f678387cd81a87bd0c73ea0123c825bc99e59.zip
Format all the codes using clang-format
Renew some test params.
-rw-r--r--.gitignore6
-rw-r--r--src/.clang-format121
-rw-r--r--src/Julian.cpp116
-rw-r--r--src/List.cpp239
-rw-r--r--src/calendar.cpp250
-rw-r--r--src/calendar.h162
-rw-r--r--src/parameters.cpp247
-rwxr-xr-xtest.sh14
8 files changed, 581 insertions, 574 deletions
diff --git a/.gitignore b/.gitignore
index 597f7ce..a029ac1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
1#Ignore all
2* 1*
3#Unignore all with extensions
4!*.* 2!*.*
5# Unignore all makefiles named Makefile or makefile 3# Unignore all makefiles named Makefile or makefile
6!Makefile 4!Makefile
@@ -10,10 +8,8 @@
10#Ignore swp 8#Ignore swp
11*.swp 9*.swp
12#Ignore res 10#Ignore res
13res.txt 11*.txt
14err.txt
15push.sh 12push.sh
16test*
17!test.sh 13!test.sh
18*.o 14*.o
19#Ignore dir data/vsop87 15#Ignore dir data/vsop87
diff --git a/src/.clang-format b/src/.clang-format
new file mode 100644
index 0000000..a1054a5
--- /dev/null
+++ b/src/.clang-format
@@ -0,0 +1,121 @@
1---
2Language: Cpp
3# BasedOnStyle: LLVM
4AccessModifierOffset: -2
5AlignAfterOpenBracket: Align
6AlignConsecutiveAssignments: false
7AlignConsecutiveDeclarations: false
8AlignEscapedNewlines: Right
9AlignOperands: true
10AlignTrailingComments: true
11AllowAllParametersOfDeclarationOnNextLine: true
12AllowShortBlocksOnASingleLine: false
13AllowShortCaseLabelsOnASingleLine: false
14AllowShortFunctionsOnASingleLine: All
15AllowShortIfStatementsOnASingleLine: false
16AllowShortLoopsOnASingleLine: false
17AlwaysBreakAfterDefinitionReturnType: None
18AlwaysBreakAfterReturnType: None
19AlwaysBreakBeforeMultilineStrings: false
20AlwaysBreakTemplateDeclarations: MultiLine
21BinPackArguments: true
22BinPackParameters: true
23BraceWrapping:
24 AfterClass: false
25 AfterControlStatement: false
26 AfterEnum: false
27 AfterFunction: false
28 AfterNamespace: false
29 AfterObjCDeclaration: false
30 AfterStruct: false
31 AfterUnion: false
32 AfterExternBlock: false
33 BeforeCatch: false
34 BeforeElse: false
35 IndentBraces: false
36 SplitEmptyFunction: true
37 SplitEmptyRecord: true
38 SplitEmptyNamespace: true
39BreakBeforeBinaryOperators: None
40BreakBeforeBraces: Attach
41BreakBeforeInheritanceComma: false
42BreakInheritanceList: BeforeColon
43BreakBeforeTernaryOperators: true
44BreakConstructorInitializersBeforeComma: false
45BreakConstructorInitializers: BeforeColon
46BreakAfterJavaFieldAnnotations: false
47BreakStringLiterals: true
48ColumnLimit: 80
49CommentPragmas: '^ IWYU pragma:'
50CompactNamespaces: false
51ConstructorInitializerAllOnOneLineOrOnePerLine: false
52ConstructorInitializerIndentWidth: 4
53ContinuationIndentWidth: 4
54Cpp11BracedListStyle: true
55DerivePointerAlignment: false
56DisableFormat: false
57ExperimentalAutoDetectBinPacking: false
58FixNamespaceComments: true
59ForEachMacros:
60 - foreach
61 - Q_FOREACH
62 - BOOST_FOREACH
63IncludeBlocks: Preserve
64IncludeCategories:
65 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
66 Priority: 2
67 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
68 Priority: 3
69 - Regex: '.*'
70 Priority: 1
71IncludeIsMainRegex: '(Test)?$'
72IndentCaseLabels: false
73IndentPPDirectives: None
74IndentWidth: 4
75IndentWrappedFunctionNames: false
76JavaScriptQuotes: Leave
77JavaScriptWrapImports: true
78KeepEmptyLinesAtTheStartOfBlocks: true
79MacroBlockBegin: ''
80MacroBlockEnd: ''
81MaxEmptyLinesToKeep: 1
82NamespaceIndentation: None
83ObjCBinPackProtocolList: Auto
84ObjCBlockIndentWidth: 2
85ObjCSpaceAfterProperty: false
86ObjCSpaceBeforeProtocolList: true
87PenaltyBreakAssignment: 2
88PenaltyBreakBeforeFirstCallParameter: 19
89PenaltyBreakComment: 300
90PenaltyBreakFirstLessLess: 120
91PenaltyBreakString: 1000
92PenaltyBreakTemplateDeclaration: 10
93PenaltyExcessCharacter: 1000000
94PenaltyReturnTypeOnItsOwnLine: 60
95PointerAlignment: Right
96ReflowComments: true
97SortIncludes: true
98SortUsingDeclarations: true
99SpaceAfterCStyleCast: false
100SpaceAfterTemplateKeyword: true
101SpaceBeforeAssignmentOperators: true
102SpaceBeforeCpp11BracedList: false
103SpaceBeforeCtorInitializerColon: true
104SpaceBeforeInheritanceColon: true
105SpaceBeforeParens: ControlStatements
106SpaceBeforeRangeBasedForLoopColon: true
107SpaceInEmptyParentheses: false
108SpacesBeforeTrailingComments: 1
109SpacesInAngles: false
110SpacesInContainerLiterals: true
111SpacesInCStyleCastParentheses: false
112SpacesInParentheses: false
113SpacesInSquareBrackets: false
114Standard: Cpp11
115StatementMacros:
116 - Q_UNUSED
117 - QT_REQUIRE_VERSION
118TabWidth: 8
119UseTab: Never
120...
121
diff --git a/src/Julian.cpp b/src/Julian.cpp
index 907c94e..5a0522b 100644
--- a/src/Julian.cpp
+++ b/src/Julian.cpp
@@ -9,93 +9,83 @@
9 * 但是我目前提供的中time_t类型为64位整数,因而可以表示数千年的时间范围 9 * 但是我目前提供的中time_t类型为64位整数,因而可以表示数千年的时间范围
10 */ 10 */
11 11
12double Julian::d[23][5]={ 12double Julian::d[23][5] = {
13 {-4000, 108371.700000, -13036.800000, 392.000000, 0.000000}, 13 {-4000, 108371.700000, -13036.800000, 392.000000, 0.000000},
14 { -500, 17201.000000, -627.820000, 16.170000, -0.341300}, 14 {-500, 17201.000000, -627.820000, 16.170000, -0.341300},
15 { -150, 12200.600000, -346.410000, 5.403000, -0.159300}, 15 {-150, 12200.600000, -346.410000, 5.403000, -0.159300},
16 { 150, 9113.800000, -328.130000, -1.647000, 0.037700}, 16 {150, 9113.800000, -328.130000, -1.647000, 0.037700},
17 { 500, 5707.500000, -391.410000, 0.915000, 0.314500}, 17 {500, 5707.500000, -391.410000, 0.915000, 0.314500},
18 { 900, 2203.400000, -283.450000, 13.034000, -0.177800}, 18 {900, 2203.400000, -283.450000, 13.034000, -0.177800},
19 { 1300, 490.100000, -57.350000, 2.085000, -0.007200}, 19 {1300, 490.100000, -57.350000, 2.085000, -0.007200},
20 { 1600, 120.000000, -9.810000, -1.532000, 0.140300}, 20 {1600, 120.000000, -9.810000, -1.532000, 0.140300},
21 { 1700, 10.200000, -0.910000, 0.510000, -0.037000}, 21 {1700, 10.200000, -0.910000, 0.510000, -0.037000},
22 { 1800, 13.400000, -0.720000, 0.202000, -0.019300}, 22 {1800, 13.400000, -0.720000, 0.202000, -0.019300},
23 { 1830, 7.800000, -1.810000, 0.416000, -0.024700}, 23 {1830, 7.800000, -1.810000, 0.416000, -0.024700},
24 { 1860, 8.300000, -0.130000, -0.406000, 0.029200}, 24 {1860, 8.300000, -0.130000, -0.406000, 0.029200},
25 { 1880, -5.400000, 0.320000, -0.183000, 0.017300}, 25 {1880, -5.400000, 0.320000, -0.183000, 0.017300},
26 { 1900, -2.300000, 2.060000, 0.169000, -0.013500}, 26 {1900, -2.300000, 2.060000, 0.169000, -0.013500},
27 { 1920, 21.200000, 1.690000, -0.304000, 0.016700}, 27 {1920, 21.200000, 1.690000, -0.304000, 0.016700},
28 { 1940, 24.200000, 1.220000, -0.064000, 0.003100}, 28 {1940, 24.200000, 1.220000, -0.064000, 0.003100},
29 { 1960, 33.200000, 0.510000, 0.231000, -0.010900}, 29 {1960, 33.200000, 0.510000, 0.231000, -0.010900},
30 { 1980, 51.000000, 1.290000, -0.026000, 0.003200}, 30 {1980, 51.000000, 1.290000, -0.026000, 0.003200},
31 { 2000, 63.870000, 0.100000, 0.000000, 0.000000}, 31 {2000, 63.870000, 0.100000, 0.000000, 0.000000},
32 { 2005, 64.700000, 0.210000, 0.000000, 0.000000}, 32 {2005, 64.700000, 0.210000, 0.000000, 0.000000},
33 { 2012, 66.800000, 0.220000, 0.000000, 0.000000}, 33 {2012, 66.800000, 0.220000, 0.000000, 0.000000},
34 { 2018, 69.000000, 0.360000, 0.000000, 0.000000}, 34 {2018, 69.000000, 0.360000, 0.000000, 0.000000},
35 { 2028, 72.600000, 0.000000, 0.000000, 0.000000} 35 {2028, 72.600000, 0.000000, 0.000000, 0.000000}};
36};
37 36
38double Julian::dt_ext(int y,double jsd) 37double Julian::dt_ext(int y, double jsd) {
39{ 38 double dy = (double)(y - 1820) / 100.0;
40 double dy=(double)(y-1820)/100.0; 39 return -20 + jsd * dy * dy;
41 return -20+jsd*dy*dy;
42} 40}
43 41
44//计算力学时与世界时之差,传入年份 42//计算力学时与世界时之差,传入年份
45double Julian::delta_t(int y) 43double Julian::delta_t(int y) {
46{ 44 int y0 = d[22][0]; //表中最后一行的年份
47 int y0=d[22][0];//表中最后一行的年份 45 double t0 = d[22][1]; //表中最后一行的delta_t
48 double t0=d[22][1];//表中最后一行的delta_t
49 double jsd; 46 double jsd;
50 47
51 if(y>y0) 48 if (y > y0) {
52 { 49 jsd = 31;
53 jsd=31; 50 if (y - y0 > 100) {
54 if(y-y0>100) 51 return dt_ext(y, jsd);
55 {
56 return dt_ext(y,jsd);
57 } 52 }
58 53
59 double v=dt_ext(y,jsd); 54 double v = dt_ext(y, jsd);
60 double dv=dt_ext(y0,jsd)-t0; 55 double dv = dt_ext(y0, jsd) - t0;
61 return v-dv*(y0+100-y)/100; 56 return v - dv * (y0 + 100 - y) / 100;
62 } 57 }
63 58
64 double res; 59 double res;
65 for(int i=0;i<22;i++) 60 for (int i = 0; i < 22; i++) {
66 { 61 if (y < d[i + 1][0]) {
67 if(y<d[i+1][0])
68 {
69 break; 62 break;
70 } 63 }
71 double t1=(y-d[i][0])/(d[i+1][0]-d[i][0])*10; 64 double t1 = (y - d[i][0]) / (d[i + 1][0] - d[i][0]) * 10;
72 double t2=t1*t1; 65 double t2 = t1 * t1;
73 double t3=t2*t1; 66 double t3 = t2 * t1;
74 res=d[i][1]+d[i][2]*t1+d[i][3]*t2+d[i][4]*t3; 67 res = d[i][1] + d[i][2] * t1 + d[i][3] * t2 + d[i][4] * t3;
75 } 68 }
76 return res; 69 return res;
77} 70}
78 71
79// 计算儒略日 72// 计算儒略日
80double Julian::getJulianDay(time_t time) 73double Julian::getJulianDay(time_t time) {
81{ 74 double t = (double)time;
82 double t=(double)time; 75 // 2440587.5为1970年1月1日0时的儒略日数
83 //2440587.5为1970年1月1日0时的儒略日数 76 return (double)t / 86400.0 + 2440587.5;
84 return (double)t/86400.0+2440587.5;
85} 77}
86 78
87// 计算儒略千年数,自JD2000(即2000年1月1日12时)起算 79// 计算儒略千年数,自JD2000(即2000年1月1日12时)起算
88double Julian::getJulianKiloYear(time_t time) 80double Julian::getJulianKiloYear(time_t time) {
89{
90 double jd = getJulianDay(time); 81 double jd = getJulianDay(time);
91 //2451545.0为2000年1月1日12时的儒略日数,365250.0为一千年的天数 82 // 2451545.0为2000年1月1日12时的儒略日数,365250.0为一千年的天数
92 return (double)(jd-2451545.0)/365250.0; 83 return (double)(jd - 2451545.0) / 365250.0;
93} 84}
94 85
95//儒略千年数转时间戳 86//儒略千年数转时间戳
96time_t Julian::kiloYearToTime(double t,int year) 87time_t Julian::kiloYearToTime(double t, int year) {
97{ 88 double jd = t * 365250.0 + 2451545.0;
98 double jd=t*365250.0+2451545.0; 89 time_t time = (time_t)((jd - 2440587.5) * 86400.0 - delta_t(year));
99 time_t time=(time_t)((jd-2440587.5)*86400.0-delta_t(year));
100 return time; 90 return time;
101} 91}
diff --git a/src/List.cpp b/src/List.cpp
index 99aa1a6..b4600bc 100644
--- a/src/List.cpp
+++ b/src/List.cpp
@@ -1,37 +1,32 @@
1#include "calendar.h" 1#include "calendar.h"
2 2
3List::List() 3List::List() {
4{
5 // 为方便初始化,链表头结点设为空节点,注意不要使用 4 // 为方便初始化,链表头结点设为空节点,注意不要使用
6 head=new point(0,0,0,0,0,0,false,false,false,-1,-1,false,0); 5 head = new point(0, 0, 0, 0, 0, 0, false, false, false, -1, -1, false, 0);
7 tail=head; 6 tail = head;
8} 7}
9 8
10List::~List() 9List::~List() {
11{ 10 point *p = head;
12 point* p=head; 11 while (p != NULL) {
13 while(p!=NULL) 12 point *q = p->next;
14 {
15 point* q=p->next;
16 delete p; 13 delete p;
17 p=q; 14 p = q;
18 } 15 }
19
20} 16}
21 17
22// 链表尾部插入 18// 链表尾部插入
23void List::append(Date* date,bool isShuo,bool isJieqi,bool isZhongqi,int JieqiIndex,double time) 19void List::append(Date *date, bool isShuo, bool isJieqi, bool isZhongqi,
24{ 20 int JieqiIndex, double time) {
25 point* p=new point(date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,isShuo,isJieqi,isZhongqi,JieqiIndex,0,false,time); 21 point *p = new point(date->tm_year + 1900, date->tm_mon + 1, date->tm_mday,
26 tail->next=p; 22 date->tm_hour, date->tm_min, date->tm_sec, isShuo,
27 tail=p; 23 isJieqi, isZhongqi, JieqiIndex, 0, false, time);
24 tail->next = p;
25 tail = p;
28 26
29 if(isShuo) 27 if (isShuo) {
30 {
31 shuori_vec.push_back(p); 28 shuori_vec.push_back(p);
32 } 29 } else if (isJieqi && isZhongqi) {
33 else if(isJieqi&&isZhongqi)
34 {
35 zhongqi_vec.push_back(p); 30 zhongqi_vec.push_back(p);
36 } 31 }
37} 32}
@@ -43,194 +38,142 @@ void List::append(Date* date,bool isShuo,bool isJieqi,bool isZhongqi,int JieqiIn
43 * 这是今历沿用的顺治时宪历之规定, 38 * 这是今历沿用的顺治时宪历之规定,
44 * 即朔日只要和中气同日,不论先后,该中气即算作下一月 39 * 即朔日只要和中气同日,不论先后,该中气即算作下一月
45 */ 40 */
46void List::lunar_sort() 41void List::lunar_sort() {
47{ 42 point *cur, *pre;
48 point* cur,*pre;
49 bool flag; 43 bool flag;
50 do 44 do {
51 { 45 flag = false;
52 flag=false; 46 pre = head;
53 pre=head; 47 do {
54 do 48 cur = pre->next;
55 { 49 if (later(cur, cur->next)) {
56 cur=pre->next; 50 flag = true;
57 if(later(cur,cur->next)) 51 pre->next = cur->next;
58 { 52 cur->next = cur->next->next;
59 flag=true; 53 pre->next->next = cur;
60 pre->next=cur->next;
61 cur->next=cur->next->next;
62 pre->next->next=cur;
63 } 54 }
64 pre=pre->next; 55 pre = pre->next;
65 }while(pre->next!=tail); 56 } while (pre->next != tail);
66 }while(flag); 57 } while (flag);
67 58
68 for(pre=head;pre->next!=tail;pre=pre->next) 59 for (pre = head; pre->next != tail; pre = pre->next) {
69 { 60 cur = pre->next;
70 cur=pre->next; 61 if (cur->isZhongqi && cur->next->isShuo &&
71 if(cur->isZhongqi&&cur->next->isShuo&&cur->next->year==cur->year&&cur->next->mon==cur->mon&&cur->next->day==cur->day) 62 cur->next->year == cur->year && cur->next->mon == cur->mon &&
72 { 63 cur->next->day == cur->day) {
73 pre->next=cur->next; 64 pre->next = cur->next;
74 cur->next=cur->next->next; 65 cur->next = cur->next->next;
75 pre->next->next=cur; 66 pre->next->next = cur;
76 } 67 }
77 } 68 }
78} 69}
79 70
80 71bool List::later(point *a, point *b) {
81bool List::later(point* a,point* b)
82{
83 // 比较a是否比b晚 72 // 比较a是否比b晚
84 // 比较年 73 // 比较年
85 if(a->year>b->year) 74 if (a->year > b->year) {
86 {
87 return true; 75 return true;
88 } 76 } else if (a->year < b->year) {
89 else if(a->year<b->year)
90 {
91 return false; 77 return false;
92 } 78 }
93 // 比较月 79 // 比较月
94 else if(a->mon>b->mon) 80 else if (a->mon > b->mon) {
95 {
96 return true; 81 return true;
97 } 82 } else if (a->mon < b->mon) {
98 else if(a->mon<b->mon)
99 {
100 return false; 83 return false;
101 } 84 }
102 // 比较日 85 // 比较日
103 else if(a->day>b->day) 86 else if (a->day > b->day) {
104 {
105 return true; 87 return true;
106 } 88 } else if (a->day < b->day) {
107 else if(a->day<b->day)
108 {
109 return false; 89 return false;
110 } 90 }
111 // 比较时 91 // 比较时
112 else if(a->hour>b->hour) 92 else if (a->hour > b->hour) {
113 {
114 return true; 93 return true;
115 } 94 } else if (a->hour < b->hour) {
116 else if(a->hour<b->hour)
117 {
118 return false; 95 return false;
119 } 96 }
120 // 比较分 97 // 比较分
121 else if(a->min>b->min) 98 else if (a->min > b->min) {
122 {
123 return true; 99 return true;
124 } 100 } else if (a->min < b->min) {
125 else if(a->min<b->min)
126 {
127 return false; 101 return false;
128 } 102 }
129 // 比较秒 103 // 比较秒
130 else if(a->sec>b->sec) 104 else if (a->sec > b->sec) {
131 {
132 return true; 105 return true;
133 } 106 } else if (a->sec < b->sec) {
134 else if(a->sec<b->sec)
135 {
136 return false; 107 return false;
137 } 108 } else {
138 else
139 {
140 return false; 109 return false;
141 } 110 }
142} 111}
143 112
144//置闰月 113//置闰月
145void List::Run() 114void List::Run() {
146{ 115 point *cur;
147 point* cur; 116 int i = 0, j = 0;
148 int i=0,j=0; 117 int mon_index = 11;
149 int mon_index=11;
150 bool flag; 118 bool flag;
151 while(later(zhongqi_vec[12],shuori_vec[i])) 119 while (later(zhongqi_vec[12], shuori_vec[i])) {
152 {
153 i++; 120 i++;
154 } 121 }
155 122
156 if(i==13) 123 if (i == 13) {
157 {
158 //冬至之间有13个朔日,置闰 124 //冬至之间有13个朔日,置闰
159 for(j=0;j<shuori_vec.size()-1;j++) 125 for (j = 0; j < shuori_vec.size() - 1; j++) {
160 { 126 flag = true;
161 flag=true; 127 cur = shuori_vec[j]->next;
162 cur=shuori_vec[j]->next; 128 while (cur != shuori_vec[j + 1]) {
163 while(cur!=shuori_vec[j+1]) 129 if (cur->isZhongqi) {
164 {
165 if(cur->isZhongqi)
166 {
167 //本月有中气,不置闰 130 //本月有中气,不置闰
168 flag=false; 131 flag = false;
169 } 132 }
170 cur=cur->next; 133 cur = cur->next;
171 } 134 }
172 if(flag) 135 if (flag) {
173 { 136 shuori_vec[j]->MonthIndex = mon_index;
174 shuori_vec[j]->MonthIndex=mon_index; 137 shuori_vec[j]->RunYue = true;
175 shuori_vec[j]->RunYue=true;
176 j++; 138 j++;
177 break; 139 break;
178 } 140 } else {
179 else
180 {
181 mon_index++; 141 mon_index++;
182 if(mon_index==13) 142 if (mon_index == 13) {
183 { 143 mon_index = 1;
184 mon_index=1;
185 } 144 }
186 shuori_vec[j]->MonthIndex=mon_index; 145 shuori_vec[j]->MonthIndex = mon_index;
187 shuori_vec[j]->RunYue=false; 146 shuori_vec[j]->RunYue = false;
188 } 147 }
189 } 148 }
190
191 } 149 }
192 //冬至之间有12个朔日,不置闰 150 //冬至之间有12个朔日,不置闰
193 //同时处理置闰完毕之后的朔日 151 //同时处理置闰完毕之后的朔日
194 for(;j<shuori_vec.size()-1;j++) 152 for (; j < shuori_vec.size() - 1; j++) {
195 {
196 mon_index++; 153 mon_index++;
197 if(mon_index==13) 154 if (mon_index == 13) {
198 { 155 mon_index = 1;
199 mon_index=1;
200 } 156 }
201 shuori_vec[j]->MonthIndex=mon_index; 157 shuori_vec[j]->MonthIndex = mon_index;
202 shuori_vec[j]->RunYue=false; 158 shuori_vec[j]->RunYue = false;
203 } 159 }
204} 160}
205 161
206//输出链表内容 162//输出链表内容
207void List::output() 163void List::output() {
208{ 164 for (point *i = head->next; i != NULL; i = i->next) {
209 for(point* i=head->next;i!=NULL;i=i->next) 165 printf("%d-%02d-%02d %02d:%02d:%02d ", i->year, i->mon, i->day,
210 { 166 i->hour, i->min, i->sec);
211 printf("%d-%02d-%02d %02d:%02d:%02d ",i->year,i->mon,i->day,i->hour,i->min,i->sec); 167 if (i->isJieqi) {
212 if(i->isJieqi) 168 printf("%s\n", jieqi[i->JieqiIndex]);
213 { 169 } else if (i->isShuo) {
214 printf("%s",jieqi[i->JieqiIndex]);
215 if(i->isZhongqi)
216 {
217 printf(" 中气");
218 }
219 printf("\n");
220 }
221 else if(i->isShuo)
222 {
223 printf("朔日"); 170 printf("朔日");
224 if(i->RunYue) 171 if (i->RunYue) {
225 { 172 printf(" 闰%d月", i->MonthIndex);
226 printf(" 闰%d月",i->MonthIndex); 173 } else {
227 } 174 printf(" %d月", i->MonthIndex);
228 else
229 {
230 printf(" %d月",i->MonthIndex);
231 } 175 }
232 printf("\n"); 176 printf("\n");
233 } 177 }
234 } 178 }
235
236} 179}
diff --git a/src/calendar.cpp b/src/calendar.cpp
index 492cdbc..dcb96d7 100644
--- a/src/calendar.cpp
+++ b/src/calendar.cpp
@@ -4,136 +4,123 @@
4#include <ctime> 4#include <ctime>
5 5
6/*以下为"calendar.h规定之量*/ 6/*以下为"calendar.h规定之量*/
7double pi=3.14159265358979323846; 7double pi = 3.14159265358979323846;
8double day=86400; 8double day = 86400;
9double delta=1e-11; 9double delta = 1e-11;
10char jieqi[25][10]={"冬至","小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"}; 10char jieqi[25][10] = {"冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分",
11 "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑",
12 "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降",
13 "立冬", "小雪", "大雪", "冬至"};
11 14
12/*计算需要用的类的实例化*/ 15/*计算需要用的类的实例化*/
13Julian julian; 16Julian julian;
14parameter p; 17parameter p;
15List list; 18List list;
16 19
17 20Date *input(char *argv) {
18Date* input(char* argv) 21 Date *date = new Date;
19{
20 Date* date=new Date;
21 22
22 // 输入年份,自当年元旦起算 23 // 输入年份,自当年元旦起算
23 date->tm_year=atoi(argv)-1900; 24 date->tm_year = atoi(argv) - 1900;
24 date->tm_mon=0; 25 date->tm_mon = 0;
25 date->tm_mday=1; 26 date->tm_mday = 1;
26 date->tm_hour=0; 27 date->tm_hour = 0;
27 date->tm_min=0; 28 date->tm_min = 0;
28 date->tm_sec=0; 29 date->tm_sec = 0;
29 30
30 return date; 31 return date;
31} 32}
32 33
33/*计算当年二十四节气时刻,自去年冬至到本年冬至*/ 34/*计算当年二十四节气时刻,自去年冬至到本年冬至*/
34void JieQi(Date* date) 35void JieQi(Date *date) {
35{
36 //计算起始时间为去年12月19日0时,开始寻找去年冬至 36 //计算起始时间为去年12月19日0时,开始寻找去年冬至
37 time_t time=mktime(date); 37 time_t time = mktime(date);
38 time-=13*day; 38 time -= 13 * day;
39 39
40 double t,t_end,t_middle;//采用二分法计算,t与t_end为间隔24h的两个时刻 40 double t, t_end, t_middle; //采用二分法计算,t与t_end为间隔24h的两个时刻
41 double target_angle;//目标角度 41 double target_angle; //目标角度
42 Date* date_tmp; 42 Date *date_tmp;
43 43
44 //计算每个节气对应太阳地心黄经 44 //计算每个节气对应太阳地心黄经
45 for(int i=0;i<25;i++,time+=12*day) 45 for (int i = 0; i < 25; i++, time += 12 * day) {
46 { 46 target_angle = 15 * i + 270;
47 target_angle=15*i+270; 47 if (target_angle >= 360)
48 if(target_angle>=360) 48 target_angle -= 360;
49 target_angle-=360;
50 49
51 t=julian.getJulianKiloYear(time); 50 t = julian.getJulianKiloYear(time);
52 t_end=julian.getJulianKiloYear(time+day); 51 t_end = julian.getJulianKiloYear(time + day);
53 52
54 //定春分 53 //定春分
55 if(target_angle==0) 54 if (target_angle == 0) {
56 {
57 /* 春分太阳地心视黄经为0,一般二分法不便于计算 55 /* 春分太阳地心视黄经为0,一般二分法不便于计算
58 * 因而限定范围为[355,360)∪(0,5],即春分前后各5度 56 * 因而限定范围为[355,360)∪(0,5],即春分前后各5度
59 * 当t_end时刻太阳地心视黄经在[355,360)时,证明春分在后边,t和t_end前进24h 57 * 当t_end时刻太阳地心视黄经在[355,360)时,证明春分在后边,t和t_end前进24h
60 */ 58 */
61 while(p.sun_longitude(t_end)<360&&p.sun_longitude(t_end)>355) 59 while (p.sun_longitude(t_end) < 360 &&
62 { 60 p.sun_longitude(t_end) > 355) {
63 time+=day; 61 time += day;
64 t=t_end; 62 t = t_end;
65 t_end=julian.getJulianKiloYear(time+day); 63 t_end = julian.getJulianKiloYear(time + day);
66 } 64 }
67 /* 循环体time每次在已经计算出的上一节气基础上前进12日,理论上春分在t_end之后 65 /* 循环体time每次在已经计算出的上一节气基础上前进12日,理论上春分在t_end之后
68 * 当跳出上一while循环时理论上春分时刻正在t与t_end之间 66 * 当跳出上一while循环时理论上春分时刻正在t与t_end之间
69 * 为保险起见,添加这个循环 67 * 为保险起见,添加这个循环
70 * 当t时刻太阳地心视黄经在[0,5]时,证明春分在前边,t和t_end后退24h 68 * 当t时刻太阳地心视黄经在[0,5]时,证明春分在前边,t和t_end后退24h
71 */ 69 */
72 while(p.sun_longitude(t)<5) 70 while (p.sun_longitude(t) < 5) {
73 { 71 time -= day;
74 time-=day; 72 t_end = t;
75 t_end=t; 73 t = julian.getJulianKiloYear(time);
76 t=julian.getJulianKiloYear(time);
77 } 74 }
78 75
79 //二分法计算春分 76 //二分法计算春分
80 while(t_end-t>delta) 77 while (t_end - t > delta) {
81 { 78 t_middle = (t + t_end) / 2;
82 t_middle=(t+t_end)/2; 79 if (p.sun_longitude(t_middle) < 360 &&
83 if(p.sun_longitude(t_middle)<360&&p.sun_longitude(t_middle)>355) 80 p.sun_longitude(t_middle) > 355) {
84 { 81 t = t_middle;
85 t=t_middle; 82 } else {
86 } 83 t_end = t_middle;
87 else
88 {
89 t_end=t_middle;
90 } 84 }
91 } 85 }
92 } 86 }
93 //其他情况 87 //其他情况
94 else 88 else {
95 {
96 //当t_end时刻太阳地心视黄经小于目标角度,节气在后,t和t_end前进24h 89 //当t_end时刻太阳地心视黄经小于目标角度,节气在后,t和t_end前进24h
97 while(p.sun_longitude(t_end)<target_angle) 90 while (p.sun_longitude(t_end) < target_angle) {
98 { 91 time += day;
99 time+=day; 92 t = t_end;
100 t=t_end; 93 t_end = julian.getJulianKiloYear(time + day);
101 t_end=julian.getJulianKiloYear(time+day);
102 } 94 }
103 95
104 //当t时刻太阳地心视黄经大于目标角度,节气在前,t和t_end后退24h 96 //当t时刻太阳地心视黄经大于目标角度,节气在前,t和t_end后退24h
105 //该循环也是一个保险循环 97 //该循环也是一个保险循环
106 while(p.sun_longitude(t)>target_angle) 98 while (p.sun_longitude(t) > target_angle) {
107 { 99 time -= day;
108 time-=day; 100 t_end = t;
109 t_end=t; 101 t = julian.getJulianKiloYear(time);
110 t=julian.getJulianKiloYear(time);
111 } 102 }
112 103
113 while(t_end-t>delta) 104 while (t_end - t > delta) {
114 { 105 t_middle = (t + t_end) / 2;
115 t_middle=(t+t_end)/2; 106 if (p.sun_longitude(t_middle) < target_angle) {
116 if(p.sun_longitude(t_middle)<target_angle) 107 t = t_middle;
117 { 108 } else {
118 t=t_middle; 109 t_end = t_middle;
119 }
120 else
121 {
122 t_end=t_middle;
123 } 110 }
124 } 111 }
125 } 112 }
126 113
127 //链表记录节气信息 114 //链表记录节气信息
128 time=julian.kiloYearToTime(t,i==0?date->tm_year+1899:date->tm_year+1900); 115 time = julian.kiloYearToTime(t, i == 0 ? date->tm_year + 1899
129 date_tmp=localtime(&time); 116 : date->tm_year + 1900);
130 list.append(date_tmp,false,true,i%2==0,i,t); 117 date_tmp = localtime(&time);
118 list.append(date_tmp, false, true, i % 2 == 0, i, t);
131 } 119 }
132} 120}
133 121
134// 用以判断朔日的函数,返回true则太阳地心黄经大于月球地心黄经,即朔日在此后 122// 用以判断朔日的函数,返回true则太阳地心黄经大于月球地心黄经,即朔日在此后
135bool date_forward(double sun_longitude,double moon_longitude) 123bool date_forward(double sun_longitude, double moon_longitude) {
136{
137 /* 判断逻辑 124 /* 判断逻辑
138 * 当moon_longitude<sun_longitude时,由于时刻已经在朔日附近 125 * 当moon_longitude<sun_longitude时,由于时刻已经在朔日附近
139 * 因而可以判断朔日在该时刻之后 126 * 因而可以判断朔日在该时刻之后
@@ -142,90 +129,84 @@ bool date_forward(double sun_longitude,double moon_longitude)
142 * 否则,大于20时候,度数相差过大,理论上只可能为moon_longitude已接近360,sun_longitude略微大于0 129 * 否则,大于20时候,度数相差过大,理论上只可能为moon_longitude已接近360,sun_longitude略微大于0
143 * 此时实际上是月亮应当追赶太阳,因而朔日在此后 130 * 此时实际上是月亮应当追赶太阳,因而朔日在此后
144 */ 131 */
145 return moon_longitude < sun_longitude ? true : (moon_longitude-sun_longitude >= 20); 132 return moon_longitude < sun_longitude
133 ? true
134 : (moon_longitude - sun_longitude >= 20);
146} 135}
147 136
148void ShuoRi(int year) 137void ShuoRi(int year) {
149{ 138 double t, t_end, end,
150 double t,t_end,end,t_middle;//采用二分法计算,t与t_end为间隔24h的两个时刻 139 t_middle; //采用二分法计算,t与t_end为间隔24h的两个时刻
151 time_t time; 140 time_t time;
152 Date* date_tmp=new Date; 141 Date *date_tmp = new Date;
153 142
154 //根据zhongqi_vec的最后一项(今年冬至)计算冬至下一日的0时刻 143 //根据zhongqi_vec的最后一项(今年冬至)计算冬至下一日的0时刻
155 date_tmp->tm_year=list.zhongqi_vec[12]->year-1900; 144 date_tmp->tm_year = list.zhongqi_vec[12]->year - 1900;
156 date_tmp->tm_mon=list.zhongqi_vec[12]->mon-1; 145 date_tmp->tm_mon = list.zhongqi_vec[12]->mon - 1;
157 date_tmp->tm_mday=list.zhongqi_vec[12]->day+1; 146 date_tmp->tm_mday = list.zhongqi_vec[12]->day + 1;
158 date_tmp->tm_hour=0; 147 date_tmp->tm_hour = 0;
159 date_tmp->tm_min=0; 148 date_tmp->tm_min = 0;
160 date_tmp->tm_sec=0; 149 date_tmp->tm_sec = 0;
161 date_tmp->tm_isdst=-1; 150 date_tmp->tm_isdst = -1;
162 time=mktime(date_tmp); 151 time = mktime(date_tmp);
163 end=julian.getJulianKiloYear(time); 152 end = julian.getJulianKiloYear(time);
164 153
165 // 计算去年冬至时刻的time 154 // 计算去年冬至时刻的time
166 date_tmp->tm_year=list.zhongqi_vec[0]->year-1900; 155 date_tmp->tm_year = list.zhongqi_vec[0]->year - 1900;
167 date_tmp->tm_mon=list.zhongqi_vec[0]->mon-1; 156 date_tmp->tm_mon = list.zhongqi_vec[0]->mon - 1;
168 date_tmp->tm_mday=list.zhongqi_vec[0]->day; 157 date_tmp->tm_mday = list.zhongqi_vec[0]->day;
169 date_tmp->tm_hour=list.zhongqi_vec[0]->hour; 158 date_tmp->tm_hour = list.zhongqi_vec[0]->hour;
170 date_tmp->tm_min=list.zhongqi_vec[0]->min; 159 date_tmp->tm_min = list.zhongqi_vec[0]->min;
171 date_tmp->tm_sec=list.zhongqi_vec[0]->sec; 160 date_tmp->tm_sec = list.zhongqi_vec[0]->sec;
172 date_tmp->tm_isdst=-1; 161 date_tmp->tm_isdst = -1;
173 time=mktime(date_tmp); 162 time = mktime(date_tmp);
174 163
175 delete date_tmp; 164 delete date_tmp;
176 165
177 // 定朔日 166 // 定朔日
178 for(t=julian.getJulianKiloYear(time);t<=end;time+=25*day) 167 for (t = julian.getJulianKiloYear(time); t <= end; time += 25 * day) {
179 {
180 // 每月长度为28-30天,因而每次循环前进25天 168 // 每月长度为28-30天,因而每次循环前进25天
181 t=julian.getJulianKiloYear(time); 169 t = julian.getJulianKiloYear(time);
182 t_end=julian.getJulianKiloYear(time+day); 170 t_end = julian.getJulianKiloYear(time + day);
183 171
184 // 太阳在月亮之前,月亮追赶,故朔日在后,t和t_end前进24h 172 // 太阳在月亮之前,月亮追赶,故朔日在后,t和t_end前进24h
185 while(date_forward(p.sun_longitude(t_end),p.moon_longitude(t_end))) 173 while (date_forward(p.sun_longitude(t_end), p.moon_longitude(t_end))) {
186 { 174 time += day;
187 time+=day; 175 t = t_end;
188 t=t_end; 176 t_end = julian.getJulianKiloYear(time + day);
189 t_end=julian.getJulianKiloYear(time+day);
190 } 177 }
191 // 太阳在月亮之后,月亮落后,故朔日在前,t和t_end后退24h(用以保险) 178 // 太阳在月亮之后,月亮落后,故朔日在前,t和t_end后退24h(用以保险)
192 while(!date_forward(p.sun_longitude(t),p.moon_longitude(t))) 179 while (!date_forward(p.sun_longitude(t), p.moon_longitude(t))) {
193 { 180 time -= day;
194 time-=day; 181 t_end = t;
195 t_end=t; 182 t = julian.getJulianKiloYear(time);
196 t=julian.getJulianKiloYear(time);
197 } 183 }
198 184
199 while(t_end-t>=delta) 185 while (t_end - t >= delta) {
200 { 186 t_middle = (t + t_end) / 2;
201 t_middle=(t+t_end)/2; 187 if (date_forward(p.sun_longitude(t_middle),
202 if(date_forward(p.sun_longitude(t_middle),p.moon_longitude(t_middle))) 188 p.moon_longitude(t_middle))) {
203 { 189 t = t_middle;
204 t=t_middle; 190 } else {
205 } 191 t_end = t_middle;
206 else
207 {
208 t_end=t_middle;
209 } 192 }
210 } 193 }
211 // 输出朔日信息 194 // 输出朔日信息
212 time=julian.kiloYearToTime(t,year-1); 195 time = julian.kiloYearToTime(t, year - 1);
213 date_tmp=localtime(&time); 196 date_tmp = localtime(&time);
214 list.append(date_tmp,true,false,false,-1,t); 197 list.append(date_tmp, true, false, false, -1, t);
215 } 198 }
216} 199}
217 200
218int main(int argc,char* argv[]) 201int main(int argc, char *argv[]) {
219{
220 202
221 if(argc!=2) 203 if (argc != 2) {
222 { 204 printf("Usage: %s year\\n\n", argv[0]);
223 printf("Usage: %s year\\n\n",argv[0]);
224 return 0; 205 return 0;
225 } 206 }
226 Date* date=input(argv[1]); 207 Date *date = input(argv[1]);
227 int year=date->tm_year+1900; 208 int year = date->tm_year + 1900;
228 double begin,end; 209 double begin, end;
229 210
230 JieQi(date); 211 JieQi(date);
231 ShuoRi(year); 212 ShuoRi(year);
@@ -240,7 +221,6 @@ int main(int argc,char* argv[])
240 221
241 // 释放内存,使用List的析构函数 222 // 释放内存,使用List的析构函数
242 223
243
244 delete date; 224 delete date;
245 225
246 return 0; 226 return 0;
diff --git a/src/calendar.h b/src/calendar.h
index b17e0d5..73676f5 100644
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -1,12 +1,12 @@
1#ifndef _CALENDAR_H_ 1#ifndef _CALENDAR_H_
2#define _CALENDAR_H_ 2#define _CALENDAR_H_
3 3
4#include <iostream>
5#include <string>
6#include <ctime> 4#include <ctime>
7#include <vector>
8#include <fstream> 5#include <fstream>
6#include <iostream>
9#include <math.h> 7#include <math.h>
8#include <string>
9#include <vector>
10using namespace std; 10using namespace std;
11 11
12extern double pi; 12extern double pi;
@@ -14,114 +14,110 @@ extern double delta;
14extern char jieqi[25][10]; 14extern char jieqi[25][10];
15 15
16typedef struct tm Date; 16typedef struct tm Date;
17struct point 17struct point {
18{ 18 int year, mon, day, hour, min, sec;
19 int year,mon,day,hour,min,sec; 19 bool isShuo, isJieqi, isZhongqi;
20 bool isShuo,isJieqi,isZhongqi; 20 int JieqiIndex, MonthIndex;
21 int JieqiIndex,MonthIndex;
22 bool RunYue; 21 bool RunYue;
23 double time; 22 double time;
24 point* next; 23 point *next;
25 24
26 point(int year,int mon,int day,int hour,int min,int sec,bool isShuo,bool isJieqi,bool isZhongqi,int JieqiIndex,int MonthIndex,bool RunYue,double time) 25 point(int year, int mon, int day, int hour, int min, int sec, bool isShuo,
27 { 26 bool isJieqi, bool isZhongqi, int JieqiIndex, int MonthIndex,
28 this->year=year; 27 bool RunYue, double time) {
29 this->mon=mon; 28 this->year = year;
30 this->day=day; 29 this->mon = mon;
31 this->hour=hour; 30 this->day = day;
32 this->min=min; 31 this->hour = hour;
33 this->sec=sec; 32 this->min = min;
34 this->isShuo=isShuo; 33 this->sec = sec;
35 this->isJieqi=isJieqi; 34 this->isShuo = isShuo;
36 this->isZhongqi=isZhongqi; 35 this->isJieqi = isJieqi;
37 this->JieqiIndex=JieqiIndex; 36 this->isZhongqi = isZhongqi;
38 this->MonthIndex=MonthIndex; 37 this->JieqiIndex = JieqiIndex;
39 this->RunYue=RunYue; 38 this->MonthIndex = MonthIndex;
40 this->time=time; 39 this->RunYue = RunYue;
41 this->next=NULL; 40 this->time = time;
41 this->next = NULL;
42 } 42 }
43}; 43};
44 44
45class Julian 45class Julian {
46{ 46 private:
47 private: 47 static double d[23][5];
48 static double d[23][5];
49 48
50 double dt_ext(int y,double jsd); 49 double dt_ext(int y, double jsd);
51 50
52 //计算力学时与世界时之差,传入年份 51 //计算力学时与世界时之差,传入年份
53 double delta_t(int y); 52 double delta_t(int y);
54 public:
55 // 计算儒略日
56 double getJulianDay(time_t time);
57 53
58 // 计算儒略千年数 54 public:
59 double getJulianKiloYear(time_t time); 55 // 计算儒略日
56 double getJulianDay(time_t time);
60 57
61 //儒略千年数转时间戳 58 // 计算儒略千年数
62 time_t kiloYearToTime(double t,int year); 59 double getJulianKiloYear(time_t time);
63};
64
65
66class parameter
67{
68 private:
69 60
70 // 计算地球日心黄经 61 //儒略千年数转时间戳
71 double get_longitude(vector<double> l,double t); 62 time_t kiloYearToTime(double t, int year);
63};
72 64
73 // 计算地球日心黄纬 65class parameter {
74 double get_latitude(vector<double> b,double t); 66 private:
67 // 计算地球日心黄经
68 double get_longitude(vector<double> l, double t);
75 69
76 double get_R(vector<double> r,double t); 70 // 计算地球日心黄纬
71 double get_latitude(vector<double> b, double t);
77 72
78 // 转换FK5误差,返回弧度制 73 double get_R(vector<double> r, double t);
79 double delta_FK5(double L,double B,double T);
80 74
81 //取章动 75 // FK5误度制
82 vector<double> get_angle(double T); 76 double delta_FK5(double L, double B, double T);
83 77
84 //章动 78 //获取章动关角
85 double nutation(double T); 79 vector<double> get_angle(double T);
86 80
87 //行差修正,返回弧度制 81 //修正
88 double aberration(double R); 82 double nutation(double T);
89 83
90 //地日数,L地球日黄经B为球日黄纬R为日距 84 //
91 vector<vector<double>> get_parameters(double t); 85 double aberration(double R);
92 86
93 public: 87 // 获取地日运行参数,L为地球日心黄经,B为地球日心黄纬,R为地日距离
88 vector<vector<double>> get_parameters(double t);
94 89
95 double sun_longitude(double t); 90 public:
91 double sun_longitude(double t);
96 92
97 double moon_longitude(double t); 93 double moon_longitude(double t);
98}; 94};
99 95
100class List 96class List {
101{ 97 private:
102 private: 98 point *head, *tail; //链表头尾指针
103 point *head,*tail;//链表头尾指针 99
100 bool later(point *a, point *b);
104 101
105 bool later(point* a,point* b); 102 public:
103 vector<point *> shuori_vec; //记录各朔日的地址
104 vector<point *> zhongqi_vec; //记录各中气的地址
106 105
107 public: 106 List();
108 vector<point*> shuori_vec; //记录各朔日的地址 107 ~List();
109 vector<point*> zhongqi_vec;//记录各中气的地址
110 108
111 List(); 109 // 链表尾部插入
112 ~List(); 110 void append(Date *date, bool isShuo, bool isJieqi, bool isZhongqi,
111 int JieqiIndex, double time);
113 112
114 // 链表尾部插入 113 //对链表进行“排序”
115 void append(Date* date,bool isShuo,bool isJieqi,bool isZhongqi,int JieqiIndex,double time); 114 void lunar_sort();
116
117 //对链表进行“排序”
118 void lunar_sort();
119 115
120 //置闰月 116 //置闰月
121 void Run(); 117 void Run();
122 118
123 //输出链表内容 119 //输出链表内容
124 void output(); 120 void output();
125}; 121};
126 122
127#endif 123#endif
diff --git a/src/parameters.cpp b/src/parameters.cpp
index 8a99160..57d98c2 100644
--- a/src/parameters.cpp
+++ b/src/parameters.cpp
@@ -1,130 +1,126 @@
1#include "calendar.h"
2#include "parameters.h" 1#include "parameters.h"
2#include "calendar.h"
3using namespace std; 3using namespace std;
4 4
5//凡无特殊说明的函数,全部返回弧度制 5//凡无特殊说明的函数,全部返回弧度制
6 6
7// 计算地球日心黄经 7// 计算地球日心黄经
8double parameter::get_longitude(vector<double> l,double t) 8double parameter::get_longitude(vector<double> l, double t) {
9{ 9 double L = l[0];
10 double L=l[0]; 10 for (int i = 1; i < l.size(); i++) {
11 for(int i=1;i<l.size();i++) 11 L += l[i] * pow(t, i);
12 {
13 L+=l[i]*pow(t,i);
14 } 12 }
15 //返回弧度制,太阳地心黄经=地球日心黄经+180° 13 //返回弧度制,太阳地心黄经=地球日心黄经+180°
16 return L+pi; 14 return L + pi;
17} 15}
18 16
19// 计算地球日心黄纬 17// 计算地球日心黄纬
20double parameter::get_latitude(vector<double> b,double t) 18double parameter::get_latitude(vector<double> b, double t) {
21{ 19 double B = b[0];
22 double B=b[0]; 20 for (int i = 1; i < b.size(); i++) {
23 for(int i=1;i<b.size();i++) 21 B += b[i] * pow(t, i);
24 {
25 B+=b[i]*pow(t,i);
26 } 22 }
27 //地心黄纬=-太阳黄纬 23 //地心黄纬=-太阳黄纬
28 return -B; 24 return -B;
29} 25}
30 26
31// 计算地日距离,单位为天文单位 27// 计算地日距离,单位为天文单位
32double parameter::get_R(vector<double> r,double t) 28double parameter::get_R(vector<double> r, double t) {
33{ 29 double R = r[0];
34 double R=r[0]; 30 for (int i = 1; i < r.size(); i++) {
35 for(int i=1;i<r.size();i++) 31 R += r[i] * pow(t, i);
36 {
37 R+=r[i]*pow(t,i);
38 } 32 }
39 return R; 33 return R;
40} 34}
41 35
42// 转换FK5误差 36// 转换FK5误差
43double parameter::delta_FK5(double L,double B,double T) 37double parameter::delta_FK5(double L, double B, double T) {
44{ 38 // L转角度制
45 //L转角度制 39 L *= 180 / pi;
46 L*=180/pi;
47 //计算L',角度制 40 //计算L',角度制
48 double L_p=L-1.397*T-0.00031*T*T; 41 double L_p = L - 1.397 * T - 0.00031 * T * T;
49 //计算L',弧度制 42 //计算L',弧度制
50 L_p*=pi/180; 43 L_p *= pi / 180;
51 while(L_p<0) 44 while (L_p < 0)
52 L_p+=2*pi; 45 L_p += 2 * pi;
53 while(L_p>=2*pi) 46 while (L_p >= 2 * pi)
54 L_p-=2*pi; 47 L_p -= 2 * pi;
55 //计算delta_L,单位为角秒 48 //计算delta_L,单位为角秒
56 double delta_L=-0.09033+0.03916*(cos(L_p)+sin(L_p))*tan(B); 49 double delta_L = -0.09033 + 0.03916 * (cos(L_p) + sin(L_p)) * tan(B);
57 //转换为弧度制 50 //转换为弧度制
58 delta_L*=pi/(180*3600); 51 delta_L *= pi / (180 * 3600);
59 return delta_L; 52 return delta_L;
60} 53}
61 54
62//章动有关角,结果均为角度制 55//章动有关角,结果均为角度制
63vector<double> parameter::get_angle(double T) 56vector<double> parameter::get_angle(double T) {
64{
65 vector<double> ang; 57 vector<double> ang;
66 //平距角 58 //平距角
67 ang.push_back(297.85036+445267.111480*T-0.0019142*T*T+T*T*T/189474); 59 ang.push_back(297.85036 + 445267.111480 * T - 0.0019142 * T * T +
60 T * T * T / 189474);
68 //日地平近点角 61 //日地平近点角
69 ang.push_back(357.52772+35999.050340*T-0.0001603*T*T-T*T*T/300000); 62 ang.push_back(357.52772 + 35999.050340 * T - 0.0001603 * T * T -
63 T * T * T / 300000);
70 //月球平近点角 64 //月球平近点角
71 ang.push_back(134.96298+477198.867398*T+0.0086972*T*T+T*T*T/56250); 65 ang.push_back(134.96298 + 477198.867398 * T + 0.0086972 * T * T +
66 T * T * T / 56250);
72 //月球纬度参数 67 //月球纬度参数
73 ang.push_back(93.27191+483202.017538*T-0.0036825*T*T+T*T*T/327270); 68 ang.push_back(93.27191 + 483202.017538 * T - 0.0036825 * T * T +
69 T * T * T / 327270);
74 //黄道与月球平轨道交点黄经 70 //黄道与月球平轨道交点黄经
75 ang.push_back(125.04452-1934.136261*T+0.0020708*T*T+T*T*T/450000); 71 ang.push_back(125.04452 - 1934.136261 * T + 0.0020708 * T * T +
72 T * T * T / 450000);
76 return ang; 73 return ang;
77} 74}
78 75
79//章动修正 76//章动修正
80double parameter::nutation(double T) 77double parameter::nutation(double T) {
81{ 78 vector<double> ang = get_angle(T);
82 vector<double> ang=get_angle(T);
83 double sita; 79 double sita;
84 double s,s1,s2; 80 double s, s1, s2;
85 double c,c1,c2; 81 double c, c1, c2;
86 double m,n,o,p,q; 82 double m, n, o, p, q;
87 83
88 s=c=0; 84 s = c = 0;
89 for(int i=0;i<nutation_size;i++) 85 for (int i = 0; i < nutation_size; i++) {
90 { 86 sita = nutation_parameters[i][0] * ang[0] +
91 sita=nutation_parameters[i][0]*ang[0]+nutation_parameters[i][1]*ang[1]+nutation_parameters[i][2]*ang[2]+nutation_parameters[i][3]*ang[3]+nutation_parameters[i][4]*ang[4]; 87 nutation_parameters[i][1] * ang[1] +
92 sita*=pi/180; 88 nutation_parameters[i][2] * ang[2] +
93 s+=(nutation_parameters[i][5]+nutation_parameters[i][6]*T)*sin(sita); 89 nutation_parameters[i][3] * ang[3] +
94 //c+=(nutation_parameters[i][7]+nutation_parameters[i][8]*T)*cos(sita); 90 nutation_parameters[i][4] * ang[4];
91 sita *= pi / 180;
92 s += (nutation_parameters[i][5] + nutation_parameters[i][6] * T) *
93 sin(sita);
94 // c+=(nutation_parameters[i][7]+nutation_parameters[i][8]*T)*cos(sita);
95 } 95 }
96 // 计算得到的s和c单位0.0001秒,转换为弧度制 96 // 计算得到的s和c单位0.0001秒,转换为弧度制
97 s*=0.0001; 97 s *= 0.0001;
98 s*=pi/(180*3600); 98 s *= pi / (180 * 3600);
99 return s; 99 return s;
100} 100}
101 101
102//光行差修正 102//光行差修正
103double parameter::aberration(double R) 103double parameter::aberration(double R) {
104{
105 //公式,单位0.0001角秒 104 //公式,单位0.0001角秒
106 double delta=-20.4898/R; 105 double delta = -20.4898 / R;
107 //转换为弧度制 106 //转换为弧度制
108 delta*=pi/(180*3600); 107 delta *= pi / (180 * 3600);
109 return delta; 108 return delta;
110} 109}
111 110
112// 获取地日运行参数,L为地球日心黄经,B为地球日心黄纬,R为地日距离 111// 获取地日运行参数,L为地球日心黄经,B为地球日心黄纬,R为地日距离
113vector<vector<double>> parameter::get_parameters(double t) 112vector<vector<double>> parameter::get_parameters(double t) {
114{ 113 double l = 0;
115 double l=0; 114 double a, b, c, num_tmp = 0;
116 double a,b,c,num_tmp=0;
117 vector<vector<double>> parameters; 115 vector<vector<double>> parameters;
118 vector<double> tmp; 116 vector<double> tmp;
119 117
120 //计算L 118 //计算L
121 tmp.resize(0); 119 tmp.resize(0);
122 for(int i=0;i<L_size;i++) 120 for (int i = 0; i < L_size; i++) {
123 { 121 num_tmp = 0;
124 num_tmp=0; 122 for (int j = 0; j < L_length[i]; j++) {
125 for(int j=0;j<L_length[i];j++) 123 num_tmp += L[i][j][0] * cos(L[i][j][1] + L[i][j][2] * t);
126 {
127 num_tmp+=L[i][j][0]*cos(L[i][j][1]+L[i][j][2]*t);
128 } 124 }
129 tmp.push_back(num_tmp); 125 tmp.push_back(num_tmp);
130 } 126 }
@@ -132,12 +128,10 @@ vector<vector<double>> parameter::get_parameters(double t)
132 128
133 //计算B 129 //计算B
134 tmp.resize(0); 130 tmp.resize(0);
135 for(int i=0;i<B_size;i++) 131 for (int i = 0; i < B_size; i++) {
136 { 132 num_tmp = 0;
137 num_tmp=0; 133 for (int j = 0; j < B_length[i]; j++) {
138 for(int j=0;j<B_length[i];j++) 134 num_tmp += B[i][j][0] * cos(B[i][j][1] + B[i][j][2] * t);
139 {
140 num_tmp+=B[i][j][0]*cos(B[i][j][1]+B[i][j][2]*t);
141 } 135 }
142 tmp.push_back(num_tmp); 136 tmp.push_back(num_tmp);
143 } 137 }
@@ -145,18 +139,15 @@ vector<vector<double>> parameter::get_parameters(double t)
145 139
146 //计算R 140 //计算R
147 tmp.resize(0); 141 tmp.resize(0);
148 for(int i=0;i<R_size;i++) 142 for (int i = 0; i < R_size; i++) {
149 { 143 num_tmp = 0;
150 num_tmp=0; 144 for (int j = 0; j < R_length[i]; j++) {
151 for(int j=0;j<R_length[i];j++) 145 num_tmp += R[i][j][0] * cos(R[i][j][1] + R[i][j][2] * t);
152 {
153 num_tmp+=R[i][j][0]*cos(R[i][j][1]+R[i][j][2]*t);
154 } 146 }
155 tmp.push_back(num_tmp); 147 tmp.push_back(num_tmp);
156 } 148 }
157 parameters.push_back(tmp); 149 parameters.push_back(tmp);
158 150
159
160 /* 最终传参情况: 151 /* 最终传参情况:
161 * parameters[0]为L系列,用来计算地球日心黄经 152 * parameters[0]为L系列,用来计算地球日心黄经
162 * parameters[1]为B系列,用来计算地球日心黄纬 153 * parameters[1]为B系列,用来计算地球日心黄纬
@@ -166,71 +157,71 @@ vector<vector<double>> parameter::get_parameters(double t)
166} 157}
167 158
168// 计算太阳地心黄经,外部调用,返回角度制 159// 计算太阳地心黄经,外部调用,返回角度制
169double parameter::sun_longitude(double t) 160double parameter::sun_longitude(double t) {
170{
171 //从文件中计算地日运行参数 161 //从文件中计算地日运行参数
172 vector<vector<double>> p=get_parameters(t); 162 vector<vector<double>> p = get_parameters(t);
173 163
174 //取出各类参数 164 //取出各类参数
175 vector<double> l=p[0],b=p[1],r=p[2]; 165 vector<double> l = p[0], b = p[1], r = p[2];
176 166
177 //计算地球日心黄经纬,返回弧度制/天文单位 167 //计算地球日心黄经纬,返回弧度制/天文单位
178 double L=get_longitude(l,t); 168 double L = get_longitude(l, t);
179 double B=get_latitude(b,t); 169 double B = get_latitude(b, t);
180 double R=get_R(r,t); 170 double R = get_R(r, t);
181
182 171
183 //以下修正需要的都是儒略世纪数而非千年数 172 //以下修正需要的都是儒略世纪数而非千年数
184 //转FK5误差,返回弧度制 173 //转FK5误差,返回弧度制
185 L+=delta_FK5(L,B,10*t); 174 L += delta_FK5(L, B, 10 * t);
186 //章动修正,返回弧度制 175 //章动修正,返回弧度制
187 L+=nutation(10*t); 176 L += nutation(10 * t);
188 //光行差修正,返回弧度制 177 //光行差修正,返回弧度制
189 L+=aberration(R); 178 L += aberration(R);
190 179
191 180 // L转角度制
192 //L转角度制 181 L *= 180 / pi;
193 L*=180/pi; 182 while (L < 0)
194 while(L<0) 183 L += 360;
195 L+=360; 184 while (L >= 360)
196 while(L>=360) 185 L -= 360;
197 L-=360;
198 return L; 186 return L;
199} 187}
200 188
201// 计算月球地心黄经,外部调用,返回角度制 189// 计算月球地心黄经,外部调用,返回角度制
202double parameter::moon_longitude(double t) 190double parameter::moon_longitude(double t) {
203{ 191 double T = 10 * t;
204 double T=10*t; 192 vector<double> angles = get_angle(T);
205 vector<double> angles=get_angle(T); 193 double a, b, c, d, moon_longitude_a;
206 double a,b,c,d,moon_longitude_a; 194
207 195 double L = 218.3164591 + 481267.88134236 * T - 0.0013268 * T * T +
208 double L=218.3164591+481267.88134236*T-0.0013268*T*T+T*T*T/538841-T*T*T*T/65194000;//月球平黄经 196 T * T * T / 538841 - T * T * T * T / 65194000; //月球平黄经
209 double EI=0,sita=0; 197 double EI = 0, sita = 0;
210 double E=1-0.002516*T-0.0000074*T*T;//地球离心率 198 double E = 1 - 0.002516 * T - 0.0000074 * T * T; //地球离心率
211 199
212 for(int i=0;i<moon_size;i++) 200 for (int i = 0; i < moon_size; i++) {
213 { 201 sita = moon_longitude_parameters[i][0] * angles[0] +
214 sita=moon_longitude_parameters[i][0]*angles[0]+moon_longitude_parameters[i][1]*angles[1]+moon_longitude_parameters[i][2]*angles[2]+moon_longitude_parameters[i][3]*angles[3]; 202 moon_longitude_parameters[i][1] * angles[1] +
215 sita*=pi/180; 203 moon_longitude_parameters[i][2] * angles[2] +
216 EI+=moon_longitude_parameters[i][4]*sin(sita)*pow(E,fabs(moon_longitude_parameters[i][1])); 204 moon_longitude_parameters[i][3] * angles[3];
205 sita *= pi / 180;
206 EI += moon_longitude_parameters[i][4] * sin(sita) *
207 pow(E, fabs(moon_longitude_parameters[i][1]));
217 } 208 }
218 209
219 //地外行星影响月球地心黄经修正项 210 //地外行星影响月球地心黄经修正项
220 double a1,a2; 211 double a1, a2;
221 a1=119.75+131.849*T; 212 a1 = 119.75 + 131.849 * T;
222 a2=53.09+479264.290*T; 213 a2 = 53.09 + 479264.290 * T;
223 214
224 EI+=3958.0*sin(a1*pi/180); 215 EI += 3958.0 * sin(a1 * pi / 180);
225 EI+=1962.0*sin((L-angles[3])*pi/180); 216 EI += 1962.0 * sin((L - angles[3]) * pi / 180);
226 EI+=318.0*sin(a2*pi/180); 217 EI += 318.0 * sin(a2 * pi / 180);
227 218
228 L+=EI/1000000; 219 L += EI / 1000000;
229 L+=180/pi*nutation(T);//地球章动修正 220 L += 180 / pi * nutation(T); //地球章动修正
230 221
231 while(L<0) 222 while (L < 0)
232 L+=360; 223 L += 360;
233 while(L>=360) 224 while (L >= 360)
234 L-=360; 225 L -= 360;
235 return L; 226 return L;
236} 227}
diff --git a/test.sh b/test.sh
index 547054c..645eabe 100755
--- a/test.sh
+++ b/test.sh
@@ -8,36 +8,26 @@
8# Created Time : 2023-10-06 8# Created Time : 2023-10-06
9########################################################################## 9##########################################################################
10 10
11# 写一个脚本,测试已经生成的main的功能
12# 输入年份为自1976年至2076年的任意年份
13# 如果未出现段错误就重定向输出到res.txt,否则输出到err.txt,并在屏幕上显示出错的年份 11# 如果未出现段错误就重定向输出到res.txt,否则输出到err.txt,并在屏幕上显示出错的年份
14 12
15# 设置要测试的可执行文件 13# 设置要测试的可执行文件
16executable="main" 14executable="main"
17 15
18# 清空res.txt和err.txt
19echo "" > res.txt 16echo "" > res.txt
20 17
21# 循环测试年份,计算总用时为多少秒
22start_time=$(date +%s) 18start_time=$(date +%s)
23for year in {1900..2100}; do 19for year in {1800..2200}; do
24 echo "==================测试年份 $year=====================" 20 echo "==================测试年份 $year====================="
25 21
26 # 执行可执行文件,并捕获标准输出和标准错误
27 output=$(./$executable "$year" 2>&1) 22 output=$(./$executable "$year" 2>&1)
28 23
29 # 获取命令的退出状态码
30 exit_code=$? 24 exit_code=$?
31
32 if [ $exit_code -eq 0 ]; then 25 if [ $exit_code -eq 0 ]; then
33 # 执行正常,将输出重定向到res.txt
34 echo -e "$year:\n$output" >> res.txt 26 echo -e "$year:\n$output" >> res.txt
35 # echo "执行正常"
36 else 27 else
37 # 执行异常,将错误信息重定向到err.txt 28 # 执行异常,将错误信息重定向到err.txt
38 echo -e "$year:\n$output" >> err.txt 29 echo -e "$year:\n$output" >> err.txt
39 echo "执行异常(退出码: $exit_code)" 30 echo "执行异常(退出码: $exit_code)"
40 # 停止执行
41 exit 1 31 exit 1
42 fi 32 fi
43done 33done