简明万年历编制(C语言 )
编制万年历的要素:
农历公历对照,显示星期,农历干支年,当年生肖,国定节假日,寒天九九,暑日三伏,入梅出梅,节气时间,生辰八字等。
我编写万年历课题的内容:
一、漂亮的软件界面设计制作
二、阳历阴历对照 : 显示阴历的算法,对照,定位显示
三、加入节气节假日 : 完成像样的台历式月历显示
四、加入农历干支生肖:较完善的台历显示
五、日历式显示 :有寒天九九,暑日三伏,入梅出梅
六、生辰八字查询 :完整显示生辰八字,五星,二十八宿,十二建,五行纳音
七、节气交节时刻计算:精确时刻计算难度较高,减精度的简易算法或数据法
八、程序设计有:界面互动功能,点击日期可即时查看是日农历信息
农历算法采用数据数组方法,200年日历数据量不大。程序启动时读入即可。
数据结构18位,如daList[2000]="110010010110000205"; 前12位表示正月到腊月大小月,1为农历大月30天,0为小月29天。 第13,14位表示农历闰月,13位为农历闰月大小,14位为闰几月,
后4位表示农历年首个朔日,即俗称的正月初一的公历日期,如2月5日。
节气交节时刻计算,天文算法很精准,但太复杂,数据数组方法数据量太大,都不合适。如要求精确时间,可用数据数组方法。本程序采用曾次亮先生的算法,算法简单,但精度差些。如要精准度就采用数据数组方法,200年的数据量还可以,现在存储和内存容量都较大。我已编译了数据,需要的可索取。
台历式显示月历是公历和农历格式化打印,7天一星期打印输出。农历显示包括初一改为那个月,是节气日期改为节气名称,法定节假日显示。节假日既然是国家法定的,那就应从1949年开始显示。其实各节日哪时开始要考证,故且从权统一从1949年开始。此前也就只显示传统节日。
月历和按天日历都显示当月节气中气时间,同时显示指定查询日生辰八字。
生辰八字显示年月日六字加另列出的时辰二字。
另外还显示日八字的五行二十八宿十二建的排列字,如:甲寅 大溪水胃满 。
八字都有显示五行纳音,如:甲子 海中金 。
民间有俗称今年是金猪年金猴年。其实要看年柱的五行,如:
1984年:甲子 海中金 就是金鼠年
八字年柱月柱算法有二种,此程序采用较通用的,即年柱以立春日启算,月柱以月首节气日启算。
这里有五行纳音,二十八宿,十二建的算法。程序中有注释供同好参考。
屏幕点击可查询该日,显示各项信息,另加节假日,寒日九九,暑日三伏,入梅出梅信息。
本万年历适应用范围(1900-2100),用图形方法绘出,可加贴底图,可屏幕截图保存图片,共享图片。另外可添加图片输出和打印输出功能。贴图的图片起个文件名放在手机根目录就会自动更换。若要编制年份跨期长的万年历,可向我索取数据资料。我有(B.C.850-3000)的daList(3000)阴历数据。另外还有精确的节气时间数据 jqdata ( 3000 ) 。
下面的代码是用简单的C语言写的,很简洁,适用于初学者。我是在安卓手机上编写的,显示是手机界面。
( 代码中print...是算法测试用,这是我的测试方法,已注释掉 )
以下是源码:
//**************************************
//* 简明万年历 (1900-2100) ver. 2.5.1
//**************************************
Canvas cs;
string sBarDes[10];
int nBarId[10];
float src[4]; //ClearDraw (cls) clear screen
FileInput filebox;
string fname; //filename
int ds[3]; //get date yymmdd
int dy,dm,dd;
int wd; //weekday
int alln,alln1;
int i,k,ns,leap;
double nleap, nleapd; //农历闰月,0无闰,闰月大小
int n,n0,n1;
string s,s0,ss,s5, s6 ;
string s1,s2,s3,s4;
string s11, s12, s13, s14 ;
string wds,wdss; //weekday
float x0,y0,x1,y1;
float sx,sy;
string daList[2200] ;
//string jqdata[2200] ;
double dy0,dy1,dm1,dd1;
string dy2,dm2,dd2 ;
double hh1,mm1,ss1;
string hh2,mm2,ss2;
double jn; //jnum
string jname1,jname2;
string jqnames;
string jz60s;
double jd;
double juD,tht,yrD;
double sD; //shouD
double vs,dalt; //solar
string das0,das1,das2; // 0 last yy, 1 this yy, 2 new
double ysm,ysd; //年首月,年首日
int msd[12]; //月朔日
int msd0,msd1;
int mdx ; //农历月大小
int chuxi; //除夕在廿九
string nlms,nlds; //农历月$,农历日$
string getms,getds, mss$ ; //for print nlm$,nld$
string gzs,ggzs; //干支
int gzn;
string sxs,gsxs; //生肖
int sxn;
int jqdn,jqd1,jqd2; //print solar day ( calendar )
string jqs1,jqs2;
string jqss1,jqss2;
int gzy,gzm,gzd,gzh; //干支 yy mm dd hh
string gzys,gzms,gzds,gzhs;
int gzn1;
int yz,mz; //年柱 月柱
string bzs; //八字
string whss,g12ss,st28ss; //五行 十二建 二十八宿
int dzd0,dzd1; //冬至日
int fmn,mn,fn; //母亲节父亲节
int isdraw;
int setc; //set day color in red
string fd$ ; // fdd$ ;
string p1, p2, p3, p4, p5 ;
string mon$;
int context; //canvasProc屏幕触控
int obj;
int id;
int event; //Proc
int kx,ky, dn, dln ;
main(){
setTitle ("简明月历 (1900-2100)");
jqnames="小寒大寒立春雨水惊蛰春分清明谷雨立夏小满芒种夏至小暑大暑立秋处暑白露秋分寒露霜降立冬小雪大雪冬至";
nlds="初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十初一初二初三";
wdss="星期日星期一星期二星期三星期四星期五星期六";
nlms="冬月腊月正月二月三月四月五月六月七月八月九月十月冬月腊月";
gzs="甲子乙丑丙寅丁卯戊辰己巳庚午辛未壬申癸酉甲戌乙亥丙子丁丑戊寅己卯庚辰辛己壬午癸未甲申乙酉丙戌丁亥戊子己丑庚寅辛卯壬辰癸巳甲午乙未丙申丁酉戊戌己亥庚子辛丑壬寅癸卯甲辰乙巳丙午丁未戊申己酉庚戌辛亥壬子癸丑甲寅乙卯丙辰丁巳戊午己未庚申辛酉壬戌癸亥";
sxs="鼠牛虎兔龙蛇马羊猴鸡狗猪";
whss="海中金炉中火大林木路旁土剑锋金山头火洞下水城墙土白腊金杨柳木泉中水屋上土霹雷火松柏木长流水沙中金山下火平地木壁上土金箔金佛灯火天河水大驿土钗钏金桑松木大溪水沙中土天上火石榴木大海水";
g12ss="建除满平定执破危成收开闭";
st28ss="角亢氐房心尾箕斗牛女虚危室壁奎娄胃昴毕觜参井鬼柳星张翼轸";
//cs.SetBackground(200,250,200);
setDisplay (1);
cs.Active ();
sBarDes[0]="输入日期";
nBarId[0]=100;
sBarDes[1]="显示月历";
nBarId[1]=101;
sBarDes[2]="< 上一月 ";
nBarId[2]=102;
sBarDes[3]="下一月 > ";
nBarId[3]=103;
sBarDes[4]="退出程序";
nBarId[4]=104;
sBarDes[5]=" ";
nBarId[5]=105;
setToolBarHeight(10);
setButtonTextSize(13);
setToolBarBackgroundColor(255,250,250,250);
setButtonColor(255,240,240,240);
setButtonTextColor(255,0,0,220);
setToolBar(100,myToolBarProc,sBarDes,nBarId,6);
cs.SetProc (context, mycanvasProc); //触控
readDat (); //read calendar data 1900-2100
isdraw=0;
fname="/storage/emulated/0/jiac.jpg";
cs.DrawBitmap(fname,0,2); //加底图
showVer () ;
getDate(ds); //getDate = today
dy=ds[0]; dm=ds[1]; dd=ds[2];
getWeekday();
calendar(); //show calendar at start
cs.SetTextSize (60);
ss="Welcome you ...... ! " ;
cs.SetColor(205,250,150,0);
cs.DrawText (ss, 35, 100);
cs.Update () ;
while (){}
}//main ()
showVer (){ //启动页
cs.SetTextStyle (1);
cs.SetFillMode(1);
cs.SetColor(50,220,220,20);
cs.DrawRect (0,940,720,1030);
cs.DrawRect (540,30,716,400);
cs.SetTextSize (66);
ss="萬年历" ;
cs.SetColor(205,0,100,180);
cs.DrawText (ss, 35, 985);
cs.SetColor(205,180,250,250);
cs.DrawText (ss, 30, 980);
cs.SetFillMode(0);
cs.SetColor(205,250,130,0);
cs.DrawText (ss, 30, 980);
cs.SetTextStyle (0);
cs.SetFillMode(1);
cs.SetTextSize (26);
s="编译人:张纯叔 (micelu@126.com) ";
cs.DrawText(s,30,1020);
cs.DrawText("Version 2.5.1",460,1020);
cs.Update ();
}//showVer ()
mycanvasProc (int context,int obj,int id,int event,float x,float y){
dln=dln+1 ; //触控:减少屏幕闪烁
if ((dln-dln/3*3)==0){ goto isdo ; }
return ;
//*******
isdo :
cs.SetFillMode (1);//0不填色,1填色
if (x>45&&x<520&&y>260&&y<720){
kx=(int)((x+40)/70)*70; //日历区位取整数
ky=(int)((y-265)/80)*80;
kx=kx/70;
ky=ky/80;
dn=(ky)*7+kx-wd; //选定日期 dn
if (dn<1) dn=1 ; //dn=the first day
if (dn>ns) dn=dd ; //dn=today
}
dd=dn; //click to chose this day
getWeekday () ;
calendar() ; //renew the day
}//mycanvasProc ()
inputDate (){ //日期输入
string sDat[101];
getDate(ds); //getDate = today
pickDate("输入日期:",ds); //input date
clearOutput ();
//print ds[0],ds[1],ds[2];
dy=ds[0];
dm=ds[1];
dd=ds[2];
print "InputDate = ",dy ,"-",dm,"-",dd;
dd2=intToString(dd); //this day $
getWeekday () ;
}//inputDate()
getWeekday (){//计算月首日星期几
int ty;
int tm;
clearOutput ();
ty=dy;
tm=dm;
if (dm<3){
ty=dy-1;
tm=dm+12; }
//first day=1 this month
//iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)
//mod 7 基姆拉尔森公式
alln=2*tm+3*(tm+1)/5+ty+(int)(ty/4);
alln=alln-(int)(ty/100)+(int)(ty/400)+2;
wd=alln-alln/7*7; //mod (alln,7)
wds=subString(wdss,wd*3,3);
string yds; //for gz day wh 28star 12jian
string ydds;
double tms;
yds="000031059090120151181212243273304334";
ydds=subString(yds,(dm-1)*3,3);
tms=stringToDouble(ydds);
alln1=(dy-1900)*365+((dy-1900-1)/4)+(int)(tms)+1;
if ((dy-dy/4*4)==0&&dm>2)alln1=alln1+1;
print "all days = ",alln," ",alln1;
// return weekday = wds $
}//getWeekday ()
calnlds(){ //计算农历要素
//calculate 农历月$ getms 农历日$ getds*******
//double nleap,nleapd; //农历闰月,0无闰,闰月大小
s=daList[dy-1];
das0=s;
print "last year = ",dy-1;
print "last year das0 = ", das0;
s=daList[dy];
das1=s;
print "this year = ",dy;
print "this year das1 = ",das1;
s=subString(das1,15,1);
ysm=stringToDouble(s);
print "年首月 = ",(int)(ysm);
s=subString(das1,16,2);
ysd=stringToDouble(s);
print "月首日 = ",(int)(ysd);
s=subString(das1,13,1);
if (s=="a") s="10" ;
nleap=stringToDouble (s);
n=(int)(nleap);
s=subString(das1,12,1);
nleapd=stringToDouble (s) ;
nleapd=(int)nleapd ;
print "nleap = ", n," nleapd = ",nleapd;
if(nleap==0){
ss=subString (das0,10,2)+subString (das1,0,12);
}else {ss=subString(das0,11,1)+subString(das1,0,n)+subString(das1,12,1)+subString(das1,n,12-n);}
if (dy==1919) ss="11010010011011" ;
if (dy==1984) ss="11101100100101" ;
if (dy==2052) ss="11010010010111" ;
das2=ss; //纠正偏差
print "new das2 = ",das2;
print " ";
//**** calculate msd(12) // 年 月朔日$
n0=(int)(ysd); //年首日起算
if (dy-(int)(dy/4)*4==0){leap=1;}else{leap=0;}
//print "leap = ",leap;
if (ysm==1){
s=subString(das2,1,1);
if (s=="1"){n=30;}else{n=29;}
msd[1]=n0;
msd[2]=msd[1]+n-31; }
if (ysm==2){
s=subString(das2,1,1);
if (s=="1"){n=30;}else{n=29;}
msd[1]=31+n0-n;
msd[2]=n0; }
s=subString(das2,2,1);
if (s=="1"){n=30;}else{n=29;}
msd[3]=msd[2]+n-28-leap;
s=subString(das2,3,1);
if (s=="1"){n=30;}else{n=29;}
msd[4]=msd[3]+n-31;
s=subString(das2,4,1);
if (s=="1"){n=30;}else{n=29;}
msd[5]=msd[4]+n-30;
s=subString(das2,5,1);
if (s=="1"){n=30;}else{n=29;}
msd[6]=msd[5]+n-31;
s=subString(das2,6,1);
if (s=="1"){n=30;}else{n=29;}
msd[7]=msd[6]+n-30;
s=subString(das2,7,1);
if (s=="1"){n=30;}else{n=29;}
msd[8]=msd[7]+n-31;
s=subString(das2,8,1);
if (s=="1"){n=30;}else{n=29;}
msd[9]=msd[8]+n-31;
s=subString(das2,9,1);
if (s=="1"){n=30;}else{n=29;}
msd[10]=msd[9]+n-30;
s=subString(das2,10,1);
if (s=="1"){n=30;}else{n=29;}
msd[11]=msd[10]+n-31;
s=subString(das2,11,1);
if (s=="1"){n=30;}else{n=29;}
msd[12]=msd[11]+n-30;
print "全年朔日 : ";
for(i=1;i<13;i++){
print "dm= ",i," ",msd[i];}
getds=" ";
n0=msd[dm]; //msd 月朔日
s=subString(das2,dm-1,1);
if (n0<=1) s=subString (das2,dm,1);
if(s=="1"){n=30;}else{n=29;}
if(n0<=1)n0=n+n0;
if(n0>30)n0=n0-30 ;
msd1=n0;
print "月朔日msd1: ", msd1 ;
string gs1,gs2;
gs1=subString(nlds,(n-n0+1)*2,(n0-1)*2);
gs2=subString(nlds,0,(31-n0+1)*2);
getds=gs1+gs2;
print "getds = "+getds; //农历日$
//农历月名$ ** 1919 1984 2052 rn=2-1
n1=(int)(nleap); //2017 nleap n1=6;
if(ysm==2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ;
if (msd1>22){ // 22-02-01 正月初一
getms=subString(nlms,dm*2+2,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm+1 ; }
} //正月为 2 月份
if(ysm==1){ //正月为 1 月份
if(dm<n1+1){
getms=subString(nlms,dm*2+2,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm ; }
if(dm==n1+1){
getms="闰"+subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2,2);
mdx=dm+1 ; }
if(dm>n1+1){
getms=subString(nlms,dm*2,2);
mss$="闰"+subString(nlms,dm*2-2,2);
mdx=dm ; }
if(dm>n1+2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ; }
}
//y1984 闰10月小, y1919 闰7月大, y2052闰8月小
if(dy==1919||dy==1984||dy==2052){
if(dm<n1+1){ //正月为 2 月份
k=0 ; if (dm>4) k=2 ;
getms=subString(nlms,dm*2+k,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm ;
if (k==2) mdx=dm+1 ; }
if(dm==n1+1){
getms="闰"+subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2,2);
mdx=dm+1 ; }
if(dm>n1+1){
getms=subString(nlms,dm*2,2);
mss$="闰"+subString(nlms,dm*2-2,2);
mdx=dm ; }
if(dm>n1+2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ; }
}
if(dy==2052&&dm==4) {
getms=subString(nlms,dm*2+2,2);
mdx=dm+1 ; }
s1=getms ; //print " 月"
if(s1=="冬月")s1="十一月";
if(s1=="腊月")s1="十二月";
getms=s1 ;
s1=mss$; //print " 月"
if(s1=="冬月")s1="十一月";
if(s1=="腊月")s1="十二月";
mss$=s1 ; //替换
s3=subString(das2,mdx ,1);
if (dy==1984){ s3=subString (das2, dm+1, 1) ; }
if(s3=="1"){s3="大"; chuxi=0; }
else{s3="小"; chuxi=1; }
print "本月 getms = ", getms+" "+s3;
print "上月 mss$ = ", mss$ ;
print "月份 = ",dm," , 农历月 = ",getms+s3;
}//calnlds ()
calendar(){
//计算和显示日历calculate and show calendar *****
calnlds(); //取得农历日$ getms, getds
cs.ClearDraw (0,src); //清屏
string fname;
fname="/storage/emulated/0/jiac.jpg";
cs.DrawBitmap(fname,0,2); //加底图
showVer () ; //显示界面
isdraw=0;
print "show weekday = ",wd; //test
cs.SetTextStyle (1); //粗体
cs.SetStrokeWidth (1);
s=intToString (dm); //print big dm
if (dm<10){sx=250;}else{sx=170;}
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextSize (300); //print big dm
cs.SetColor (80,0,160,0);
cs.DrawText (s,sx-70,595);
cs.SetFillMode (0);//0不填色,1填色
cs.SetTextSize (300); //print big dm
cs.SetColor (200,250,100,0);
cs.DrawText (s,sx-70,595);
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextSize (19);
cs.SetColor (255,255,0,0);
s="星期日";
cs.DrawText (s,33,230);
s="星期六";
cs.DrawText (s,452 ,230);
cs.SetColor(255,0,0,240);
s="星期一 星期二 星期三 星期四 星期五”;
cs.DrawText (s,106, 230);
cs.DrawLine(10,200,540,200);
cs.DrawLine(10,250,540,250);
cs.DrawLine(10,750,690,750);
cs.SetTextSize (66); //print yymm
s=intToString (dy)+" · ";
leap=0;
n=0;
if (dm<10)n=20;
s1=intToString (dm);
cs.SetColor(220,0,90,0);
cs.DrawText (s+s1,250+n+4,180+3);
cs.SetColor(255,0,0,240);
cs.DrawText (s+s1,250+n,180);
cs.SetFillMode (0);//0不填色,1填色
cs.SetColor(255,250,160,0);
cs.DrawText (s+s1,250+n,180); //print yymm
cs.SetColor(255,0,0,240);
cs.SetFillMode (1);//0不填色,1填色
//**** calculate solarterm //show 节气
dy2=intToString(dy); //show 节气
dm2=intToString(dm);
dy1=stringToDouble(dy2);
dm1=stringToDouble(dm2);
cs.SetTextSize (30);
dy0=dy1;
n=dm*2-1;
caljq(); //节气计算
jqd1=(int)(dd1);
jqs1=subString(jname2,0,2);
cs.DrawText (jname2,40,790);
jqss1=jname2;
n=dm*2;
caljq (); //节气计算
jqd2=(int)(dd1);
jqs2=subString(jname2,0,2);
cs.DrawText(jname2,40,830);
jqss2=jname2;
if (dm==12)dzd1=jqd2; //show 九九
print "本年冬至:”,dzd1;
if (dm<4){
n=24;
dy0=dy1-1;
caljq ();
dzd0=(int)(dd1);
print "上年冬至:”,dzd0;}
if(dm==1)s="January";
if(dm==2)s="February";
if(dm==3)s="March";
if(dm==4)s="April";
if(dm==5)s="May";
if(dm==6)s="June";
if(dm==7)s="July";
if(dm==8)s="August";
if(dm==9)s="September";
if(dm==10)s="October";
if(dm==11)s="Novamber";
if(dm==12)s="December";
//sx=(1100-len(s)*20)/2;
cs.SetTextSize (32);
cs.DrawText (s,550,70);
//print 干支年 生肖
if(ysm==2&&dm==1){n=dy-4-1;}else{n=dy-4;}
gzn=(n-n/60*60);
//print "gzn = ",gzn;
ggzs=subString(gzs,gzn*2,2);
//print "gz $ = ",ggzs;
s1=getms+s3;
s=ggzs+"年"+s1 ; //年干支
sxn=gzn-gzn/12*12; //生肖
gsxs=subString(sxs,sxn,1);
ggzs=s+"("+gsxs+")";
cs.SetTextSize (26); //干支年月生肖
cs.DrawText(ggzs,30, 180);
//台历式月历定位打印输出较为复杂,
//下面介绍一种算法,
//输出为 6行 7列,sx=7列, sy=6行,
//x1, y1 调整打印坐标
string nss ; //计算是月天数
double dns ;
nss="00312831303130313130313031" ;
s=subString (nss, dm*2, 2 ) ;
dns=stringToDouble (s) ;
ns=(int)(dns) ;
if (dy/4*4==dy)leap=1;
if (dm==2&&leap==1)ns=29 ;
print "days in month (ns) = ", ns ;
cs.SetColor (255,0,0,240);
fmn=0; k=dd ; //打印月历
for (i=1;i<=ns;i++){//print a.d. print get ms ds $
cs.SetColor (255,0,0,240);
cs.SetTextSize (30);
n=0; setc=0;
sx=(i+wd-1)-((i+wd-1)/7*7); //mod (sx,7)
sy=(i+wd-1)/7;
if (sx==0||sx==6)cs.SetColor(255,255,0,0);
if (i==1&&dy>1948){ //设置节日红色显示
if (dm==1||dm==5||dm==6||dm==7||dm==8||dm==10){ cs.SetColor(255,255,0,0); }
}
if(dm==ysm&&i==ysd-1)cs.SetColor (255,255,0,0);
if(dm==ysm&&i==ysd)cs.SetColor (255,255,0,0);
if (sx==0)fmn=fmn+1; //父亲节母亲节第几周
if (dm==5&&fmn==2&&sx==0)mn=i;
if (dm==6&&fmn==3&&sx==0)fn=i;
//for father mather festival
x1=sx*70+114; //调整打印坐标
y1=sy*80+300;
s=intToString(i);
n=0;
if (len(s)==1)n=10;
cs.DrawText (s,x1+n-70, y1); //print date$
cs.SetTextSize (20);
// **** s="初一"; //打印农历日期 *******
n=0;
s=subString (getds,(i-1)*2,2); //print dd$
s2=s;
if(s=="初一"){
s=getms; //print " m月"
if (ysm==2&&msd1==1&& i>29){
//****y1984-5 y2024-12
s=subString (nlms,dm*2+2,2); }
if(s=="冬月")s="十一月";
if(s=="腊月")s="十二月"; }
//**** show festival ***************
//**** output solarterm on table
if(i==jqd1)s=jqs1;
if(i==jqd2)s=jqs2;
// print mn,fn;
if(dm==1&&i==1) s="元旦节";
if(dm==ysm&&i==ysd-1)s="除夕";
if(dm==ysm&&i==ysd)s="春节";
if (dy>1948){
if(dm==2&&i==14)s="情人节";
if(dm==3&&i==8)s="妇女节";
if(dm==3&&i==12)s="植树节";
if(dm==5&&i==1)s="劳动节";
if(dm==5&&i==4)s="青年节";
if(dm==5&&i==mn)s="母亲节";
if(dm==6&&i==fn)s="父亲节";
if(dm==6&&i==1)s="儿童节";
if(dm==7&&i==1)s="建党节";
if(dm==8&&i==1)s="建军节";
if(dm==9&&i==10)s="教师节";
if(dm==10&&i==1) s="国庆节";
}
if(dm==12&&i==25) s="圣诞节";
if(getms=="二月"&&s2=="十五"&& i<msd1){s="元宵节";setc=12;}
if(getms=="正月"&&s2=="十五"&& i>msd1){s="元宵节";setc=12;}
if(getms=="三月"&&s2=="初二"&& i<msd1)s="龙抬头";
if(getms=="二月"&&s2=="初二"&& i>msd1)s="龙抬头";
if(getms=="六月"&&s2=="初五"&& i<msd1){s="端'午节"; setc=12;}
if(getms=="五月"&&s2=="初五"&& i>msd1){s="端午节"; setc=12;}
if(getms=="八月"&&s2=="初七"&&i<msd1)s="七夕节";
if(getms=="七月"&&s2=="初七"&&i>msd1)s="七夕节";
if(getms=="八月"&&s2=="十五"&&i<msd1)s="中元节";
if(getms=="七月"&&s2=="十五"&&i>msd1)s="中元节";
if(getms=="九月"&&s2=="十五"&&i<msd1){s="中秋节"; setc=12; s6=s ; }
s6="" ;
if(getms=="八月"&&s2=="十五"&& i>msd1){s="中秋节"; setc=12; s6=s ; }
if(dm==10&&i==1){ s="国庆节"; }
if(getms=="十月"&&s2=="初九"&& i<msd1){s="重阳节"; setc=12;}
if(getms=="九月"&&s2=="初九"&& i>msd1){s="重阳节";setc=12;}
if(getms=="正月"&&s2=="初八"&&i<msd1)s="腊八节";
if(getms=="十二月"&&s2=="初八"&&i>msd1)s="腊八节";
if(getms=="正月"&&s2=="廿三"&& i<msd1)s="小年";
if(getms=="十二月"&&s2=="廿三"&& i>msd1)s="小年";
if (i==(msd1-1)&&chuxi==1&&s1=="十二月"&&s2=="廿九"&&dm<2)s="除夕";
if (setc==12)cs.SetColor (255,255,0,0);
if (len(s)==3)n=10;
cs.DrawText(s,x1-2-n-70, y1+30); //print ch
if (dd==i) fd$=s ; //get fd day ****
if(dd==i){ //draw today mark ****
cs.SetFillMode (0) ;
cs.SetColor (255,250,0,0);
cs.DrawRect (x1-80,y1-30,x1-25,y1+10);
cs.SetFillMode (1) ;
cs.SetColor (100,250,250,20);
cs.DrawRect (x1-80,y1-30,x1-25,y1+10); }
} //print a.d. dd$ festival
printBday() ; //print today big dd
//calculate GZ,gzy,gzm,gzd,alln
print "节气日 : ",jqd1;
alln1=alln1+dd-1; //all days
n=(dy+2096);
if(dm<2)n=n-1;
if(dm==2&&dd<jqd1)n=n-1;
gzy=n-(int)(n/60*60);
s1=subString(gzs,gzy*2,2);
if(dd<jqd1){mz=1;}else{mz=0;}
gzn1=(dy+2096)*12+dm-mz;
gzm=gzn1-(int)(gzn1/60*60);
s2=subString (gzs,gzm*2,2);
n1=alln1+9;
gzd=n1-(int)(n1/60*60);
s3=subString(gzs,gzd*2,2);
gzh=(gzd-(int)(gzd/5*5))*12;
s4=subString(gzs,gzh*2,2);
cs.SetColor(255,255,0,240);
cs.SetTextSize(27);
dd2=intToString(dd); //this day $
if(len(dd2)==1)dd2="0"+dd2;
s="日期 : "+dy2+" 年 "+dm2+" 月 "+dd2+ " 日";
cs.DrawText(s,40,870);
gzys=s1;
gzms=s2;
gzds=s3;
gzhs=s4;
s="八字 : "+s1+" "+s2+" "+s3+" "+s4;
bzs=s; //bazi y,m,d,h
cs.DrawText(s,40,910);
print bzs;
x0=400;
y0=787;
cs.SetTextSize(24);
s="起时 : ";
cs.DrawText(s,400,y0);
s="23 - 1 11 - 13";
cs.DrawText(s,400,y0+30);
s=" 1 - 3 13 - 15";
cs.DrawText(s,400,y0+60);
s=" 3 - 5 15 - 17";
cs.DrawText(s,400,y0+90);
s=" 5 - 7 17 - 19";
cs.DrawText(s,400,y0+120);
s=" 7 - 9 19 - 21";
cs.DrawText(s,400,y0+150);
s=" 9 - 11 21 - 23";
cs.DrawText(s,400,y0+180);
string ws1,ws2 ;
for(i=0;i<6;i++){
ws1=subString(gzs,(gzh+i)*2,2);
ws2=subString(gzs,(gzh+6+i)*2,2);
s=ws1+" "+ws2;
cs.DrawText(s,480,y0+30+i*30); }
//八字五行十二建二十八宿
//string s11, s12, s13, s14 ;
s=" " ; ss=" " ; //与数伏有冲突置空
cs.SetTextSize (24);
s11=subString (whss,(gzy/2)*3,3);
s12=subString (whss,(gzm/2)*3,3);
s13=subString (whss,(gzd/2)*3,3);
s14=subString (whss,(gzh/2)*3,3);
s="年 : "+s1+s11; //show 五行
cs.DrawText (s,510,640);
s="月 : "+s2+s12;
cs.DrawText (s,510,670);
s="日 : "+s3+s13 ;
cs.DrawText (s,510,700);
s="时 : "+s4+s14;
cs.DrawText (s,510,730);
n=alln1+3; //print 28stars
n1=n-n/28*28;
s5=subString (st28ss,n1,1);
cs.DrawText (ss,657,660);
n=alln1-(dy-1900)*12-dm+10; //show 12建日
if (dd>=jqd1)n=n-1;
n1=n-n/12*12;
s6=s5+subString(g12ss,n1,1);
cs.DrawText (s6,667,700);
//**** print BZwh八字五行,九九,,梅天,伏天
print_bzjjff ( ) ;
//*********************
setDisplay (1);
cs.Update ();
}//calendar () ***********************
printBday(){ //print today big dd
n0=wd+dd-1 ;
n1=n0-n0/7*7 ;
wds=subString(wdss,n1*3,3) ;
s=intToString (dd) ;
if (dd<10) { n=45 ; }else{ n=0 ; }
cs.SetColor (255,0,100,0);
cs.SetTextSize (120);
cs.DrawText(s, 555+n, 195 ); //字阴影
if (n1==0||n1==6) { cs.SetColor (255,255,0,0); }
else { cs.SetColor (255,0,0,240); }
if (dd==1&&dy>1948){ //设置节日红色显示
if (dm==1||dm==5||dm==6||dm==7||dm==8||dm==10){ cs.SetColor(255,255,0,0); }
}
if(dm==ysm&&dd==ysd-1)cs.SetColor (255,255,0,0);
if(dm==ysm&&dd==ysd)cs.SetColor (255,255,0,0);
cs.SetTextSize (120);
cs.DrawText(s, 550+n, 190 ); //字本色
if (n1==0||n1==6) { cs.SetColor (255,255,0,0); }
else { cs.SetColor (255,0,0,240); }
cs.SetTextSize (28);
cs.DrawText(wds , 590, 280 );
cs.SetFillMode (0);//0不填色,1填色
if (n1==0||n1==6) { cs.SetColor (255,250,250,0); }
else { cs.SetColor (255,250,160,0); }
cs.SetTextSize (120);
cs.DrawText(s, 550+n, 190 ); //字金线
cs.SetTextSize (28);
cs.DrawText(wds , 590, 280 );
cs.SetFillMode (1); //0不填色,1填色
if (n1==0||n1==6) { cs.SetColor (255,250,0,0); }
else { cs.SetColor (255,0,0,240); }
cs.SetTextSize (26);
s1=getds ;
s2=subString (s1 , dd*2-2, 2) ;
ss=getms ; //本月
if (msd1==1&& dd>30){ //y1984-5-31月尾初日
ss=subString (nlms,dm*2+2,2); }
if (dd<msd1) ss=mss$ ; //上月
if(ss=="冬月")ss="十一月";
if(ss=="腊月")ss="十二月";
ss=ss+s2 ;
n=len(ss) ;
cs.DrawText(ss , 620-n*10, 240 ); //ch yymm
cs.SetColor (255,250,0,240) ;
if (dd==jqd1) { //节气
ss="今日"+jqs1 ;
cs.DrawText(ss , 580, 360 ); }
if (dd==jqd2) {
ss="今日"+jqs2 ;
cs.DrawText(ss , 580, 360 ); }
cs.SetTextSize (30);
if (fd$==jqs1||fd$==jqs2) fd$=" " ;
s4=subString (fd$, 0, 1) ;
if (s4=="初"||s4=="十"||s4=="廿"||s4=="二"||s4=="三"){ fd$=" " ; }
s4=subString (fd$, 1, 1) ;
s5=subString (fd$, 2, 1) ;
if (s4=="月"||s5=="月") fd$=" " ; //只显示节日
fd$=fd$+s6 ;
n=len(fd$) ; s6=" " ; //节日
cs.DrawText(fd$ , 621-n*11.2, 320 );
// cs.Update() ;
}//printBday()
print_bzjjff ( ){
//show BZ & 九九三伏入梅出梅
//芒种后丙日入梅,小暑后未日出梅
//连冬起九, 冬至日为一九第一天
int jjiu,jiu1,jiu2; //print and show 九九
string jius;
jius="一二三四五六七八九";
if (dm>11&&dd>=dzd1||dm<4){
if(dm==12&&dd>=dzd1)jjiu=dd-dzd1;
if(dm==1)jjiu=31-dzd0+dd;
if(dm==2)jjiu=31-dzd0+31+dd;
if(dm==3&&dd<13)jjiu=31-dzd0+31+28+dd;
jiu2=jjiu-(int)(jjiu/9*9)+1;
jiu1=(int)(jjiu/9)+1;
print "jiu1 = ",jiu1," jiu2 = ",jiu2;
s0=subString (jius,jiu1-1,1);
s=intToString (jiu2);
ss=s0+"九第 "+s+" 天 ";
if(jjiu>80)ss=" ";
print jjiu;
print ss;
if (dm==3&&dd>12)ss=" ";
cs.SetTextSize (26);
cs.DrawText (ss,570,390);
} //show jiujiu$
ss=" "; // gzds=s3 ;
if (dm==6&&dd>4&&dd<17){
s0=subString (s3,0,1);
if (s0=="丙"){ ss="今日入梅";}else{ss=" ";
print s0 ; }
cs.DrawText (ss,583,330); }
if (dm==7&&dd>=6&&dd<18){
//** 20240706小暑出梅同日故 dd>=6
s0=subString (s3,1,1);
if (s0=="未"){ ss="今日出梅";}else{ss=" ";}
cs.DrawText (ss,583,330); }
//show fu day ******
//夏至后第三个庚日起10天为初伏
//夏至后第四个庚日到立秋后第一个庚日为中伏
//立秋后第一个庚日起10天为末伏
int fn;
string fu1,fu2,fu3;
fu1="初伏第";
fu2="中伏第";
fu3="末伏第";
n=(dd-dd/10*10)-((gzd-gzd/10*10)-6);
if (n<10)n=n+10;
print n," 日干支 庚日 ",gzd;
if (dm==7&&dd>n-1){
n0=dd-n+1;
print n0;
if (dd>n-1&&dd<=n+9){
s=fu1+intToString (n0);}
if (dd>n+9){
s=fu2+intToString (n0-10);}
ss=s+"天";
cs.DrawText (ss,575,390); }
if (dm==8){
if (dd<n+10){
n0=31-n-10+dd;
if (dd<n)
{ss=fu2+intToString (n0)+"天"; }
if (dd>=n){ss=fu3+intToString (n0-20)+"天";}
cs.DrawText (ss,575, 390); }
} //show three fu day
}//print_bzjjff ()
myToolBarProc(int nBtn,int nContext) {
if(nBtn==100){//计算星期, 显示月历
inputDate () ;
calendar();
}
if(nBtn==101){//显示月历
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
getWeekday ();
calendar () ;
}
if(nBtn==102){//上一月
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
dm=dm-1 ;
if (dm<1) { dy=dy-1 ; dm=12 ; }
if (dm==2&&dd>28){ dd=28 ; }
if (dd>30){ dd=30 ; }
getWeekday ();
calendar () ;
}
if(nBtn==103){//下一月
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
dm=dm+1 ;
if (dm>12) { dy=dy+1 ; dm=1; }
if (dm==2&&dd>28){ dd=28 ; }
if (dd>30){ dd=30 ; }
getWeekday ();
calendar () ;
}
if(nBtn==104){//退出程序
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
if(nBtn==105){//空
setDisplay (0);
}
}//Toolbar () ***********************
caljq(){//calculate solar ** return jname2
juD=dy0*(365.2423112-0.000000000000064
*(dy0-100)*(dy0-100)- 0.00000003047
*(dy0-100))+15.218427*n+1721050.71301;
//juD=juD-0.00215;
tht=0.0003*dy0-0.372781384-0.2617913325*n;
yrD=(1.945*sin(tht)-0.01206*sin(2*tht))
*(1.048994-0.00002583 *dy0);
sD=-0.0018*sin(2.313908653*dy0
-0.439822951-3.0443*n);
//'vs = juD '** 平气
vs = (juD + yrD + sD); // '** 定气
dalt=-15+(juD-2382148)*(juD-2382148)/41048480;
//print dalt;
dalt = dalt/86400;
//print dalt;
jd = vs - 0.5 - dalt-0.025;
int gg;
gg=n-(int)(n/2*2);
jdtoGD ();
//jqs1=subString (jqnames,(n-1)*2,2);
//print "jqs1 = ",jqs1;
s=jqs1+" " +jname2;
//print jname2;
}//caljq() ***********************************
//calculate jd to GD ** return jname2 *****
jdtoGD(){
double a,b,c,d,e;
double F;
double allss;
F=jd-(int)(jd);
//print " ";
//print " JD = ",jd;
//print " 时分秒 日小数 = ",F;
a=(int)(jd+0.5);
b=a+1537;
c=(int)((b-122.1)/365.25);
d=(int)(365.25*c);
e=(int)((b-d)/30.6001);
dd1=b-d-(int)(30.6001*e);
dm1=e-1-(int)((e/14)*12);
dy1=c-4715-(int)((7+dm1)/10);
//print a," ",b," ",c," ",d," ",e;
dy2=intToString (dy);
dm2=intToString (dm);
dd2=doubleToString (dd1);
if (len(dm2)==1)dm2="0"+dm2;
if (dd1<10)dd2="0"+dd2;
dd2=subString (dd2,0,2);
//print dy2+" 年 "+dm2+" 月 "+dd2+" 日 ";
if(n==24)jqdn=(int)(dd1);
if (n==24&&dm1<3)jqdn=jqdn+1;
//日allss 的小数转为时分秒
allss=(int)((jd-a)*86400+43200.5);
//print "allss = ", allss;
hh1=(int)(allss/3600);
mm1=(int)((allss-hh1*3600)/60);
ss1=(int)(allss-hh1*3600-mm1*60);
if(ss1>=60){
ss1=ss1-60;
mm1=mm1+1;}
if(mm1>=60){
mm1=mm1-60;
hh1=hh1+1;}
//print "JD 转为 GD,计算结果:”;
hh2=doubleToString(hh1);
mm2=doubleToString(mm1);
ss2=doubleToString(ss1);
if(hh1<10){
hh2="0"+doubleToString(hh1);}
if(mm1<10){
mm2="0"+doubleToString(mm1);}
if(ss1<10){
ss2="0"+doubleToString(ss1);}
hh2=subString (hh2,0,2);
mm2=subString (mm2,0,2);
ss2=subString (ss2,0,2);
jname1=subString(jqnames,(n-1)*2,2);
//print "节气 : ",jname1;
jname2=jname1+" > "+dm2+"-"+dd2+" "+hh2+":"+mm2+":"+ss2;
//return jname2;
}//jdtoGD() **************
readDat(){
daList[1899] = "101010110101000210";
daList[1900] = "010010111101080131";
daList[1901] = "010010101110000219";
daList[1902] = "101001010111000208";
daList[1903] = "010100100110050129";
daList[1904]= "110100100110000216";
daList[1905] = "110110010101000204";
daList[1906]= "011010101010140125";
daList[1907] = "010101101010000213";
daList[1908] = "100110101101000202";
daList[1909]= "010010101110020122";
daList[1910]= "010010101110000210";
daList[1911] = "101001001101060130";
daList[1912]= "101001001101000218";
daList[1913]= "110100100101000206";
daList[1914] = "110101010100150126";
daList[1915]= "101101010101000214";
daList[1916]= "010101101010000204";
daList[1917]= "100101101101020123";
daList[1918]= "100101011011000211";
daList[1919]= "010010011011170201";
daList[1920]= "010010011011000220";
daList[1921]= "101001001011000208";
daList[1922]= "101100100101050128";
daList[1923]= "011010100101000216";
daList[1924] = "011011010100000205";
daList[1925] = "101011011010140124";
daList[1926] = "001010110110000213";
daList[1927] = "100101010111000202";
daList[1928]= "010010010111020123";
daList[1929]= "010010010111000210";
daList[1930] = "011001001011060130";
daList[1931] = "110101001010000217";
daList[1932] = "111010100101000206";
daList[1933] = "011011010100150126";
daList[1934] = "010110101101000214";
daList[1935] = "001010110110000204";
daList[1936]= "100100110111130124";
daList[1937] = "100100101110000211";
daList[1938]= "110010010110170131";
daList[1939] = "110010010101000219";
daList[1940] = "110101001010000208";
daList[1941]= "110110001010160127";
daList[1942] = "101101010101000215";
daList[1943]= "010101101010000205";
daList[1944] = "101010101101140125";
daList[1945]= "001001011101000213";
daList[1946] = "100100101101000202";
daList[1947]= "110010010101020122";
daList[1948]= "101010010101000210";
daList[1949]= "101101010101070129";
daList[1950] = "011011001010000217";
daList[1951] = "101101010101000206";
daList[1952] = "010101011010150127";
daList[1953]= "010011011010000214";
daList[1954]= "101001011011000203";
daList[1955]= "010100101011130124";
daList[1956] = "010100101011000212";
daList[1957] = "101010010101080131";
daList[1958] = "111010010101000218";
daList[1959]= "011010101010000208";
daList[1960]= "101011010101060128";
daList[1961] = "101010110101000215";
daList[1962] = "010010110110000205";
daList[1963] = "101001010111040125";
daList[1964]= "101001010111000213";
daList[1965]= "010100100110000202";
daList[1966]= "111010010011030121";
daList[1967] = "110110010101000209";
daList[1968]= "010110101010070130";
daList[1969] = "010101101010000217";
daList[1970]= "100101101101000206";
daList[1971]= "010010101110050127";
daList[1972]= "010010101101000215";
daList[1973]= "101001001101000203";
daList[1974]= "110100100110040123";
daList[1975]= "110100100101000211";
daList[1976]= "110101010010080131";
daList[1977]= "101101010100000218";
daList[1978]= "101101101010000207";
daList[1979]= "100101101101160128";
daList[1980]="100101011011000216";
daList[1981]="010010011011000205";
daList[1982]="101011001011040125";
daList[1983]="101001001011000213";
daList[1984]="1011001001110a0202";
daList[1985]="011010100101000220";
daList[1986]="011011010100000209";
daList[1987]="101011011010060129";
daList[1988]="101010110110000217";
daList[1989]="100100110111000206";
daList[1990]="010010010111050127";
daList[1991]="010010010111000215";
daList[1992]="011001001011000204";
daList[1993]="011010100101030123";
daList[1994]="111010100101000210";
daList[1995]="011010110010080131";
daList[1996]="010110101100000219";
daList[1997]="101010110110000207";
daList[1998]="100101101101050128";
daList[1999]="100100101110000216";
daList[2000]="110010010110000205";
daList[2001]="110101001010040124";
daList[2002]="110101001010000212";
daList[2003]="110110100101000201";
daList[2004]="010110101010020122";
daList[2005]="010101101010000209";
daList[2006]="101010111011070129";
daList[2007]="001001011101000218";
daList[2008]="100100101101000207";
daList[2009]="110010101011050126";
daList[2010]="101010010101000214";
daList[2011]="101101001010000203";
daList[2012]="101110101010040123";
daList[2013]="101011010101000210";
daList[2014]="010101011101090131";
daList[2015]="010010111010000219";
daList[2016]= "101001011011000208";
daList[2017]= "010100010111160128";
daList[2018]= "010100101011000216";
daList[2019]= "101010010011000205";
daList[2020]= "011110010101040125";
daList[2021]= "011010101010000212";
daList[2022]= "101011010101000201";
daList[2023]= "010110110101020122";
daList[2024]= "010010110110000210";
daList[2025]= "101001101110060129";
daList[2026]= "101001001110000217";
daList[2027]= "110100100110000206";
daList[2028]= "111010100110050126";
daList[2029]= "110101010011000213";
daList[2030]= "010110101010000203";
daList[2031] = "011101101010030123";
daList[2032]= "100101101101000211";
daList[2033] = "010010111101070131";
daList[2034]= "010010101101000219";
daList[2035] = "101001001101000208";
daList[2036]= "110100001011060128";
daList[2037]= "110100100101000215";
daList[2038] = "110101010010000204";
daList[2039] = "110111010100050124";
daList[2040]= "101101011010000212";
daList[2041]= "010101101101000201";
daList[2042]= "010101011011020122";
daList[2043]= "010010011011000210";
daList[2044]= "101001010111070130";
daList[2045]= "101001001011000217";
daList[2046]= "101010100101000206";
daList[2047] = "101100100101150126";
daList[2048] = "011011010010000214";
daList[2049] = "101011011011000202";
daList[2050]= "011101101010050124";
daList[2051]= "100100110111000211";
daList[2052]= "010010011111080201";
daList[2053] = "010010010111000219";
daList[2054]= "011001001011000208";
daList[2055] = "011010001010160128";
daList[2056] = "111010100101000215";
daList[2057]= "011010110010000204";
daList[2058] = "101001111100140124";
daList[2059] = "101010101110000212";
daList[2060]= "100100101110000202";
daList[2061]= "110100101110030121";
daList[2062] = "110010010110000209";
daList[2063] = "110101010101070129";
daList[2064]= "110101001010000217";
daList[2065] = "110110100101000205";
daList[2066]= "010111010101050126";
daList[2067] = "010101101010000214";
daList[2068]= "101001101101000203";
daList[2069]= "010101011101040123";
daList[2070]= "010101101101000211";
daList[2071] = "101010011011080131";
daList[2072] = "101010010101000219";
daList[2073]= "101101001010000207";
daList[2074] = "101101101010060127";
daList[2075] = "101011010101000215";
daList[2076] = "010101011010000205";
daList[2077] = "101010111010040124";
daList[2078]= "101001011011000212";
daList[2079]= "010100101011000202";
daList[2080] = "101100100111030122";
daList[2081]= "011010010011000209";
daList[2082] = "011100110011070129";
daList[2083] = "011010101010000217";
daList[2084]= "101011010101000206";
daList[2085] = "010010110101150126";
daList[2086]= "010010110110000214";
daList[2087]= "101001010111000203";
daList[2088]= "010101001110040124";
daList[2089] = "110100010110000210";
daList[2090]= "111010010110080130";
daList[2091]= "110101010010000218";
daList[2092] = "110110101010000207";
daList[2093]= "011010101010060127";
daList[2094] = "010101101101000215";
daList[2095]= "010010101110000205";
daList[2096]= "101010011101040125";
daList[2097] = "101001001101000212";
daList[2098] = "110100010101000201";
daList[2099] = "111100100101020121";
daList[2100] = "110101010010000209";
return;
}
//**** END ****