|
Tài trợ cho PIC Vietnam |
RTOS và Thuật toán với PIC RTOS và Các thuật toán dùng cho PIC/dsPIC/PIC32 Mod: phamminhtuan |
|
Ðiều Chỉnh | Xếp Bài |
28-06-2011, 08:50 PM | #1 |
Đệ tử 5 túi
Tham gia ngày: Dec 2010
Bài gửi: 101
: |
thuat toan chuyen doi duong lich sang am lich
ai da tung lam thi ra tay chi giúp voi,dang lam do an ben cai nay ma lam hoai khong ra.em dua vao thuat toan chuyen doi tren mang cua tac gia ho ngoc duc ma chuyen doi no khong dung gi ca .ko biet la do chuyen sang c nay khong hop . em co mot doan code nho chuyen doi tu ngon ngu java sang ccs ko biet dung ko cao thu biet xin chi gium voi thank nhieu
code : // cong thuc ham chuyen doi am lich unsigned long jdFromDate(signed int8 dd, signed int8 mm, signed int8 yy) { int a, m,y1,jd; a = (int)((14 - mm)/12); y1 = yy + 4800 - a; m = mm + 12*a - 3; jd = dd + (int)((153*m + 2)/5) + 365*y1 +(int)(y1/4) - (int)(y1/100) +(int)(y1/400) - 32045; if (jd < 2299161) jd = dd + (int)((153*m + 2)/5) + 365*y1 + (int)(y1/4) - 32083; return jd; } //tinh ngay soc int getNewMoonDay(unsigned long k,unsigned int timezone) { float T1, T2, T3, dr, Jd1, M, Mpr, P, C1, deltat, JdNew; T = k/1236.85; T2 = T1 * T1; T3 = T2 * T1; dr = 3.1415926/180; Jd1 = 2415020.75933 + 29.53058868*k + 0.0001178*T2 - 0.000000155*T3; Jd1 = Jd1 + 0.00033*sin((166.56 + 132.87*T1 - 0.009173*T2)*dr); M = 359.2242 + 29.10535608*k - 0.0000333*T2 - 0.00000347*T3; Mpr = 306.0253 + 385.81691806*k + 0.0107306*T2 + 0.00001236*T3; P = 21.2964 + 390.67050646*k - 0.0016528*T2 - 0.00000239*T3; C1=(0.1734 - 0.000393*T1)*sin(M*dr) + 0.0021*sin(2*dr*M); C1 = C1 - 0.4068*sin(Mpr*dr) + 0.0161*sin(dr*2*Mpr); C1 = C1 - 0.0004*sin(dr*3*Mpr); C1 = C1 + 0.0104*sin(dr*2*P) - 0.0051*sin(dr*(M+Mpr)); C1 = C1 - 0.0074*sin(dr*(M-Mpr)) + 0.0004*sin(dr*(2*P+M)); C1 = C1 - 0.0004*sin(dr*(2*P-M)) - 0.0006*sin(dr*(2*P+Mpr)); C1 = C1 + 0.0010*sin(dr*(2*P-Mpr)) + 0.0005*sin(dr*(2*Mpr+M)); if (T1 < -11) deltat = 0.001 + 0.000839*T1 + 0.0002261*T2 - 0.00000845*T3 - 0.000000081*T*T3; else deltat= -0.000278 + 0.000265*T1 + 0.000262*T2; JdNew = Jd1 + C1 - deltat; return (int)(JdNew + 0.5 + 7/24); } // tinh tao do mat troi int getSunLongitude( int jdn,int timezone) { double T1, T2, dr, M, L0, DL, L; T1 = (jdn - 2451545.5 - 7/24) / 36525; T2 = T1*T1; dr = 3.1415926/180; M = 357.52910 + 35999.05030*T1 - 0.0001559*T2 - 0.00000048*T1*T2; L0 = 280.46645 + 36000.76983*T1 + 0.0003032*T2; DL = (1.914600 - 0.004817*T1 - 0.000014*T2)*sin(dr*M); DL = DL + (0.019993 - 0.000101*T1)*sin(dr*2*M) + 0.000290*sin(dr*3*M); L = L0 + DL; L = L*dr; L = L - 3.1415926*2*(int)(L/(3.1415926*2)); return (L / 3.1415926 * 6); } // Tim ngay bat dau thang 11 am lich ----------------------------------------- int getLunarMonth11( int yy, int timezone ) { unsigned long k, off, nm, sunLong; off = jdFromDate(31, 12, yy) - 2415021; k = (int)(off / 29.530588853); nm = getNewMoonDay(k,7); sunLong = getSunLongitude((int)nm,7); if (sunLong >= 9) nm = getNewMoonDay((int)k-1,7); return (int)nm; } char getLeapMonthOffset(double a11, int timezone) { double k, last, arc; long l; char tmp; k =(int) ((a11 - 2415021.076998695) / 29.530588853 + 0.5); last = 0; l = 1; tmp = getNewMoonDay((int)(k+l),7); arc = getSunLongitude((int)tmp,7); do { last = arc; l ++; arc = getSunLongitude((int)tmp,7); } while (arc != last && l < 14); return l-1; } void AMLICH() { unsigned long k, dayNumber, monthStart, a11, b11, lunarDay, lunarMonth, lunarYear, lunarLeap, diff, leapMonthDiff; char dd, mm, yy; unsigned int8 ld1,ld2, lm1,lm2; short ly1,ly2; dd =28; mm= 06; yy= 11; dayNumber = jdFromDate(dd, mm, yy); k = (dayNumber - 2415021.076998695) / 29.530588853; monthStart = getNewMoonDay((int)(k+1),7); if (monthStart > dayNumber) monthStart = getNewMoonDay(k,7); a11 = getLunarMonth11(yy,7); b11 = a11; if (a11 >= monthStart) { lunarYear = yy; a11 = getLunarMonth11(yy-1,7); } else { lunarYear = yy+1; b11 = getLunarMonth11(yy+1,7); } lunarDay = dayNumber-monthStart+1; diff = (int)((monthStart - a11)/29); lunarLeap = 0; lunarMonth = diff+11; if (b11 - a11 > 365) { leapMonthDiff = getLeapMonthOffset(a11,7); if (diff >= leapMonthDiff) { lunarMonth = diff + 10; if (diff == leapMonthDiff) lunarLeap = 1; } } if (lunarMonth > 12) lunarMonth = lunarMonth - 12; if (lunarMonth >= 11 && diff < 4) lunarYear = lunarYear- 1; portb=lunarDay; ld2=lunarDay/10; ld1=lunarDay%10; lm2 = lunarMonth/10; lm1 = lunarMonth%10; cai cho ben java math.sin neu viet nhu vay ccs ko dich dc.em bo no di co sao ko vi em co su dung thu vien math.h |
|
|