├── .gitattributes ├── .gitignore ├── SharpSxwnl.sln ├── SharpSxwnl ├── ClassDiagram.cd ├── JD.cs ├── JWdata.cs ├── JieQiInfo.cs ├── JnbArrayList.cs ├── Lunar.cs ├── LunarHelper.cs ├── LunarInfoListT.cs ├── Properties │ └── AssemblyInfo.cs ├── SSQ.cs ├── SZJ.cs ├── SharpSxwnl.csproj ├── SharpSxwnl.xml ├── XL.cs ├── ZB.cs ├── ob.cs ├── oba.cs ├── obb.cs ├── sun_moon.cs └── xList.cs ├── TestSharpSxwnl ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── TestSharpSxwnl.csproj ├── frmMainTest.Designer.cs ├── frmMainTest.cs ├── frmMainTest.resx ├── frmMethodsTest.Designer.cs ├── frmMethodsTest.cs └── frmMethodsTest.resx └── test ├── App.config ├── Program.cs ├── Properties └── AssemblyInfo.cs └── test.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | /test 244 | -------------------------------------------------------------------------------- /SharpSxwnl.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSxwnl", "SharpSxwnl\SharpSxwnl.csproj", "{B37552EC-C668-4A11-977A-16BC1D21B847}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestSharpSxwnl", "TestSharpSxwnl\TestSharpSxwnl.csproj", "{437A253A-DB9C-43A5-AC32-81AB24C7F053}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{771D44CF-541A-44C6-94DA-2997E96F6267}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {B37552EC-C668-4A11-977A-16BC1D21B847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {B37552EC-C668-4A11-977A-16BC1D21B847}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {B37552EC-C668-4A11-977A-16BC1D21B847}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {B37552EC-C668-4A11-977A-16BC1D21B847}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {437A253A-DB9C-43A5-AC32-81AB24C7F053}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {437A253A-DB9C-43A5-AC32-81AB24C7F053}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {437A253A-DB9C-43A5-AC32-81AB24C7F053}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {437A253A-DB9C-43A5-AC32-81AB24C7F053}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {771D44CF-541A-44C6-94DA-2997E96F6267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {771D44CF-541A-44C6-94DA-2997E96F6267}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {771D44CF-541A-44C6-94DA-2997E96F6267}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {771D44CF-541A-44C6-94DA-2997E96F6267}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /SharpSxwnl/ClassDiagram.cd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | RQADAgCIAAAiAAIBBYgAAAAAAQEAEEgAAgEAQAAAQAg= 7 | Helper.cs 8 | 9 | 10 | 11 | 12 | 13 | AAAQBAgAAAIAACAAkAAAAAAACAACCIACQ4QABAIAIAE= 14 | JD.cs 15 | 16 | 17 | 18 | 19 | 20 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= 21 | JnbArrayList.cs 22 | 23 | 24 | 25 | 26 | 27 | AAAAAAAgAAAAAAAAAAAEAAAAgAIQAAAARAAAAAAJAiA= 28 | JWdata.cs 29 | 30 | 31 | 32 | 33 | 34 | QAAAEKABAAAgCACgAAAEEAAEIAgAAQBAAgCgBAAAAAA= 35 | Lunar.cs 36 | 37 | 38 | 39 | 40 | 41 | AAAAAAABAAAAAAAAAAgQgALBCgGAhECEQIEAAUgAAAA= 42 | LunarInfoListT.cs 43 | 44 | 45 | 46 | 47 | 48 | INAkAgKRACEAAACAhAIBAgJE2wACwKBEoiCgpAEAgAA= 49 | ob.cs 50 | 51 | 52 | 53 | 54 | 55 | AAAAAAAAAAAEIAAAAIAERAAAAAAAAAAAAAAAAAAACAA= 56 | oba.cs 57 | 58 | 59 | 60 | 61 | 62 | kBRCAAAAUBACIoDCFRiRAgIBIQBAAABAACCQAAEAAAQ= 63 | obb.cs 64 | 65 | 66 | 67 | 68 | 69 | gAQAGAAgABIAAEAAACCAAAAAhAiAAAIgAAAAAIAiLAo= 70 | SSQ.cs 71 | 72 | 73 | 74 | 75 | 76 | ADCAAkIAAAIBA8QBIBgKhgBAAUgAEMAAIAQBAgYEEAA= 77 | sun_moon.cs 78 | 79 | 80 | 81 | 82 | 83 | AACAIAAAAAAAAAAAAAAAEAAAIAAIABAAAAwAAgQAQAA= 84 | SZJ.cs 85 | 86 | 87 | 88 | 89 | 90 | AgIAAAAIDABAJCAAABBQYgAAhAAhIAAAAwIAAAAAICA= 91 | XL.cs 92 | 93 | 94 | 95 | 96 | 97 | AACACAIAQAAAIAQAAABADIQAACAAAgAACAADSIAAAAA= 98 | ZB.cs 99 | 100 | 101 | 102 | 103 | 104 | AAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAA= 105 | xList.cs 106 | 107 | 108 | 109 | 110 | 111 | gAAAAAAAAAAEAAAQAAAAAAQAIAACAACAAAAAAEAAAQA= 112 | JieQiInfo.cs 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /SharpSxwnl/JD.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 日期元件 9 | /// 10 | public static class JD 11 | { 12 | #region 公共属性(注: 初始转换时为公共字段, 已改写, 请参阅“转换时增加的私有字段”) 13 | 14 | /// 15 | /// 年 16 | /// 17 | public static double Y 18 | { 19 | get { return JD.__Y; } 20 | set { JD.__Y = value; } 21 | } 22 | 23 | /// 24 | /// 月 25 | /// 26 | public static double M 27 | { 28 | get { return JD.__M; } 29 | set { JD.__M = value; } 30 | } 31 | 32 | /// 33 | /// 日 34 | /// 35 | public static double D 36 | { 37 | get { return JD.__D; } 38 | set { JD.__D = value; } 39 | } 40 | 41 | /// 42 | /// 时 43 | /// 44 | public static double h 45 | { 46 | get { return JD.__h; } 47 | set { JD.__h = value; } 48 | } 49 | 50 | /// 51 | /// 分 52 | /// 53 | public static double m 54 | { 55 | get { return JD.__m; } 56 | set { JD.__m = value; } 57 | } 58 | 59 | /// 60 | /// 秒 61 | /// 62 | public static double s 63 | { 64 | get { return JD.__s; } 65 | set { JD.__s = value; } 66 | } 67 | 68 | /// 69 | /// 星期中文名称 70 | /// 71 | public static string[] Weeks 72 | { 73 | get { return JD.__Weeks; } 74 | set { JD.__Weeks = value; } 75 | } 76 | 77 | #endregion 公共属性 78 | 79 | 80 | 81 | #region 私有字段 82 | 83 | /// 84 | /// TD - UT1 计算表 85 | /// 86 | private static double[] dts = new double[] { 87 | -4000,108371.7,-13036.80,392.000, 0.0000, -500, 17201.0, -627.82, 16.170,-0.3413, 88 | -150, 12200.6, -346.41, 5.403,-0.1593, 150, 9113.8, -328.13, -1.647, 0.0377, 89 | 500, 5707.5, -391.41, 0.915, 0.3145, 900, 2203.4, -283.45, 13.034,-0.1778, 90 | 1300, 490.1, -57.35, 2.085,-0.0072, 1600, 120.0, -9.81, -1.532, 0.1403, 91 | 1700, 10.2, -0.91, 0.510,-0.0370, 1800, 13.4, -0.72, 0.202,-0.0193, 92 | 1830, 7.8, -1.81, 0.416,-0.0247, 1860, 8.3, -0.13, -0.406, 0.0292, 93 | 1880, -5.4, 0.32, -0.183, 0.0173, 1900, -2.3, 2.06, 0.169,-0.0135, 94 | 1920, 21.2, 1.69, -0.304, 0.0167, 1940, 24.2, 1.22, -0.064, 0.0031, 95 | 1960, 33.2, 0.51, 0.231,-0.0109, 1980, 51.0, 1.29, -0.026, 0.0032, 96 | 2000, 63.87, 0.1, 0, 0, 2005 97 | }; 98 | 99 | #endregion 私有字段 100 | 101 | 102 | 103 | #region 公共方法 104 | /// 105 | /// 二次曲线外推 106 | /// 107 | /// 108 | /// 109 | /// 110 | public static double deltatExt(double y, double jsd) 111 | { 112 | double dy = (y - 1820) / 100; 113 | return -20 + jsd * dy * dy; 114 | } 115 | 116 | 117 | 118 | /// 119 | /// 计算世界时与原子时之差,传入年 120 | /// 121 | /// 年 122 | /// 123 | public static double deltatT(double y) 124 | { 125 | if (y >= 2005) 126 | { 127 | //sd 是2005年之后几年(一值到y1年)的速度估计。 128 | //jsd 是y1年之后的加速度估计。瑞士星历表jsd=31,NASA网站jsd=32,skmap的jsd=29 129 | double y1 = 2014, sd = 0.4, jsd = 31; 130 | if (y <= y1) 131 | return 64.7 + (y - 2005) * sd; //直线外推 132 | double v = JD.deltatExt(y, jsd); //二次曲线外推 133 | double dv = JD.deltatExt(y1, jsd) - (64.7 + (y1 - 2005) * sd); //y1年的二次外推与直线外推的差 134 | if (y < y1 + 100) 135 | v -= dv * (y1 + 100 - y) / 100; 136 | return v; 137 | } 138 | int i; 139 | double[] d = JD.dts; 140 | for (i = 0; i < d.Length; i += 5) 141 | if (y < d[i + 5]) 142 | break; 143 | double t1 = (y - d[i]) / (d[i + 5] - d[i]) * 10, t2 = t1 * t1, t3 = t2 * t1; 144 | return d[i + 1] + d[i + 2] * t1 + d[i + 3] * t2 + d[i + 4] * t3; 145 | } 146 | 147 | 148 | 149 | /// 150 | /// 传入儒略日(J2000起算),计算TD-UT(单位:日) 151 | /// 152 | /// J2000起算的儒略日 153 | /// 154 | public static double deltatT2(double t) 155 | { 156 | return JD.deltatT(t / 365.2425 + 2000) / 86400.0; 157 | } 158 | 159 | 160 | 161 | /// 162 | /// 公历转儒略日 163 | /// 164 | /// 年 165 | /// 月 166 | /// 日 167 | /// 168 | public static double JD__(double y, double m, double d) // C#: 为了避免与类名相同而冲突(被视为构造函数), 按转换规范 1 为方法名添加下划线 169 | { 170 | double n = 0, G = 0; 171 | if (y * 372 + m * 31 + LunarHelper.int2(d) >= 588829) 172 | G = 1; //判断是否为格里高利历日1582*372+10*31+15 173 | if (m <= 2) { m += 12; y--; } 174 | if (G != 0) 175 | { 176 | n = LunarHelper.int2(y / 100); 177 | n = 2 - n + LunarHelper.int2(n / 4); 178 | } //加百年闰 179 | return LunarHelper.int2(365.25 * (y + 4716) + 0.01) + LunarHelper.int2(30.6001 * (m + 1)) + d + n - 1524.5; 180 | } 181 | 182 | 183 | 184 | /// 185 | /// 公历转儒略日 186 | /// 187 | /// 188 | public static double toJD() 189 | { 190 | return JD.JD__(JD.Y, JD.M, JD.D + ((JD.s / 60 + JD.m) / 60 + JD.h) / 24); 191 | } 192 | 193 | 194 | 195 | /// 196 | /// 儒略日数转公历 197 | /// 198 | /// 儒略日 199 | public static void setFromJD(double jd) 200 | { 201 | jd += 0.5; 202 | double A = LunarHelper.int2(jd), F = jd - A, D; //取得日数的整数部份A及小数部分F 203 | if (A >= 2299161) 204 | { 205 | D = LunarHelper.int2((A - 1867216.25) / 36524.25); 206 | A += 1 + D - LunarHelper.int2(D / 4); 207 | } 208 | A += 1524; //向前移4年零2个月 209 | JD.Y = LunarHelper.int2((A - 122.1) / 365.25); //年 210 | D = A - LunarHelper.int2(365.25 * JD.Y); //去除整年日数后余下日数 211 | JD.M = LunarHelper.int2(D / 30.6001); //月数 212 | JD.D = D - LunarHelper.int2(JD.M * 30.6001); //去除整月日数后余下日数 213 | JD.Y -= 4716; JD.M--; 214 | if (JD.M > 12) JD.M -= 12; 215 | if (JD.M <= 2) JD.Y++; 216 | 217 | //日的小数转为时分秒 218 | F *= 24; JD.h = LunarHelper.int2(F); F -= JD.h; 219 | F *= 60; JD.m = LunarHelper.int2(F); F -= JD.m; 220 | F *= 60; JD.s = F; 221 | } 222 | 223 | 224 | 225 | /// 226 | /// 日期转为串 227 | /// 228 | /// 229 | public static string toStr() 230 | { 231 | string Y = " " + JD.Y, M = "0" + JD.M, D = "0" + JD.D; 232 | double h = JD.h, m = JD.m, s = LunarHelper.int2(JD.s + .5); 233 | if (s >= 60) { s -= 60; m++; } 234 | if (m >= 60) { m -= 60; h++; } 235 | string hStr = "0" + h, mStr = "0" + m, sStr = "0" + s; 236 | Y = Y.Substring(Y.Length - 5, 5); 237 | M = M.Substring(M.Length - 2, 2); 238 | D = D.Substring(D.Length - 2, 2); 239 | hStr = hStr.Substring(hStr.Length - 2, 2); 240 | mStr = mStr.Substring(mStr.Length - 2, 2); 241 | sStr = sStr.Substring(sStr.Length - 2, 2); 242 | return Y + "-" + M + "-" + D + " " + hStr + ":" + mStr + ":" + sStr; 243 | } 244 | 245 | 246 | 247 | /// 248 | /// 儒略日数转公历, 并且返回日期转化的时间串 249 | /// 250 | /// 251 | /// 252 | public static string setFromJD_str(double jd) 253 | { 254 | JD.setFromJD(jd); 255 | return JD.toStr(); 256 | } 257 | 258 | 259 | /// 260 | /// 提取jd中的时间(去除日期) 261 | /// 262 | /// 263 | /// 264 | public static string timeStr(double jd) 265 | { 266 | double h, m, s; 267 | jd += 0.5; jd = (jd - LunarHelper.int2(jd)); 268 | jd *= 24; h = LunarHelper.int2(jd); jd -= h; 269 | jd *= 60; m = LunarHelper.int2(jd); jd -= m; 270 | jd *= 60; s = LunarHelper.int2(jd + 0.5); 271 | if (s >= 60) { s -= 60; m++; } 272 | if (m >= 60) { m -= 60; h++; } 273 | string hStr = "0" + h, mStr = "0" + m, sStr = "0" + s; 274 | return hStr.Substring(hStr.Length - 2, 2) + ':' + mStr.Substring(mStr.Length - 2, 2) + ':' + sStr.Substring(sStr.Length - 2, 2); 275 | } 276 | 277 | 278 | 279 | #region 星期相关的公共方法 280 | 281 | /// 282 | /// 星期计算 283 | /// 284 | /// 285 | /// 286 | public static double getWeek(double jd) 287 | { 288 | return LunarHelper.int2(jd + 1.5) % 7; 289 | } 290 | 291 | 292 | /// 293 | /// 求y年m月的第n个星期w的儒略日数 294 | /// 295 | /// 年 296 | /// 月 297 | /// 298 | /// 星期w 299 | /// 300 | public static double nnweek(double y, double m, double n, double w) 301 | { 302 | double jd = JD.JD__(y, m, 1.5); //月首儒略日 303 | double w0 = (jd + 1) % 7; //月首的星期 304 | double r = jd - w0 + 7 * n + w; //jd-w0+7*n是和n个星期0,起算下本月第一行的星期日(可能落在上一月)。加w后为第n个星期w 305 | if (w >= w0) r -= 7; //第1个星期w可能落在上个月,造成多算1周,所以考虑减1周 306 | if (n == 5) 307 | { 308 | m++; if (m > 12) { m = 1; y++; } //下个月 309 | if (r >= JD.JD__(y, m, 1.5)) r -= 7; //r跑到下个月则减1周 310 | } 311 | return r; 312 | } 313 | 314 | #endregion 星期相关的公共方法 315 | 316 | 317 | #endregion 公共方法 318 | 319 | 320 | 321 | #region 转换时增加的私有字段(用于封装成公共属性, 按转换规范 10 命名) 322 | 323 | private static double __Y = 2000; // 年 324 | private static double __M = 1; // 月 325 | private static double __D = 1; // 日 326 | private static double __h = 12; // 时 327 | private static double __m = 0; // 分 328 | private static double __s = 0; // 秒 329 | private static string[] __Weeks = new string[] { "日", "一", "二", "三", "四", "五", "六", "七" }; // 星期中文名称 330 | 331 | #endregion 332 | 333 | } 334 | } 335 | -------------------------------------------------------------------------------- /SharpSxwnl/JWdata.cs: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------------------------------------- 2 | 地理经纬度数据: 3 | 4 | 经纬度的压缩编码细节(以经度79度48分 北纬12度49分 为例,): 5 | 字元表 s = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 共62个字元 6 | 数字 0 编码为 s 中的第 1 个字符(0) 7 | 数字 1 编码为 s 中的第 2 个字符(1) 8 | 数字 10 编码为 s 中的第 11 个字符(A) 9 | 数字 59 编码为 s 中的第 60 个字符(x) 10 | ... 11 | 1.将'度'减去73,即79-73 = 6,因为我国各地经度在73到133度之间,减73之后,经度就变为0到60之间的数 12 | 2.使用字元表对 '6度'进行编码,得到字符6,编码后只用一个字母就可以表示"度" 13 | 3.使用字元表对'48分'进行编码,得到字符m,编码后只用一个字母就可以表示"分" 14 | 4.最后,79度48分被编码为 6m 15 | 5.同样方法对纬度编码(但不用减73)得到 Cn 16 | 6.经纬度的总编码为(纬度放在前) Cn6m 17 | 7.解码过程是上面过程的逆运算。通过以上处理,比常规表示法减少60%的数据量 18 | -------------------------------------------------------------------------------------------------------------------*/ 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Text; 23 | using System.Xml; 24 | using System.Text.RegularExpressions; 25 | 26 | namespace SharpSxwnl 27 | { 28 | /// 29 | /// 经纬及时区类 30 | /// 31 | public static class JWdata 32 | { 33 | #region 公共属性(注: 初始转换时为公共字段, 已改写, 请参阅“转换时增加的私有字段”) 34 | 35 | /// 36 | /// 经度(弧度值) 37 | /// 38 | public static double J { get; set; } // = 0; 39 | 40 | /// 41 | /// 纬度(弧度值) 42 | /// 43 | public static double W { get; set; } // = 0; 44 | 45 | /// 46 | /// 存储压缩的各地经纬度数据, 功能类似于交错数组 string[][] 47 | /// 48 | public static xList> JWv 49 | { 50 | get { return JWdata.__JWv; } 51 | set { JWdata.__JWv = value; } 52 | } 53 | 54 | /// 55 | /// 存储压缩的各时区数据, 功能类似于交错数组 string[][] 56 | /// 57 | public static xList> SQv 58 | { 59 | get { return JWdata.__SQv; } 60 | set { JWdata.__SQv = value; } 61 | } 62 | 63 | #endregion 64 | 65 | 66 | 67 | 68 | #region 私有方法 69 | 70 | /// 71 | /// 初始化数据 72 | /// 73 | private static int InitJWdata() 74 | { 75 | JWdata.DaylightInfo = String.Empty; 76 | JWdata.SQDescription = String.Empty; 77 | 78 | //---------------------------------------------------------------------------------------- 79 | // 加载 Xml 数据: 各地经纬度表, 时区表 80 | // 注: 加载时自动去除 Xml 各行数据前、后端的所有空白字符, 但对数据内部的空白字符不作处理 81 | //---------------------------------------------------------------------------------------- 82 | if (LunarHelper.SxwnlXmlData != null) 83 | { 84 | const string JWvXPath = "SharpSxwnl/SxwnlData/Data[@Id = 'JWdata_JWv']"; 85 | const string SQvXPath = "SharpSxwnl/SxwnlData/Data[@Id = 'JWdata_SQv']"; 86 | 87 | XmlNode foundNode; 88 | Regex regexToTrim = new Regex(@"(^\s*)|(\s*$)"); // C#: 匹配任何前后端的空白字符 89 | char[] lineFlags = new char[] { '\r', '\n' }; 90 | 91 | 92 | // 读取并解开各地经纬度表 93 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(JWvXPath); 94 | if (foundNode != null) 95 | { 96 | string[] strJWv = regexToTrim.Replace(foundNode.InnerText, "").Split(lineFlags, StringSplitOptions.RemoveEmptyEntries); 97 | for (int i = 0; i < strJWv.Length; i++) 98 | { 99 | JWdata.JWv.Add(new xList()); 100 | JWdata.JWv[i].AddRange(regexToTrim.Replace(strJWv[i], "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); //解开清单 101 | } 102 | } 103 | 104 | 105 | // 读取并解开各时区表 106 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(SQvXPath); 107 | if (foundNode != null) 108 | { 109 | string[] strSQv = regexToTrim.Replace(foundNode.InnerText, "").Split(lineFlags, StringSplitOptions.RemoveEmptyEntries); 110 | for (int i = 0; i < strSQv.Length; i++) 111 | { 112 | JWdata.SQv.Add(new xList()); 113 | JWdata.SQv[i].AddRange(regexToTrim.Replace(strSQv[i], "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); //解开各地时区清单 114 | } 115 | } 116 | 117 | } 118 | 119 | return 1; 120 | } 121 | 122 | 123 | #endregion 124 | 125 | 126 | 127 | #region 公共方法 128 | 129 | /// 130 | /// 经纬度解压缩 131 | /// 132 | /// 经纬度字符串(压缩格式) 133 | public static void JWdecode(string v) 134 | { 135 | int i; 136 | char[] vChar = v.ToCharArray(); 137 | int[] vAscii = new int[4]; 138 | for (i = 0; i < 4; i++) //对经纬度解压缩 139 | { 140 | vAscii[i] = vChar[i]; 141 | if (vAscii[i] > 96) vAscii[i] -= (97 - 36); 142 | else if (vAscii[i] > 64) vAscii[i] -= (65 - 10); 143 | else vAscii[i] -= 48; 144 | } 145 | JWdata.J = -(vAscii[2] + vAscii[3] / 60d + 73) / 180d * Math.PI; // C#: 注意数据类型 146 | JWdata.W = (vAscii[0] + vAscii[1] / 60d) / 180d * Math.PI; 147 | } 148 | 149 | #endregion 150 | 151 | 152 | 153 | #region 转换时新增的公共属性和方法 154 | 155 | /// 156 | /// 时差 157 | /// 158 | public static double SQTimeDifference { get; set; } // = 0; // 时差 159 | 160 | /// 161 | /// 日光参数 162 | /// 163 | public static string DaylightInfo { get; set; } // = ""; // 日光参数 164 | 165 | /// 166 | /// 时区描述 167 | /// 168 | public static string SQDescription { get; set; } // = ""; // 时区描述 169 | 170 | 171 | /// 172 | /// 解析时区信息数据, 并保存到静态公共属性中 173 | /// 174 | /// 175 | public static void SQdecode(string strSQInfo) 176 | { 177 | string[] SQInfos = strSQInfo.Split('#'); 178 | JWdata.SQTimeDifference = double.Parse(SQInfos[0]); 179 | JWdata.DaylightInfo = SQInfos[1]; 180 | JWdata.SQDescription = SQInfos[2]; 181 | } 182 | 183 | #endregion 184 | 185 | 186 | 187 | 188 | #region 转换时增加的私有字段(主要用于封装成公共属性, 按转换规范 10 命名), 及其初始化 189 | 190 | /// 191 | /// 存储压缩的各地经纬度数据 192 | /// 193 | private static xList> __JWv = new xList>(); // C#: 注: 与下面的数据相关, 共 32 个省区 194 | 195 | /// 196 | /// 存储压缩的各时区数据 197 | /// 198 | private static xList> __SQv = new xList>(); // C#: 注: 与下面的数据相关, 共 6 个大洲 199 | 200 | private static int nothing = JWdata.InitJWdata(); // C#: 通过一个私有字段的赋值来初始化本类的数组 201 | 202 | #endregion 203 | 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /SharpSxwnl/JieQiInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 节气信息(转换时新增的类) 9 | /// 10 | public class JieQiInfo 11 | { 12 | #region 构造函数 13 | 14 | public JieQiInfo() 15 | { 16 | this.Name = String.Empty; 17 | this.Time = String.Empty; 18 | this.YueJian = String.Empty; 19 | } 20 | 21 | #endregion 22 | 23 | 24 | 25 | #region 公共属性 26 | 27 | /// 28 | /// 节气名称 29 | /// 30 | public string Name { get; set; } 31 | 32 | /// 33 | /// 交节时间(儒历日) 34 | /// 35 | public double JDTime { get; set; } 36 | 37 | /// 38 | /// 交节时间串 39 | /// 40 | public string Time { get; set; } 41 | 42 | /// 43 | /// 实历交节时间(儒历日, 精度仅至年月日) 44 | /// 45 | public double HistoricalJDTime { get; set; } 46 | 47 | /// 48 | /// 实历交节时间串(仅年月日可用, 时间部分均为 12:00:00) 49 | /// 50 | public string HistoricalTime { get; set; } 51 | 52 | /// 53 | /// 交节时间与实历交节时间是否存在差异的标记 54 | /// 55 | public bool DifferentTime { get; set; } 56 | 57 | /// 58 | /// 节气标志: True - 节, False - 气 59 | /// 60 | public bool JieOrQi { get; set; } 61 | 62 | /// 63 | /// 月建(地支), 仅对节论月建(气不论月建) 64 | /// 65 | public string YueJian { get; set; } 66 | 67 | /// 68 | /// 实历月建(地支), 仅对节论月建(气不论月建) 69 | /// 70 | public int DayDifference { get; set; } 71 | 72 | #endregion 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /SharpSxwnl/JnbArrayList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections; 5 | using System.Xml; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace SharpSxwnl 9 | { 10 | /// 11 | /// 纪年表数据 12 | /// 13 | public class JnbArrayList : ArrayList // 由于存在多种数据类型, 故派生于 ArrayList, 需要装箱和拆箱操作 14 | { 15 | /// 16 | /// 构造函数, 完成纪年表数据的加载 17 | /// 18 | public JnbArrayList() 19 | { 20 | 21 | //---------------------------------------------------------------------------------------- 22 | // 加载 Xml 数据: 历史纪年表 23 | // 注: 加载时自动去除历史纪年表 Xml 数据中所有的空白字符 24 | //---------------------------------------------------------------------------------------- 25 | if (LunarHelper.SxwnlXmlData != null) 26 | { 27 | const string JnbXPath = "SharpSxwnl/SxwnlData/Data[@Id = 'obb_JNB']"; 28 | 29 | XmlNode foundNode; 30 | Regex regexToTrim = new Regex(@"\s*"); // C#: 匹配任何空白字符, 用于去除所有空白字符 31 | int i; 32 | 33 | // 读取并解开历史纪年表 34 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(JnbXPath); 35 | if (foundNode != null) 36 | { 37 | string[] JNB = regexToTrim.Replace(foundNode.InnerText, "").Split(','); 38 | 39 | this.AddRange(JNB); 40 | for (i = 0; i < JNB.Length; i += 7) 41 | { 42 | this[i] = int.Parse((string)(this[i])); 43 | this[i + 1] = int.Parse((string)(this[i + 1])); 44 | this[i + 2] = int.Parse((string)(this[i + 2])); 45 | } 46 | } 47 | } 48 | } 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /SharpSxwnl/LunarInfoListT.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections; 5 | 6 | namespace SharpSxwnl 7 | { 8 | /// 9 | /// 由于在 Javascript 中, 数组可以有自己的属性, 为了对应此功能, 设计本类 10 | /// 可用的方案: 使用 List<T> 或 ArrayList, 使用前者可以提高代码的效率, 后者则需要装箱拆箱和显式类型转换操作 11 | /// 12 | /// 13 | public class LunarInfoListT : List // 派生于泛型 List 类, 以提高代码的效率 14 | { 15 | #region 公共属性(注: 初始转换时为公共字段, 已改写) 16 | 17 | /// 18 | /// 升(时间) 19 | /// 20 | public double s__ { get; set; } // = 0; 21 | 22 | /// 23 | /// 中(时间) 24 | /// 25 | public double z__ { get; set; } // = 0; 26 | 27 | /// 28 | /// 降(时间) 29 | /// 30 | public double j__ { get; set; } // = 0; 31 | 32 | /// 33 | /// 晨(时间) 34 | /// 35 | public double c__ { get; set; } // = 0; 36 | 37 | /// 38 | /// 昏(时间) 39 | /// 40 | public double h__ { get; set; } // = 0; 41 | 42 | /// 43 | /// 晨昏差(时间) 44 | /// 45 | public double ch__ { get; set; } // = 0; 46 | 47 | /// 48 | /// 升降差(时间) 49 | /// 50 | public double sj__ { get; set; } // = 0; 51 | 52 | 53 | 54 | /// 55 | /// 升(时间串) 56 | /// 57 | public string s { get; set; } // = ""; 58 | 59 | /// 60 | /// 中(时间串) 61 | /// 62 | public string z { get; set; } // = ""; 63 | 64 | /// 65 | /// 降(时间串) 66 | /// 67 | public string j { get; set; } // = ""; 68 | 69 | /// 70 | /// 晨(时间串) 71 | /// 72 | public string c { get; set; } // = ""; 73 | 74 | /// 75 | /// 昏(时间串) 76 | /// 77 | public string h { get; set; } // = ""; 78 | 79 | /// 80 | /// 日照时间(串) 81 | /// 82 | public string ch { get; set; } // = ""; 83 | 84 | /// 85 | /// 昼长(时间串) 86 | /// 87 | public string sj { get; set; } // = ""; 88 | 89 | /// 90 | /// 月出时间(串) 91 | /// 92 | public string Ms { get; set; } // = ""; 93 | 94 | /// 95 | /// 月亮中天时间(串) 96 | /// 97 | public string Mz { get; set; } // = ""; 98 | 99 | /// 100 | /// 月落时间(串) 101 | /// 102 | public string Mj { get; set; } // = ""; 103 | 104 | 105 | 106 | /// 107 | /// 本属性(字段)有不同的含义: 108 | /// (1) 用于月对象 LunarInfoListT lun 的属性(字段) dn: 该月的总天数; 109 | /// (2) 用于多天的升中降容器 LunarInfoListT> rts 的属性(字段) dn: 要求计算升中降信息的天数 110 | /// 111 | public double dn { get; set; } // = 0; 112 | 113 | /// 114 | /// 指定时刻的天体时角 115 | /// 116 | public double H { get; set; } // = 0; 117 | 118 | /// 119 | /// 本属性(字段)有不同的含义: 升起对应的时角(月亮?), 或地平以下50分的时角(太阳?) 120 | /// 121 | public double H0 { get; set; } // = 0; 122 | 123 | /// 124 | /// 地平以下6度的时角(太阳?) 125 | /// 126 | public double H1 { get; set; } // = 0; 127 | 128 | 129 | 130 | /// 131 | /// 节气的儒略日 132 | /// 133 | public double pe1 { get; set; } // = 0; 134 | 135 | /// 136 | /// 节气的儒略日 137 | /// 138 | public double pe2 { get; set; } // = 0; 139 | 140 | 141 | /// 142 | /// 值等于 Count 属性(只读) 143 | /// 144 | public int Length { get { return this.Count; } } 145 | 146 | #endregion 147 | 148 | 149 | 150 | #region 构造函数 151 | 152 | public LunarInfoListT() 153 | { 154 | } 155 | 156 | 157 | /// 158 | /// 构造函数, 添加指定数目的元素到本类中, 并赋初值 159 | /// 160 | /// 要添加的元素个数 161 | /// 元素的初值(泛型) 162 | public LunarInfoListT(int itemsCount, T initValue) 163 | { 164 | for (int i = 0; i < itemsCount; i++) 165 | { 166 | this.Add(initValue); 167 | } 168 | } 169 | 170 | #endregion 171 | 172 | } 173 | 174 | 175 | } 176 | -------------------------------------------------------------------------------- /SharpSxwnl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列属性集 6 | // 控制。更改这些属性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("SharpSxwnl")] 9 | [assembly: AssemblyDescription("农历计算类库, 算法源自许剑伟先生的寿星万年历 4.11 .")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpSxwnl")] 13 | [assembly: AssemblyCopyright("版权所有 © 2009, 飞翼软件工作室.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 属性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("2f8be587-765d-45b6-a183-6215badf61e9")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SharpSxwnl/SSQ.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 实朔实气计算器 9 | /// 10 | public static class SSQ 11 | { 12 | #region 私有字段 13 | 14 | /// 15 | /// 朔修正表 16 | /// 17 | private static string SB = SSQ.init(1); // 朔修正表 18 | 19 | /// 20 | /// 气修正表 21 | /// 22 | private static string QB = SSQ.init(0); // 气修正表 23 | 24 | /// 25 | /// 朔直线拟合参数 26 | /// 27 | private static double[] suoKB = new double[]{ //朔直线拟合参数 28 | 1457698.231017,29.53067166, // -721-12-17 h=0.00032 古历·春秋 29 | 1546082.512234,29.53085106, // -479-12-11 h=0.00053 古历·战国 30 | 1640640.735300,29.53060000, // -221-10-31 h=0.01010 古历·秦汉 31 | 1642472.151543,29.53085439, // -216-11-04 h=0.00040 古历·秦汉 32 | 33 | 1683430.509300,29.53086148, // -104-12-25 h=0.00313 汉书·律历志(太初历)平气平朔 34 | 1752148.041079,29.53085097, // 85-02-13 h=0.00049 后汉书·律历志(四分历) 35 | 1807665.420323,29.53059851, // 237-02-12 h=0.00033 晋书·律历志(景初历) 36 | 1883618.114100,29.53060000, // 445-01-24 h=0.00030 宋书·律历志(何承天元嘉历) 37 | 1907360.704700,29.53060000, // 510-01-26 h=0.00030 宋书·律历志(祖冲之大明历) 38 | 1936596.224900,29.53060000, // 590-02-10 h=0.01010 随书·律历志(开皇历) 39 | 1939135.675300,29.53060000, // 597-01-24 h=0.00890 随书·律历志(大业历) 40 | 1947168.00// 619-01-21 41 | }; 42 | 43 | /// 44 | /// 气直线拟合参数 45 | /// 46 | private static double[] qiKB = new double[]{ //气直线拟合参数 47 | 1640650.479938,15.21842500, // -221-11-09 h=0.01709 古历·秦汉 48 | 1642476.703182,15.21874996, // -216-11-09 h=0.01557 古历·秦汉 49 | 50 | 1683430.515601,15.218750011, // -104-12-25 h=0.01560 汉书·律历志(太初历)平气平朔 回归年=365.25000 51 | 1752157.640664,15.218749978, // 85-02-23 h=0.01559 后汉书·律历志(四分历) 回归年=365.25000 52 | 1807675.003759,15.218620279, // 237-02-22 h=0.00010 晋书·律历志(景初历) 回归年=365.24689 53 | 1883627.765182,15.218612292, // 445-02-03 h=0.00026 宋书·律历志(何承天元嘉历) 回归年=365.24670 54 | 1907369.128100,15.218449176, // 510-02-03 h=0.00027 宋书·律历志(祖冲之大明历) 回归年=365.24278 55 | 1936603.140413,15.218425000, // 590-02-17 h=0.00149 随书·律历志(开皇历) 回归年=365.24220 56 | 1939145.524180,15.218466998, // 597-02-03 h=0.00121 随书·律历志(大业历) 回归年=365.24321 57 | 1947180.798300,15.218524844, // 619-02-03 h=0.00052 新唐书·历志(戊寅元历)平气定朔 回归年=365.24460 58 | 1964362.041824,15.218533526, // 666-02-17 h=0.00059 新唐书·历志(麟德历) 回归年=365.24480 59 | 1987372.340971,15.218513908, // 729-02-16 h=0.00096 新唐书·历志(大衍历,至德历) 回归年=365.24433 60 | 1999653.819126,15.218530782, // 762-10-03 h=0.00093 新唐书·历志(五纪历) 回归年=365.24474 61 | 2007445.469786,15.218535181, // 784-02-01 h=0.00059 新唐书·历志(正元历,观象历) 回归年=365.24484 62 | 2021324.917146,15.218526248, // 822-02-01 h=0.00022 新唐书·历志(宣明历) 回归年=365.24463 63 | 2047257.232342,15.218519654, // 893-01-31 h=0.00015 新唐书·历志(崇玄历) 回归年=365.24447 64 | 2070282.898213,15.218425000, // 956-02-16 h=0.00149 旧五代·历志(钦天历) 回归年=365.24220 65 | 2073204.872850,15.218515221, // 964-02-16 h=0.00166 宋史·律历志(应天历) 回归年=365.24437 66 | 2080144.500926,15.218530782, // 983-02-16 h=0.00093 宋史·律历志(乾元历) 回归年=365.24474 67 | 2086703.688963,15.218523776, // 1001-01-31 h=0.00067 宋史·律历志(仪天历,崇天历) 回归年=365.24457 68 | 2110033.182763,15.218425000, // 1064-12-15 h=0.00669 宋史·律历志(明天历) 回归年=365.24220 69 | 2111190.300888,15.218425000, // 1068-02-15 h=0.00149 宋史·律历志(崇天历) 回归年=365.24220 70 | 2113731.271005,15.218515671, // 1075-01-30 h=0.00038 李锐补修(奉元历) 回归年=365.24438 71 | 2120670.840263,15.218425000, // 1094-01-30 h=0.00149 宋史·律历志 回归年=365.24220 72 | 2123973.309063,15.218425000, // 1103-02-14 h=0.00669 李锐补修(占天历) 回归年=365.24220 73 | 2125068.997336,15.218477932, // 1106-02-14 h=0.00056 宋史·律历志(纪元历) 回归年=365.24347 74 | 2136026.312633,15.218472436, // 1136-02-14 h=0.00088 宋史·律历志(统元历,乾道历,淳熙历) 回归年=365.24334 75 | 2156099.495538,15.218425000, // 1191-01-29 h=0.00149 宋史·律历志(会元历) 回归年=365.24220 76 | 2159021.324663,15.218425000, // 1199-01-29 h=0.00149 宋史·律历志(统天历) 回归年=365.24220 77 | 2162308.575254,15.218461742, // 1208-01-30 h=0.00146 宋史·律历志(开禧历) 回归年=365.24308 78 | 2178485.706538,15.218425000, // 1252-05-15 h=0.04606 淳祐历 回归年=365.24220 79 | 2178759.662849,15.218445786, // 1253-02-13 h=0.00231 会天历 回归年=365.24270 80 | 2185334.020800,15.218425000, // 1271-02-13 h=0.00520 宋史·律历志(成天历) 回归年=365.24220 81 | 2187525.481425,15.218425000, // 1277-02-12 h=0.00520 本天历 回归年=365.24220 82 | 2188621.191481,15.218437484, // 1280-02-13 h=0.00013 元史·历志(郭守敬授时历) 回归年=365.24250 83 | 2321919.49// 1645-02-04 84 | }; 85 | 86 | #endregion 私有字段 87 | 88 | 89 | 90 | #region 私有方法 91 | 92 | /// 93 | /// 低精度定朔计算,在2000年至600,误差在2小时以内(仍比古代日历精准很多) 94 | /// 95 | /// 96 | /// 97 | private static double so_low(double W) 98 | { 99 | double v = 7771.37714500204; 100 | double t = (W + 1.08472) / v; 101 | t -= (-0.0000331 * t * t 102 | + 0.10976 * Math.Cos(0.785 + 8328.6914 * t) 103 | + 0.02224 * Math.Cos(0.187 + 7214.0629 * t) 104 | - 0.03342 * Math.Cos(4.669 + 628.3076 * t)) / v 105 | + (32 * (t + 1.8) * (t + 1.8) - 20) / 86400 / 36525; 106 | return t * 36525 + 8d / 24d; 107 | } 108 | 109 | 110 | /// 111 | /// 低精度定气计算, 最大误差小于30分钟,平均5分 112 | /// 113 | /// 114 | /// 115 | private static double qi_low(double W) 116 | { 117 | double t, L, v = 628.3319653318; 118 | t = (W - 4.895062166) / v; //第一次估算,误差2天以内 119 | t -= (53 * t * t + 334116 * Math.Cos(4.67 + 628.307585 * t) + 2061 * Math.Cos(2.678 + 628.3076 * t) * t) / v / 10000000; //第二次估算,误差2小时以内 120 | 121 | L = 48950621.66 + 6283319653.318 * t + 53 * t * t //平黄经 122 | + 334166 * Math.Cos(4.669257 + 628.307585 * t) //地球椭圆轨道级数展开 123 | + 3489 * Math.Cos(4.6261 + 1256.61517 * t) //地球椭圆轨道级数展开 124 | + 2060.6 * Math.Cos(2.67823 + 628.307585 * t) * t //一次泊松项 125 | - 994 - 834 * Math.Sin(2.1824 - 33.75705 * t); //光行差与章动修正 126 | 127 | t -= (L / 10000000 - W) / 628.332 + (32 * (t + 1.8) * (t + 1.8) - 20) / 86400 / 36525; 128 | return t * 36525 + 8d / 24d; 129 | } 130 | 131 | 132 | /// 133 | /// 较高精度定气计算 134 | /// 135 | /// 136 | /// 137 | private static double qi_high(double W) 138 | { 139 | double t = XL.S_aLon_t2(W) * 36525; 140 | t = t - JD.deltatT2(t) + 8d / 24d; 141 | double v = ((t + 0.5) % 1) * 86400; 142 | if (v < 600 || v > 86400 - 600) t = XL.S_aLon_t(W) * 36525 - JD.deltatT2(t) + 8d / 24d; 143 | return t; 144 | } 145 | 146 | 147 | /// 148 | /// 较高精度朔计算 149 | /// 150 | /// 151 | /// 152 | private static double so_high(double W) 153 | { 154 | double t = XL.MS_aLon_t2(W) * 36525; 155 | t = t - JD.deltatT2(t) + 8d / 24d; 156 | double v = ((t + 0.5) % 1) * 86400; 157 | if (v < 600 || v > 86400 - 600) t = XL.MS_aLon_t(W) * 36525 - JD.deltatT2(t) + 8d / 24d; 158 | return t; 159 | } 160 | 161 | 162 | 163 | /// 164 | /// 气朔解压缩 165 | /// 166 | /// 167 | /// 168 | private static string jieya(string s) 169 | { 170 | string o = "0000000000", o2 = o + o; 171 | StringBuilder sb = new StringBuilder(s, 32768); 172 | sb.Replace("J", "00"); 173 | sb.Replace("I", "000"); 174 | sb.Replace("H", "0000"); 175 | sb.Replace("G", "00000"); 176 | sb.Replace("t", "02"); 177 | sb.Replace("s", "002"); 178 | sb.Replace("r", "0002"); 179 | sb.Replace("q", "00002"); 180 | sb.Replace("p", "000002"); 181 | sb.Replace("o", "0000002"); 182 | sb.Replace("n", "00000002"); 183 | sb.Replace("m", "000000002"); 184 | sb.Replace("l", "0000000002"); 185 | sb.Replace("k", "01"); 186 | sb.Replace("j", "0101"); 187 | sb.Replace("i", "001"); 188 | sb.Replace("h", "001001"); 189 | sb.Replace("g", "0001"); 190 | sb.Replace("f", "00001"); 191 | sb.Replace("e", "000001"); 192 | sb.Replace("d", "0000001"); 193 | sb.Replace("c", "00000001"); 194 | sb.Replace("b", "000000001"); 195 | sb.Replace("a", "0000000001"); 196 | sb.Replace("A", o2 + o2 + o2); 197 | sb.Replace("B", o2 + o2 + o); 198 | sb.Replace("C", o2 + o2); 199 | sb.Replace("D", o2 + o); 200 | sb.Replace("E", o2); 201 | sb.Replace("F", o); 202 | return sb.ToString(); 203 | } 204 | 205 | 206 | /// 207 | /// 初使化: 朔修正表, 气修正表 208 | /// 209 | /// 210 | /// 211 | private static string init(int type) 212 | { 213 | StringBuilder suoS = new StringBuilder(), qiS = new StringBuilder(); 214 | // 619-01-21开始16598个朔日修正表 d0=1947168 215 | suoS.Append("EqoFscDcrFpmEsF2DfFideFelFpFfFfFiaipqti1ksttikptikqckstekqttgkqttgkqteksttikptikq2fjstgjqttjkqttgkqt"); 216 | suoS.Append("ekstfkptikq2tijstgjiFkirFsAeACoFsiDaDiADc1AFbBfgdfikijFifegF1FhaikgFag1E2btaieeibggiffdeigFfqDfaiBkF"); 217 | suoS.Append("1kEaikhkigeidhhdiegcFfakF1ggkidbiaedksaFffckekidhhdhdikcikiakicjF1deedFhFccgicdekgiFbiaikcfi1kbFibef"); 218 | suoS.Append("gEgFdcFkFeFkdcfkF1kfkcickEiFkDacFiEfbiaejcFfffkhkdgkaiei1ehigikhdFikfckF1dhhdikcfgjikhfjicjicgiehdik"); 219 | suoS.Append("cikggcifgiejF1jkieFhegikggcikFegiegkfjebhigikggcikdgkaFkijcfkcikfkcifikiggkaeeigefkcdfcfkhkdgkegieid"); 220 | suoS.Append("hijcFfakhfgeidieidiegikhfkfckfcjbdehdikggikgkfkicjicjF1dbidikFiggcifgiejkiegkigcdiegfggcikdbgfgefjF1"); 221 | suoS.Append("kfegikggcikdgFkeeijcfkcikfkekcikdgkabhkFikaffcfkhkdgkegbiaekfkiakicjhfgqdq2fkiakgkfkhfkfcjiekgFebicg"); 222 | suoS.Append("gbedF1jikejbbbiakgbgkacgiejkijjgigfiakggfggcibFifjefjF1kfekdgjcibFeFkijcfkfhkfkeaieigekgbhkfikidfcje"); 223 | suoS.Append("aibgekgdkiffiffkiakF1jhbakgdki1dj1ikfkicjicjieeFkgdkicggkighdF1jfgkgfgbdkicggfggkidFkiekgijkeigfiski"); 224 | suoS.Append("ggfaidheigF1jekijcikickiggkidhhdbgcfkFikikhkigeidieFikggikhkffaffijhidhhakgdkhkijF1kiakF1kfheakgdkif"); 225 | suoS.Append("iggkigicjiejkieedikgdfcggkigieeiejfgkgkigbgikicggkiaideeijkefjeijikhkiggkiaidheigcikaikffikijgkiahi1"); 226 | suoS.Append("hhdikgjfifaakekighie1hiaikggikhkffakicjhiahaikggikhkijF1kfejfeFhidikggiffiggkigicjiekgieeigikggiffig"); 227 | suoS.Append("gkidheigkgfjkeigiegikifiggkidhedeijcfkFikikhkiggkidhh1ehigcikaffkhkiggkidhh1hhigikekfiFkFikcidhh1hit"); 228 | suoS.Append("cikggikhkfkicjicghiediaikggikhkijbjfejfeFhaikggifikiggkigiejkikgkgieeigikggiffiggkigieeigekijcijikgg"); 229 | suoS.Append("ifikiggkideedeijkefkfckikhkiggkidhh1ehijcikaffkhkiggkidhh1hhigikhkikFikfckcidhh1hiaikgjikhfjicjicgie"); 230 | suoS.Append("hdikcikggifikigiejfejkieFhegikggifikiggfghigkfjeijkhigikggifikiggkigieeijcijcikfksikifikiggkidehdeij"); 231 | suoS.Append("cfdckikhkiggkhghh1ehijikifffffkhsFngErD1pAfBoDd1BlEtFqA2AqoEpDqElAEsEeB2BmADlDkqBtC1FnEpDqnEmFsFsAFn"); 232 | suoS.Append("llBbFmDsDiCtDmAB2BmtCgpEplCpAEiBiEoFqFtEqsDcCnFtADnFlEgdkEgmEtEsCtDmADqFtAFrAtEcCqAE1BoFqC1F1DrFtBmF"); 233 | suoS.Append("tAC2ACnFaoCgADcADcCcFfoFtDlAFgmFqBq2bpEoAEmkqnEeCtAE1bAEqgDfFfCrgEcBrACfAAABqAAB1AAClEnFeCtCgAADqDoB"); 234 | suoS.Append("mtAAACbFiAAADsEtBqAB2FsDqpFqEmFsCeDtFlCeDtoEpClEqAAFrAFoCgFmFsFqEnAEcCqFeCtFtEnAEeFtAAEkFnErAABbFkAD"); 235 | suoS.Append("nAAeCtFeAfBoAEpFtAABtFqAApDcCGJ"); 236 | //1645-02-03开始7582个节气修正表 237 | qiS.Append("EmcFs22AFsckF2tsDtFqEtF1posFdFgiFseFtmelpsEfhkF2anmelpFlF1ikrotcnEqEq2FfqmcDsrFor22FgFrcgDscFs22FgEe"); 238 | qiS.Append("FtE2sfFs22sCoEsaF2tsD1FpeE2eFsssEciFsFnmelpFcFhkF2tcnEqEpFgkrotcnEqrEtFermcDsrE222FgBmcmr22DaEfnaF22"); 239 | qiS.Append("2sD1FpeForeF2tssEfiFpEoeFssD1iFstEqFppDgFstcnEqEpFg11FscnEqrAoAF2ClAEsDmDtCtBaDlAFbAEpAAAAAD2FgBiBqo"); 240 | qiS.Append("BbnBaBoAAAAAAAEgDqAdBqAFrBaBoACdAAf1AACgAAAeBbCamDgEifAE2AABa1C1BgFdiAAACoCeE1ADiEifDaAEqAAFe1AcFbcA"); 241 | qiS.Append("AAAAF1iFaAAACpACmFmAAAAAAAACrDaAAADG0"); 242 | 243 | if (type == 1) 244 | { 245 | return SSQ.jieya(suoS.ToString()); 246 | } 247 | else 248 | { 249 | return SSQ.jieya(qiS.ToString()); 250 | } 251 | } 252 | 253 | #endregion 私有方法 254 | 255 | 256 | 257 | #region 公共方法(1) 258 | 259 | /// 260 | /// jd 应靠近所要取得的气朔日, 当参数 qs="气" 时,算节气的儒略日 261 | /// 262 | /// 263 | /// 264 | /// 265 | public static double calc(double jd, string qs) 266 | { 267 | jd += LunarHelper.J2000; // C#: 改为常量 268 | int i; 269 | double D; 270 | string n; 271 | double[] B = SSQ.suoKB; 272 | double pc = 14; 273 | 274 | if (qs == "气") { B = SSQ.qiKB; pc = 7; } 275 | double f1 = B[0] - pc, f2 = B[B.Length - 1] - pc, f3 = 2436935; 276 | 277 | if (jd < f1 || jd >= f3) 278 | { 279 | // 平气朔表中首个之前,使用现代天文算法。1960.1.1以后,使用现代天文算法 (这一部分调用了qi_high和so_high,所以需星历表支持) 280 | if (qs == "气") 281 | return Math.Floor(SSQ.qi_high(Math.Floor((jd + pc - 2451259) / 365.2422 * 24) * Math.PI / 12) + 0.5); //2451259是1999.3.21,太阳视黄经为0,春分.定气计算 282 | else 283 | return Math.Floor(SSQ.so_high(Math.Floor((jd + pc - 2451551) / 29.5306) * Math.PI * 2) + 0.5); //2451551是2000.1.7的那个朔日,黄经差为0.定朔计算 284 | } 285 | 286 | if (jd >= f1 && jd < f2) 287 | { 288 | // 平气或平朔 289 | for (i = 0; i < B.Length; i += 2) if (jd + pc < B[i + 2]) 290 | break; 291 | D = B[i] + B[i + 1] * Math.Floor((jd + pc - B[i]) / B[i + 1]); 292 | D = Math.Floor(D + 0.5); 293 | if (D == 1683460) D++; //如果使用太初历计算-103年1月24日的朔日,结果得到的是23日,这里修正为24日(实历)。修正后仍不影响-103的无中置闰。如果使用秦汉历,得到的是24日,本行D不会被执行。 294 | return D - LunarHelper.J2000; // C#: 改为常量 295 | } 296 | 297 | if (jd >= f2 && jd < f3) 298 | { 299 | // 定气或定朔 300 | if (qs == "气") 301 | { 302 | D = Math.Floor(SSQ.qi_low(Math.Floor((jd + pc - 2451259) / 365.2422 * 24) * Math.PI / 12) + 0.5); //2451259是1999.3.21,太阳视黄经为0,春分.定气计算 303 | n = SSQ.QB.Substring((int)(Math.Floor((jd - f2) / 365.2422 * 24)), 1); //找定气修正值 304 | } 305 | else 306 | { 307 | D = Math.Floor(SSQ.so_low(Math.Floor((jd + pc - 2451551) / 29.5306) * Math.PI * 2) + 0.5); //2451551是2000.1.7的那个朔日,黄经差为0.定朔计算 308 | n = SSQ.SB.Substring((int)(Math.Floor((jd - f2) / 29.5306)), 1); //找定朔修正值 309 | } 310 | if (n == "1") return D + 1; 311 | if (n == "2") return D - 1; 312 | return D; 313 | } 314 | 315 | return 0; // C#: 新增 316 | } 317 | 318 | #endregion 公共方法(1) 319 | 320 | 321 | 322 | #region 公共属性(注: 初始转换时为公共字段, 已改写, 请参阅“转换时增加的私有字段”) 323 | 324 | // 排月序(生成实际年历),在调用calcY()后得到以下数据 325 | // 时间系统全部使用北京时,即使是天象时刻的输出,也是使用北京时 326 | // 如果天象的输出不使用北京时,会造成显示混乱,更严重的是无法与古历比对 327 | 328 | /// 329 | /// 闰月位置 330 | /// 331 | public static int leap { get; set; } // = 0; //闰月位置 332 | 333 | /// 334 | /// 各月名称 335 | /// 336 | //------------------------------------------------------------------------------------------------------------ 337 | // 初次转换时的语句如下: 338 | // public static string[] ym = new string[32]; //各月名称 339 | //------------------------------------------------------------------------------------------------------------ 340 | public static string[] ym 341 | { 342 | get { return SSQ.__ym; } 343 | set { SSQ.__ym = value; } 344 | } 345 | 346 | /// 347 | /// 中气表, 功能与 doulbe[] 类似, 但它有自定义属性的 348 | /// 349 | //------------------------------------------------------------------------------------------------------------------------------------ 350 | // 初次转换时的语句如下: 351 | // public static LunarInfoListT ZQ = new LunarInfoListT(31, 0d); //中气表,其中.liqiu是节气立秋的儒略日,计算三伏时用到 352 | //------------------------------------------------------------------------------------------------------------------------------------ 353 | public static LunarInfoListT ZQ 354 | { 355 | get { return SSQ.__ZQ; } 356 | set { SSQ.__ZQ = value; } 357 | } 358 | 359 | /// 360 | /// 合朔表 361 | /// 362 | //------------------------------------------------------------------------------------------------------------ 363 | // 初次转换时的语句如下: 364 | // public static double[] HS = new double[32]; //合朔表 365 | //------------------------------------------------------------------------------------------------------------ 366 | public static double[] HS 367 | { 368 | get { return SSQ.__HS; } 369 | set { SSQ.__HS = value; } 370 | } 371 | 372 | /// 373 | /// 各月大小 374 | /// 375 | //------------------------------------------------------------------------------------------------------------ 376 | // 初次转换时的语句如下: 377 | // public static double[] dx = new double[32]; //各月大小 378 | //------------------------------------------------------------------------------------------------------------ 379 | public static double[] dx 380 | { 381 | get { return SSQ.__dx; } 382 | set { SSQ.__dx = value; } 383 | } 384 | 385 | /// 386 | /// 年计数 387 | /// 388 | //------------------------------------------------------------------------------------------------------------ 389 | // 初次转换时的语句如下: 390 | // public static double[] Yn = new double[1]; //年计数 391 | //------------------------------------------------------------------------------------------------------------ 392 | public static double[] Yn 393 | { 394 | get { return SSQ.__Yn; } 395 | set { SSQ.__Yn = value; } 396 | } 397 | 398 | #endregion 公共属性 399 | 400 | 401 | 402 | #region 公共方法(2) 403 | 404 | /// 405 | /// 农历排月序计算,可定出农历,有效范围:两个冬至之间(冬至一 ≤ d < 冬至二) 406 | /// 407 | /// 408 | public static void calcY(double jd) 409 | { 410 | LunarInfoListT A = SSQ.ZQ; 411 | double[] B = SSQ.HS; // 中气表,日月合朔表(整日) 412 | int i; 413 | double W, w; 414 | 415 | // 该年的气 416 | W = LunarHelper.int2((jd - 355 + 183) / 365.2422) * 365.2422 + 355; // 355是2000.12冬至,得到较靠近jd的冬至估计值 417 | if (SSQ.calc(W, "气") > jd) W -= 365.2422; 418 | for (i = 0; i < 25; i++) A[i] = SSQ.calc(W + 15.2184 * i, "气"); // 25个节气时刻(北京时间),从冬至开始到下一个冬至以后 419 | A.pe1 = SSQ.calc(W - 15.2, "气"); A.pe2 = SSQ.calc(W - 30.4, "气"); // 补算二气,确保一年中所有月份的“气”全部被计算在内 420 | 421 | // 今年"首朔"的日月黄经差w 422 | w = SSQ.calc(A[0], "朔"); // 求较靠近冬至的朔日 423 | if (w > A[0]) w -= 29.53; 424 | 425 | // 该年所有朔,包含14个月的始末 426 | for (i = 0; i < 15; i++) 427 | { 428 | B[i] = SSQ.calc(w + 29.5306 * i, "朔"); 429 | } 430 | 431 | // 月大小 432 | SSQ.leap = 0; 433 | for (i = 0; i < 14; i++) 434 | { 435 | SSQ.dx[i] = SSQ.HS[i + 1] - SSQ.HS[i]; // 月大小 436 | SSQ.ym[i] = i.ToString(); // 月序初始化 437 | } 438 | 439 | 440 | 441 | // -721年至-104年的后九月及月建问题,与朔有关,与气无关 442 | double YY = LunarHelper.int2((SSQ.ZQ[0] + 10 + 180) / 365.2422) + 2000; // 确定年份 443 | if (YY >= -721 && YY <= -104) 444 | { 445 | double ly = 0, b0 = 0, k0 = 0, x0 = 0; // ly为历元(本历首月的儒略数),x0月建,lName闰月名称,b0,k0为置闰拟合参数 446 | string lName = ""; 447 | if (YY >= -721) { ly = 1457698 - LunarHelper.J2000; k0 = 12.368422; b0 = 0.342; lName = "十三"; x0 = 2; } // 春秋历,ly为-722.12.17 448 | if (YY >= -479) { ly = 1546083 - LunarHelper.J2000; k0 = 12.368422; b0 = 0.500; lName = "十三"; x0 = 2; } // 战国历,ly为-480.12.11 449 | if (YY >= -220) { ly = 1640641 - LunarHelper.J2000; k0 = 12.369000; b0 = 0.866; lName = "后九"; x0 = 11; } // 秦汉历,ly为-221.10.31; 450 | double nY = LunarHelper.int2((SSQ.HS[0] - ly + 100) / 365.25); // 年积数 451 | double f1 = LunarHelper.int2(b0 + nY * k0), f2 = LunarHelper.int2(b0 + nY * k0 + k0), f3; // f1有本年首的月积数,f2为下一年首的月积数 452 | f1 = LunarHelper.int2(f1); f2 = LunarHelper.int2(f2); 453 | for (i = 0; i < 14; i++) 454 | { 455 | f3 = LunarHelper.int2((SSQ.HS[i] - ly + 15) / 29.5306); // 该月积数 456 | if (f3 < f2) f3 -= f1; else f3 -= f2; 457 | if (f3 < 12) SSQ.ym[i] = obb.ymc[(int)((f3 + x0) % 12)]; else SSQ.ym[i] = lName; 458 | } 459 | 460 | } 461 | 462 | // 无中气置闰法确定闰月,(气朔结合法,数据源需有冬至开始的的气和朔) 463 | if (B[13] <= A[24]) 464 | { 465 | // 第13月的月末没有超过冬至(不含冬至),说明今年含有13个月 466 | for (i = 1; B[i + 1] > A[2 * i] && i < 13; i++) ; //在13个月中找第1个没有中气的月份 467 | SSQ.leap = i; 468 | for (; i < 14; i++) SSQ.ym[i] = (int.Parse(SSQ.ym[i]) - 1).ToString(); 469 | } 470 | 471 | // 名称转换(月建别名) 472 | for (i = 0; i < 14; i++) 473 | { 474 | double Dm = SSQ.HS[i] + LunarHelper.J2000, v2 = int.Parse(SSQ.ym[i]); // Dm初一的儒略日,v2为月建序号 475 | string mc = obb.ymc[(int)(v2 % 12)]; // 月建对应的默认月名称:建子十一,建丑十二,建寅为正…… 476 | if (Dm >= 1724360 && Dm <= 1729794) mc = obb.ymc[(int)((v2 + 1) % 12)]; // 8.01.15至 23.12.02 建子为十二,其它顺推 477 | else if (Dm >= 1807724 && Dm <= 1808699) mc = obb.ymc[(int)((v2 + 1) % 12)]; // 237.04.12至239.12.13 建子为十二,其它顺推 478 | else if (Dm >= 1999349 && Dm <= 1999467) mc = obb.ymc[(int)((v2 + 2) % 12)]; // 761.12.02至762.03.30 建子为正月,其它顺推 479 | else if (Dm >= 1973067 && Dm <= 1977112) { if (v2 % 12 == 0) mc = "正"; if (v2 == 2) mc = "一"; } // 689.12.18至701.01.14 建子为正月,建寅为一月,其它不变 480 | 481 | if (Dm == 1729794 || Dm == 1808699) mc = "拾贰"; // 239.12.13及23.12.02均为十二月,为避免两个连续十二月,此处改名 482 | 483 | SSQ.ym[i] = mc; 484 | } 485 | } 486 | 487 | #endregion 公共方法(2) 488 | 489 | 490 | 491 | #region 转换时增加的私有字段(用于封装成公共属性, 按转换规范 10 命名) 492 | 493 | private static string[] __ym = new string[32]; //各月名称 494 | private static LunarInfoListT __ZQ = new LunarInfoListT(31, 0d); //中气表,其中.liqiu是节气立秋的儒略日,计算三伏时用到 495 | private static double[] __HS = new double[32]; //合朔表 496 | private static double[] __dx = new double[32]; //各月大小 497 | private static double[] __Yn = new double[1]; //年计数 498 | 499 | #endregion 500 | 501 | 502 | 503 | 504 | #region 转换时新增加的方法 505 | 506 | /// 507 | /// 新增方法: 计算节气, 并返回计算的节气总数, 在调用本方法并读取 SSQ.ZQ 数据后, 应该清零 SSQ.ZQ 508 | /// 509 | /// 510 | /// 511 | /// 512 | public static int calcJieQi(double jd, bool calcMultiPeriod) 513 | { 514 | LunarInfoListT A = SSQ.ZQ; 515 | double[] B = SSQ.HS; // 中气表,日月合朔表(整日) 516 | int i; 517 | double W; 518 | 519 | if (!calcMultiPeriod) // 只计算某年的节气 520 | { 521 | W = LunarHelper.int2((jd - 355 + 183) / 365.2422) * 365.2422 + 355; // 355是2000.12冬至,得到较靠近jd的冬至估计值 522 | if (SSQ.calc(W, "气") > jd) W -= 365.2422; 523 | for (i = 0; i < 25; i++) A[i] = SSQ.calc(W + 15.2184 * i, "气"); // 25个节气时刻(北京时间),从冬至开始到下一个冬至以后 524 | A.pe1 = SSQ.calc(W - 15.2, "气"); A.pe2 = SSQ.calc(W - 30.4, "气"); // 补算二气,确保一年中所有月份的“气”全部被计算在内 525 | } 526 | else // 需计算从霜降至下 2 个大寒之后的节气, 用于计算指定日期的所属节气, 上一节气, 下一节气等信息 527 | { 528 | W = LunarHelper.int2((jd - 355 + 183) / 365.2422) * 365.2422 + 296; // 296是2000.10.23霜降(距200.1.1的天数),得到较靠近jd的霜降估计值 529 | if (SSQ.calc(W, "气") > jd) W -= 365.2422; 530 | for (i = 0; i < 31; i++) A[i] = SSQ.calc(W + 15.2184 * i, "气"); // 31个节气时刻(北京时间),从霜降至开始到下 2 个大寒以后 531 | } 532 | return ((!calcMultiPeriod ? 25 : 31)); 533 | } 534 | 535 | 536 | 537 | #endregion 538 | 539 | } 540 | } 541 | -------------------------------------------------------------------------------- /SharpSxwnl/SZJ.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 日月的升中天降,不考虑气温和气压的影响 9 | /// 10 | public static class SZJ 11 | { 12 | #region 私有字段(注: 初始转换时为公共字段, 已改写) 13 | 14 | /// 15 | /// 站点地理经度,向东测量为负 16 | /// 17 | private static double L = 0; //站点地理经度,向东测量为负 18 | 19 | /// 20 | /// 站点地理纬度 21 | /// 22 | private static double fa = 0; //站点地理纬度 23 | 24 | /// 25 | /// TD-UT 26 | /// 27 | private static double dt = 0; //TD-UT 28 | 29 | /// 30 | /// 黄赤交角 31 | /// 32 | private static double E = 0.409092614; //黄赤交角 33 | 34 | #endregion 35 | 36 | 37 | 38 | #region 公共属性(注: 初始转换时为公共字段, 已改写) 39 | 40 | /// 41 | /// 多天的升中降 42 | /// 该字段为嵌套的 LunarInfoListT 实例, 与交错数组 double[][] 的功能类似, 但它的特别之处在于拥有自定义的字段(属性) 43 | /// 44 | //------------------------------------------------------------------------------------------------------------------------------ 45 | // C#: 改写时要注意的是该属性应该先初始化(见本类的 calcRTS 方法), 初始转换时的语句如下: 46 | //public static LunarInfoListT> rts = new LunarInfoListT>(); // 多天的升中降 47 | //------------------------------------------------------------------------------------------------------------------------------ 48 | public static LunarInfoListT> rts { get; set; } // 多天的升中降 49 | 50 | #endregion 51 | 52 | 53 | 54 | #region 公共方法 55 | 56 | /// 57 | /// h地平纬度,w赤纬,返回时角 58 | /// 59 | /// 60 | /// 61 | /// 62 | public static double getH(double h, double w) 63 | { 64 | double c = (Math.Sin(h) - Math.Sin(SZJ.fa) * Math.Sin(w)) / Math.Cos(SZJ.fa) / Math.Cos(w); 65 | if (Math.Abs(c) > 1) return Math.PI; 66 | return Math.Acos(c); 67 | } 68 | 69 | 70 | /// 71 | /// 章动同时影响恒星时和天体坐标,所以不计算章动。返回时角及赤经纬 72 | /// 73 | /// 74 | /// 75 | /// 76 | public static void Mcoord(double jd, double H0, LunarInfoListT z) 77 | { 78 | XL.M_coord((jd + SZJ.dt) / 36525, z, 30, 20, 8); //低精度月亮赤经纬 79 | ZB.llrConv(z, SZJ.E); //转为赤道坐标 80 | z.H = LunarHelper.rad2mrad(ZB.gst(jd, SZJ.dt) - SZJ.L - z[0]); 81 | if (z.H > Math.PI) z.H -= LunarHelper.pi2; //得到此刻天体时角 82 | if (H0 != 0) z.H0 = SZJ.getH(0.7275 * LunarHelper.cs_rEar / z[2] - 34 * 60 / LunarHelper.rad, z[1]); //升起对应的时角 83 | } 84 | 85 | 86 | /// 87 | /// 月亮到中升降时刻计算,传入jd含义与St()函数相同 88 | /// 89 | /// 90 | /// 91 | public static LunarInfoListT Mt(double jd) 92 | { 93 | SZJ.dt = JD.deltatT2(jd); 94 | SZJ.E = ZB.hcjj(jd / 36525); 95 | jd -= LunarHelper.mod2(0.1726222 + 0.966136808032357 * jd - 0.0366 * SZJ.dt - SZJ.L / LunarHelper.pi2, 1); //查找最靠近当日中午的月上中天,mod2的第1参数为本地时角近似值 96 | 97 | LunarInfoListT r = new LunarInfoListT(3, 0d); 98 | double sv = LunarHelper.pi2 * 0.966; 99 | r.z__ = r.s__ = r.j__ = r.c__ = r.h__ = jd; 100 | SZJ.Mcoord(jd, 1, r); //月亮坐标 101 | r.s__ += (-r.H0 - r.H) / sv; 102 | r.j__ += (r.H0 - r.H) / sv; 103 | r.z__ += (0 - r.H) / sv; 104 | SZJ.Mcoord(r.s__, 1, r); r.s__ += (-r.H0 - r.H) / sv; 105 | SZJ.Mcoord(r.j__, 1, r); r.j__ += (+r.H0 - r.H) / sv; 106 | SZJ.Mcoord(r.z__, 0, r); r.z__ += (0 - r.H) / sv; 107 | return r; 108 | } 109 | 110 | 111 | /// 112 | /// 章动同时影响恒星时和天体坐标,所以不计算章动。返回时角及赤经纬 113 | /// 114 | /// 115 | /// 116 | /// 117 | /// 118 | public static void Scoord(double jd, double H0, double H1, LunarInfoListT z) 119 | { 120 | z[0] = XL.E_Lon((jd + SZJ.dt) / 36525, 5) + Math.PI - 20.5 / LunarHelper.rad; //太阳坐标(修正了光行差) 121 | z[1] = 0d; z[2] = 1d; // C#: 添加 d, 强制为 double 类型, 否则在把该元素显式转换为 double 时会出错 122 | ZB.llrConv(z, SZJ.E); // 转为赤道坐标 123 | z.H = LunarHelper.rad2rrad(ZB.gst(jd, SZJ.dt) - SZJ.L - z[0]); //得到此刻天体时角 124 | if (H0 != 0) z.H0 = SZJ.getH(-50 * 60 / LunarHelper.rad, z[1]); //地平以下50分 125 | if (H1 != 0) z.H1 = SZJ.getH(-Math.PI / 30, z[1]); // 地平以下6度 126 | } 127 | 128 | 129 | /// 130 | /// 太阳到中升降时刻计算,传入jd是当地中午12点时间对应的2000年首起算的格林尼治时间UT 131 | /// 132 | /// 133 | /// 134 | public static LunarInfoListT St(double jd) 135 | { 136 | SZJ.dt = JD.deltatT2(jd); 137 | SZJ.E = ZB.hcjj(jd / 36525); 138 | jd -= LunarHelper.mod2(jd - SZJ.L / LunarHelper.pi2, 1); //查找最靠近当日中午的日上中天,mod2的第1参数为本地时角近似值 139 | 140 | LunarInfoListT r = new LunarInfoListT(3, 0d); 141 | double sv = LunarHelper.pi2; 142 | r.z__ = r.s__ = r.j__ = r.c__ = r.h__ = jd; 143 | SZJ.Scoord(jd, 1, 1, r); //太阳坐标 144 | r.s__ += (-r.H0 - r.H) / sv; //升起 145 | r.j__ += (r.H0 - r.H) / sv; //降落 146 | r.c__ += (-r.H1 - r.H) / sv; //民用晨 147 | r.h__ += (r.H1 - r.H) / sv; //民用昏 148 | r.z__ += (0 - r.H) / sv; //中天 149 | SZJ.Scoord(r.s__, 1, 0, r); r.s__ += (-r.H0 - r.H) / sv; 150 | SZJ.Scoord(r.j__, 1, 0, r); r.j__ += (+r.H0 - r.H) / sv; 151 | SZJ.Scoord(r.c__, 0, 1, r); r.c__ += (-r.H1 - r.H) / sv; 152 | SZJ.Scoord(r.h__, 0, 1, r); r.h__ += (+r.H1 - r.H) / sv; 153 | SZJ.Scoord(r.z__, 0, 0, r); r.z__ += (0 - r.H) / sv; 154 | return r; 155 | } 156 | 157 | 158 | 159 | /// 160 | /// 多天升中降计算,jd是当地起始儒略日(中午时刻),sq是时区 161 | /// 162 | /// 163 | /// 164 | /// 165 | /// 166 | /// 167 | public static void calcRTS(double jd, double n, double Jdl, double Wdl, double sq) 168 | { 169 | int i; 170 | double c; 171 | LunarInfoListT r; // C#: 不需要实例化, 因此注释语句的后半部分: = new LunarInfoListT(3, 0d); 172 | 173 | // C#: 由于将 rts 设置为自动实现的公共属性, 故添加了以下代码段来初始化 174 | if (SZJ.rts == null) 175 | SZJ.rts = new LunarInfoListT>(); 176 | 177 | if (SZJ.rts.Count == 0) 178 | { 179 | for (i = 0; i < 31; i++) 180 | { 181 | SZJ.rts.Add(new LunarInfoListT()); 182 | // SZJ.rts[i] = new LunarInfoListT(); 183 | } 184 | } 185 | SZJ.L = Jdl; SZJ.fa = Wdl; sq /= 24; //设置站点参数 186 | for (i = 0; i < n; i++) { r = SZJ.rts[i]; r.Ms = r.Mz = r.Mj = ""; } 187 | for (i = -1; i <= n; i++) 188 | { 189 | if (i >= 0 && i < n) 190 | { 191 | //太阳 192 | r = SZJ.St(jd + i + sq); 193 | ((SZJ.rts[i])).s = JD.timeStr(r.s__ - sq); //升 194 | ((SZJ.rts[i])).z = JD.timeStr(r.z__ - sq); //中 195 | ((SZJ.rts[i])).j = JD.timeStr(r.j__ - sq); //降 196 | ((SZJ.rts[i])).c = JD.timeStr(r.c__ - sq); //晨 197 | ((SZJ.rts[i])).h = JD.timeStr(r.h__ - sq); //昏 198 | ((SZJ.rts[i])).ch = JD.timeStr(r.h__ - r.c__ - 0.5); //光照时间,timeStr()内部+0.5,所以这里补上-0.5 199 | ((SZJ.rts[i])).sj = JD.timeStr(r.j__ - r.s__ - 0.5); //昼长 200 | } 201 | r = SZJ.Mt(jd + i + sq); //月亮 202 | c = LunarHelper.int2(r.s__ - sq + 0.5) - jd; if (c >= 0 && c < n) (SZJ.rts[(int)c]).Ms = JD.timeStr(r.s__ - sq); 203 | c = LunarHelper.int2(r.z__ - sq + 0.5) - jd; if (c >= 0 && c < n) (SZJ.rts[(int)c]).Mz = JD.timeStr(r.z__ - sq); 204 | c = LunarHelper.int2(r.j__ - sq + 0.5) - jd; if (c >= 0 && c < n) (SZJ.rts[(int)c]).Mj = JD.timeStr(r.j__ - sq); 205 | } 206 | SZJ.rts.dn = n; 207 | } 208 | 209 | #endregion 210 | 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /SharpSxwnl/SharpSxwnl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {B37552EC-C668-4A11-977A-16BC1D21B847} 9 | Library 10 | Properties 11 | SharpSxwnl 12 | SharpSxwnl 13 | v2.0 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 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 | PreserveNewest 69 | 70 | 71 | 72 | 79 | -------------------------------------------------------------------------------- /SharpSxwnl/ZB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 坐标类 9 | /// 10 | public static class ZB 11 | { 12 | #region 公共属性(注: 初始转换时为字段, 已改写为自动实现的属性) 13 | 14 | /// 15 | /// 黄经章动 16 | /// 17 | public static double dL { get; set; } // = 0; 18 | 19 | /// 20 | /// 交角章动 21 | /// 22 | public static double dE { get; set; } // = 0; 23 | 24 | /// 25 | /// 保存空间两点连线与地球的交点: 经(?) 26 | /// 27 | public static double le_J { get; set; } // = 0; 28 | 29 | /// 30 | /// 保存空间两点连线与地球的交点: 纬(?) 31 | /// 32 | public static double le_W { get; set; } // = 0; 33 | 34 | /// 35 | /// (?) 36 | /// 37 | public static double le_R1 { get; set; } // = 0; 38 | 39 | #endregion 40 | 41 | 42 | 43 | #region 私有字段(注: 初始转换时为公共字段, 已改写) 44 | 45 | /// 46 | /// 章动计算时使用的数据(?) 47 | /// 48 | private static double[] nutB = new double[] { 49 | 2.1824, -33.75705, 36e-6,-1720,920, 50 | 3.5069, 1256.66393, 11e-6,-132, 57, 51 | 1.3375,16799.4182, -51e-6, -23, 10, 52 | 4.3649, -67.5141, 72e-6, 21, -9, 53 | 0.04, -628.302, 0, -14, 0, 54 | 2.36, 8328.691, 0, 7, 0, 55 | 3.46, 1884.966, 0, -5, 2, 56 | 5.44, 16833.175, 0, -4, 2, 57 | 3.69, 25128.110, 0, -3, 0, 58 | 3.55, 628.362, 0, 2, 0 59 | }; 60 | 61 | #endregion 62 | 63 | 64 | 65 | #region 公共方法 66 | 67 | /// 68 | /// 球面坐标旋转 69 | /// 70 | /// 71 | /// 72 | public static void llrConv(double[] JW, double E) 73 | { 74 | //黄道赤道坐标变换,赤到黄E取负 75 | double sinE = Math.Sin(E), cosE = Math.Cos(E); 76 | double sinJ = Math.Sin(JW[0]), cosJ = Math.Cos(JW[0]); 77 | double sinW = Math.Sin(JW[1]), cosW = Math.Cos(JW[1]), tanW = Math.Tan(JW[1]); 78 | JW[0] = Math.Atan2(sinJ * cosE - tanW * sinE, cosJ); 79 | JW[1] = Math.Asin(cosE * sinW + sinE * cosW * sinJ); 80 | JW[0] = LunarHelper.rad2mrad(JW[0]); 81 | } 82 | 83 | /// 84 | /// 球面坐标旋转 85 | /// 86 | /// 87 | /// 88 | public static void llrConv(LunarInfoListT JW, double E) // C#: 新扩展出来的方法 89 | { 90 | //黄道赤道坐标变换,赤到黄E取负 91 | double sinE = Math.Sin(E), cosE = Math.Cos(E); 92 | double sinJ = Math.Sin((JW[0])), cosJ = Math.Cos((JW[0])); 93 | double sinW = Math.Sin((JW[1])); 94 | double cosW = Math.Cos((JW[1])); 95 | double tanW = Math.Tan((JW[1])); 96 | JW[0] = Math.Atan2(sinJ * cosE - tanW * sinE, cosJ); 97 | JW[1] = Math.Asin(cosE * sinW + sinE * cosW * sinJ); 98 | JW[0] = LunarHelper.rad2mrad((JW[0])); 99 | } 100 | 101 | 102 | 103 | /// 104 | /// 球面转直角坐标 105 | /// 106 | /// 107 | /// 108 | /// 109 | /// 110 | public static void llr2xyz(double J, double W, double R, double[] z) 111 | { 112 | z[0] = R * Math.Cos(W) * Math.Cos(J); 113 | z[1] = R * Math.Cos(W) * Math.Sin(J); 114 | z[2] = R * Math.Sin(W); 115 | } 116 | 117 | 118 | 119 | /// 120 | /// 直角坐标转球 121 | /// 122 | /// 123 | /// 124 | /// 125 | /// 126 | public static void xyz2llr(double x, double y, double z, double[] q) 127 | { 128 | q[2] = Math.Sqrt(x * x + y * y + z * z); 129 | q[1] = Math.Asin(z / q[2]); 130 | q[0] = LunarHelper.rad2mrad(Math.Atan2(y, x)); 131 | } 132 | 133 | 134 | 135 | /// 136 | /// 章动(黄经章动和交角章动)计算,t是世纪数 137 | /// 138 | /// 世纪数 139 | public static void nutation(double t) 140 | { 141 | int i; 142 | double c, a, t2 = t * t, dL = 0, dE = 0; 143 | double[] B = ZB.nutB; 144 | for (i = 0; i < B.Length; i += 5) 145 | { 146 | c = B[i] + B[i + 1] * t + B[i + 2] * t2; 147 | if (i == 0) a = -1.742 * t; else a = 0; 148 | dL += (B[i + 3] + a) * Math.Sin(c); 149 | dE += B[i + 4] * Math.Cos(c); 150 | } 151 | ZB.dL = dL / 100 / LunarHelper.rad; //黄经章动 152 | ZB.dE = dE / 100 / LunarHelper.rad; //交角章动 153 | } 154 | 155 | 156 | 157 | /// 158 | /// 只计算黄经章动 159 | /// 160 | /// 161 | /// 162 | public static double nutationLon(double t) 163 | { 164 | int i; 165 | double a, t2 = t * t, dL = 0; 166 | double[] B = ZB.nutB; 167 | for (i = 0; i < B.Length; i += 5) 168 | { 169 | if (i == 0) a = -1.742 * t; else a = 0; 170 | dL += (B[i + 3] + a) * Math.Sin(B[i] + B[i + 1] * t + B[i + 2] * t2); 171 | } 172 | return dL / 100 / LunarHelper.rad; 173 | } 174 | 175 | 176 | /// 177 | /// 返回黄赤交角,t是世纪数 178 | /// 179 | /// 世纪数 180 | /// 181 | public static double hcjj(double t) 182 | { 183 | double t2 = t * t, t3 = t2 * t, t4 = t3 * t; 184 | return (84381.4088 - 46.836051 * t - 0.0001667 * t2 - 0.00199911 * t3 - 0.000000523 * t4) / LunarHelper.rad; 185 | } 186 | 187 | 188 | 189 | /// 190 | /// 求角度差(未测试) 191 | /// 192 | /// 193 | /// 194 | /// 195 | /// 196 | /// 197 | public static double j1_j2(double J1, double W1, double J2, double W2) 198 | { 199 | double dJ = LunarHelper.rad2rrad(J1 - J2), dW = W1 - W2; 200 | if (Math.Abs(dJ) < 1 / 1000 && Math.Abs(dW) < 1 / 1000) 201 | { 202 | dJ *= Math.Cos((W1 + W2) / 2); 203 | return Math.Sqrt(dJ * dJ + dW * dW); 204 | } 205 | return Math.Acos(Math.Sin(W1) * Math.Sin(W2) + Math.Cos(W1) * Math.Cos(W2) * Math.Cos(dJ)); 206 | } 207 | 208 | 209 | /// 210 | /// 传入T是2000年首起算的日数(UT),dt是deltatT(日),精度要求不高时dt可取值为0 211 | /// 返回格林尼治恒星时(不含赤经章动及非多项式部分),即格林尼治子午圈的平春风点起算的赤经 212 | /// 213 | /// 2000年首起算的日数(UT) 214 | /// deltatT(日) 215 | /// 216 | public static double gst(double T, double dt) 217 | { 218 | double t = (T + dt) / 36525, t2 = t * t, t3 = t2 * t, t4 = t3 * t; 219 | return LunarHelper.pi2 * (0.7790572732640 + 1.00273781191135448 * T) //严格说这里的T是UT,下一行的t是力学时(世纪数) 220 | + (0.014506 + 4612.15739966 * t + 1.39667721 * t2 - 0.00009344 * t3 + 0.00001882 * t4) / LunarHelper.rad; 221 | } 222 | 223 | 224 | /// 225 | /// 太阳光行差,t是世纪数 226 | /// 227 | /// 世纪数 228 | /// 229 | public static double gxc_sunLon(double t) 230 | { 231 | double v = -0.043126 + 628.301955 * t - 0.000002732 * t * t; //平近点角 232 | double e = 0.016708634 - 0.000042037 * t - 0.0000001267 * t * t; 233 | return (-20.49552 * (1 + e * Math.Cos(v))) / LunarHelper.rad; //黄经光行差 234 | } 235 | 236 | 237 | /// 238 | /// 黄纬光行差 239 | /// 240 | /// 241 | /// 242 | public static double gxc_sunLat(double t) 243 | { 244 | return 0; 245 | } 246 | 247 | 248 | /// 249 | /// 月球经度光行差,误差0.07" 250 | /// 251 | /// 252 | /// 253 | public static double gxc_moonLon(double t) 254 | { 255 | return -3.4E-6; 256 | } 257 | 258 | 259 | /// 260 | /// 月球纬度光行差,误差0.006" 261 | /// 262 | /// 263 | /// 264 | public static double gxc_moonLat(double t) 265 | { 266 | return 0.063 * Math.Sin(0.057 + 8433.4662 * t + 0.000064 * t * t) / LunarHelper.rad; 267 | } 268 | 269 | 270 | /// 271 | /// 大气折射,ho是视高度 272 | /// 273 | /// 274 | /// 275 | public static double AR(double ho) 276 | { 277 | return -0.0002909 / Math.Tan(ho + 0.002227 / (ho + 0.07679)); 278 | } 279 | 280 | 281 | /// 282 | /// 大气折射,h是真高度 283 | /// 284 | /// 285 | /// 286 | public static double AR2(double h) 287 | { 288 | return 0.0002967 / Math.Tan(h + 0.003138 / (h + 0.08919)); 289 | } 290 | 291 | 292 | /// 293 | /// 视差修正 294 | /// 295 | /// 赤道坐标 296 | /// 时角 297 | /// 地理纬度 298 | /// 海拔(千米) 299 | public static void parallax(double[] z, double H, double fa, double high) 300 | { 301 | double dw = 1d; 302 | if (z[2] < 500) dw = LunarHelper.cs_AU; 303 | z[2] *= dw; 304 | double r0, x0, y0, z0, f = 0.99664719; 305 | double u = Math.Atan(f * Math.Tan(fa)); 306 | double g = z[0] + H; 307 | r0 = LunarHelper.cs_rEar * Math.Cos(u) + high * Math.Cos(fa); //站点与地地心向径的赤道投影长度 308 | z0 = LunarHelper.cs_rEar * Math.Sin(u) * f + high * Math.Sin(fa); //站点与地地心向径的轴向投影长度 309 | x0 = r0 * Math.Cos(g); 310 | y0 = r0 * Math.Sin(g); 311 | 312 | ZB.llr2xyz(z[0], z[1], z[2], z); 313 | z[0] -= x0; z[1] -= y0; z[2] -= z0; 314 | ZB.xyz2llr(z[0], z[1], z[2], z); 315 | z[2] /= dw; 316 | } 317 | 318 | 319 | 320 | /// 321 | /// 求空间两点连线与地球的交点(靠近点1的交点),返回在ZB.le_J,le_W,赤道坐标。R1,R2单位是千米 322 | /// 323 | /// 324 | /// 325 | /// 326 | /// 327 | /// 328 | /// 329 | public static void line_earth(double J1, double W1, double R1, double J2, double W2, double R2) 330 | { 331 | double x1 = R1 * Math.Cos(W1) * Math.Cos(J1), y1 = R1 * Math.Cos(W1) * Math.Sin(J1), z1 = R1 * Math.Sin(W1); 332 | double x2 = R2 * Math.Cos(W2) * Math.Cos(J2), y2 = R2 * Math.Cos(W2) * Math.Sin(J2), z2 = R2 * Math.Sin(W2); 333 | double dx = x2 - x1, dy = y2 - y1, dz = z2 - z1, f = 0.99664719, r = LunarHelper.cs_rEar; //直线参数及地球参数 334 | double x, y, z, lh = 0; 335 | if (Math.Abs(dx) < Math.Abs(dy)) //必要时仑换 336 | { lh = dx; dx = dy; dy = lh; lh = x1; x1 = y1; y1 = lh; lh = 1; } 337 | double a = dy / dx, b = y1 - a * x1, c = dz / dx / f, d = z1 / f - c * x1; 338 | double A = a * a + c * c + 1, B = a * b + c * d, C = b * b + d * d - r * r, D = B * B - A * C; 339 | if (D < 0) { ZB.le_J = ZB.le_W = 100; return; } //返回100表示无解 340 | D = Math.Sqrt(D); if (x1 + B / A < 0) D = -D; 341 | x = (-B + D) / A; y = a * x + b; z = (c * x + d) / f; 342 | ZB.le_R1 = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1)); 343 | if (lh != 0) { lh = x; x = y; y = lh; } 344 | ZB.le_W = Math.Atan(z / Math.Sqrt(x * x + y * y)); 345 | ZB.le_J = LunarHelper.rad2mrad(Math.Atan2(y, x)); 346 | } 347 | 348 | #endregion 349 | 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /SharpSxwnl/ob.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 日对象 9 | /// 10 | public class OB 11 | { 12 | #region 构造函数 13 | 14 | public OB() 15 | { 16 | this.ThisJieQi = new JieQiInfo(); 17 | this.PreviousJieQi = new JieQiInfo(); 18 | this.NextJieQi = new JieQiInfo(); 19 | } 20 | 21 | #endregion 构造函数 22 | 23 | 24 | 25 | #region 公共属性(注: 初始转换时为公共字段, 已改写) 26 | 27 | #region 日的公历信息 28 | 29 | /// 30 | /// 2000.0起算儒略日,北京时12:00 31 | /// 32 | public double d0 { get; set; } // = 0; // 2000.0起算儒略日,北京时12:00 33 | 34 | /// 35 | /// 所在公历月内日序数 36 | /// 37 | public double di { get; set; } // = 0; // 所在公历月内日序数 38 | 39 | /// 40 | /// 所在公历年,同lun.y 41 | /// 42 | public int y { get; set; } // = 0; // 所在公历年,同lun.y 43 | 44 | /// 45 | /// 所在公历月,同lun.m 46 | /// 47 | public int m { get; set; } // = 0; // 所在公历月,同lun.m 48 | 49 | /// 50 | /// 日名称(公历) 51 | /// 52 | public int d { get; set; } // = 0; // 日名称(公历) 53 | 54 | /// 55 | /// 所在公历月的总天数,同lun.d0 56 | /// 57 | public double dn { get; set; } // = 0; // 所在公历月的总天数,同lun.d0 58 | 59 | /// 60 | /// 所在月的月首的星期,同lun.w0 61 | /// 62 | public double week0 { get; set; } // = 0; // 所在月的月首的星期,同lun.w0 63 | 64 | /// 65 | /// 星期 66 | /// 67 | public double week { get; set; } // = 0; // 星期 68 | 69 | /// 70 | /// 在本月中的周序号 71 | /// 72 | public double weeki { get; set; } // = 0; // 在本月中的周序号 73 | 74 | /// 75 | /// 本月的总周数 76 | /// 77 | public double weekN { get; set; } // = 0; // 本月的总周数 78 | 79 | #endregion 80 | 81 | 82 | 83 | #region 日的农历信息 84 | 85 | /// 86 | /// 距农历月首的编移量,0对应初一 87 | /// 88 | public double Ldi { get; set; } // = 0; // 距农历月首的编移量,0对应初一 89 | 90 | /// 91 | /// 日名称(农历),即'初一,初二等' 92 | /// 93 | public string Ldc { get; set; } // = ""; // 日名称(农历),即'初一,初二等' 94 | 95 | /// 96 | /// 距冬至的天数 97 | /// 98 | public double cur_dz { get; set; } // = 0; // 距冬至的天数 99 | 100 | /// 101 | /// 距夏至的天数 102 | /// 103 | public double cur_xz { get; set; } // = 0; // 距夏至的天数 104 | 105 | /// 106 | /// 距立秋的天数 107 | /// 108 | public double cur_lq { get; set; } // = 0; // 距立秋的天数 109 | 110 | /// 111 | /// 距芒种的天数 112 | /// 113 | public double cur_mz { get; set; } // = 0; // 距芒种的天数 114 | 115 | /// 116 | /// 距小暑的天数 117 | /// 118 | public double cur_xs { get; set; } // = 0; // 距小暑的天数 119 | 120 | /// 121 | /// 月名称 122 | /// 123 | public string Lmc { get; set; } // = ""; // 月名称 124 | 125 | /// 126 | /// 月大小 127 | /// 128 | public double Ldn { get; set; } // = 0; // 月大小 129 | 130 | /// 131 | /// 闰状况(值为'闰'或空串) 132 | /// 133 | public string Lleap { get; set; } // = ""; // 闰状况(值为'闰'或空串) 134 | 135 | /// 136 | /// 下个月名称,判断除夕时要用到 137 | /// 138 | public string Lmc2 { get; set; } // = ""; // 下个月名称,判断除夕时要用到 139 | 140 | 141 | #region 日的农历纪年、月、日、时及星座 142 | 143 | /// 144 | /// 农历纪年(10进制,1984年起算,分界点可以是立春也可以是春节,在程序中选择一个) 145 | /// 146 | public double Lyear { get; set; } // = 0; // 农历纪年(10进制,1984年起算,分界点可以是立春也可以是春节,在程序中选择一个) 147 | 148 | /// 149 | /// 干支纪年(立春) 150 | /// 151 | public string Lyear2 { get; set; } // = ""; // 干支纪年(立春) 152 | 153 | /// 154 | /// 纪月处理,1998年12月7日(大雪)开始连续进行节气计数,0为甲子 155 | /// 156 | public double Lmonth { get; set; } // = 0; // 纪月处理,1998年12月7日(大雪)开始连续进行节气计数,0为甲子 157 | 158 | /// 159 | /// 干支纪月 160 | /// 161 | public string Lmonth2 { get; set; } // = ""; // 干支纪月 162 | 163 | /// 164 | /// 干支纪日 165 | /// 166 | public string Lday2 { get; set; } // = ""; // 纪日 167 | 168 | /// 169 | /// 干支纪时 170 | /// 171 | public double Ltime2 { get; set; } // = 0; // 纪时 172 | 173 | /// 174 | /// 星座 175 | /// 176 | public string XiZ { get; set; } // = ""; // 星座 177 | 178 | #endregion 179 | #endregion 日的农历信息 180 | 181 | 182 | 183 | #region 日的回历信息 184 | 185 | /// 186 | /// 年(回历) 187 | /// 188 | public double Hyear { get; set; } // = 0; // 年(回历) 189 | 190 | /// 191 | /// 月(回历) 192 | /// 193 | public double Hmonth { get; set; } // = 0; // 月(回历) 194 | 195 | /// 196 | /// 日(回历) 197 | /// 198 | public double Hday { get; set; } // = 0; // 日(回历) 199 | 200 | #endregion 201 | 202 | 203 | 204 | #region 日的其它信息 205 | 206 | /// 207 | /// 月相名称 208 | /// 209 | public string yxmc { get; set; } // = ""; // 月相名称 210 | 211 | /// 212 | /// 月相时刻(儒略日) 213 | /// 214 | public string yxjd { get; set; } // = ""; // 月相时刻(儒略日) 215 | 216 | /// 217 | /// 月相时间串 218 | /// 219 | public string yxsj { get; set; } // = ""; // 月相时间串 220 | 221 | /// 222 | /// 节气名称 223 | /// 224 | public string jqmc { get; set; } // = ""; // 节气名称 225 | 226 | /// 227 | /// 节气时刻(儒略日) 228 | /// 229 | public string jqjd { get; set; } // = ""; // 节气时刻(儒略日) 230 | 231 | /// 232 | /// 节气时间串 233 | /// 234 | public string jqsj { get; set; } // = ""; // 节气时间串 235 | 236 | #endregion 237 | 238 | 239 | 240 | #region C#: 从 Javascript 代码中提取出来的其他字段(属性) 241 | 242 | /// 243 | /// 农历纪年(10进制,1984年起算) 244 | /// 245 | public double Lyear0 { get; set; } // = 0; // 农历纪年(10进制,1984年起算) 246 | 247 | /// 248 | /// 干支纪年(正月) 249 | /// 250 | public string Lyear3 { get; set; } // = ""; // 干支纪年(正月) 251 | 252 | /// 253 | /// 黄帝纪年 254 | /// 255 | public double Lyear4 { get; set; } // = 0; // 黄帝纪年 256 | 257 | /// 258 | /// A 类节日纪念日(重要喜庆日子名称(可将日子名称置红)) 259 | /// 260 | public string A { get; set; } // = ""; 261 | 262 | /// 263 | /// B 类节日纪念日(重要日子名称) 264 | /// 265 | public string B { get; set; } // = ""; 266 | 267 | /// 268 | /// C 类节日纪念日(各种日子名称(连成一大串, 以空格符分隔)) 269 | /// 270 | public string C { get; set; } // = ""; 271 | 272 | /// 273 | /// 放假的标志 274 | /// 275 | public double Fjia { get; set; } // = 0; 276 | 277 | /// 278 | /// 八字信息: 真太阳时间 279 | /// 280 | public string bz_zty { get; set; } // = ""; 281 | 282 | /// 283 | /// 八字信息: 干支纪年 284 | /// 285 | public string bz_jn { get; set; } // = ""; 286 | 287 | /// 288 | /// 八字信息: 干支纪月 289 | /// 290 | public string bz_jy { get; set; } // = ""; 291 | 292 | /// 293 | /// 八字信息: 干支纪日 294 | /// 295 | public string bz_jr { get; set; } // = ""; 296 | 297 | /// 298 | /// 八字信息: 干支纪时 299 | /// 300 | public string bz_js { get; set; } // = ""; 301 | 302 | /// 303 | /// 八字信息: 干支纪时(从子时至亥时共 12 个时辰的干支集合, 以空格分隔 304 | /// 305 | public string bz_JS { get; set; } // = ""; 306 | 307 | /// 308 | /// 节气名称(实历?) 309 | /// 310 | public string Ljq { get; set; } // = ""; 311 | 312 | #endregion 313 | 314 | 315 | #endregion 公共属性 316 | 317 | 318 | 319 | #region 转换时新增的公共属性 320 | 321 | /// 322 | /// 八字信息: 平太阳时间 323 | /// 324 | public string bz_pty { get; set; } // = ""; 325 | 326 | /// 327 | /// 所属节令 328 | /// 329 | public JieQiInfo ThisJieQi { get; set; } 330 | 331 | /// 332 | /// 上一节令 333 | /// 334 | public JieQiInfo PreviousJieQi { get; set; } 335 | 336 | /// 337 | /// 下一节令 338 | /// 339 | public JieQiInfo NextJieQi { get; set; } 340 | 341 | /// 342 | /// 每日的十二建信息, 即: {建, 除, 满, 平, 定, 执, 破, 危, 成, 收, 开, 闭} 其中之一 343 | /// 344 | public string Ri12Jian { get; set; } 345 | 346 | #endregion 347 | 348 | } 349 | } 350 | -------------------------------------------------------------------------------- /SharpSxwnl/oba.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Text.RegularExpressions; 5 | using System.Xml; 6 | 7 | namespace SharpSxwnl 8 | { 9 | /// 10 | /// 公历基础构件,JD物件的补充(主要用于计算节假日, 纪念日, 回历信息等) 11 | /// 12 | public static class oba 13 | { 14 | #region 公共属性(注: 初始转换时为公共字段, 已改写, 请参阅“转换时增加的私有字段”) 15 | 16 | /// 17 | /// 按周规则定义的世界性节日(纪念日) 18 | /// 19 | public static xList wFtv 20 | { 21 | get{ return oba.__wFtv; } 22 | set{ oba.__wFtv = value; } 23 | } 24 | 25 | /// 26 | /// 各月的节日(纪念日), 将原 Javascript 代码进行了适当的改写 27 | /// 28 | public static xList> sFtv 29 | { 30 | get { return oba.__sFtv; } 31 | set { oba.__sFtv = value; } 32 | } 33 | 34 | #endregion 35 | 36 | 37 | 38 | 39 | #region 公共方法 40 | 41 | /// 42 | /// 计算某日节日的信息, 并保存信息到日对象中 43 | /// 44 | /// 日对象 45 | /// 日对象 46 | public static void getDayName(OB u, OB r) 47 | { 48 | string m0 = (u.m < 10 ? "0" : "") + u.m; 49 | string d0 = (u.d < 10 ? "0" : "") + u.d; 50 | int i; 51 | string s, s2, type; 52 | 53 | if (u.week == 0 || u.week == 6) 54 | r.Fjia = 1; // 星期日或星期六放假 55 | 56 | // 按公历日期查找 57 | for (i = 0; i < oba.sFtv[u.m - 1].Length; i++) // C#: 注: 属性 sFtv 在初始化时已经包含了 12 个元素, 以对应 12 个月 58 | { 59 | // 公历节日或纪念日,遍历本月节日表 60 | s = oba.sFtv[u.m - 1][i]; 61 | if (s.Length < 3 || s.Substring(0, 2) != d0) // C#: 新增了第 1 个判断条件 62 | continue; 63 | s = s.Substring(2, s.Length - 2); 64 | type = s.Substring(0, 1); 65 | if (s.Length >= 6 && s.Substring(5, 1) == "-") 66 | { 67 | // 有年限的节日 68 | if (u.y < (int.Parse(s.Substring(1, 4))) || u.y > (int.Parse(s.Substring(6, 4)))) continue; 69 | s = s.Substring(10, s.Length - 10); 70 | } 71 | else 72 | { 73 | if (u.y < 1850) continue; 74 | s = s.Substring(1, s.Length - 1); 75 | } 76 | if (type == "#") { r.A += s + " "; r.Fjia = 1; } //放假的节日 77 | if (type == "I") r.B += s + " "; //主要 78 | if (type == ".") r.C += s + " "; //其它 79 | } 80 | 81 | // 按周规则查找 82 | double w = u.weeki; 83 | if (u.week >= u.week0) w += 1; 84 | double w2 = w; 85 | if (u.weeki == u.weekN - 1) w2 = 5; 86 | string w__ = m0 + w + u.week; // d日在本月的第几个星期某 87 | string w2__ = m0 + w2 + u.week; 88 | 89 | for (i = 0; i < oba.wFtv.Length; i++) 90 | { 91 | s = oba.wFtv[i]; 92 | s2 = s.Substring(0, 4); 93 | if (s2 != w__ && s2 != w2__) continue; 94 | type = s.Substring(4, 1); 95 | s = s.Substring(5, s.Length - 5); 96 | if (type == "#") { r.A += s + " "; r.Fjia = 1; } 97 | if (type == "I") r.B += s + " "; 98 | if (type == ".") r.C += s + " "; 99 | } 100 | } 101 | 102 | 103 | 104 | /// 105 | /// 回历计算, 并保存信息到日对象中 106 | /// 107 | /// 2000.0起算儒略日,北京时12:00 108 | /// 日对象 109 | public static void getHuiLi(double d0, OB r) 110 | { 111 | // 以下算法使用Excel测试得到,测试时主要关心年临界与月临界 112 | double z, y, m, d; 113 | d = d0 + 503105; z = LunarHelper.int2((d + 0.1) / 10631); // 10631为一周期(30年) 114 | d -= z * 10631; y = LunarHelper.int2((d + 0.5) / 354.366); // 加0.5的作用是保证闰年正确(一周中的闰年是第2,5,7,10,13,16,18,21,24,26,29年) 115 | d -= LunarHelper.int2(y * 354.366 + 0.5); m = LunarHelper.int2((d + 0.11) / 29.51); // 分子加0.11,分每加0.01的作用是第354或355天的的月分保持为12月(m=11) 116 | d -= LunarHelper.int2(m * 29.51 + 0.5); 117 | r.Hyear = z * 30 + y + 1; 118 | r.Hmonth = m + 1; 119 | r.Hday = d + 1; 120 | } 121 | 122 | #endregion 公共方法 123 | 124 | 125 | 126 | 127 | #region 转换时增加的私有字段(用于封装成公共属性, 按转换规范 10 命名) 128 | 129 | /// 130 | /// 按周规则定义的世界性节日(纪念日) 131 | /// 132 | private static xList __wFtv = oba.getwFtvData(); 133 | 134 | /// 135 | /// 各月的节日(纪念日), 功能类似于交错数组 136 | /// 137 | private static xList> __sFtv = oba.getsFtvData(); // 国历节日,#表示放假日,I表示重要节日或纪念日 138 | 139 | #endregion 140 | 141 | 142 | 143 | #region 转换时新增的方法 144 | 145 | /// 146 | /// 从 Xml 文档对象加载 wFtv 数据 147 | /// 148 | /// 149 | private static xList getwFtvData() 150 | { 151 | xList result = new xList(); 152 | 153 | //---------------------------------------------------------------------------------------- 154 | // 加载 Xml 数据: 按周规则定义的节日(纪念日) 155 | // 注: 加载时自动去除各行 Xml 数据前、后端的所有空白字符, 但对数据内部的空白字符不作处理 156 | //---------------------------------------------------------------------------------------- 157 | if (LunarHelper.SxwnlXmlData != null) 158 | { 159 | const string wFtvXPath = "SharpSxwnl/SxwnlData/Data[@Id = 'oba_wFtv']"; 160 | XmlNode foundNode; 161 | Regex regexToTrim = new Regex(@"(^\s*)|(\s*$)"); // C#: 匹配任何空白字符 162 | 163 | // 读取并解开数据 164 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(wFtvXPath); 165 | if (foundNode != null) 166 | { 167 | string[] wftv = regexToTrim.Replace(foundNode.InnerText, "").Split(new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries); 168 | 169 | for (int i = 0; i < wftv.Length; i++) 170 | result.Add(regexToTrim.Replace(wftv[i], "")); 171 | } 172 | } 173 | 174 | return result; 175 | } 176 | 177 | 178 | 179 | /// 180 | /// 从 Xml 文档对象加载 sFtv 数据 181 | /// 182 | /// 183 | private static xList> getsFtvData() 184 | { 185 | const int monthNumPerYear = 12; 186 | xList> result = new xList>(); 187 | 188 | for (int i = 0; i < monthNumPerYear; i++) // C#: 预置 12 个元素 189 | result.Add(new xList()); 190 | 191 | //---------------------------------------------------------------------------------------- 192 | // 加载 Xml 数据: 按周规则定义的节日(纪念日) 193 | // 注: 加载时自动去除各行 Xml 数据前、后端的所有空白字符, 但对数据内部的空白字符不作处理 194 | //---------------------------------------------------------------------------------------- 195 | if (LunarHelper.SxwnlXmlData != null) 196 | { 197 | XmlNode foundNode; 198 | Regex regexToTrim = new Regex(@"(^\s*)|(\s*$)"); // C#: 匹配前、后端的任何空白字符 199 | 200 | for (int i = 0; i < monthNumPerYear; i++) 201 | { 202 | string xPath = "SharpSxwnl/SxwnlData/Data[@Id = 'oba_sFtv']/Month[@Id = '" + (i + 1).ToString() + "']"; 203 | 204 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(xPath); 205 | if (foundNode != null) 206 | { 207 | string[] sftv = regexToTrim.Replace(foundNode.InnerText, "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 208 | for (int j = 0; j < sftv.Length; j++) 209 | result[i].Add(regexToTrim.Replace(sftv[j], "")); 210 | } 211 | 212 | } 213 | } 214 | 215 | return result; 216 | } 217 | 218 | #endregion 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /SharpSxwnl/obb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections; 5 | using System.Xml; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace SharpSxwnl 9 | { 10 | /// 11 | /// 农历基础构件(常数、通用函数等) 12 | /// 13 | public static class obb 14 | { 15 | #region 公共属性(注: 初始转换时为公共字段, 已改写, 请参阅“转换时增加的私有字段”) 16 | 17 | /// 18 | /// 数字 0 - 10 对应的中文名称 19 | /// 20 | public static string[] numCn 21 | { 22 | get { return obb.__numCn; } 23 | set { obb.__numCn = value; } 24 | } 25 | 26 | /// 27 | /// 十天干表 28 | /// 29 | public static string[] Gan 30 | { 31 | get { return obb.__Gan; } 32 | set { obb.__Gan = value; } 33 | } 34 | 35 | /// 36 | /// 十二地支表 37 | /// 38 | public static string[] Zhi 39 | { 40 | get { return obb.__Zhi; } 41 | set { obb.__Zhi = value; } 42 | } 43 | 44 | /// 45 | /// 十二属相表 46 | /// 47 | public static string[] ShX 48 | { 49 | get { return obb.__ShX; } 50 | set { obb.__ShX = value; } 51 | } 52 | 53 | /// 54 | /// 十二星座表 55 | /// 56 | public static string[] XiZ 57 | { 58 | get { return obb.__XiZ; } 59 | set { obb.__XiZ = value; } 60 | } 61 | 62 | /// 63 | /// 月相名称表 64 | /// 65 | public static string[] yxmc 66 | { 67 | get { return obb.__yxmc; } 68 | set { obb.__yxmc = value; } 69 | } 70 | 71 | /// 72 | /// 廿四节气表 73 | /// 74 | public static string[] jqmc 75 | { 76 | get { return obb.__jqmc; } 77 | set { obb.__jqmc = value; } 78 | } 79 | 80 | /// 81 | /// 农历各月的名称, 从 "十一" 月开始, 即从月建 "子" 开始, 与十二地支的顺序对应 82 | /// 83 | public static string[] ymc 84 | { 85 | get { return obb.__ymc; } 86 | set { obb.__ymc = value; } 87 | } 88 | 89 | /// 90 | /// 农历各日的名称 91 | /// 92 | public static string[] rmc 93 | { 94 | get { return obb.__rmc; } 95 | set { obb.__rmc = value; } 96 | } 97 | 98 | /// 99 | /// 历史纪年表 100 | /// 101 | public static JnbArrayList JNB 102 | { 103 | get { return obb.__JNB; } 104 | set { obb.__JNB = value; } 105 | } 106 | 107 | #endregion 公共属性 108 | 109 | 110 | 111 | #region 公共方法 112 | 113 | /// 114 | /// 取年号 115 | /// 116 | /// 公历年(天文纪年, 如 -1 表示常规纪年的"公元前2年") 117 | /// 118 | public static string getNH(int y) 119 | { 120 | int i, j; 121 | string c, s = ""; 122 | JnbArrayList ob = obb.JNB; 123 | for (i = 0; i < ob.Count; i += 7) 124 | { 125 | j = (int)ob[i]; 126 | if (y < j || y >= j + (int)ob[i + 1]) continue; 127 | c = (string)ob[i + 6] + (y - j + 1 + (int)ob[i + 2]) + "年"; // 年号及年次 128 | s += (s.Length > 0 ? ";" : "") + "[" + ob[i + 3] + "]" + ob[i + 4] + " " + ob[i + 5] + " " + c; // i为年号元年,i+3朝代,i+4朝号,i+5皇帝,i+6年号 129 | } 130 | return s; 131 | } 132 | 133 | 134 | /// 135 | /// 计算农历节日 136 | /// 137 | /// 138 | /// 139 | public static void getDayName(OB u, OB r) 140 | { 141 | int i; 142 | 143 | // 按农历日期查找重点节假日 144 | string d = u.Lmc + (u.Lmc.Length < 2 ? "月" : "") + u.Ldc; 145 | if (u.Lleap != "闰") 146 | { 147 | for (i = 0; i < obb.LunarFeasts.Length; i++) // C#: 查表, 查找农历节假日 148 | { 149 | if (d == obb.LunarFeasts[i].Lmc) 150 | { 151 | r.A += obb.LunarFeasts[i].A; 152 | r.B += obb.LunarFeasts[i].B; 153 | r.C += obb.LunarFeasts[i].C; 154 | r.Fjia = obb.LunarFeasts[i].Fjia; 155 | } 156 | } 157 | } 158 | if (u.Lmc2 == "正") 159 | { 160 | // 最后一月 161 | if (d == "十二三十" && u.Ldn == 30) { r.A += "除夕 "; r.Fjia = 1; } 162 | if (d == "十二廿九" && u.Ldn == 29) { r.A += "除夕 "; r.Fjia = 1; } 163 | if (d == "十二廿三") r.B += "小年 "; 164 | } 165 | if (u.Ljq.Length > 0) 166 | { 167 | for (i = 0; i < obb.JieQiFeasts.Length; i++) // C#: 查找是否有放假的节气 168 | { 169 | if (u.Ljq == obb.JieQiFeasts[i]) // C#: 匹配 170 | break; 171 | } 172 | if (i < obb.JieQiFeasts.Length) { r.A += u.Ljq + " "; r.Fjia = 1; } 173 | else r.B += u.Ljq + " "; 174 | } 175 | 176 | // 农历杂节 177 | string w, w2; 178 | if (u.cur_dz >= 0 && u.cur_dz < 81) 179 | { // 数九 180 | w = obb.numCn[(int)Math.Floor(u.cur_dz / 9) + 1]; 181 | if (u.cur_dz % 9 == 0) r.B += "『" + w + "九』 "; 182 | else r.C += w + "九第" + (u.cur_dz % 9 + 1) + "天 "; 183 | } 184 | 185 | w = u.Lday2.Substring(0, 1); 186 | w2 = u.Lday2.Substring(1, 1); 187 | if (u.cur_xz > 20 && u.cur_xz <= 30 && w == "庚") r.B += "初伏 "; 188 | if (u.cur_xz > 30 && u.cur_xz <= 40 && w == "庚") r.B += "中伏 "; 189 | if (u.cur_lq > 0 && u.cur_lq <= 10 && w == "庚") r.B += "末伏 "; 190 | if (u.cur_mz > 0 && u.cur_mz <= 10 && w == "丙") r.B += "入梅 "; 191 | if (u.cur_xs > 0 && u.cur_xs <= 12 && w2 == "未") r.B += "出梅 "; 192 | } 193 | 194 | 195 | 196 | /// 197 | /// 命理八字计算, 并保存到日对象 ob 中 198 | /// 199 | /// 格林尼治UT(J2000起算) 200 | /// 本地经度 201 | /// 日对象 202 | public static void mingLiBaZi(double jd, double J, OB ob) 203 | { 204 | mingLiBaZi(jd, J, ob, BaZiTypeS.Normal); 205 | } 206 | 207 | 208 | /// 209 | /// 命理八字计算, 并保存到日对象 ob 中 210 | /// 211 | /// 格林尼治UT(J2000起算) 212 | /// 本地经度 213 | /// 日对象 214 | /// 南半球的标志 215 | public static void mingLiBaZi(double jd, double J, OB ob, BaZiTypeS baziTypeS) 216 | { 217 | int i; 218 | string c; 219 | double v; 220 | double jd2 = jd + JD.deltatT2(jd); // 力学时 221 | double w = XL.S_aLon(jd2 / 36525, -1); // 此刻太阳视黄经 222 | double k = LunarHelper.int2((w / LunarHelper.pi2 * 360 + 45 + 15 * 360) / 30); // 1984年立春起算的节气数(不含中气) 223 | jd += XL.shiCha2(jd2 / 36525) - J / Math.PI / 2; // 本地真太阳时(使用低精度算法计算时差) 224 | ob.bz_zty = JD.timeStr(jd); 225 | 226 | jd += 13d / 24d; // 转为前一日23点起算(原jd为本日中午12点起算) // C#: 注意数据类型 227 | double D = Math.Floor(jd), SC = LunarHelper.int2((jd - D) * 12); // 日数与时辰 228 | 229 | v = LunarHelper.int2(k / 12 + 6000000); ob.bz_jn = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 230 | v = k + 2 + 60000000; ob.bz_jy = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 231 | 232 | // C#: 新增的代码段, 计算南半球八字(仅纪月不同) 233 | switch (baziTypeS) 234 | { 235 | case BaZiTypeS.TianChongDiChong: 236 | ob.bz_jy = obb.Gan[(int)((v + 4) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 237 | break; 238 | 239 | case BaZiTypeS.TianKeDiChong: 240 | ob.bz_jy = obb.Gan[(int)((v + 6) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 241 | break; 242 | 243 | case BaZiTypeS.TianTongDiChong: 244 | ob.bz_jy = obb.Gan[(int)((v + 0) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 245 | break; 246 | 247 | default: 248 | break; 249 | } 250 | 251 | 252 | v = D - 6 + 9000000; ob.bz_jr = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 253 | v = (D - 1) * 12 + 90000000 + SC; ob.bz_js = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 254 | 255 | v -= SC; 256 | ob.bz_JS = ""; // 全天纪时表 257 | for (i = 0; i < 13; i++) 258 | { 259 | // 一天中包含有13个纪时 260 | c = obb.Gan[(int)((v + i) % 10)] + obb.Zhi[(int)((v + i) % 12)]; // 各时辰的八字 261 | if (SC == i) 262 | { 263 | ob.bz_js = c; 264 | // c = "" + c + ""; //红色显示这时辰 // C#: 注释, 即取消格式显示 265 | } 266 | ob.bz_JS += (i != 0 ? " " : "") + c; 267 | } 268 | } 269 | 270 | 271 | /// 272 | /// 精气计算 273 | /// 274 | /// 275 | /// 276 | public static double qi_accurate(double W) 277 | { 278 | double t = XL.S_aLon_t(W) * 36525; 279 | return t - JD.deltatT2(t) + 8d / 24d; // 精气 280 | } 281 | 282 | 283 | /// 284 | /// 精朔计算 285 | /// 286 | /// 287 | /// 288 | public static double so_accurate(double W) 289 | { 290 | double t = XL.MS_aLon_t(W) * 36525; 291 | return t - JD.deltatT2(t) + 8d / 24d; // 精朔 292 | } 293 | 294 | 295 | /// 296 | /// 精气计算法 2: 297 | /// 298 | /// 299 | /// 300 | public static double qi_accurate2(double jd) 301 | { 302 | return obb.qi_accurate(Math.Floor((jd + 293) / 365.2422 * 24) * Math.PI / 12); //精气 303 | } 304 | 305 | 306 | /// 307 | /// 精朔计算法 2: 308 | /// 309 | /// 310 | /// 311 | public static double so_accurate2(double jd) 312 | { 313 | return obb.so_accurate(Math.Floor((jd + 8) / 29.5306) * Math.PI * 2); // 精朔 314 | } 315 | 316 | #endregion 317 | 318 | 319 | 320 | #region 转换时新增的方法 321 | 322 | /// 323 | /// 命理八字计算(普通计算, 不转换为当地真太阳时), 并保存到日对象 ob 中 324 | /// 325 | /// 格林尼治UT(J2000起算) 326 | /// 本地经度 327 | /// 日对象 328 | public static void mingLiBaZiNormal(double jd, double J, OB ob) 329 | { 330 | mingLiBaZiNormal(jd, J, ob, BaZiTypeS.Normal); 331 | } 332 | 333 | 334 | /// 335 | /// 命理八字计算(普通计算, 不转换为当地真太阳时), 并保存到日对象 ob 中 336 | /// 337 | /// 格林尼治UT(J2000起算) 338 | /// 本地经度 339 | /// 日对象 340 | /// 南半球的标志 341 | public static void mingLiBaZiNormal(double jd, double J, OB ob, BaZiTypeS baziTypeS) 342 | { 343 | int i; 344 | string c; 345 | double v; 346 | double jd2 = jd + JD.deltatT2(jd); // 力学时 347 | double w = XL.S_aLon(jd2 / 36525, -1); // 此刻太阳视黄经 348 | double k = LunarHelper.int2((w / LunarHelper.pi2 * 360 + 45 + 15 * 360) / 30); // 1984年立春起算的节气数(不含中气) 349 | 350 | //---------------------------------------------------------------------------------------------- 351 | // C#: 注: 仅有下列代码段与 mingLiBaZi 方法中的代码不同, 其余部分都是相同的 352 | //---------------------------------------------------------------------------------------------- 353 | jd += 0 - J / Math.PI / 2; // 将格林尼治UT(J2000起算), 转换为本地时间, 不必考虑真太阳与平太阳时之间的时差 354 | ob.bz_zty = ""; // 真太阳时置空串 355 | ob.bz_pty = JD.timeStr(jd); // 计算平太阳时 356 | 357 | jd += 13d / 24d; // 转为前一日23点起算(原jd为本日中午12点起算) // C#: 注意数据类型 358 | double D = Math.Floor(jd), SC = LunarHelper.int2((jd - D) * 12); // 日数与时辰 359 | 360 | v = LunarHelper.int2(k / 12 + 6000000); ob.bz_jn = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 361 | v = k + 2 + 60000000; ob.bz_jy = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 362 | 363 | // C#: 新增的代码段, 计算南半球八字(仅纪月不同) 364 | switch (baziTypeS) 365 | { 366 | case BaZiTypeS.TianChongDiChong: 367 | ob.bz_jy = obb.Gan[(int)((v + 4) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 368 | break; 369 | 370 | case BaZiTypeS.TianKeDiChong: 371 | ob.bz_jy = obb.Gan[(int)((v + 6) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 372 | break; 373 | 374 | case BaZiTypeS.TianTongDiChong: 375 | ob.bz_jy = obb.Gan[(int)((v + 0) % 10)] + obb.Zhi[(int)((v + 6) % 12)]; 376 | break; 377 | 378 | default: 379 | break; 380 | } 381 | 382 | 383 | v = D - 6 + 9000000; ob.bz_jr = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 384 | v = (D - 1) * 12 + 90000000 + SC; ob.bz_js = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)]; 385 | 386 | v -= SC; 387 | ob.bz_JS = ""; // 全天纪时表 388 | for (i = 0; i < 13; i++) 389 | { 390 | // 一天中包含有13个纪时 391 | c = obb.Gan[(int)((v + i) % 10)] + obb.Zhi[(int)((v + i) % 12)]; // 各时辰的八字 392 | if (SC == i) 393 | { 394 | ob.bz_js = c; 395 | // c = "" + c + ""; //红色显示这时辰 // C#: 注释, 即取消格式显示 396 | } 397 | ob.bz_JS += (i != 0 ? " " : "") + c; 398 | } 399 | } 400 | 401 | 402 | /// 403 | /// 从 Xml 对象中读取农历节日的定义 404 | /// 405 | /// 406 | private static xList getLunarFeasts() 407 | { 408 | const string xPath = "SharpSxwnl/SxwnlData/Data[@Id = 'obb_getDayName']"; 409 | xList result = new xList(); 410 | 411 | if (LunarHelper.SxwnlXmlData != null) 412 | { 413 | XmlNodeList foundNodeList = LunarHelper.SxwnlXmlData.SelectNodes(xPath); 414 | if (foundNodeList.Count > 0) 415 | { 416 | for (int i = 0; i < foundNodeList.Count; i++) 417 | for (int j = 0; j < foundNodeList[i].ChildNodes.Count; j++) 418 | { 419 | result.Add(new OB()); // 添加日对象来记录节点信息 420 | XmlAttributeCollection xmlAttr = foundNodeList[i].ChildNodes[j].Attributes; 421 | result[result.Count - 1].Lmc = xmlAttr.GetNamedItem("Day").InnerText; 422 | result[result.Count - 1].A = xmlAttr.GetNamedItem("A").InnerText; 423 | result[result.Count - 1].B = xmlAttr.GetNamedItem("B").InnerText; 424 | result[result.Count - 1].C = xmlAttr.GetNamedItem("C").InnerText; 425 | result[result.Count - 1].Fjia = LunarHelper.VAL(xmlAttr.GetNamedItem("Fjia").InnerText) == 0 ? 0 : 1; 426 | } 427 | } 428 | 429 | } 430 | 431 | return result; 432 | } 433 | 434 | 435 | /// 436 | /// 从 Xml 对象中读取农历节日的定义 437 | /// 438 | /// 439 | private static xList getJieQiFeasts() 440 | { 441 | const string xPath = "SharpSxwnl/SxwnlData/Data[@Id = 'obb_JieqiFjia']"; 442 | xList result = new xList(); 443 | 444 | if (LunarHelper.SxwnlXmlData != null) 445 | { 446 | XmlNode foundNode; 447 | Regex regexToTrim = new Regex(@"\s*"); // C#: 匹配任何空白字符, 用于去除所有空白字符 448 | 449 | // 读取并解开历史纪年表 450 | foundNode = LunarHelper.SxwnlXmlData.SelectSingleNode(xPath); 451 | if (foundNode != null) 452 | { 453 | string[] jieqiFeasts = regexToTrim.Replace(foundNode.InnerText, "").Split(','); 454 | result.AddRange(jieqiFeasts); 455 | } 456 | 457 | } 458 | 459 | return result; 460 | } 461 | 462 | #endregion 转换时新增的方法 463 | 464 | 465 | 466 | #region 转换时增加的私有字段(用于封装成公共属性, 按转换规范 10 命名) 467 | 468 | // 数字 0 - 10 对应的中文名称 469 | private static string[] __numCn = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" }; //中文数字 470 | 471 | // 十天干表 472 | private static string[] __Gan = new string[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" }; 473 | 474 | // 十二地支表 475 | private static string[] __Zhi = new string[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" }; 476 | 477 | // 十二属相表 478 | private static string[] __ShX = new string[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" }; 479 | 480 | // 十二星座表 481 | private static string[] __XiZ = new string[] { "摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手" }; 482 | 483 | // 月相名称表 484 | private static string[] __yxmc = new string[] { "朔", "上弦", "望", "下弦" }; //月相名称表 485 | 486 | // 廿四节气表 487 | private static string[] __jqmc = new string[] { "冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪" }; 488 | 489 | // 农历各月的名称, 从 "十一" 月开始, 即从月建 "子" 开始, 与十二地支的顺序对应 490 | private static string[] __ymc = new string[] { "十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十" }; //月名称,建寅 491 | 492 | // 农历各日的名称 493 | private static string[] __rmc = new string[] { "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一" }; 494 | 495 | // 历史纪年表 496 | private static JnbArrayList __JNB = new JnbArrayList(); 497 | 498 | // 廿四节气对应的月建表, 与 __jqmc 对应 499 | private static string[] __JieQiYueJian = new string[] { "子", "丑", "丑", "寅", "寅", "卯", "卯", "辰", "辰", "巳", "巳", "午", "午", "未", "未", "申", "申", "酉", "酉", "戌", "戌", "亥", "亥", "子" }; 500 | 501 | // 日十二建表 502 | private static string[] __RiJian12 = new string[] { "建", "除", "满", "平", "定", "执", "破", "危", "成", "收", "开", "闭" }; 503 | 504 | // 双重日十二建表 505 | private static string[] __DoubleRiJian12 = new string[] { "建", "除", "满", "平", "定", "执", "破", "危", "成", "收", "开", "闭", 506 | "建", "除", "满", "平", "定", "执", "破", "危", "成", "收", "开", "闭" }; 507 | // 双重十二地支表 508 | private static string[] __DoubleZhi = new string[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥", 509 | "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" }; 510 | // 农历节日的定义 511 | private static xList __LunarFeasts = obb.getLunarFeasts(); 512 | 513 | // 二十四节气假日的定义 514 | private static xList __JieQiFeasts = obb.getJieQiFeasts(); 515 | 516 | #endregion 517 | 518 | 519 | 520 | #region 转换时新增的公共属性 521 | 522 | /// 523 | /// 廿四节气对应的月建表, 与 jqmc 属性对应, 因此"气"的月建使用节的月建 524 | /// 525 | public static string[] JieQiYueJian 526 | { 527 | get { return obb.__JieQiYueJian; } 528 | set { obb.__JieQiYueJian = value; } 529 | } 530 | 531 | /// 532 | /// 日十二建表 533 | /// 534 | public static string[] RiJian12 535 | { 536 | get { return obb.__RiJian12; } 537 | set { obb.__RiJian12 = value; } 538 | } 539 | 540 | /// 541 | /// 双重日十二建表 542 | /// 543 | public static string[] DoubleRiJian12 544 | { 545 | get { return obb.__DoubleRiJian12; } 546 | set { obb.__DoubleRiJian12 = value; } 547 | } 548 | 549 | /// 550 | /// 双重十二地支表 551 | /// 552 | public static string[] DoubleZhi 553 | { 554 | get { return obb.__DoubleZhi; } 555 | set { obb.__DoubleZhi = value; } 556 | } 557 | 558 | /// 559 | /// 农历节日的定义 560 | /// 561 | public static xList LunarFeasts 562 | { 563 | get { return obb.__LunarFeasts; } 564 | set { obb.__LunarFeasts = value; } 565 | } 566 | 567 | /// 568 | /// 二十四节气假日的定义 569 | /// 570 | public static xList JieQiFeasts 571 | { 572 | get { return obb.__JieQiFeasts; } 573 | set { obb.__JieQiFeasts = value; } 574 | } 575 | 576 | #endregion 577 | 578 | } 579 | } 580 | -------------------------------------------------------------------------------- /SharpSxwnl/sun_moon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// 太阳月亮计算类 9 | /// 10 | public class sun_moon 11 | { 12 | #region 构造函数 13 | 14 | public sun_moon() 15 | { 16 | } 17 | 18 | #endregion 19 | 20 | 21 | 22 | #region 公共属性(注: 初始转换时为公共字段, 已改写) 23 | 24 | #region 基本参数 25 | 26 | /// 27 | /// 力学时 28 | /// 29 | public double T { get; set; } // = 0; 30 | 31 | /// 32 | /// 站点经度 33 | /// 34 | public double L { get; set; } // = 0; 35 | 36 | /// 37 | /// 站点纬度 38 | /// 39 | public double fa { get; set; } // = 0; 40 | 41 | /// 42 | /// TD-UT 43 | /// 44 | public double dt { get; set; } // = 0; 45 | 46 | /// 47 | /// UT 48 | /// 49 | public double jd { get; set; } // = 0; 50 | 51 | /// 52 | /// 黄经章 53 | /// 54 | public double dL { get; set; } // = 0; 55 | 56 | /// 57 | /// 交角章动 58 | /// 59 | public double dE { get; set; } // = 0; 60 | 61 | /// 62 | /// 真黄赤交角 63 | /// 64 | public double E { get; set; } // = 0; 65 | 66 | /// 67 | /// 真恒星时(不考虑非多项式部分) 68 | /// 69 | public double gst { get; set; } // = 0; 70 | 71 | #endregion 基本参数 72 | 73 | 74 | 75 | #region 月球参数 76 | 77 | /// 78 | /// 月球视黄经 79 | /// 80 | public double mHJ { get; set; } // = 0; 81 | 82 | /// 83 | /// 月球视黄纬 84 | /// 85 | public double mHW { get; set; } // = 0; 86 | 87 | /// 88 | /// 地月质心距 89 | /// 90 | public double mR { get; set; } // = 0; 91 | 92 | /// 93 | /// 月球视赤经 94 | /// 95 | public double mCJ { get; set; } // = 0; 96 | 97 | /// 98 | /// 月球赤纬 99 | /// 100 | public double mCW { get; set; } // = 0; 101 | 102 | /// 103 | /// 此时的天体时角 104 | /// 105 | public double mShiJ { get; set; } // = 0; 106 | 107 | /// 108 | /// 修正了视差的赤道坐标: 月球视赤经 109 | /// 110 | public double mCJ2 { get; set; } // = 0; 111 | 112 | /// 113 | /// 修正了视差的赤道坐标: 月球赤纬 114 | /// 115 | public double mCW2 { get; set; } // = 0; 116 | 117 | /// 118 | /// 修正了视差的赤道坐标: 地月质心距 119 | /// 120 | public double mR2 { get; set; } // = 0; 121 | 122 | /// 123 | /// 方位角 124 | /// 125 | public double mDJ { get; set; } // = 0; 126 | 127 | /// 128 | /// 高度角 129 | /// 130 | public double mDW { get; set; } // = 0; 131 | 132 | /// 133 | /// 方位角(大气折射修正后) 134 | /// 135 | public double mPJ { get; set; } // = 0; 136 | 137 | /// 138 | /// 高度角(大气折射修正后) 139 | /// 140 | public double mPW { get; set; } // = 0; 141 | 142 | #endregion 143 | 144 | 145 | 146 | #region 太阳参数 147 | 148 | /// 149 | /// 太阳视黄经 150 | /// 151 | public double sHJ { get; set; } // = 0; 152 | 153 | /// 154 | /// 太阳视黄纬 155 | /// 156 | public double sHW { get; set; } // = 0; 157 | 158 | /// 159 | /// 日地质心距 160 | /// 161 | public double sR { get; set; } // = 0; 162 | 163 | /// 164 | /// 太阳视赤经 165 | /// 166 | public double sCJ { get; set; } // = 0; 167 | 168 | /// 169 | /// 太阳视赤纬 170 | /// 171 | public double sCW { get; set; } // = 0; 172 | 173 | /// 174 | /// 太阳时角 175 | /// 176 | public double sShiJ { get; set; } // = 0; 177 | 178 | /// 179 | /// 修正了视差的赤道坐标: 太阳视赤经 180 | /// 181 | public double sCJ2 { get; set; } // = 0; 182 | 183 | /// 184 | /// 修正了视差的赤道坐标: 太阳视赤纬 185 | /// 186 | public double sCW2 { get; set; } // = 0; 187 | 188 | /// 189 | /// 修正了视差的赤道坐标: 日地质心距 190 | /// 191 | public double sR2 { get; set; } // = 0; 192 | 193 | /// 194 | /// 方位角 195 | /// 196 | public double sDJ { get; set; } // = 0; 197 | 198 | /// 199 | /// 高度角 200 | /// 201 | public double sDW { get; set; } // = 0; 202 | 203 | /// 204 | /// 方位角(大气折射修正后) 205 | /// 206 | public double sPJ { get; set; } // = 0; 207 | 208 | /// 209 | /// 高度角(大气折射修正后) 210 | /// 211 | public double sPW { get; set; } // = 0; 212 | 213 | #endregion 214 | 215 | 216 | 217 | #region 其他参数 218 | 219 | /// 220 | /// 时差(单位:日) 221 | /// 222 | public double sc { get; set; } // = 0; 223 | 224 | /// 225 | /// 平太阳时 226 | /// 227 | public double pty { get; set; } // = 0; 228 | 229 | /// 230 | /// 真太阳时 231 | /// 232 | public double zty { get; set; } // = 0; 233 | 234 | /// 235 | /// 月亮视半径(角秒) 236 | /// 237 | public double mRad { get; set; } // = 0; 238 | 239 | /// 240 | /// 太阳视半径(角秒) 241 | /// 242 | public double sRad { get; set; } // = 0; 243 | 244 | /// 245 | /// 月亮地心视半径(角秒) 246 | /// 247 | public double e_mRad { get; set; } // = 0; 248 | 249 | /// 250 | /// 地本影在月球向径处的半径(角秒) 251 | /// 252 | public double eShadow { get; set; } // = 0; 253 | 254 | /// 255 | /// 地本影在月球向径处的半径(角秒) 256 | /// 257 | public double eShadow2 { get; set; } // = 0; 258 | 259 | /// 260 | /// 月亮被照面比例 261 | /// 262 | public double mIll { get; set; } // = 0; 263 | 264 | /// 265 | /// 中心食计算: 经 266 | /// 267 | public double zx_J { get; set; } // = 0; 268 | 269 | /// 270 | /// 中心食计算: 纬 271 | /// 272 | public double zx_W { get; set; } // = 0; 273 | 274 | #endregion 275 | 276 | #endregion 公共属性 277 | 278 | 279 | 280 | 281 | #region 公共方法 282 | /// 283 | /// 计算 sun_moon 类的成员。参数:T是力学时,站点经度L,纬度fa,海拔high(千米) 284 | /// 285 | /// 力学时 286 | /// 站点经度 287 | /// 站点纬度 288 | /// 海拔 289 | public void calc(double T, double L, double fa, double high) 290 | { 291 | //基本参数计算 292 | this.T = T; 293 | this.L = L; this.fa = fa; 294 | this.dt = JD.deltatT2(T); //TD-UT 295 | this.jd = T - this.dt; //UT 296 | T /= 36525; ZB.nutation(T); 297 | this.dL = ZB.dL; //黄经章 298 | this.dE = ZB.dE; //交角章动 299 | this.E = ZB.hcjj(T) + this.dE; //真黄赤交角 300 | this.gst = ZB.gst(this.jd, this.dt) + this.dL * Math.Cos(this.E); //真恒星时(不考虑非多项式部分) 301 | double[] z = new double[4]; 302 | 303 | //=======月亮======== 304 | //月亮黄道坐标 305 | XL.M_coord(T, z, -1, -1, -1); //月球坐标 306 | z[0] = LunarHelper.rad2mrad(z[0] + ZB.gxc_moonLon(T) + this.dL); z[1] += ZB.gxc_moonLat(T); //补上月球光行差及章动 307 | this.mHJ = z[0]; this.mHW = z[1]; this.mR = z[2]; //月球视黄经,视黄纬,地月质心距 308 | 309 | //月球赤道坐标 310 | ZB.llrConv(z, this.E); //转为赤道坐标 311 | this.mCJ = z[0]; this.mCW = z[1]; //月球视赤经,月球赤纬 312 | 313 | //月亮时角计算 314 | this.mShiJ = LunarHelper.rad2mrad(this.gst - L - z[0]); //得到此刻天体时角 315 | if (this.mShiJ > Math.PI) this.mShiJ -= LunarHelper.pi2; 316 | 317 | //修正了视差的赤道坐标 318 | ZB.parallax(z, this.mShiJ, fa, high); //视差修正 319 | this.mCJ2 = z[0]; this.mCW2 = z[1]; this.mR2 = z[2]; 320 | 321 | //月亮时角坐标 322 | z[0] += Math.PI / 2d - this.gst + L; //转到相对于地平赤道分点的赤道坐标(时角坐标) 323 | 324 | //月亮地平坐标 325 | ZB.llrConv(z, Math.PI / 2 - fa); //转到地平坐标(只改经纬度) 326 | z[0] = LunarHelper.rad2mrad(Math.PI / 2 - z[0]); 327 | this.mDJ = z[0]; this.mDW = z[1]; //方位角,高度角 328 | if (z[1] > 0) z[1] += ZB.AR2(z[1]); //大气折射修正 329 | this.mPJ = z[0]; this.mPW = z[1]; //方位角,高度角 330 | 331 | //=======太阳======== 332 | //太阳黄道坐标 333 | XL.E_coord(T, z, -1, -1, -1); //地球坐标 334 | z[0] = LunarHelper.rad2mrad(z[0] + Math.PI + ZB.gxc_sunLon(T) + this.dL); //补上太阳光行差及章动 335 | z[1] = -z[1] + ZB.gxc_sunLat(T); //z数组为太阳地心黄道视坐标 336 | this.sHJ = z[0]; this.sHW = z[1]; this.sR = z[2]; //太阳视黄经,视黄纬,日地质心距 337 | 338 | //太阳赤道坐标 339 | ZB.llrConv(z, this.E); //转为赤道坐标 340 | this.sCJ = z[0]; this.sCW = z[1]; //太阳视赤经,视赤纬 341 | 342 | //太阳时角计算 343 | this.sShiJ = LunarHelper.rad2mrad(this.gst - L - z[0]); //得到此刻天体时角 344 | if (this.sShiJ > Math.PI) this.sShiJ -= LunarHelper.pi2; 345 | 346 | //修正了视差的赤道坐标 347 | ZB.parallax(z, this.sShiJ, fa, high); //视差修正 348 | this.sCJ2 = z[0]; this.sCW2 = z[1]; this.sR2 = z[2]; 349 | 350 | //太阳时角坐标 351 | z[0] += Math.PI / 2 - this.gst + L; //转到相对于地平赤道分点的赤道坐标 352 | 353 | //太阳地平坐标 354 | ZB.llrConv(z, Math.PI / 2 - fa); 355 | z[0] = LunarHelper.rad2mrad(Math.PI / 2 - z[0]); 356 | //z[1] -= 8.794/rad/z[2]*Math.cos(z[1]); //直接在地平坐标中视差修正(这里把地球看为球形,精度比ZB.parallax()稍差一些) 357 | this.sDJ = z[0]; this.sDW = z[1]; //方位角,高度角 358 | 359 | if (z[1] > 0) z[1] += ZB.AR2(z[1]); //大气折射修正 360 | this.sPJ = z[0]; this.sPW = z[1]; //方位角,高度角 361 | 362 | //=======其它======== 363 | //时差计算 364 | double t = T / 10; double t2 = t * t, t3 = t2 * t, t4 = t3 * t, t5 = t4 * t; 365 | double Lon = (1753469512 + 6283319653318 * t + 529674 * t2 + 432 * t3 - 1124 * t4 - 9 * t5 + 630 * Math.Cos(6 + 3 * t)) / 1000000000 + Math.PI - 20.5 / LunarHelper.rad; //修正了光行差的太阳平黄经 366 | Lon = LunarHelper.rad2mrad(Lon - (this.sCJ - this.dL * Math.Cos(this.E))); //(修正了光行差的平黄经)-(不含dL*cos(E)的视赤经) 367 | if (Lon > Math.PI) Lon -= LunarHelper.pi2; //得到时差,单位是弧度 368 | this.sc = Lon / LunarHelper.pi2; //时差(单位:日) 369 | 370 | //真太阳与平太阳 371 | this.pty = this.jd - L / LunarHelper.pi2; //平太阳时 372 | this.zty = this.jd - L / LunarHelper.pi2 + this.sc; //真太阳时 373 | 374 | //视半径 375 | //this.mRad = XL.moonRad(this.mR,this.mDW); //月亮视半径(角秒) 376 | this.mRad = 358473400d / this.mR2; //月亮视半径(角秒) 377 | this.sRad = 959.63 / this.sR2; //太阳视半径(角秒) 378 | this.e_mRad = 358473400d / this.mR; //月亮地心视半径(角秒) 379 | this.eShadow = (LunarHelper.cs_rEarA / this.mR * LunarHelper.rad - (959.63 - 8.794) / this.sR) * 51 / 50; //地本影在月球向径处的半径(角秒),式中51/50是大气厚度补偿 380 | this.eShadow2 = (LunarHelper.cs_rEarA / this.mR * LunarHelper.rad + (959.63 + 8.794) / this.sR) * 51 / 50; //地半影在月球向径处的半径(角秒),式中51/50是大气厚度补偿 381 | this.mIll = XL.moonIll(T); //月亮被照面比例 382 | 383 | //中心食计算 384 | if (Math.Abs(LunarHelper.rad2rrad(this.mCJ - this.sCJ)) < 50 / 180 * Math.PI) 385 | { 386 | ZB.line_earth(this.mCJ, this.mCW, this.mR, this.sCJ, this.sCW, this.sR * LunarHelper.cs_AU); 387 | this.zx_J = LunarHelper.rad2rrad(this.gst - ZB.le_J); 388 | this.zx_W = ZB.le_W; //无解返回值是100 389 | } 390 | else this.zx_J = this.zx_W = 100; 391 | } 392 | 393 | 394 | /// 395 | /// 把太阳月亮信息形成 HTML 字符串 396 | /// 397 | /// 是否显示ΔT, 黄经章等信息 398 | /// 399 | public string toHTML(double fs) 400 | { 401 | StringBuilder sb = new StringBuilder(); 402 | sb.Append(""); 403 | 404 | sb.Append(""); 408 | 409 | sb.Append(""); 416 | 417 | sb.Append(""); 423 | 424 | if (fs != 0) 425 | { 426 | sb.Append(""); 433 | } 434 | sb.Append("
"); 405 | sb.Append("平太阳 " + JD.timeStr(this.pty) + " 真太阳 " + JD.timeStr(this.zty) + "
"); 406 | sb.Append("时差 " + LunarHelper.m2fm(this.sc * 86400, 2, 1) + " 月亮被照亮 " + (this.mIll * 100).ToString("F2") + "% "); 407 | sb.Append("
表一       月亮            太阳\r\n");
410 |             sb.Append("视黄经 " + LunarHelper.rad2str(this.mHJ, 0) + "  " + LunarHelper.rad2str(this.sHJ, 0) + "\r\n");
411 |             sb.Append("视黄纬 " + LunarHelper.rad2str(this.mHW, 0) + "  " + LunarHelper.rad2str(this.sHW, 0) + "\r\n");
412 |             sb.Append("视赤经 " + LunarHelper.rad2str(this.mCJ, 1) + "  " + LunarHelper.rad2str(this.sCJ, 1) + "\r\n");
413 |             sb.Append("视赤纬 " + LunarHelper.rad2str(this.mCW, 0) + "  " + LunarHelper.rad2str(this.sCW, 0) + "\r\n");
414 |             sb.Append("距离     " + this.mR.ToString("F0") + "千米          " + this.sR.ToString("F6") + "AU" + "\r\n");
415 |             sb.Append("
表二       月亮            太阳\r\n");
418 |             sb.Append("方位角 " + LunarHelper.rad2str(this.mPJ, 0) + "  " + LunarHelper.rad2str(this.sPJ, 0) + "\r\n");
419 |             sb.Append("高度角 " + LunarHelper.rad2str(this.mPW, 0) + "  " + LunarHelper.rad2str(this.sPW, 0) + "\r\n");
420 |             sb.Append("时角   " + LunarHelper.rad2str(this.mShiJ, 0) + "  " + LunarHelper.rad2str(this.sShiJ, 0) + "\r\n");
421 |             sb.Append("视半径(观测点) " + LunarHelper.m2fm(this.mRad, 2, 0) + "     " + LunarHelper.m2fm(this.sRad, 2, 0) + "\r\n");
422 |             sb.Append("
"); 427 | sb.Append("力学时 " + JD.setFromJD_str(this.T + LunarHelper.J2000)); 428 | sb.Append(" ΔT=" + (this.dt * 86400).ToString("F1") + "秒
"); 429 | sb.Append("黄经章 " + (this.dL / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" "); 430 | sb.Append("交角章 " + (this.dE / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" "); 431 | sb.Append("ε=" + LunarHelper.trim(LunarHelper.rad2str(this.E, 0))); 432 | sb.Append("
"); 435 | return sb.ToString(); 436 | } 437 | 438 | #endregion 公共方法 439 | 440 | 441 | 442 | #region 转换时新增的方法 443 | 444 | /// 445 | /// 把太阳月亮信息形成纯文本字符串 446 | /// 447 | /// 是否显示ΔT, 黄经章等信息 448 | /// 449 | public string toText(double fs) 450 | { 451 | StringBuilder sb = new StringBuilder(); 452 | sb.Append("平太阳 " + JD.timeStr(this.pty) + " 真太阳 " + JD.timeStr(this.zty) + "\r\n"); 453 | sb.Append("时差 " + LunarHelper.m2fm(this.sc * 86400, 2, 1) + " 月亮被照亮 " + (this.mIll * 100).ToString("F2") + "% "); 454 | sb.Append("\r\n"); 455 | 456 | sb.Append("\r\n表一 月亮 太阳\r\n"); 457 | sb.Append("视黄经 " + LunarHelper.rad2str(this.mHJ, 0) + " " + LunarHelper.rad2str(this.sHJ, 0) + "\r\n"); 458 | sb.Append("视黄纬 " + LunarHelper.rad2str(this.mHW, 0) + " " + LunarHelper.rad2str(this.sHW, 0) + "\r\n"); 459 | sb.Append("视赤经 " + LunarHelper.rad2str(this.mCJ, 1) + " " + LunarHelper.rad2str(this.sCJ, 1) + "\r\n"); 460 | sb.Append("视赤纬 " + LunarHelper.rad2str(this.mCW, 0) + " " + LunarHelper.rad2str(this.sCW, 0) + "\r\n"); 461 | sb.Append("距离 " + this.mR.ToString("F0") + "千米 " + this.sR.ToString("F6") + "AU" + "\r\n"); 462 | 463 | sb.Append("\r\n表二 月亮 太阳\r\n"); 464 | sb.Append("方位角 " + LunarHelper.rad2str(this.mPJ, 0) + " " + LunarHelper.rad2str(this.sPJ, 0) + "\r\n"); 465 | sb.Append("高度角 " + LunarHelper.rad2str(this.mPW, 0) + " " + LunarHelper.rad2str(this.sPW, 0) + "\r\n"); 466 | sb.Append("时角 " + LunarHelper.rad2str(this.mShiJ, 0) + " " + LunarHelper.rad2str(this.sShiJ, 0) + "\r\n"); 467 | sb.Append("视半径(观测点) " + LunarHelper.m2fm(this.mRad, 2, 0) + " " + LunarHelper.m2fm(this.sRad, 2, 0) + "\r\n"); 468 | 469 | if (fs != 0) 470 | { 471 | sb.Append("\r\n力学时 " + JD.setFromJD_str(this.T + LunarHelper.J2000)); 472 | sb.Append(" ΔT=" + (this.dt * 86400).ToString("F1") + "秒\r\n"); 473 | sb.Append("黄经章 " + (this.dL / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" "); 474 | sb.Append("交角章 " + (this.dE / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" "); 475 | sb.Append("\r\nε=" + LunarHelper.trim(LunarHelper.rad2str(this.E, 0))); 476 | } 477 | return sb.ToString(); 478 | } 479 | 480 | #endregion 481 | } 482 | } 483 | -------------------------------------------------------------------------------- /SharpSxwnl/xList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SharpSxwnl 6 | { 7 | /// 8 | /// List<T> 的派生类 9 | /// 10 | /// 11 | public class xList : List 12 | { 13 | #region 公共属性 14 | 15 | /// 16 | /// 值等于 Count 属性(只读) 17 | /// 18 | public int Length { get { return this.Count; } } 19 | 20 | #endregion 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | 5 | namespace TestSharpSxwnl 6 | { 7 | static class Program 8 | { 9 | /// 10 | /// 应用程序的主入口点。 11 | /// 12 | [STAThread] 13 | static void Main() 14 | { 15 | Application.EnableVisualStyles(); 16 | Application.SetCompatibleTextRenderingDefault(false); 17 | Application.Run(new frmMainTest()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列属性集 6 | // 控制。更改这些属性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("TestSharpSxwnl")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TestSharpSxwnl")] 13 | [assembly: AssemblyCopyright("Copyright © 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 属性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("a9d2296d-8a7a-4288-ab40-5e4c5d70c559")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TestSharpSxwnl.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestSharpSxwnl.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TestSharpSxwnl.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TestSharpSxwnl/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TestSharpSxwnl/TestSharpSxwnl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {437A253A-DB9C-43A5-AC32-81AB24C7F053} 9 | WinExe 10 | Properties 11 | TestSharpSxwnl 12 | TestSharpSxwnl 13 | v2.0 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | ..\SharpSxwnl\bin\Debug\SharpSxwnl.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Form 53 | 54 | 55 | frmMethodsTest.cs 56 | 57 | 58 | Form 59 | 60 | 61 | frmMainTest.cs 62 | 63 | 64 | 65 | 66 | frmMainTest.cs 67 | 68 | 69 | frmMethodsTest.cs 70 | 71 | 72 | ResXFileCodeGenerator 73 | Resources.Designer.cs 74 | Designer 75 | 76 | 77 | True 78 | Resources.resx 79 | True 80 | 81 | 82 | SettingsSingleFileGenerator 83 | Settings.Designer.cs 84 | 85 | 86 | True 87 | Settings.settings 88 | True 89 | 90 | 91 | 92 | 93 | 94 | 95 | 102 | -------------------------------------------------------------------------------- /TestSharpSxwnl/frmMainTest.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 39 125 | 126 | -------------------------------------------------------------------------------- /TestSharpSxwnl/frmMethodsTest.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace TestSharpSxwnl 2 | { 3 | partial class frmMethodsTest 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.label3 = new System.Windows.Forms.Label(); 34 | this.label4 = new System.Windows.Forms.Label(); 35 | this.label5 = new System.Windows.Forms.Label(); 36 | this.label6 = new System.Windows.Forms.Label(); 37 | this.label7 = new System.Windows.Forms.Label(); 38 | this.label8 = new System.Windows.Forms.Label(); 39 | this.label9 = new System.Windows.Forms.Label(); 40 | this.label10 = new System.Windows.Forms.Label(); 41 | this.labelLunarHelper = new System.Windows.Forms.Label(); 42 | this.labelJWdata = new System.Windows.Forms.Label(); 43 | this.label11 = new System.Windows.Forms.Label(); 44 | this.label12 = new System.Windows.Forms.Label(); 45 | this.label13 = new System.Windows.Forms.Label(); 46 | this.label14 = new System.Windows.Forms.Label(); 47 | this.label15 = new System.Windows.Forms.Label(); 48 | this.label16 = new System.Windows.Forms.Label(); 49 | this.SuspendLayout(); 50 | // 51 | // label1 52 | // 53 | this.label1.AutoSize = true; 54 | this.label1.Cursor = System.Windows.Forms.Cursors.Hand; 55 | this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 56 | this.label1.Location = new System.Drawing.Point(49, 28); 57 | this.label1.Name = "label1"; 58 | this.label1.Size = new System.Drawing.Size(179, 12); 59 | this.label1.TabIndex = 1; 60 | this.label1.Text = "\"*\" + trim(\"\\t 123 \\r\") + \"*\""; 61 | this.label1.Click += new System.EventHandler(this.label1_Click); 62 | // 63 | // label2 64 | // 65 | this.label2.AutoSize = true; 66 | this.label2.Cursor = System.Windows.Forms.Cursors.Hand; 67 | this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 68 | this.label2.Location = new System.Drawing.Point(49, 49); 69 | this.label2.Name = "label2"; 70 | this.label2.Size = new System.Drawing.Size(563, 12); 71 | this.label2.TabIndex = 2; 72 | this.label2.Text = "year2Ayear(-1), year2Ayear(\"B2009\"), year2Ayear(10000), year2Ayear(\"*4713\"), year" + 73 | "2Ayear(\"B0\")"; 74 | this.label2.Click += new System.EventHandler(this.label2_Click); 75 | // 76 | // label3 77 | // 78 | this.label3.AutoSize = true; 79 | this.label3.Cursor = System.Windows.Forms.Cursors.Hand; 80 | this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 81 | this.label3.Location = new System.Drawing.Point(49, 71); 82 | this.label3.Name = "label3"; 83 | this.label3.Size = new System.Drawing.Size(311, 12); 84 | this.label3.TabIndex = 3; 85 | this.label3.Text = "Ayear2year(\"-1\"), Ayear2year(\"0\"), Ayear2year(2009)"; 86 | this.label3.Click += new System.EventHandler(this.label3_Click); 87 | // 88 | // label4 89 | // 90 | this.label4.AutoSize = true; 91 | this.label4.Cursor = System.Windows.Forms.Cursors.Hand; 92 | this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 93 | this.label4.Location = new System.Drawing.Point(49, 92); 94 | this.label4.Name = "label4"; 95 | this.label4.Size = new System.Drawing.Size(407, 12); 96 | this.label4.TabIndex = 4; 97 | this.label4.Text = "timeStr2hour(\"12\"), timeStr2hour(\"12:30\"), timeStr2hour(\"12:30:36\")"; 98 | this.label4.Click += new System.EventHandler(this.label4_Click); 99 | // 100 | // label5 101 | // 102 | this.label5.AutoSize = true; 103 | this.label5.Cursor = System.Windows.Forms.Cursors.Hand; 104 | this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 105 | this.label5.Location = new System.Drawing.Point(49, 114); 106 | this.label5.Name = "label5"; 107 | this.label5.Size = new System.Drawing.Size(563, 12); 108 | this.label5.TabIndex = 5; 109 | this.label5.Text = "rad2str(3.14, 0), rad2str(-3.14, 1), str2rad(\"+179°54\'31.49\\\"\"), str2rad(\"-179°54" + 110 | "\'31.49\\\"\")\r\n"; 111 | this.label5.Click += new System.EventHandler(this.label5_Click); 112 | // 113 | // label6 114 | // 115 | this.label6.AutoSize = true; 116 | this.label6.Cursor = System.Windows.Forms.Cursors.Hand; 117 | this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 118 | this.label6.Location = new System.Drawing.Point(49, 143); 119 | this.label6.Name = "label6"; 120 | this.label6.Size = new System.Drawing.Size(191, 12); 121 | this.label6.TabIndex = 6; 122 | this.label6.Text = "rad2str2(3.14), rad2str2(-3.14)"; 123 | this.label6.Click += new System.EventHandler(this.label6_Click); 124 | // 125 | // label7 126 | // 127 | this.label7.AutoSize = true; 128 | this.label7.Cursor = System.Windows.Forms.Cursors.Hand; 129 | this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 130 | this.label7.Location = new System.Drawing.Point(49, 164); 131 | this.label7.Name = "label7"; 132 | this.label7.Size = new System.Drawing.Size(197, 12); 133 | this.label7.TabIndex = 7; 134 | this.label7.Text = "m2fm(121, 2, 0), m2fm(121, 0, 1)"; 135 | this.label7.Click += new System.EventHandler(this.label7_Click); 136 | // 137 | // label8 138 | // 139 | this.label8.AutoSize = true; 140 | this.label8.Cursor = System.Windows.Forms.Cursors.Hand; 141 | this.label8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 142 | this.label8.Location = new System.Drawing.Point(49, 185); 143 | this.label8.Name = "label8"; 144 | this.label8.Size = new System.Drawing.Size(623, 12); 145 | this.label8.TabIndex = 8; 146 | this.label8.Text = "rad2mrad(0), rad2mrad(Math.PI / 2), rad2mrad(Math.PI * 2), rad2mrad(Math.PI * 3)," + 147 | " rad2mrad(Math.PI * 4)"; 148 | this.label8.Click += new System.EventHandler(this.label8_Click); 149 | // 150 | // label9 151 | // 152 | this.label9.AutoSize = true; 153 | this.label9.Cursor = System.Windows.Forms.Cursors.Hand; 154 | this.label9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 155 | this.label9.Location = new System.Drawing.Point(49, 206); 156 | this.label9.Name = "label9"; 157 | this.label9.Size = new System.Drawing.Size(683, 12); 158 | this.label9.TabIndex = 9; 159 | this.label9.Text = "rad2rrad(0), rad2rrad(-PI/2), rad2rrad(PI), rad2rrad(-PI), rad2rrad(PI * 2), rad2" + 160 | "rrad(-PI * 2), rad2rrad(-PI * 3)"; 161 | this.label9.Click += new System.EventHandler(this.label9_Click); 162 | // 163 | // label10 164 | // 165 | this.label10.AutoSize = true; 166 | this.label10.Cursor = System.Windows.Forms.Cursors.Hand; 167 | this.label10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 168 | this.label10.Location = new System.Drawing.Point(49, 227); 169 | this.label10.Name = "label10"; 170 | this.label10.Size = new System.Drawing.Size(329, 12); 171 | this.label10.TabIndex = 10; 172 | this.label10.Text = "mod2(1, 2), mod2(1.2, 2.2), mod2(2, 1), mod2(2.2, 1.2)"; 173 | this.label10.Click += new System.EventHandler(this.label10_Click); 174 | // 175 | // labelLunarHelper 176 | // 177 | this.labelLunarHelper.AutoSize = true; 178 | this.labelLunarHelper.Location = new System.Drawing.Point(12, 9); 179 | this.labelLunarHelper.Name = "labelLunarHelper"; 180 | this.labelLunarHelper.Size = new System.Drawing.Size(95, 12); 181 | this.labelLunarHelper.TabIndex = 11; 182 | this.labelLunarHelper.Text = "LunarHelper 类:"; 183 | // 184 | // labelJWdata 185 | // 186 | this.labelJWdata.AutoSize = true; 187 | this.labelJWdata.Location = new System.Drawing.Point(12, 384); 188 | this.labelJWdata.Name = "labelJWdata"; 189 | this.labelJWdata.Size = new System.Drawing.Size(65, 12); 190 | this.labelJWdata.TabIndex = 12; 191 | this.labelJWdata.Text = "JWdata 类:"; 192 | // 193 | // label11 194 | // 195 | this.label11.AutoSize = true; 196 | this.label11.Cursor = System.Windows.Forms.Cursors.Hand; 197 | this.label11.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 198 | this.label11.Location = new System.Drawing.Point(49, 405); 199 | this.label11.Name = "label11"; 200 | this.label11.Size = new System.Drawing.Size(125, 12); 201 | this.label11.TabIndex = 13; 202 | this.label11.Text = "JWdecode(\"P3Tg昆明\")\r\n"; 203 | this.label11.Click += new System.EventHandler(this.label11_Click); 204 | // 205 | // label12 206 | // 207 | this.label12.AutoSize = true; 208 | this.label12.Cursor = System.Windows.Forms.Cursors.Hand; 209 | this.label12.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 210 | this.label12.Location = new System.Drawing.Point(49, 257); 211 | this.label12.Name = "label12"; 212 | this.label12.Size = new System.Drawing.Size(497, 12); 213 | this.label12.TabIndex = 14; 214 | this.label12.Text = "SUBSTRING(\"1\",0,2), SUBSTRING(\"1\",-1,2), SUBSTRING(\"1\",0,-1), SUBSTRING(\"abc\",1,2" + 215 | ")"; 216 | this.label12.Click += new System.EventHandler(this.label12_Click); 217 | // 218 | // label13 219 | // 220 | this.label13.AutoSize = true; 221 | this.label13.Cursor = System.Windows.Forms.Cursors.Hand; 222 | this.label13.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 223 | this.label13.Location = new System.Drawing.Point(49, 272); 224 | this.label13.Name = "label13"; 225 | this.label13.Size = new System.Drawing.Size(677, 12); 226 | this.label13.TabIndex = 15; 227 | this.label13.Text = "VAL(\"1\"), VAL(\"$1\"), VAL(\"$-1\"), VAL(\"-1E3\"), VAL(\"$1E-3\"), VAL(\"-123%\"), VAL(\"AB" + 228 | "C\"), VAL(\"123D\"), VAL(\"$+.E+%\")"; 229 | this.label13.Click += new System.EventHandler(this.label13_Click); 230 | // 231 | // label14 232 | // 233 | this.label14.AutoSize = true; 234 | this.label14.Cursor = System.Windows.Forms.Cursors.Hand; 235 | this.label14.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 236 | this.label14.Location = new System.Drawing.Point(49, 287); 237 | this.label14.Name = "label14"; 238 | this.label14.Size = new System.Drawing.Size(665, 12); 239 | this.label14.TabIndex = 16; 240 | this.label14.Text = "VAL(\"¥+1\"), VAL(\"¥+-1\"), VAL(\"¥-1.2\"), VAL(\"¥$\"), VAL(\"¥-.E-%\"), VAL(\"¥-12.3%\"), " + 241 | "VAL(\"A100\"), VAL(\"1.2\")"; 242 | this.label14.Click += new System.EventHandler(this.label14_Click); 243 | // 244 | // label15 245 | // 246 | this.label15.AutoSize = true; 247 | this.label15.Cursor = System.Windows.Forms.Cursors.Hand; 248 | this.label15.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 249 | this.label15.Location = new System.Drawing.Point(49, 303); 250 | this.label15.Name = "label15"; 251 | this.label15.Size = new System.Drawing.Size(701, 12); 252 | this.label15.TabIndex = 17; 253 | this.label15.Text = "VAL(\"001.88\"), VAL(\"001.88\", 1), VAL(\"001.88\", 1L), VAL(\".22\"), VAL(\".88.22\"), VA" + 254 | "L(\".22E2\"), VAL(\" 2\"), VAL(\"$ 2\")"; 255 | this.label15.Click += new System.EventHandler(this.label15_Click); 256 | // 257 | // label16 258 | // 259 | this.label16.AutoSize = true; 260 | this.label16.Cursor = System.Windows.Forms.Cursors.Hand; 261 | this.label16.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 262 | this.label16.Location = new System.Drawing.Point(49, 319); 263 | this.label16.Name = "label16"; 264 | this.label16.Size = new System.Drawing.Size(611, 12); 265 | this.label16.TabIndex = 18; 266 | this.label16.Text = "VAL(\"\"), VAL(\"E3\"), VAL(\"3E\"), VAL(\"3E+\"), VAL(\"3E-\"), VAL(\"3E2\"), VAL(\"3E.2\"), V" + 267 | "AL(\".E2\"), VAL(\"+1\")"; 268 | this.label16.Click += new System.EventHandler(this.label16_Click); 269 | // 270 | // frmMethodsTest 271 | // 272 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 273 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 274 | this.ClientSize = new System.Drawing.Size(769, 521); 275 | this.Controls.Add(this.label16); 276 | this.Controls.Add(this.label15); 277 | this.Controls.Add(this.label14); 278 | this.Controls.Add(this.label13); 279 | this.Controls.Add(this.label12); 280 | this.Controls.Add(this.label11); 281 | this.Controls.Add(this.labelJWdata); 282 | this.Controls.Add(this.labelLunarHelper); 283 | this.Controls.Add(this.label10); 284 | this.Controls.Add(this.label9); 285 | this.Controls.Add(this.label8); 286 | this.Controls.Add(this.label7); 287 | this.Controls.Add(this.label6); 288 | this.Controls.Add(this.label5); 289 | this.Controls.Add(this.label4); 290 | this.Controls.Add(this.label3); 291 | this.Controls.Add(this.label2); 292 | this.Controls.Add(this.label1); 293 | this.Name = "frmMethodsTest"; 294 | this.Text = "测试转换的方法"; 295 | this.ResumeLayout(false); 296 | this.PerformLayout(); 297 | 298 | } 299 | 300 | #endregion 301 | 302 | private System.Windows.Forms.Label label1; 303 | private System.Windows.Forms.Label label2; 304 | private System.Windows.Forms.Label label3; 305 | private System.Windows.Forms.Label label4; 306 | private System.Windows.Forms.Label label5; 307 | private System.Windows.Forms.Label label6; 308 | private System.Windows.Forms.Label label7; 309 | private System.Windows.Forms.Label label8; 310 | private System.Windows.Forms.Label label9; 311 | private System.Windows.Forms.Label label10; 312 | private System.Windows.Forms.Label labelLunarHelper; 313 | private System.Windows.Forms.Label labelJWdata; 314 | private System.Windows.Forms.Label label11; 315 | private System.Windows.Forms.Label label12; 316 | private System.Windows.Forms.Label label13; 317 | private System.Windows.Forms.Label label14; 318 | private System.Windows.Forms.Label label15; 319 | private System.Windows.Forms.Label label16; 320 | } 321 | } 322 | 323 | -------------------------------------------------------------------------------- /TestSharpSxwnl/frmMethodsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using SharpSxwnl; 9 | 10 | namespace TestSharpSxwnl 11 | { 12 | public partial class frmMethodsTest : Form 13 | { 14 | public frmMethodsTest() 15 | { 16 | InitializeComponent(); 17 | } 18 | 19 | private void label1_Click(object sender, EventArgs e) 20 | { 21 | MessageBox.Show("*" + LunarHelper.trim("\t 123 \r") + "*", "返回结果:"); 22 | } 23 | 24 | private void label2_Click(object sender, EventArgs e) 25 | { 26 | MessageBox.Show(LunarHelper.year2Ayear(-1) + "\r" + LunarHelper.year2Ayear("B2009") + "\r" + 27 | LunarHelper.year2Ayear(10000) + "\r" + LunarHelper.year2Ayear("-4713") + "\r" + 28 | LunarHelper.year2Ayear("B0"), "返回结果:"); 29 | } 30 | 31 | private void label3_Click(object sender, EventArgs e) 32 | { 33 | MessageBox.Show(LunarHelper.Ayear2year("-1") + "\r" + LunarHelper.Ayear2year("0") + "\r" + 34 | LunarHelper.Ayear2year(2009), "返回结果:"); 35 | } 36 | 37 | private void label4_Click(object sender, EventArgs e) 38 | { 39 | MessageBox.Show(LunarHelper.timeStr2hour("12") + "\r" + LunarHelper.timeStr2hour("12:30") + "\r" + 40 | LunarHelper.timeStr2hour("12:30:36"), "返回结果:"); 41 | } 42 | 43 | private void label5_Click(object sender, EventArgs e) 44 | { 45 | MessageBox.Show(LunarHelper.rad2str(3.14, 0) + "\r" + LunarHelper.rad2str(-3.14, 1) + 46 | "\r\r " + LunarHelper.str2rad("+179°54'31.49\"") + 47 | "\r" + LunarHelper.str2rad("-179°54'31.49\""), "返回结果:"); 48 | } 49 | 50 | private void label6_Click(object sender, EventArgs e) 51 | { 52 | MessageBox.Show(LunarHelper.rad2str2(3.14) + "\r" + LunarHelper.rad2str2(-3.14), "返回结果:"); 53 | } 54 | 55 | private void label7_Click(object sender, EventArgs e) 56 | { 57 | MessageBox.Show(LunarHelper.m2fm(121, 2, 0) + "\r" + LunarHelper.m2fm(121, 0, 1), "返回结果:"); 58 | } 59 | 60 | private void label8_Click(object sender, EventArgs e) 61 | { 62 | MessageBox.Show(LunarHelper.rad2mrad(0) + "\r" + LunarHelper.rad2mrad(Math.PI / 2) + "\r" + 63 | LunarHelper.rad2mrad(Math.PI * 2) + "\r" + LunarHelper.rad2mrad(Math.PI * 3) + "\r" + 64 | LunarHelper.rad2mrad(Math.PI * 4), "返回结果:"); 65 | } 66 | 67 | private void label9_Click(object sender, EventArgs e) 68 | { 69 | MessageBox.Show(LunarHelper.rad2rrad(0) + "\r" + LunarHelper.rad2rrad(-Math.PI/2) + "\r" + 70 | LunarHelper.rad2rrad(Math.PI) + "\r" + LunarHelper.rad2rrad(-Math.PI) + "\r" + 71 | LunarHelper.rad2rrad(Math.PI * 2) + "\r" + LunarHelper.rad2rrad(-Math.PI * 2) + "\r" + 72 | LunarHelper.rad2rrad(-Math.PI * 3), "返回结果:"); 73 | } 74 | 75 | private void label10_Click(object sender, EventArgs e) 76 | { 77 | MessageBox.Show(LunarHelper.mod2(1, 2) + "\r" + LunarHelper.mod2(1.2, 2.2) + "\r" + 78 | LunarHelper.mod2(2, 1) + "\r" + LunarHelper.mod2(2.2, 1.2), "返回结果:"); 79 | } 80 | 81 | private void label11_Click(object sender, EventArgs e) 82 | { 83 | JWdata.JWdecode("P3Tg昆明"); 84 | MessageBox.Show("经: " + LunarHelper.rad2str2(JWdata.J) + "\r纬: " + LunarHelper.rad2str2(JWdata.W), "返回结果:"); 85 | 86 | } 87 | 88 | private void label12_Click(object sender, EventArgs e) 89 | { 90 | MessageBox.Show("_" + LunarHelper.SUBSTRING("1", 0, 2) + "_" + "\r" + 91 | "_" + LunarHelper.SUBSTRING("1", -1, 2) + "_" + "\r" + 92 | "_" + LunarHelper.SUBSTRING("1", 0, -1) + "_" + "\r" + 93 | "_" + LunarHelper.SUBSTRING("abc", 1, 2) + "_", "返回结果(注意前后均增加了下划线):"); 94 | } 95 | 96 | private void label13_Click(object sender, EventArgs e) 97 | { 98 | MessageBox.Show(LunarHelper.VAL("1") + "\r" + 99 | LunarHelper.VAL("$1") + "\r" + 100 | LunarHelper.VAL("$-1") + "\r" + 101 | LunarHelper.VAL("-1E3") + "\r" + 102 | LunarHelper.VAL("$1E-3") + "\r" + 103 | LunarHelper.VAL("-123%") + "\r" + 104 | LunarHelper.VAL("ABC") + "\r" + 105 | LunarHelper.VAL("123D") + "\r" + 106 | LunarHelper.VAL("$+.E+%"), "返回结果:"); 107 | } 108 | 109 | private void label14_Click(object sender, EventArgs e) 110 | { 111 | MessageBox.Show(LunarHelper.VAL("¥+1") + "\r" + 112 | LunarHelper.VAL("¥+-1") + "\r" + 113 | LunarHelper.VAL("¥-1.2") + "\r" + 114 | LunarHelper.VAL("¥$") + "\r" + 115 | LunarHelper.VAL("¥-.E-%") + "\r" + 116 | LunarHelper.VAL("¥-12.3%") + "\r" + 117 | LunarHelper.VAL("A100") + "\r" + 118 | LunarHelper.VAL("1.2") + "\r", "返回结果:"); 119 | } 120 | 121 | private void label15_Click(object sender, EventArgs e) 122 | { 123 | MessageBox.Show(LunarHelper.VAL("001.88") + "\r" + 124 | LunarHelper.VAL("001.88", 1) + "\r" + 125 | LunarHelper.VAL("001.88", 1L) + "\r" + 126 | LunarHelper.VAL(".22") + "\r" + 127 | LunarHelper.VAL(".88.22") + "\r" + 128 | LunarHelper.VAL(".22E2") + "\r" + 129 | LunarHelper.VAL(" 2") + "\r" + 130 | LunarHelper.VAL("$ 2") + "\r", "返回结果:"); 131 | } 132 | 133 | private void label16_Click(object sender, EventArgs e) 134 | { 135 | MessageBox.Show(LunarHelper.VAL("") + "\r" + 136 | LunarHelper.VAL("E3") + "\r" + 137 | LunarHelper.VAL("3E") + "\r" + 138 | LunarHelper.VAL("3E+") + "\r" + 139 | LunarHelper.VAL("3E-") + "\r" + 140 | LunarHelper.VAL("3E2") + "\r" + 141 | LunarHelper.VAL("3E.2") + "\r" + 142 | LunarHelper.VAL(".E2") + "\r" + 143 | LunarHelper.VAL("+1") + "\r", "返回结果:"); 144 | } 145 | 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /TestSharpSxwnl/frmMethodsTest.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /test/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/Program.cs: -------------------------------------------------------------------------------- 1 | using SharpSxwnl; 2 | using System; 3 | using System.Text; 4 | 5 | namespace test 6 | { 7 | internal class Program 8 | { 9 | private static void Main(string[] args) 10 | { 11 | Program p = new Program(); 12 | Lunar lun = new Lunar(); 13 | double curJD, curTZ; 14 | sun_moon smc = new sun_moon(); 15 | 16 | DateTime nowDT = DateTime.Now; 17 | curTZ = -8;//TimeZone.CurrentTimeZone.GetUtcOffset(nowDT).Negate().TotalHours; // 中国: 东 8 区 18 | curJD = LunarHelper.NowUTCmsSince19700101(nowDT) / 86400000d - 10957.5 - curTZ / 24d; //J2000起算的儒略日数(当前本地时间) 19 | JD.setFromJD(curJD + LunarHelper.J2000); 20 | string Cal_y = JD.Y.ToString(); 21 | string Cal_m = JD.M.ToString(); 22 | 23 | curJD = LunarHelper.int2(curJD + 0.5); 24 | 25 | // double By = LunarHelper.year2Ayear(this.Cal_y.Text); 26 | //// C#: 注: 使用上句也可以, 如果在调用泛型方法时, 不指定类型, C# 编译器将自动推断其类型 27 | double By = LunarHelper.year2Ayear(Cal_y); // 自动推断类型为: string 28 | double Bm = int.Parse(Cal_m); 29 | lun.yueLiHTML((int)By, (int)Bm, curJD, nowDT.Day);//html月历生成,结果返回在lun中,curJD为当前日期(用于设置今日标识) 30 | //显示n指定的日期信息 31 | OB ob = lun.lun[nowDT.Day - 1]; 32 | // double vJ = JWdata.J, vW = JWdata.W; 33 | double vJ = -1.9768762660922441, vW = 0.40346194541935582;//广州 34 | string thisDaySunMoonInfo = p.RTS1(ob.d0, vJ, vW, curTZ); // p.RTS1(ob.d0, vJ, vW, curTZ); // 计算并显示指定日期的日月升降信息 35 | StringBuilder sb = new StringBuilder(); 36 | 37 | sb.AppendLine(LunarHelper.Ayear2year(ob.y) + "年" + ob.m + "月" + ob.d + "日");//公历日期 38 | sb.AppendLine(ob.Lyear3 + "年 星期" + JD.Weeks[(int)(ob.week)] + " " + ob.XiZ);// 丁酉年 星期日 狮子座 39 | sb.AppendLine(ob.Lyear4 + "年 " + ob.Lleap + ob.Lmc + "月" + (ob.Ldn > 29 ? "大 " : "小 ") + ob.Ldc + "日");// 4715年 润六月大 初八日 40 | sb.AppendLine(ob.Lyear2 + "年 " + ob.Lmonth2 + "月 " + ob.Lday2 + "日");// 丁酉年 丁未月 戊午日 41 | sb.AppendLine("回历[" + ob.Hyear + "年" + ob.Hmonth + "月" + ob.Hday + "日]");//回历[1438年11月6日] 42 | 43 | Console.WriteLine(thisDaySunMoonInfo); 44 | Console.WriteLine(sb.ToString()); 45 | Console.ReadLine(); 46 | } 47 | 48 | #region 计算并返回日月升中降信息 49 | 50 | private string RTS1(double jd, double vJ, double vW, double tz) 51 | { 52 | SZJ.calcRTS(jd, 1, vJ, vW, tz); //升降计算,使用北时时间,tz=-8指东8区,jd+tz应在当地正午左右(误差数小时不要紧) 53 | string s; 54 | LunarInfoListT ob = SZJ.rts[0]; 55 | JD.setFromJD(jd + LunarHelper.J2000); 56 | s = "日出 " + ob.s + " 日落 " + ob.j + " 中天 " + ob.z + "\r\n" 57 | + "月出 " + ob.Ms + " 月落 " + ob.Mj + " 月中 " + ob.Mz + "\r\n" 58 | + "晨起天亮 " + ob.c + " 晚上天黑 " + ob.h + "\r\n" 59 | + "日照时间 " + ob.sj + " 白天时间 " + ob.ch + "\r\n"; 60 | return s; 61 | } 62 | 63 | #endregion 计算并返回日月升中降信息 64 | } 65 | } -------------------------------------------------------------------------------- /test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("test")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("771d44cf-541a-44c6-94da-2997e96f6267")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {771D44CF-541A-44C6-94DA-2997E96F6267} 8 | Exe 9 | Properties 10 | test 11 | test 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | False 38 | ..\SharpSxwnl\bin\Debug\SharpSxwnl.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 64 | --------------------------------------------------------------------------------