Beispiel #1
0
        /// <summary>
        /// 计算世界时与原子时之差,传入年
        /// </summary>
        /// <param name="y">年</param>
        /// <returns></returns>
        public static double deltatT(double y)
        {
            if (y >= 2005)
            {
                //sd 是2005年之后几年(一值到y1年)的速度估计。
                //jsd 是y1年之后的加速度估计。瑞士星历表jsd=31,NASA网站jsd=32,skmap的jsd=29
                double y1 = 2014, sd = 0.4, jsd = 31;
                if (y <= y1)
                {
                    return(64.7 + (y - 2005) * sd);                            //直线外推
                }
                double v  = JD.deltatExt(y, jsd);                              //二次曲线外推
                double dv = JD.deltatExt(y1, jsd) - (64.7 + (y1 - 2005) * sd); //y1年的二次外推与直线外推的差
                if (y < y1 + 100)
                {
                    v -= dv * (y1 + 100 - y) / 100;
                }
                return(v);
            }
            int i;

            double[] d = JD.dts;
            for (i = 0; i < d.Length; i += 5)
            {
                if (y < d[i + 5])
                {
                    break;
                }
            }
            double t1 = (y - d[i]) / (d[i + 5] - d[i]) * 10, t2 = t1 * t1, t3 = t2 * t1;

            return(d[i + 1] + d[i + 2] * t1 + d[i + 3] * t2 + d[i + 4] * t3);
        }
Beispiel #2
0
        /// <summary>
        /// 把太阳月亮信息形成纯文本字符串
        /// </summary>
        /// <param name="fs">是否显示ΔT, 黄经章等信息</param>
        /// <returns></returns>
        public string toText(double fs)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("平太阳 " + JD.timeStr(this.pty) + " 真太阳 " + JD.timeStr(this.zty) + "\r\n");
            sb.Append("时差 " + LunarHelper.m2fm(this.sc * 86400, 2, 1) + " 月亮被照亮 " + (this.mIll * 100).ToString("F2") + "% ");
            sb.Append("\r\n");

            sb.Append("\r\n表一       月亮            太阳\r\n");
            sb.Append("视黄经 " + LunarHelper.rad2str(this.mHJ, 0) + "  " + LunarHelper.rad2str(this.sHJ, 0) + "\r\n");
            sb.Append("视黄纬 " + LunarHelper.rad2str(this.mHW, 0) + "  " + LunarHelper.rad2str(this.sHW, 0) + "\r\n");
            sb.Append("视赤经 " + LunarHelper.rad2str(this.mCJ, 1) + "  " + LunarHelper.rad2str(this.sCJ, 1) + "\r\n");
            sb.Append("视赤纬 " + LunarHelper.rad2str(this.mCW, 0) + "  " + LunarHelper.rad2str(this.sCW, 0) + "\r\n");
            sb.Append("距离     " + this.mR.ToString("F0") + "千米          " + this.sR.ToString("F6") + "AU" + "\r\n");

            sb.Append("\r\n表二       月亮            太阳\r\n");
            sb.Append("方位角 " + LunarHelper.rad2str(this.mPJ, 0) + "  " + LunarHelper.rad2str(this.sPJ, 0) + "\r\n");
            sb.Append("高度角 " + LunarHelper.rad2str(this.mPW, 0) + "  " + LunarHelper.rad2str(this.sPW, 0) + "\r\n");
            sb.Append("时角   " + LunarHelper.rad2str(this.mShiJ, 0) + "  " + LunarHelper.rad2str(this.sShiJ, 0) + "\r\n");
            sb.Append("视半径(观测点) " + LunarHelper.m2fm(this.mRad, 2, 0) + "     " + LunarHelper.m2fm(this.sRad, 2, 0) + "\r\n");

            if (fs != 0)
            {
                sb.Append("\r\n力学时 " + JD.setFromJD_str(this.T + LunarHelper.J2000));
                sb.Append(" ΔT=" + (this.dt * 86400).ToString("F1") + "秒\r\n");
                sb.Append("黄经章 " + (this.dL / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" ");
                sb.Append("交角章 " + (this.dE / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" ");
                sb.Append("\r\nε=" + LunarHelper.trim(LunarHelper.rad2str(this.E, 0)));
            }
            return(sb.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// 按交节干支生成 html 年历
        /// </summary>
        /// <param name="y"></param>
        /// <returns></returns>
        public string nianLi2HTML(double y)
        {
            int           i, j;
            StringBuilder s = new StringBuilder();     // C#: 为提高字符串处理效率, 使用 StringBuilder
            StringBuilder s1 = new StringBuilder();    // C#: 为提高字符串处理效率, 使用 StringBuilder
            double        v, v2, qi = 0;

            SSQ.calcY(LunarHelper.int2((y - 2000) * 365.2422 + 180));
            for (i = 0; i < 14; i++)
            {
                if (SSQ.HS[i + 1] > SSQ.ZQ[24])
                {
                    break;                             //已包含下一年的冬至
                }
                if (SSQ.leap != 0 && i == SSQ.leap)
                {
                    s1.Append("闰");
                }
                else
                {
                    s1.Append("·");
                }
                s1.Append(SSQ.ym[i]);
                if (s1.ToString().Length < 3)
                {
                    s1.Append("月");
                }
                s1.Append(SSQ.dx[i] > 29 ? "大" : "小");
                v = SSQ.HS[i] + LunarHelper.J2000;
                s1.Append(" " + obb.Gan[(int)((v + 9) % 10)] + obb.Zhi[(int)((v + 1) % 12)]);
                s1.Append(" " + JD.setFromJD_str(v).Substring(6, 5));

                for (j = -2; j < 24; j++)
                {
                    if (j >= 0)
                    {
                        qi = SSQ.ZQ[j];
                    }
                    if (j == -1)
                    {
                        qi = SSQ.ZQ.pe1;
                    }
                    if (j == -2)
                    {
                        qi = SSQ.ZQ.pe2;
                    }

                    if (qi < SSQ.HS[i] || qi >= SSQ.HS[i + 1])
                    {
                        continue;
                    }
                    v2 = qi + LunarHelper.J2000;
                    s1.Append(" " + obb.rmc[(int)(v2 - v)] + obb.Gan[(int)((v2 + 9) % 10)] + obb.Zhi[(int)((v2 + 1) % 12)]);
                    s1.Append(obb.jqmc[(j + 24) % 24] + JD.setFromJD_str(qi + LunarHelper.J2000).Substring(6, 5));
                }
                s.Append(s1.ToString() + "<br>");
                s1.Remove(0, s1.Length);     // C#: 在转换时将原来的字符串 s1 改写为 StringBuiler, 因此添加本句
            }
            return(s.ToString());
        }
Beispiel #4
0
        /// <summary>
        /// 命理八字计算(普通计算, 不转换为当地真太阳时), 并保存到日对象 ob 中
        /// </summary>
        /// <param name="jd">格林尼治UT(J2000起算)</param>
        /// <param name="J">本地经度</param>
        /// <param name="ob">日对象</param>
        /// <param name="southernHemisphere">南半球的标志</param>
        public static void mingLiBaZiNormal(double jd, double J, OB ob, BaZiTypeS baziTypeS)
        {
            int    i;
            string c;
            double v;
            double jd2 = jd + JD.deltatT2(jd);                                               // 力学时
            double w   = XL.S_aLon(jd2 / 36525, -1);                                         // 此刻太阳视黄经
            double k   = LunarHelper.int2((w / LunarHelper.pi2 * 360 + 45 + 15 * 360) / 30); // 1984年立春起算的节气数(不含中气)

            //----------------------------------------------------------------------------------------------
            // C#: 注: 仅有下列代码段与 mingLiBaZi 方法中的代码不同, 其余部分都是相同的
            //----------------------------------------------------------------------------------------------
            jd       += 0 - J / Math.PI / 2;                                 // 将格林尼治UT(J2000起算), 转换为本地时间, 不必考虑真太阳与平太阳时之间的时差
            ob.bz_zty = "";                                                  // 真太阳时置空串
            ob.bz_pty = JD.timeStr(jd);                                      // 计算平太阳时

            jd += 13d / 24d;                                                 // 转为前一日23点起算(原jd为本日中午12点起算)   // C#: 注意数据类型
            double D = Math.Floor(jd), SC = LunarHelper.int2((jd - D) * 12); // 日数与时辰

            v = LunarHelper.int2(k / 12 + 6000000); ob.bz_jn = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)];
            v = k + 2 + 60000000; ob.bz_jy = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)];

            // C#: 新增的代码段, 计算南半球八字(仅纪月不同)
            switch (baziTypeS)
            {
            case BaZiTypeS.TianChongDiChong:
                ob.bz_jy = obb.Gan[(int)((v + 4) % 10)] + obb.Zhi[(int)((v + 6) % 12)];
                break;

            case BaZiTypeS.TianKeDiChong:
                ob.bz_jy = obb.Gan[(int)((v + 6) % 10)] + obb.Zhi[(int)((v + 6) % 12)];
                break;

            case BaZiTypeS.TianTongDiChong:
                ob.bz_jy = obb.Gan[(int)((v + 0) % 10)] + obb.Zhi[(int)((v + 6) % 12)];
                break;

            default:
                break;
            }


            v = D - 6 + 9000000; ob.bz_jr = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)];
            v = (D - 1) * 12 + 90000000 + SC; ob.bz_js = obb.Gan[(int)(v % 10)] + obb.Zhi[(int)(v % 12)];

            v       -= SC;
            ob.bz_JS = "";    // 全天纪时表
            for (i = 0; i < 13; i++)
            {
                // 一天中包含有13个纪时
                c = obb.Gan[(int)((v + i) % 10)] + obb.Zhi[(int)((v + i) % 12)];  // 各时辰的八字
                if (SC == i)
                {
                    ob.bz_js = c;
                    // c = "<font color=red>" + c + "</font>";   //红色显示这时辰   // C#: 注释, 即取消格式显示
                }
                ob.bz_JS += (i != 0 ? " " : "") + c;
            }
        }
Beispiel #5
0
        /// <summary>
        /// 多天升中降计算,jd是当地起始儒略日(中午时刻),sq是时区
        /// </summary>
        /// <param name="jd"></param>
        /// <param name="n"></param>
        /// <param name="Jdl"></param>
        /// <param name="Wdl"></param>
        /// <param name="sq"></param>
        public static void calcRTS(double jd, double n, double Jdl, double Wdl, double sq)
        {
            int    i;
            double c;
            LunarInfoListT <double> r;     // C#: 不需要实例化, 因此注释语句的后半部分:  = new LunarInfoListT<double>(3, 0d);

            // C#: 由于将 rts 设置为自动实现的公共属性, 故添加了以下代码段来初始化
            if (SZJ.rts == null)
            {
                SZJ.rts = new LunarInfoListT <LunarInfoListT <double> >();
            }

            if (SZJ.rts.Count == 0)
            {
                for (i = 0; i < 31; i++)
                {
                    SZJ.rts.Add(new LunarInfoListT <double>());
                    // SZJ.rts[i] = new LunarInfoListT();
                }
            }
            SZJ.L = Jdl; SZJ.fa = Wdl; sq /= 24; //设置站点参数
            for (i = 0; i < n; i++)
            {
                r = SZJ.rts[i]; r.Ms = r.Mz = r.Mj = "";
            }
            for (i = -1; i <= n; i++)
            {
                if (i >= 0 && i < n)
                {
                    //太阳
                    r = SZJ.St(jd + i + sq);
                    ((SZJ.rts[i])).s  = JD.timeStr(r.s__ - sq);          //升
                    ((SZJ.rts[i])).z  = JD.timeStr(r.z__ - sq);          //中
                    ((SZJ.rts[i])).j  = JD.timeStr(r.j__ - sq);          //降
                    ((SZJ.rts[i])).c  = JD.timeStr(r.c__ - sq);          //晨
                    ((SZJ.rts[i])).h  = JD.timeStr(r.h__ - sq);          //昏
                    ((SZJ.rts[i])).ch = JD.timeStr(r.h__ - r.c__ - 0.5); //光照时间,timeStr()内部+0.5,所以这里补上-0.5
                    ((SZJ.rts[i])).sj = JD.timeStr(r.j__ - r.s__ - 0.5); //昼长
                }
                r = SZJ.Mt(jd + i + sq);                                 //月亮
                c = LunarHelper.int2(r.s__ - sq + 0.5) - jd; if (c >= 0 && c < n)
                {
                    (SZJ.rts[(int)c]).Ms = JD.timeStr(r.s__ - sq);
                }
                c = LunarHelper.int2(r.z__ - sq + 0.5) - jd; if (c >= 0 && c < n)
                {
                    (SZJ.rts[(int)c]).Mz = JD.timeStr(r.z__ - sq);
                }
                c = LunarHelper.int2(r.j__ - sq + 0.5) - jd; if (c >= 0 && c < n)
                {
                    (SZJ.rts[(int)c]).Mj = JD.timeStr(r.j__ - sq);
                }
            }
            SZJ.rts.dn = n;
        }
Beispiel #6
0
        /// <summary>
        /// 较高精度朔计算
        /// </summary>
        /// <param name="W"></param>
        /// <returns></returns>
        private static double so_high(double W)
        {
            double t = XL.MS_aLon_t2(W) * 36525;

            t = t - JD.deltatT2(t) + 8d / 24d;
            double v = ((t + 0.5) % 1) * 86400;

            if (v < 600 || v > 86400 - 600)
            {
                t = XL.MS_aLon_t(W) * 36525 - JD.deltatT2(t) + 8d / 24d;
            }
            return(t);
        }
Beispiel #7
0
        /// <summary>
        /// 计算八字
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ob">日对象</param>
        /// <param name="type">八字类型</param>
        /// <param name="curTZ">时区</param>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <param name="time">时间串</param>
        /// <param name="longitudeStr">经度(度分秒格式)</param>
        /// <returns>八字字符串</returns>
        public static string ML_calc <T>(OB ob, BaZiType type, double curTZ, T year, T month, T day, string time, string longitudeStr, BaZiTypeS baziTypes)
        {
            double y = LunarHelper.year2Ayear(year);

            if (y == -10000)
            {
                return(String.Empty);
            }

            string timeName = (type == BaZiType.ZtyBaZi ? "真太阳 " :
                               (type == BaZiType.PtyBaZi ? "平太阳 " : "北京时间 "));

            double t = LunarHelper.timeStr2hour(time);

            double longitude;

            if (type == BaZiType.EL120BaZi)
            {
                longitude = LunarHelper.str2rad("-120°");    // 解析东经120°经度为弧度
            }
            else
            {
                longitude = LunarHelper.str2rad(longitudeStr);    // 解析经度为弧度
            }
            double jd = JD.JD__(y, LunarHelper.VAL(month.ToString()),
                                LunarHelper.VAL(day.ToString()) + t / 24);

            if (type == BaZiType.ZtyBaZi)
            {
                obb.mingLiBaZi(jd + curTZ / 24 - LunarHelper.J2000, longitude, ob, baziTypes);    // 八字计算, 独立于 Lunar 类
                timeName += ob.bz_zty;
            }
            else
            {
                obb.mingLiBaZiNormal(jd + curTZ / 24 - LunarHelper.J2000, longitude, ob, baziTypes);    // 八字计算, 独立于 Lunar 类
                timeName += ob.bz_pty;
            }

            // C#: 新增的代码段
            JD.setFromJD(jd);
            double yearAjusted  = JD.Y;
            double monthAjusted = JD.M;
            double dayAjusted   = JD.D;

            return("[日标]:" + "公历 " + yearAjusted + "-" + monthAjusted + "-" + dayAjusted + " 儒略日数 " + LunarHelper.int2(jd + 0.5) +
                   " 距2000年首" + LunarHelper.int2(jd + 0.5 - LunarHelper.J2000) + "日"
                   + "\r\n[八字]:" + ob.bz_jn + "年 " + ob.bz_jy + "月 " + ob.bz_jr + "日 " + ob.bz_js + "时 " + timeName
                   + "\r\n[纪时]:" + ob.bz_JS
                   + "\r\n[时标]:" + "23  01  03  05  07  09  11  13  15  17  19  21  23");
        }
Beispiel #8
0
        /// <summary>
        /// 月亮到中升降时刻计算,传入jd含义与St()函数相同
        /// </summary>
        /// <param name="jd"></param>
        /// <returns></returns>
        public static LunarInfoListT <double> Mt(double jd)
        {
            SZJ.dt = JD.deltatT2(jd);
            SZJ.E  = ZB.hcjj(jd / 36525);
            jd    -= LunarHelper.mod2(0.1726222 + 0.966136808032357 * jd - 0.0366 * SZJ.dt - SZJ.L / LunarHelper.pi2, 1); //查找最靠近当日中午的月上中天,mod2的第1参数为本地时角近似值

            LunarInfoListT <double> r = new LunarInfoListT <double>(3, 0d);
            double sv = LunarHelper.pi2 * 0.966;

            r.z__ = r.s__ = r.j__ = r.c__ = r.h__ = jd;
            SZJ.Mcoord(jd, 1, r); //月亮坐标
            r.s__ += (-r.H0 - r.H) / sv;
            r.j__ += (r.H0 - r.H) / sv;
            r.z__ += (0 - r.H) / sv;
            SZJ.Mcoord(r.s__, 1, r); r.s__ += (-r.H0 - r.H) / sv;
            SZJ.Mcoord(r.j__, 1, r); r.j__ += (+r.H0 - r.H) / sv;
            SZJ.Mcoord(r.z__, 0, r); r.z__ += (0 - r.H) / sv;
            return(r);
        }
Beispiel #9
0
        /// <summary>
        /// 把太阳月亮信息形成 HTML 字符串
        /// </summary>
        /// <param name="fs">是否显示ΔT, 黄经章等信息</param>
        /// <returns></returns>
        public string toHTML(double fs)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<table width='100%' cellspacing=1 cellpadding=0 bgcolor='#FFC0C0'>");

            sb.Append("<tr><td bgcolor=white align=center>");
            sb.Append("平太阳 " + JD.timeStr(this.pty) + " 真太阳 <font color=red>" + JD.timeStr(this.zty) + "</font><br>");
            sb.Append("时差 " + LunarHelper.m2fm(this.sc * 86400, 2, 1) + " 月亮被照亮 " + (this.mIll * 100).ToString("F2") + "% ");
            sb.Append("</td></tr>");

            sb.Append("<tr><td bgcolor=white><center><pre style='margin-top: 0; margin-bottom: 0'><font color=blue><b>表一       月亮            太阳</b></font>\r\n");
            sb.Append("视黄经 " + LunarHelper.rad2str(this.mHJ, 0) + "  " + LunarHelper.rad2str(this.sHJ, 0) + "\r\n");
            sb.Append("视黄纬 " + LunarHelper.rad2str(this.mHW, 0) + "  " + LunarHelper.rad2str(this.sHW, 0) + "\r\n");
            sb.Append("视赤经 " + LunarHelper.rad2str(this.mCJ, 1) + "  " + LunarHelper.rad2str(this.sCJ, 1) + "\r\n");
            sb.Append("视赤纬 " + LunarHelper.rad2str(this.mCW, 0) + "  " + LunarHelper.rad2str(this.sCW, 0) + "\r\n");
            sb.Append("距离     " + this.mR.ToString("F0") + "千米          " + this.sR.ToString("F6") + "AU" + "\r\n");
            sb.Append("</pre></center></td></tr>");

            sb.Append("<tr><td bgcolor=white><center><pre style='margin-top: 0; margin-bottom: 0'><font color=blue><b>表二       月亮            太阳</b></font>\r\n");
            sb.Append("方位角 " + LunarHelper.rad2str(this.mPJ, 0) + "  " + LunarHelper.rad2str(this.sPJ, 0) + "\r\n");
            sb.Append("高度角 " + LunarHelper.rad2str(this.mPW, 0) + "  " + LunarHelper.rad2str(this.sPW, 0) + "\r\n");
            sb.Append("时角   " + LunarHelper.rad2str(this.mShiJ, 0) + "  " + LunarHelper.rad2str(this.sShiJ, 0) + "\r\n");
            sb.Append("视半径(观测点) " + LunarHelper.m2fm(this.mRad, 2, 0) + "     " + LunarHelper.m2fm(this.sRad, 2, 0) + "\r\n");
            sb.Append("</pre></center></td></tr>");

            if (fs != 0)
            {
                sb.Append("<tr><td bgcolor=white align=center>");
                sb.Append("力学时 " + JD.setFromJD_str(this.T + LunarHelper.J2000));
                sb.Append(" ΔT=" + (this.dt * 86400).ToString("F1") + "秒<br>");
                sb.Append("黄经章 " + (this.dL / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" ");
                sb.Append("交角章 " + (this.dE / LunarHelper.pi2 * 360 * 3600).ToString("F2") + "\" ");
                sb.Append("ε=" + LunarHelper.trim(LunarHelper.rad2str(this.E, 0)));
                sb.Append("</td></tr>");
            }
            sb.Append("</table>");
            return(sb.ToString());
        }
Beispiel #10
0
        /// <summary>
        /// 太阳到中升降时刻计算,传入jd是当地中午12点时间对应的2000年首起算的格林尼治时间UT
        /// </summary>
        /// <param name="jd"></param>
        /// <returns></returns>
        public static LunarInfoListT <double> St(double jd)
        {
            SZJ.dt = JD.deltatT2(jd);
            SZJ.E  = ZB.hcjj(jd / 36525);
            jd    -= LunarHelper.mod2(jd - SZJ.L / LunarHelper.pi2, 1); //查找最靠近当日中午的日上中天,mod2的第1参数为本地时角近似值

            LunarInfoListT <double> r = new LunarInfoListT <double>(3, 0d);
            double sv = LunarHelper.pi2;

            r.z__ = r.s__ = r.j__ = r.c__ = r.h__ = jd;
            SZJ.Scoord(jd, 1, 1, r);       //太阳坐标
            r.s__ += (-r.H0 - r.H) / sv;   //升起
            r.j__ += (r.H0 - r.H) / sv;    //降落
            r.c__ += (-r.H1 - r.H) / sv;   //民用晨
            r.h__ += (r.H1 - r.H) / sv;    //民用昏
            r.z__ += (0 - r.H) / sv;       //中天
            SZJ.Scoord(r.s__, 1, 0, r); r.s__ += (-r.H0 - r.H) / sv;
            SZJ.Scoord(r.j__, 1, 0, r); r.j__ += (+r.H0 - r.H) / sv;
            SZJ.Scoord(r.c__, 0, 1, r); r.c__ += (-r.H1 - r.H) / sv;
            SZJ.Scoord(r.h__, 0, 1, r); r.h__ += (+r.H1 - r.H) / sv;
            SZJ.Scoord(r.z__, 0, 0, r); r.z__ += (0 - r.H) / sv;
            return(r);
        }
Beispiel #11
0
        /// <summary>
        /// 求y年m月的第n个星期w的儒略日数
        /// </summary>
        /// <param name="y">年</param>
        /// <param name="m">月</param>
        /// <param name="n"></param>
        /// <param name="w">星期w</param>
        /// <returns></returns>
        public static double nnweek(double y, double m, double n, double w)
        {
            double jd = JD.JD__(y, m, 1.5);  //月首儒略日
            double w0 = (jd + 1) % 7;        //月首的星期
            double r  = jd - w0 + 7 * n + w; //jd-w0+7*n是和n个星期0,起算下本月第一行的星期日(可能落在上一月)。加w后为第n个星期w

            if (w >= w0)
            {
                r -= 7;          //第1个星期w可能落在上个月,造成多算1周,所以考虑减1周
            }
            if (n == 5)
            {
                m++; if (m > 12)
                {
                    m = 1; y++;
                }                                 //下个月
                if (r >= JD.JD__(y, m, 1.5))
                {
                    r -= 7;                          //r跑到下个月则减1周
                }
            }
            return(r);
        }
Beispiel #12
0
        //public void yueLiHTML(int By, int Bm, double curJD)
        //{
        //    string sty_head = " style='font-family: 宋体; font-size: 14px; text-align: center; background-color: #E0E0FF; color: #000000; font-weight: bold' ";
        //    string sty_body = " style='font-family: 宋体; font-size: 12px; text-align: center ' ";
        //    string sty_date = " style='font-family: Arial Black; text-align: center;font-size: 20px' ";
        //    string sty_date2 = " style='font-family: Arial Black; text-align: center;font-size: 20px; color: #FF0000' ";
        //    string sty_cur = " style='background-color:#90D050' ";

        //    int i, j;
        //    string c, c2;
        //    string cr = "", isM;
        //    OB ob;     // 日历物件

        //    this.yueLiCalc(By, Bm);    // 农历计算

        //    // 年份处理
        //    c = this.nianhao + " 农历" + this.Ly + "年【" + this.ShX + "年】";       // 干支纪年
        //    if (c.Length > 33) c = "<span style='font-size:12px'>" + c + "</span>";
        //    else c = "<span style='font-size:16px;font-weight:bold'>" + c + "</span>";
        //    this.pg0 = c;

        //    //月历处理
        //    string ta0 = "<tr>"
        //      + "<td" + sty_head + "width='%14'>日</td>"
        //      + "<td" + sty_head + "width='%14'>一</td>"
        //      + "<td" + sty_head + "width='%14'>二</td>"
        //      + "<td" + sty_head + "width='%14'>三</td>"
        //      + "<td" + sty_head + "width='%14'>四</td>"
        //      + "<td" + sty_head + "width='%14'>五</td>"
        //      + "<td" + sty_head + "width='%14'>六</td><tr>";
        //    for (i = 0; i < this.dn; i++)
        //    {
        //        // 遍历本月各日(公历), 生成第 i 日的日历页面
        //        ob = (this.lun[i]);
        //        if (i == 0)
        //        {
        //            for (j = 0; j < this.w0; j++)     // 首行前面的空单元格(依据: 本月首日的星期)
        //                cr += "<td" + sty_body + "></td>";
        //        }

        //        c = ""; isM = "";  // 文字格式控制项
        //        if (ob.A.Length > 0)
        //            c += "<font color=red>" + this.substr2(ob.A, 4, "..") + "</font>";
        //        if (c.Length <= 0 && ob.B.Length > 0)
        //            c = "<font color=blue>" + this.substr2(ob.B, 4, "..") + "</font>";
        //        if (c.Length <= 0 && ob.Ldc == "初一")
        //            c = ob.Lleap + ob.Lmc + "月" + (ob.Ldn == 30 ? "大" : "小");   // 农历历月(闰月及大小等)
        //        if (c.Length <= 0)
        //            c = ob.Ldc;   // 取农历日名称

        //        if (ob.yxmc == "朔") isM = "<font color=#505000>●</font>";           // 取月相
        //        if (ob.yxmc == "望") isM = "<font color=#F0B000>●</font>";           // 取月相
        //        if (ob.yxmc == "上弦") isM = "<font color=#F0B000><b>∪</b></font>";
        //        if (ob.yxmc == "下弦") isM = "<font color=#F0B000><b>∩</b></font>";

        //        if (ob.jqmc.Length > 0)
        //            isM += "<font color=#00C000>◆</font>";  // 定气标记

        //        if (ob.Fjia != 0)
        //            c2 = sty_date2; //节日置红色
        //        else c2 = sty_date;

        //        //c2 += " onmouseover='showMessD(" + i + ")'";     // C#: 注掉鼠标事件, 下同
        //        //c2 += " onmouseout ='showMessD(-1)'";

        //        c2 = "<span" + c2 + ">" + ob.d + "</span>"; //公历的日名称

        //        if (ob.d0 == curJD)
        //            c2 = "<span" + sty_cur + ">" + c2 + "</span>";   // 今日标识

        //        //cr += "<td" + sty_body + "width='14%'>" + c2 + "<br>" + isM + c + "</td>";      // C#: 注释, 改写如下:
        //        cr += "<td" + sty_body + "width='14%' onmouseover='changeBackcolor(this,1)' " +
        //                      "onmouseout='changeBackcolor(this,0)'>" +
        //                      c2 + "<br>" + isM + c + "</td>";               // C#: 新改写的语句, 增加鼠标事件处理

        //        if (i == this.dn - 1)
        //        {
        //            for (j = 0; j < 6 - ob.week; j++)      // 末行后面的空单元格(依据: 本月末日的星期)
        //                cr += "<td" + sty_body + "></td>";
        //        }
        //        if (i == this.dn - 1 || ob.week == 6)
        //        {
        //            ta0 += "<tr>" + cr + "</tr>";
        //            cr = "";
        //        }
        //    }
        //    this.pg1 = "<table border=0 cellpadding=3 cellspacing=1 width='100%'>" + ta0 + "</table>";

        //    string b2 = "", b3 = "", b4 = "";
        //    int c__;
        //    for (i = 0; i < this.dn; i++)
        //    {
        //        ob = (this.lun[i]);
        //        c__ = i + 1;
        //        if (c__ < 10)
        //            c = "&nbsp;" + c__;
        //        else
        //            c = c__.ToString();
        //        //if(ob.Ldc =="初一") b1 += c +"日 "+ob.Lleap+ob.Lmc+"月" + (ob.Ldn==30?"大":"小")+" &nbsp;";
        //        if (ob.yxmc == "朔" || ob.yxmc == "望") b2 += c + "日 " + ob.yxsj + ob.yxmc + "月 &nbsp;";
        //        if (ob.yxmc == "上弦" || ob.yxmc == "下弦") b3 += c + "日 " + ob.yxsj + ob.yxmc + " &nbsp;";
        //        if (ob.jqmc.Length > 0) b4 += c + "日 " + ob.jqsj + ob.jqmc + " &nbsp;";
        //    }
        //    this.pg2 = b2 + "<br>" + b3 + "<br>" + b4;

        //    this.yueLiText(By, Bm, curJD);   // C#: 转换时新增功能而增加的语句
        //}

        #endregion 初次转换的 yueLiHTML() 方法, 因涉及大量的字符串操作, 故拟使用 StringBuiler 改写以提高效率, 但保留原代码如下

        #region 原 Lunar.js 中的独立函数转换到类中

        /// <summary>
        /// 按交节时刻生成 html 年历
        /// </summary>
        /// <param name="y"></param>
        /// <returns></returns>
        public string nianLiHTML(double y)
        {
            int           i, j;
            StringBuilder s  = new StringBuilder();   // C#: 为提高字符串处理效率, 使用 StringBuilder
            StringBuilder s1 = new StringBuilder();   // C#: 为提高字符串处理效率, 使用 StringBuilder
            string        s2;
            double        v, qi = 0;

            SSQ.calcY(LunarHelper.int2((y - 2000) * 365.2422 + 180));

            for (i = 0; i < 14; i++)
            {
                if (SSQ.HS[i + 1] > SSQ.ZQ[24])
                {
                    break;                                // 已包含下一年的冬至
                }
                if (SSQ.leap != 0 && i == SSQ.leap)
                {
                    s1.Append("闰");
                }
                else
                {
                    s1.Append("·");
                }
                s1.Append(SSQ.ym[i]);
                if (s1.ToString().Length < 3)
                {
                    s1.Append("月");
                }
                s1.Append(SSQ.dx[i] > 29 ? "大" : "小");
                s1.Append(" " + JD.setFromJD_str(SSQ.HS[i] + LunarHelper.J2000).Substring(6, 5));    // C#: 取实历初一的时间

                v  = obb.so_accurate2(SSQ.HS[i]);
                s2 = "(" + JD.setFromJD_str(v + LunarHelper.J2000).Substring(9, 11) + ")";    // C#: 取每月朔的时间(即初一)
                if (LunarHelper.int2(v + 0.5) != SSQ.HS[i])
                {
                    s2 = "<font color=red>" + s2 + "</font>";
                }
                //v=(v+0.5+LunarHelper.J2000)%1; if(v>0.5) v=1-v; if(v<8/1440) s2 = "<u>"+s2+"</u>"; //对靠近0点的加注
                s1.Append(s2);

                for (j = -2; j < 24; j++)
                {
                    if (j >= 0)
                    {
                        qi = SSQ.ZQ[j];
                    }
                    if (j == -1)
                    {
                        qi = SSQ.ZQ.pe1;
                    }
                    if (j == -2)
                    {
                        qi = SSQ.ZQ.pe2;
                    }

                    if (qi < SSQ.HS[i] || qi >= SSQ.HS[i + 1])
                    {
                        continue;
                    }
                    s1.Append(" " + obb.jqmc[(j + 24) % 24] + JD.setFromJD_str(qi + LunarHelper.J2000).Substring(6, 5));    // C#: 取节气名称和实历交节日期

                    v  = obb.qi_accurate2(qi);
                    s2 = "(" + JD.setFromJD_str(v + LunarHelper.J2000).Substring(9, 11) + ")";    // C#: 取节气时间(上年大雪-本年大雪)
                    if (LunarHelper.int2(v + 0.5) != qi)
                    {
                        s2 = "<font color=red>" + s2 + "</font>";
                    }
                    //v=(v+0.5+LunarHelper.J2000)%1; if(v>0.5) v=1-v; if(v<8/1440) s2 = "<u>"+s2+"</u>"; //对靠近0点的加注
                    s1.Append(s2);
                }
                s.Append(s1.ToString() + "<br>");
                s1.Remove(0, s1.Length);     // C#: 在转换时将原来的字符串 s1 改写为 StringBuiler, 因此添加本句
            }
            return(s.ToString());
        }
Beispiel #13
0
        /// <summary>
        /// 计算公历某一个月的"公农回"三合历, 并把相关信息保存到月对象 lun, 以及日对象 lun[?] 中
        /// </summary>
        /// <param name="By">要计算月历的年</param>
        /// <param name="Bm">要计算月历的月</param>
        public void yueLiCalc(int By, int Bm)
        {
            int    i, j;
            double c, Bd0, Bdn;

            // 日历物件初始化
            JD.h = 12; JD.m = 0; JD.s = 0.1;
            JD.Y = By; JD.M = Bm; JD.D = 1; Bd0 = LunarHelper.int2(JD.toJD()) - LunarHelper.J2000;  // 公历某年的月首,中午
            JD.M++;
            if (JD.M > 12)
            {
                JD.Y++; JD.M = 1;
            }                                                            // C#: 如果月份大于 12, 则年数 + 1, 月数取 1
            Bdn = LunarHelper.int2(JD.toJD()) - LunarHelper.J2000 - Bd0; // 本月天数(公历)

            this.w0 = (Bd0 + LunarHelper.J2000 + 1) % 7;                 //本月第一天的星期
            this.y  = By;                                                // 公历年份
            this.m  = Bm;                                                // 公历月分
            this.d0 = Bd0;
            this.dn = Bdn;

            // 所属公历年对应的农历干支纪年
            c            = By - 1984 + 9000;
            this.Ly      = obb.Gan[(int)(c % 10)] + obb.Zhi[(int)(c % 12)]; //干支纪年
            this.ShX     = obb.ShX[(int)(c % 12)];                          // 该年对应的生肖
            this.nianhao = obb.getNH(By);

            double D, w;
            OB     ob, ob2;

            // 循环提取各日信息
            for (i = 0, j = 0; i < Bdn; i++)
            {
                ob       = (this.lun[i]);
                ob.d0    = Bd0 + i;                                        // 儒略日,北京时12:00
                ob.di    = i;                                              // 公历月内日序数
                ob.y     = By;                                             // 公历年
                ob.m     = Bm;                                             // 公历月
                ob.dn    = Bdn;                                            // 公历月天数
                ob.week0 = this.w0;                                        // 月首的星期
                ob.week  = (this.w0 + i) % 7;                              // 当前日的星期
                ob.weeki = LunarHelper.int2((this.w0 + i) / 7);            // 本日所在的周序号
                ob.weekN = LunarHelper.int2((this.w0 + Bdn - 1) / 7) + 1;  // 本月的总周数
                JD.setFromJD(ob.d0 + LunarHelper.J2000); ob.d = (int)JD.D; //公历日名称

                // 农历月历
                if (SSQ.ZQ.Count == 0 || ob.d0 < SSQ.ZQ[0] || ob.d0 >= SSQ.ZQ[24])   // 如果d0已在计算农历范围内则不再计算
                {
                    SSQ.calcY(ob.d0);
                }
                int mk = (int)LunarHelper.int2((ob.d0 - SSQ.HS[0]) / 30); if (mk < 13 && SSQ.HS[mk + 1] <= ob.d0)
                {
                    mk++;                              // 农历所在月的序数
                }
                ob.Ldi    = (int)(ob.d0 - SSQ.HS[mk]); // 距农历月首的编移量,0对应初一
                ob.Ldc    = obb.rmc[(int)(ob.Ldi)];    // 农历日名称
                ob.cur_dz = ob.d0 - SSQ.ZQ[0];         // 距冬至的天数
                ob.cur_xz = ob.d0 - SSQ.ZQ[12];        // 距夏至的天数
                ob.cur_lq = ob.d0 - SSQ.ZQ[15];        // 距立秋的天数
                ob.cur_mz = ob.d0 - SSQ.ZQ[11];        // 距芒种的天数
                ob.cur_xs = ob.d0 - SSQ.ZQ[13];        // 距小暑的天数
                if (ob.d0 == SSQ.HS[mk] || ob.d0 == Bd0)
                {
                    // 月的信息
                    ob.Lmc   = SSQ.ym[mk];                                   // 月名称
                    ob.Ldn   = SSQ.dx[mk];                                   // 月大小
                    ob.Lleap = (SSQ.leap != 0 && SSQ.leap == mk) ? "闰" : ""; // 闰状况
                    ob.Lmc2  = mk < 13 ? SSQ.ym[mk + 1] : "未知";              // 下个月名称,判断除夕时要用到
                }
                else
                {
                    ob2      = (this.lun[i - 1]);
                    ob.Lmc   = ob2.Lmc; ob.Ldn = ob2.Ldn;
                    ob.Lleap = ob2.Lleap; ob.Lmc2 = ob2.Lmc2;
                }
                int qk = (int)LunarHelper.int2((ob.d0 - SSQ.ZQ[0] - 7) / 15.2184); if (qk < 23 && ob.d0 >= SSQ.ZQ[qk + 1])
                {
                    qk++;                                                                                                        //节气的取值范围是0-23
                }
                if (ob.d0 == SSQ.ZQ[qk])
                {
                    ob.Ljq = obb.jqmc[qk];
                }
                else
                {
                    ob.Ljq = "";
                }

                ob.yxmc = ob.yxjd = ob.yxsj = "";    // 月相名称,月相时刻(儒略日),月相时间串
                ob.jqmc = ob.jqjd = ob.jqsj = "";    // 定气名称,节气时刻(儒略日),节气时间串

                // 干支纪年处理
                // 以立春为界定年首
                D        = SSQ.ZQ[3] + (ob.d0 < SSQ.ZQ[3] ? -365 : 0) + 365.25 * 16 - 35; //以立春为界定纪年
                ob.Lyear = Math.Floor(D / 365.2422 + 0.5);                                //农历纪年(10进制,1984年起算)

                // 以下几行以正月初一定年首
                D = SSQ.HS[2];     // 一般第3个月为春节
                for (j = 0; j < 14; j++)
                {
                    // 找春节
                    if (SSQ.ym[j] != "正")
                    {
                        continue;
                    }
                    D = SSQ.HS[j];
                    if (ob.d0 < D)
                    {
                        D -= 365; break;
                    }                                       // 无需再找下一个正月
                }
                D         = D + 5810;                       // 计算该年春节与1984年平均春节(立春附近)相差天数估计
                ob.Lyear0 = Math.Floor(D / 365.2422 + 0.5); // 农历纪年(10进制,1984年起算)

                D         = ob.Lyear + 9000;
                ob.Lyear2 = obb.Gan[(int)(D % 10)] + obb.Zhi[(int)(D % 12)]; // 干支纪年(立春)
                D         = ob.Lyear0 + 9000;
                ob.Lyear3 = obb.Gan[(int)(D % 10)] + obb.Zhi[(int)(D % 12)]; // 干支纪年(正月)
                ob.Lyear4 = ob.Lyear0 + 1984 + 2698;                         // 黄帝纪年

                // 纪月处理,1998年12月7(大雪)开始连续进行节气计数,0为甲子
                mk = (int)LunarHelper.int2((ob.d0 - SSQ.ZQ[0]) / 30.43685);
                if (mk < 12 && ob.d0 >= SSQ.ZQ[2 * mk + 1])
                {
                    mk++;                                                                        //相对大雪的月数计算,mk的取值范围0-12
                }
                D          = mk + LunarHelper.int2((SSQ.ZQ[12] + 390) / 365.2422) * 12 + 900000; //相对于1998年12月7(大雪)的月数,900000为正数基数
                ob.Lmonth  = D % 12;
                ob.Lmonth2 = obb.Gan[(int)(D % 10)] + obb.Zhi[(int)(D % 12)];

                // 纪日,2000年1月7日起算
                D        = ob.d0 - 6 + 9000000;
                ob.Lday2 = obb.Gan[(int)(D % 10)] + obb.Zhi[(int)(D % 12)];

                // 星座
                mk = (int)LunarHelper.int2((ob.d0 - SSQ.ZQ[0] - 15) / 30.43685); if (mk < 11 && ob.d0 >= SSQ.ZQ[2 * mk + 2])
                {
                    mk++;                                                                                                          //星座所在月的序数,(如果j=13,ob.d0不会超过第14号中气)
                }
                ob.XiZ = obb.XiZ[(int)((mk + 12) % 12)] + "座";

                // 回历
                oba.getHuiLi(ob.d0, ob);

                // 节日
                ob.A = ob.B = ob.C = ""; ob.Fjia = 0;
                oba.getDayName(ob, ob);   //公历
                obb.getDayName(ob, ob);   //农历
            }

            // 以下是月相与节气的处理
            double d, jd2 = Bd0 + JD.deltatT2(Bd0) - 8d / 24d;
            int    xn;

            // 月相查找
            w = XL.MS_aLon(jd2 / 36525, 10, 3);
            w = LunarHelper.int2((w - 0.78) / Math.PI * 2) * Math.PI / 2;
            do
            {
                d  = obb.so_accurate(w);
                D  = LunarHelper.int2(d + 0.5);
                xn = (int)LunarHelper.int2(w / LunarHelper.pi2 * 4 + 4000000.01) % 4;
                w += LunarHelper.pi2 / 4;
                if (D >= Bd0 + Bdn)
                {
                    break;
                }
                if (D < Bd0)
                {
                    continue;
                }
                ob      = (this.lun[(int)(D - Bd0)]);
                ob.yxmc = obb.yxmc[xn];     // 取得月相名称
                ob.yxjd = d.ToString();
                ob.yxsj = JD.timeStr(d);
            } while (D + 5 < Bd0 + Bdn);

            // 节气查找
            w = XL.S_aLon(jd2 / 36525, 3);
            w = LunarHelper.int2((w - 0.13) / LunarHelper.pi2 * 24) * LunarHelper.pi2 / 24;
            do
            {
                d  = obb.qi_accurate(w);
                D  = LunarHelper.int2(d + 0.5);
                xn = (int)LunarHelper.int2(w / LunarHelper.pi2 * 24 + 24000006.01) % 24;
                w += LunarHelper.pi2 / 24;
                if (D >= Bd0 + Bdn)
                {
                    break;
                }
                if (D < Bd0)
                {
                    continue;
                }
                ob      = (this.lun[(int)(D - Bd0)]);
                ob.jqmc = obb.jqmc[xn];     // 取得节气名称
                ob.jqjd = d.ToString();
                ob.jqsj = JD.timeStr(d);
            } while (D + 12 < Bd0 + Bdn);

            // C#: 转换时新增的代码行
            this.CalcRiJianThisMonth();    // 计算本月所有日期的日十二建信息
        }
Beispiel #14
0
        /// <summary>
        /// 指定某日, 计算出它的所属节(气), 上一节(气), 下一节(气)信息, 并把计算结果保存在日对象中
        /// </summary>
        /// <param name="ob"></param>
        /// <returns>计算成功返回 true, 否则返回 false </returns>
        public bool CalcJieQiInfo(OB ob, CalcJieQiType calcType)
        {
            const int JiQiInfo_Name             = 0;
            const int JiQiInfo_JDTime           = 1;
            const int JiQiInfo_Time             = 2;
            const int JiQiInfo_HistoricalJDTime = 3;
            const int JiQiInfo_HistoricalTime   = 4;
            const int JiQiInfo_DifferentTime    = 5;
            const int JiQiInfo_JieOrQi          = 6;
            const int JiQiInfo_YueJian          = 7;
            const int JiQiInfo_DayDifference    = 8;

            const int PrevJieQiFlag = 0;
            const int ThisJieQiFlag = 1;
            const int NextJieQiFlag = 2;

            double    y = ob.y;
            int       j, counter = 0, thisJie = -1, jieQiPos = 0;
            JieQiInfo jieqiInfo;

            int[] jieqiInfoPos = new int[3];
            object[,] jieqiList = new object[31, 9];

            double v, qi = 0;

            int num = SSQ.calcJieQi(LunarHelper.int2((y - 2000) * 365.2422 + 180), true); // 计算节气, 以"霜降"开始

            for (j = 0; j < num; j++)                                                     // 建表
            {
                if (calcType == CalcJieQiType.CalcJie)                                    // 只计算节
                {
                    if (((j + 24) % 24) % 2 == 0)                                         // 气(跳过, 只使用节)
                    {
                        continue;
                    }
                }

                if (calcType == CalcJieQiType.CalcQi)    // 只计算气
                {
                    if (((j + 24) % 24) % 2 == 1)        // 节(跳过, 只使用气)
                    {
                        continue;
                    }
                }

                qi = SSQ.ZQ[j];

                v = obb.qi_accurate2(qi);
                jieqiList[counter, JiQiInfo_Time] = JD.setFromJD_str(v + LunarHelper.J2000);

                jieQiPos = (j + 24) % 24 + 20;      // 与 obb.jqmc 对应, "霜降"距首位"冬至"的距离为 20
                if (jieQiPos >= 24)
                {
                    jieQiPos -= 24;
                }

                jieqiList[counter, JiQiInfo_JieOrQi] = true;
                jieqiList[counter, JiQiInfo_Name]    = obb.jqmc[jieQiPos];
                jieqiList[counter, JiQiInfo_YueJian] = obb.JieQiYueJian[jieQiPos];
                jieqiList[counter, JiQiInfo_JDTime]  = v + LunarHelper.J2000;

                jieqiList[counter, JiQiInfo_HistoricalTime]   = JD.setFromJD_str(qi + LunarHelper.J2000);
                jieqiList[counter, JiQiInfo_HistoricalJDTime] = qi + LunarHelper.J2000;
                jieqiList[counter, JiQiInfo_DifferentTime]    = (LunarHelper.int2(v + 0.5) != qi ? true : false);

                jieqiList[counter, JiQiInfo_DayDifference] = (int)(LunarHelper.int2(v + 0.5) - qi);

                counter++;
            }

            for (j = 0; j < SSQ.ZQ.Count; j++)    // △重要: 由于调用了 SSQ.calcJieQi 方法, 计算了 31 个节气(超出年周期)数据, 故应清零
            {
                SSQ.ZQ[j] = 0;
            }

            if (ob.y >= 0)
            {
                int ymd = ob.y * 10000 + ob.m * 100 + ob.d; // 转换成为数值表示的日期: 如 20090422
                for (j = counter - 1; j >= 0; j--)          // 逆序查表(表中的交节日期数据是由小到大排列的)
                {
                    string jieqiTime  = (string)jieqiList[j, JiQiInfo_Time];
                    int    jieqiYear  = int.Parse(jieqiTime.Substring(0, 5));
                    int    jieqiMonth = int.Parse(jieqiTime.Substring(6, 2));
                    int    jieqiDay   = int.Parse(jieqiTime.Substring(9, 2));
                    if (jieqiYear * 10000 + jieqiMonth * 100 + jieqiDay <= ymd)    // 找到所属的节气
                    {
                        thisJie = j;
                        break;
                    }
                }
            }
            else
            {
                int ymd = ob.y * 10000 - (99 - ob.m) * 100 - (99 - ob.d);
                for (j = 0; j < counter; j++)    // 顺序查表(表中的交节日期数据是由小到大排列的, 计算为数值时也要严格递增)
                {
                    string jieqiTime  = (string)jieqiList[j, JiQiInfo_Time];
                    int    jieqiYear  = int.Parse(jieqiTime.Substring(0, 5));
                    int    jieqiMonth = int.Parse(jieqiTime.Substring(6, 2));
                    int    jieqiDay   = int.Parse(jieqiTime.Substring(9, 2));
                    int    jieqiYmd   = jieqiYear * 10000 - (99 - jieqiMonth) * 100 - (99 - jieqiDay);
                    if (jieqiYmd >= ymd)
                    {
                        if (jieqiYmd > ymd)
                        {
                            thisJie = j - 1;
                        }
                        else
                        {
                            thisJie = j;
                        }
                        break;
                    }
                }
            }

            if (thisJie > 0 && thisJie < counter)
            {
                jieqiInfoPos[ThisJieQiFlag] = thisJie;
                jieqiInfoPos[PrevJieQiFlag] = jieqiInfoPos[ThisJieQiFlag] - 1;
                jieqiInfoPos[NextJieQiFlag] = jieqiInfoPos[ThisJieQiFlag] + 1;

                for (j = 0; j < jieqiInfoPos.Length; j++)
                {
                    switch (j)
                    {
                    case PrevJieQiFlag:
                        jieqiInfo = ob.PreviousJieQi;
                        break;

                    case ThisJieQiFlag:
                        jieqiInfo = ob.ThisJieQi;
                        break;

                    case NextJieQiFlag:
                        jieqiInfo = ob.NextJieQi;
                        break;

                    default:
                        jieqiInfo = null;
                        break;
                    }

                    if (jieqiInfo != null)
                    {
                        jieqiInfo.JieOrQi = (bool)jieqiList[jieqiInfoPos[j], JiQiInfo_JieOrQi];
                        jieqiInfo.Name    = (string)jieqiList[jieqiInfoPos[j], JiQiInfo_Name];
                        jieqiInfo.YueJian = (string)jieqiList[jieqiInfoPos[j], JiQiInfo_YueJian];
                        jieqiInfo.Time    = (string)jieqiList[jieqiInfoPos[j], JiQiInfo_Time];
                        jieqiInfo.JDTime  = (double)jieqiList[jieqiInfoPos[j], JiQiInfo_JDTime];

                        jieqiInfo.HistoricalTime   = (string)jieqiList[jieqiInfoPos[j], JiQiInfo_HistoricalTime];
                        jieqiInfo.HistoricalJDTime = (double)jieqiList[jieqiInfoPos[j], JiQiInfo_HistoricalJDTime];
                        jieqiInfo.DifferentTime    = (bool)jieqiList[jieqiInfoPos[j], JiQiInfo_DifferentTime];

                        jieqiInfo.DayDifference = (int)jieqiList[jieqiInfoPos[j], JiQiInfo_DayDifference];
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #15
0
        /// <summary>
        /// 精朔计算
        /// </summary>
        /// <param name="W"></param>
        /// <returns></returns>
        public static double so_accurate(double W)
        {
            double t = XL.MS_aLon_t(W) * 36525;

            return(t - JD.deltatT2(t) + 8d / 24d);    // 精朔
        }
Beispiel #16
0
 /// <summary>
 /// 传入儒略日(J2000起算),计算TD-UT(单位:日)
 /// </summary>
 /// <param name="t">J2000起算的儒略日</param>
 /// <returns></returns>
 public static double deltatT2(double t)
 {
     return(JD.deltatT(t / 365.2425 + 2000) / 86400.0);
 }
Beispiel #17
0
 /// <summary>
 /// 公历转儒略日
 /// </summary>
 /// <returns></returns>
 public static double toJD()
 {
     return(JD.JD__(JD.Y, JD.M, JD.D + ((JD.s / 60 + JD.m) / 60 + JD.h) / 24));
 }
Beispiel #18
0
        }                                   // = 0;

        #endregion

        #endregion 公共属性



        #region 公共方法
        /// <summary>
        /// 计算 sun_moon 类的成员。参数:T是力学时,站点经度L,纬度fa,海拔high(千米)
        /// </summary>
        /// <param name="T">力学时</param>
        /// <param name="L">站点经度</param>
        /// <param name="fa">站点纬度</param>
        /// <param name="high">海拔</param>
        public void calc(double T, double L, double fa, double high)
        {
            //基本参数计算
            this.T   = T;
            this.L   = L; this.fa = fa;
            this.dt  = JD.deltatT2(T);                                        //TD-UT
            this.jd  = T - this.dt;                                           //UT
            T       /= 36525; ZB.nutation(T);
            this.dL  = ZB.dL;                                                 //黄经章
            this.dE  = ZB.dE;                                                 //交角章动
            this.E   = ZB.hcjj(T) + this.dE;                                  //真黄赤交角
            this.gst = ZB.gst(this.jd, this.dt) + this.dL * Math.Cos(this.E); //真恒星时(不考虑非多项式部分)
            double[] z = new double[4];

            //=======月亮========
            //月亮黄道坐标
            XL.M_coord(T, z, -1, -1, -1);                                                                   //月球坐标
            z[0]     = LunarHelper.rad2mrad(z[0] + ZB.gxc_moonLon(T) + this.dL); z[1] += ZB.gxc_moonLat(T); //补上月球光行差及章动
            this.mHJ = z[0]; this.mHW = z[1]; this.mR = z[2];                                               //月球视黄经,视黄纬,地月质心距

            //月球赤道坐标
            ZB.llrConv(z, this.E);            //转为赤道坐标
            this.mCJ = z[0]; this.mCW = z[1]; //月球视赤经,月球赤纬

            //月亮时角计算
            this.mShiJ = LunarHelper.rad2mrad(this.gst - L - z[0]); //得到此刻天体时角
            if (this.mShiJ > Math.PI)
            {
                this.mShiJ -= LunarHelper.pi2;
            }

            //修正了视差的赤道坐标
            ZB.parallax(z, this.mShiJ, fa, high); //视差修正
            this.mCJ2 = z[0]; this.mCW2 = z[1]; this.mR2 = z[2];

            //月亮时角坐标
            z[0] += Math.PI / 2d - this.gst + L;  //转到相对于地平赤道分点的赤道坐标(时角坐标)

            //月亮地平坐标
            ZB.llrConv(z, Math.PI / 2 - fa);  //转到地平坐标(只改经纬度)
            z[0]     = LunarHelper.rad2mrad(Math.PI / 2 - z[0]);
            this.mDJ = z[0]; this.mDW = z[1]; //方位角,高度角
            if (z[1] > 0)
            {
                z[1] += ZB.AR2(z[1]);         //大气折射修正
            }
            this.mPJ = z[0]; this.mPW = z[1]; //方位角,高度角

            //=======太阳========
            //太阳黄道坐标
            XL.E_coord(T, z, -1, -1, -1);                                                 //地球坐标
            z[0]     = LunarHelper.rad2mrad(z[0] + Math.PI + ZB.gxc_sunLon(T) + this.dL); //补上太阳光行差及章动
            z[1]     = -z[1] + ZB.gxc_sunLat(T);                                          //z数组为太阳地心黄道视坐标
            this.sHJ = z[0]; this.sHW = z[1]; this.sR = z[2];                             //太阳视黄经,视黄纬,日地质心距

            //太阳赤道坐标
            ZB.llrConv(z, this.E);            //转为赤道坐标
            this.sCJ = z[0]; this.sCW = z[1]; //太阳视赤经,视赤纬

            //太阳时角计算
            this.sShiJ = LunarHelper.rad2mrad(this.gst - L - z[0]); //得到此刻天体时角
            if (this.sShiJ > Math.PI)
            {
                this.sShiJ -= LunarHelper.pi2;
            }

            //修正了视差的赤道坐标
            ZB.parallax(z, this.sShiJ, fa, high); //视差修正
            this.sCJ2 = z[0]; this.sCW2 = z[1]; this.sR2 = z[2];

            //太阳时角坐标
            z[0] += Math.PI / 2 - this.gst + L;  //转到相对于地平赤道分点的赤道坐标

            //太阳地平坐标
            ZB.llrConv(z, Math.PI / 2 - fa);
            z[0] = LunarHelper.rad2mrad(Math.PI / 2 - z[0]);
            //z[1] -= 8.794/rad/z[2]*Math.cos(z[1]); //直接在地平坐标中视差修正(这里把地球看为球形,精度比ZB.parallax()稍差一些)
            this.sDJ = z[0]; this.sDW = z[1]; //方位角,高度角

            if (z[1] > 0)
            {
                z[1] += ZB.AR2(z[1]);         //大气折射修正
            }
            this.sPJ = z[0]; this.sPW = z[1]; //方位角,高度角

            //=======其它========
            //时差计算
            double t = T / 10; double t2 = t * t, t3 = t2 * t, t4 = t3 * t, t5 = t4 * t;
            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; //修正了光行差的太阳平黄经

            Lon = LunarHelper.rad2mrad(Lon - (this.sCJ - this.dL * Math.Cos(this.E)));                                                                                               //(修正了光行差的平黄经)-(不含dL*cos(E)的视赤经)
            if (Lon > Math.PI)
            {
                Lon -= LunarHelper.pi2;        //得到时差,单位是弧度
            }
            this.sc = Lon / LunarHelper.pi2;   //时差(单位:日)

            //真太阳与平太阳
            this.pty = this.jd - L / LunarHelper.pi2;           //平太阳时
            this.zty = this.jd - L / LunarHelper.pi2 + this.sc; //真太阳时

            //视半径
            //this.mRad = XL.moonRad(this.mR,this.mDW);  //月亮视半径(角秒)
            this.mRad     = 358473400d / this.mR2;                                                                     //月亮视半径(角秒)
            this.sRad     = 959.63 / this.sR2;                                                                         //太阳视半径(角秒)
            this.e_mRad   = 358473400d / this.mR;                                                                      //月亮地心视半径(角秒)
            this.eShadow  = (LunarHelper.cs_rEarA / this.mR * LunarHelper.rad - (959.63 - 8.794) / this.sR) * 51 / 50; //地本影在月球向径处的半径(角秒),式中51/50是大气厚度补偿
            this.eShadow2 = (LunarHelper.cs_rEarA / this.mR * LunarHelper.rad + (959.63 + 8.794) / this.sR) * 51 / 50; //地半影在月球向径处的半径(角秒),式中51/50是大气厚度补偿
            this.mIll     = XL.moonIll(T);                                                                             //月亮被照面比例

            //中心食计算
            if (Math.Abs(LunarHelper.rad2rrad(this.mCJ - this.sCJ)) < 50 / 180 * Math.PI)
            {
                ZB.line_earth(this.mCJ, this.mCW, this.mR, this.sCJ, this.sCW, this.sR * LunarHelper.cs_AU);
                this.zx_J = LunarHelper.rad2rrad(this.gst - ZB.le_J);
                this.zx_W = ZB.le_W; //无解返回值是100
            }
            else
            {
                this.zx_J = this.zx_W = 100;
            }
        }
Beispiel #19
0
 /// <summary>
 /// 儒略日数转公历, 并且返回日期转化的时间串
 /// </summary>
 /// <param name="jd"></param>
 /// <returns></returns>
 public static string setFromJD_str(double jd)
 {
     JD.setFromJD(jd);
     return(JD.toStr());
 }