using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace luca { class Program { double[] ykche = new double[] { 1640650.479938,1642476.703182,1683430.515601,1752157.640664,1807675.003759,1883627.765182,1907369.128100,1936603.140413,1939145.524180,1947180.798300,1964362.041824,1987372.340971, 1999653.819126,2007445.469786,2021324.917146,2047257.232342,2070282.898213,2073204.872850,2080144.500926,2086703.688963,2110033.182763,2111190.300888,2113731.271005,2120670.840263,2123973.309063, 2125068.997336,2136026.312633,2156099.495538,2159021.324663,2162308.575254,2178485.706538,2178759.662849,2185334.020800,2187525.481425,2188621.191481};
double[] kche = new double[] { -221, -216, -104, 84, 236, 444, 509, 589, 596, 618, 665, 728, 761, 783, 821, 892, 955, 963, 982, 1000, 1063, 1067, 1074, 1093, 1102, 1105, 1135, 1190, 1198, 1207, 1251, 1252, 1270, 1276, 1279};
double[] jkche = new double[] { 15.21842500, 15.21874996, 15.218750011, 15.218749978, 15.218620279, 15.218612292, 15.218449176, 15.218425000, 15.218466998, 15.218524844, 15.218533526, 15.218513908, 15.218530782, 15.218535181, 15.218526248, 15.218519654, 15.218425000, 15.218515221, 15.218530782, 15.218523776, 15.218425000, 15.218425000, 15.218515671, 15.218425000, 15.218425000, 15.218477932, 15.218472436, 15.218425000, 15.218425000, 15.218461742, 15.218425000, 15.218445786, 15.218425000, 15.218425000, 15.218437484}; int[] jkche2 = new int[]{ -3, -3, 0, 4, 4, 3, 3, 4, 3, 3, 4, 4, 19, 3, 3, 3, 4, 4, 4, 3, 0, 4, 3, 3, 4, 4, 4, 3, 3, 3, 10, 4, 4, 4, 4};
string[] ifGr5a=new string[]{"周曆","周曆","秦曆","殷曆","殷曆","魯曆","周曆","夏曆"};
double PI(){ return Math.PI; }
double sin(double x){ return Math.Sin(x); }
double cos(double x){ return Math.Cos (x); }
double abs(double x){ return Math.Abs(x); }
double floor(double x){ return Math.Floor (x); }
double round(double x){ return Math.Round(x); }
double tail(double x) { return x-floor(x); }
double rem(double x,double w) { return tail(x/w)*w; }
double ifGr5(double y,double m,double d){ //公曆y年m月(1,2..12,下同)d日 var v=(y-1)*365+floor((y-1)/4)+D0(y,m,d)-2; if(y>1582) v+=-floor((y-1)/100)+floor((y-1)/400)+2; var jd=(v+1721425);//等效儒略日 var opt = 0; if(jd>=-10000)opt=7;//夏曆 if(jd>=1137055)opt=3;//-1599,2,1殷曆 if(jd>=1339370)opt=0;//-1046,12,30周曆 if(jd>=1457728)opt=5;//-721,1,16魯曆 if(jd>=1547530)opt=0;//-476,11,27周曆 if(jd>=1628238)opt=2;//-255,11,15秦曆 if(jd>=1683519)opt=7;//-103,3,23夏曆 if(jd>=1724360)opt=4;//9,1,15殷曆 if(jd>=1729764)opt=7;//23,11,2夏曆 if(jd>=1807725)opt=4;//237,4,13殷曆-魏 if(jd>=1808729)opt=7;//240,1,12夏曆 if(jd>=1973067)opt=1;//689,12,18周曆-武周 if(jd>=1977082)opt=7;//700,12,15夏曆 if(jd>=1999349)opt=6;//761,12,2周曆-唐肅宗 if(jd>=1999497)opt=7;//762,4,29夏曆 return opt; } //判斷Gregorian曆還是Julian曆 double ifGr(double y, double m, double d, double opt) { //陽曆y年m月(1,2,..,12,下同)d日,opt=1,2,3分別表示標準日曆,Gregorge曆和Julian曆 if(opt==1){ if(y>1582||(y==1582&&m>10)||(y==1582&&m==10&&d>14)) return(1); //Gregorian else if(y==1582&&m==10&&d>=5&&d<=14) return(-1); //空 else return(0); //Julian } if(opt==2) return(1); //Gregorian if(opt==3) return(0); //Julian
return 0; }
double JD(double y, double m, double d, double h, double min, double sec, double zone) { var ifG=ifGr(y,m,d,1); var jt=(h+(min+sec/60)/60)/24-0.5-zone/24; //r d=(ifG)?(erD(y,m,d)+1721425+jt):(erD(y,m,d)+1721425+jt);//儒略日 var jd= (erD(y, m, d) + 1721425 + jt); return jd; }
double D0(double y, double m, double d) { var ifG=ifGr(y,m,d,1); var monL=new int[] {0,31,28,31,30,31,30,31,31,30,31,30,31}; if(ifG!=0) if((y%100!=0&&y%4==0)||(y%400==0)) monL[2]+=1; else if(y%4==0) monL[2]+=1; double v = 0; for(var i=0;i<=m-1;i++){ v+=monL[i]; } v+=d; if (y == 1582) { if (ifG == 1) v -= 10; if (ifG == -1) v = 0; //infinity } return v; }
double antiD0(double y, double x) { var m=1; for(var j=1;j<=12;j++){ var mL = D0(y, m + 1, 1) - D0(y, m, 1); if (y == 1582 && m == 10) mL = 31; if(x<=mL||j==12){ m=j; break; } else x-=mL; } return 100*m+x; }
double D(double y) { var v=(y-1)*365+floor((y-1)/4); //Julian腔爛船毞 if(y>1582) v+=-floor((y-1)/100)+floor((y-1)/400); //Gregorian腔爛船毞 return v; }
double erD(double y, double m, double d) { var v=(y-1)*365+floor((y-1)/4)+D0(y,m,d)-2; //Julian腔脹虴??毞 if(y>1582) v+=-floor((y-1)/100)+floor((y-1)/400)+2; //Gregorian腔脹虴??毞 return v; }
double S(double y, double n, int pd) { //pd?硉?0麼1ㄛ煦?桶尨??睿隅?,?滲殿隙??腔D0硉 var yk=365.2423112;///yk=365.2422226;0.00008894 var jk=y-2100; var j=0.000088931/3400*jk;if(y<2200)j=0; var="var" yk2="yk-j; " var="var" jud="y*(yk2-6.4e-14*(y-100)*(y-100)-3.047e-8*(y-100))+15.218427*n+1721050.71301;//?謹? " var="var" tht="3e-4*y-0.372781384-0.2617913325*n;//褒僅 " var="var" yrd="(1.945*sin(tht)-0.01206*sin(2*tht))*(1.048994-2.583e-5*y);//爛船?歙 " var="var" shuod="-18e-4*sin(2.313908653*y-0.439822951-3.0443*n);//侇船?歙
" double="double" vs; if="if" (pd!=0) vs="(juD+yrD+shuoD-erD(y,1,0)-1721425); " else="else" vs="(juD-erD(y,1,0)-1721425); " return="return" vs; }
double="double" S2(double y, double="double" m, double="double" d, int="int" n) { ///-221善1645妢???,?滲殿隙妢????腔D0硉 var="var" jejd="round(JD(y,m,d,20,0,0,8)*1000)/1000;" var="var" ykd="(round(JD(y,1,1,20,0,0,8)*1000)/1000)-1; " var="var" jkk="0;if(jeJD">1642468)jkk=1;if(jeJD>=1683438)jkk=2;if(jeJD>=1752164)jkk=3; if(jeJD>=1807682)jkk=4;if(jeJD>=1883654)jkk=5;if(jeJD>=1907395)jkk=6;if(jeJD>=1936615)jkk=7; if(jeJD>=1939172)jkk=8;if(jeJD>=1947207)jkk=9;if(jeJD>=1964374)jkk=10;if(jeJD>=1987385)jkk=11; if(jeJD>=1999683)jkk=12;if(jeJD>=2007445)jkk=13;if(jeJD>=2021325)jkk=14;if(jeJD>=2047258)jkk=15; if(jeJD>=2070297)jkk=16;if(jeJD>=2073219)jkk=17;if(jeJD>=2080158)jkk=18;if(jeJD>=2086705)jkk=19; if(jeJD>=2110050)jkk=20;if(jeJD>=2111205)jkk=21; if(jeJD>=2113733)jkk=22;if(jeJD>=2120673)jkk=23;if(jeJD>=2123988)jkk=24; if(jeJD>=2125084)jkk=25;if(jeJD>=2136042)jkk=26;if(jeJD>=2156102)jkk=27;if(jeJD>=2159024)jkk=28; if(jeJD>=2162311)jkk=29;if(jeJD>=2178503)jkk=30;if(jeJD>=2178776)jkk=31;if(jeJD>=2185350)jkk=32; if(jeJD>=2187542)jkk=33;if(jeJD>=2188637)jkk=34; var yk2=ykche[jkk];///場 var k=kche[jkk];//爛賜 var jk=jkche[jkk];////?墿 var jk9=jkche2[jkk];///?船 var yk3=jk*(jk9*1); var yk=(yk2*1)-(yk3*1); var jq=jk*(n+(24*(y-k-1))); var vj=jq+yk-ykd+0.5;if(y<-220||y>1646||y==1646&&m>=1)vj=0; return vj; } double S2(double y, double m, double d, double n) { ///從-221到1645史實平氣,該函數返回史實平節氣的D0值 var jeJD=round(JD(y,m,d,20,0,0,8)*1000)/1000; var ykd=(round(JD(y,1,1,20,0,0,8)*1000)/1000)-1; var jkk=0;if(jeJD>1642468)jkk=1;if(jeJD>=1683438)jkk=2;if(jeJD>=1752164)jkk=3; if(jeJD>=1807682)jkk=4;if(jeJD>=1883654)jkk=5;if(jeJD>=1907395)jkk=6;if(jeJD>=1936615)jkk=7; if(jeJD>=1939172)jkk=8;if(jeJD>=1947207)jkk=9;if(jeJD>=1964374)jkk=10;if(jeJD>=1987385)jkk=11; if(jeJD>=1999683)jkk=12;if(jeJD>=2007445)jkk=13;if(jeJD>=2021325)jkk=14;if(jeJD>=2047258)jkk=15; if(jeJD>=2070297)jkk=16;if(jeJD>=2073219)jkk=17;if(jeJD>=2080158)jkk=18;if(jeJD>=2086705)jkk=19; if(jeJD>=2110050)jkk=20;if(jeJD>=2111205)jkk=21; if(jeJD>=2113733)jkk=22;if(jeJD>=2120673)jkk=23;if(jeJD>=2123988)jkk=24; if(jeJD>=2125084)jkk=25;if(jeJD>=2136042)jkk=26;if(jeJD>=2156102)jkk=27;if(jeJD>=2159024)jkk=28; if(jeJD>=2162311)jkk=29;if(jeJD>=2178503)jkk=30;if(jeJD>=2178776)jkk=31;if(jeJD>=2185350)jkk=32; if(jeJD>=2187542)jkk=33;if(jeJD>=2188637)jkk=34; var yk2=ykche[jkk];///初數 var k=kche[jkk];//年界 var jk=jkche[jkk];////氣長 var jk9=jkche2[jkk];///節差數 var yk3=jk*(jk9*1); var yk=(yk2*1)-(yk3*1); var jq=jk*(n+(24*(y-k-1))); var vj=jq+yk-ykd+0.5;if(y<-220||y>1646||y==1646&&m>=1)vj=0; return vj; } public string jqi(double y,double m,double d, double a){ var mL=D0(y,m+1,1)-D0(y,m,1); var yr2=""+y+"年"; if(y<=0) yr2="前"+(-y+1)+"年"; var sT00="";var sT0="";var sT1="";var sT2="";var sT3="";var sT4=""; var qSt="";var sDsStr1="";var ifsj1="";////節氣 var sN00=2*m-3; var sDt00=S(y,sN00,1);if(a==3)sDt00=S2(y,m,d,sN00); var sD00=antiD0(y,floor(sDt00)); var sM00=floor(sD00/100); ///節氣交接公暦月。 var sDate00=sD00%100; var sN0=2*m-2; var sDt0=S(y,sN0,1);if(a==3)sDt0=S2(y,m,d,sN0); var sD0=antiD0(y,floor(sDt0)); var sM0=floor(sD0/100); var sDate0=sD0%100; var sN1 =2*m-1; var sDt1=S(y,sN1,1);if(a==3)sDt1=S2(y,m,d,sN1); var sD1=antiD0(y,floor(sDt1)); var sM1=floor(sD1/100); var sDate1=sD1%100; var sN2=2*m; var sDt2=S(y,sN2,1);if(a==3)sDt2=S2(y,m,d,sN2); var sD2=antiD0(y,floor(sDt2)); var sM2 = floor(sD2 / 100); var sDate2 = sD2 % 100; if (y == 1582 && m == 10) sDate2 = sDate2 + 10; var sN3=2*m+1; if(sN3>24) sN3=25; var sDt3=S(y,sN3,1);if(a==3)sDt3=S2(y,m,d,sN3); var sD3=antiD0(y,floor(sDt3)); var sM3=floor(sD3/100); var sDate3=sD3%100;
sN00=rem(sN00-1,24)+1;sN0=rem(sN0-1,24)+1;sN1=rem(sN1-1,24)+1; sN2=rem(sN2-1,24)+1; sN3=rem(sN3-1,24)+1; if(sDate2>mL) sDate2-=mL; var jqk=D0(y,m,d);var qk00=floor(sDt00); var qk0=floor(sDt0);var qk1=floor(sDt1);var qk2=floor(sDt2);var qk3=floor(sDt3); if(qk00D0(y,m,mL)) sN00=0; if(qk0D0(y,m,mL)) sN0=0; if(qk1D0(y,m,mL)) sN1=0; if(qk2D0(y,m,mL)) sN2=0; if(qk3D0(y,m,mL)) sN3=0;// sT00="%公暦"+yr2+sM00+"月"+sDate00+"日"+"東8區"+(tail(sDt00))+" 定"+(sN00)+" ";if(sN00==0) sT00=""; sT0="*公暦"+yr2+sM0+"月"+sDate0+"日"+"東8區"+(tail(sDt0))+" 定"+(sN0)+" ";if(sN0==0) sT0=""; sT1="&公暦"+yr2+sM1+"月"+sDate1+"日"+"東8區"+(tail(sDt1))+" 定"+(sN1)+" ";if(sN1==0) sT1=""; sT2="$公暦"+yr2+sM2+"月"+sDate2+"日"+"東8區"+(tail(sDt2))+" 定"+(sN2);if(sN2==0)sT2=""; sT3=" "+"#公暦"+yr2+sM3+"月"+sDate3+"日"+"東8區"+(tail(sDt3))+" 定"+(sN3);if(sN3==0)sT3=""; var qSt5="";if(a==1)qSt5="定";if(a==2)qSt5=""+"◆"; if(jqk==qk00)if(sT00==""){sDsStr1="|";} else{sDsStr1=qSt5+(sN00.ToString ())+":東8區"+(tail(sDt00).ToString ());} if(jqk==qk0)if(sT0==""){sDsStr1="|";}else{sDsStr1=qSt5+(sN0.ToString ())+":東8區"+(tail(sDt0).ToString ());} if(jqk==qk1)if(sN1==0){sDsStr1="|";}else{sDsStr1=qSt5+(sN1.ToString ())+":東8區"+(tail(sDt1).ToString ());} if(jqk==qk2)if(sN2==0){sDsStr1="|";}else{ sDsStr1=qSt5+(sN2.ToString ())+":東8區"+(tail(sDt2).ToString ());} /// if(jqk==qk3)if(sT3==""){sDsStr1="|";}else{sDsStr1=qSt5+(sN3.ToString ())+":東8區"+(tail(sDt3).ToString ());} if(jqk==qk00)if(sT00==""){qSt="";}else{qSt=qSt5+(sN00.ToString ());} if(jqk==qk0)if(sT0==""){qSt="";}else{qSt=qSt5+(sN0.ToString ());} if(jqk==qk1)if(sT1==""){qSt="";}else{qSt=qSt5+(sN1.ToString ());} if(jqk==qk2)if(sT2==""){qSt="";}else{ qSt=qSt5+(sN2.ToString ());} if (jqk == qk3) if (sT3 == "") { qSt = ""; } else { qSt = qSt5 + (sN3.ToString()); } if(a==1){return sDsStr1;}else{ if(a==2){return qSt;}else{ if(a==3){return qSt;}else{ return sT00+sT0+sT1+sT2+sT3;}}}
}/////節氣計算結束
static void Main(string[] args) { Program a = new Program(); Console.WriteLine(a.jqi(2010, 1, 1, 0)); Console.ReadKey(); } } }
|