示例#1
0
文件: moon.c 项目: Yomin/remind
void HuntPhase(int startdate, int starttim, int phas, int *date, int *time)
{
    int utcd, utct;
    int y, m, d;
    int h, min, s;
    int d1, t1;
    double k1, k2, jd, jdorig;
    double nt1, nt2;

    /* Convert from local to UTC */
    LocalToUTC(startdate, starttim, &utcd, &utct);

    /* Convert from Remind representation to year/mon/day */
    FromJulian(utcd, &y, &m, &d);
    /* Convert to a true Julian date -- sorry for the name clashes! */
    jdorig = jtime(y, m, d, (utct / 60), (utct % 60), 0);   
    jd = jdorig - 45.0;
    nt1 = meanphase(jd, 0.0, &k1);
    while(1) {
	jd += synmonth;
	nt2 = meanphase(jd, 0.0, &k2);
	if (nt1 <= jdorig && nt2 > jdorig) break;
	nt1 = nt2;
	k1 = k2;
    }
    jd = truephase(k1, phas/4.0);
    if (jd < jdorig) jd = truephase(k2, phas/4.0);

    /* Convert back to Remind format */
    jyear(jd, &y, &m, &d);
    jhms(jd, &h, &min, &s);

    d1 = Julian(y, m, d);
    t1 = h*60 + min;
    UTCToLocal(d1, t1, date, time);
}
示例#2
0
文件: tamo_moon.c 项目: tsupo/tamo
BOOL
isFullMoonDay( long _yy, long _mm, long _dd )
{
    double          jd, aom, cphase, cdist, cangdia, csund, csuang, lptime;
    long            yy, mm, dd, hh, mmm, ss; /* (直前の)朔の年月日時分秒    */
    long            uyy, umm, udd, uhh, ummm, uss;   /* UTC変換後の現在日時 */
    double          phasar[5];

    double          t1;
    int	            __y, __m, __d;
    long            tt;
    struct tm       *lm;
    time_t          t = 0;

    /*
     *  timezone を求める (UTC とローカル時間の時差を求める)
     */
    lm = localtime( &t );
#ifdef	UNIX
# ifndef	SYSV
    /* BSD系のUNIXでは、以下の処理が必要
     *  (ANSI C 登場以前の UNIX では、BSD系でない場合でも、別途対応が必要
     *   であると思われる)
     */
    if ( (lm->tm_isdst != 0) && (lm->tm_isdst != 1) ) {
        lm->tm_isdst  = 0;
        lm->tm_gmtoff = 9 * 60 * 60;
        lm->tm_zone   = "JST";
    }
    _tzname[lm->tm_isdst] = lm->tm_zone;
    _timezone = -(lm->tm_gmtoff);
# endif
#else	/* !UNIX */
# ifdef	WIN32
    {
        OSVERSIONINFO   osverInfo;
        BOOL            ret;

        osverInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
        if ( ret = GetVersionEx( &osverInfo ) ) {
            if ( (osverInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ||
                 (osverInfo.dwPlatformId == VER_PLATFORM_WIN32s       )    ) {
                /* Windows 3.x (Win32S環境), Windows95, Windows98 の場合は、
                 * 以下の処理が必要
                 */
                lm->tm_isdst = 0;
                _tzname[lm->tm_isdst] = "JST";
                _timezone = -(9 * 60 * 60);
            }
        }
    }
# endif
#endif

    /*
     *  ローカル時間で指定された年月日時分秒を UTC に変換する
     */
    t1 = ((double)absoluteFromGregorian( _dd, _mm, _yy )) * 24.0 + _timezone;
    tt = _timezone;
    uyy  = _yy;
    umm  = _mm;
    udd  = _dd;
    uhh  = 0;
    ummm = 0;
    uss  = 0;
    if ( tt < 0 ) {
        gregorianFromAbsolute( absoluteFromGregorian( _dd, _mm, _yy ) - 1,
                               &__d, &__m, &__y );
        uyy = __y;
        umm = __m;
        udd = __d;
    }
    else if ( tt > 24 * 60 * 60 ) {
        gregorianFromAbsolute( absoluteFromGregorian( _dd, _mm, _yy ) + 1,
                               &__d, &__m, &__y );
        uyy = __y;
        umm = __m;
        udd = __d;
    }
    uhh = (_timezone / (60 * 60)) % 24;
    if ( uhh < 0 )
        uhh += 24;
    ummm = (_timezone / 60) % 60;
    if ( ummm < 0 )
        ummm += 60;
    uss = _timezone % 60;
    if ( uss < 0 )
        uss += 60;

    /*
     *  UTC をユリウス日に変換する
     */
    jd = jtime( uyy, umm, udd, uhh, ummm, uss );

    /*
     *  当該ユリウス日の直前の朔の日時を求める
     */
    yy = 0;
    (void)phase( jd + 1, &cphase, &aom, &cdist, &cangdia, &csund, &csuang );
    phasehunt( jd, phasar );

    lptime = phasar[2];
    jyear( lptime, &yy, &mm, &dd );
    jhms( lptime, &hh, &mmm, &ss );

    return ( ( (yy == _yy) && (mm == _mm) && (dd == _dd) ) ? TRUE : FALSE );
}
示例#3
0
文件: tamo_moon.c 项目: tsupo/tamo
void
tamo_moon( long _yy, long _mm, long _dd, long _hh, long _mmm, long _ss,
	       int flag )
{
    double          jd, aom, cphase, cdist, cangdia, csund, csuang, lptime;
    long            yy, mm, dd, hh, mmm, ss; /* (直前の)朔の年月日時分秒    */
    long            uyy, umm, udd, uhh, ummm, uss;   /* UTC変換後の現在日時 */
    double          phasar[5];
    long            lunation;
    static double   nptime = 0.0; /* Next new moon time */

    double          t1, t2;
    int	            __y, __m, __d;
    long            tt;
    struct tm       *lm;
    time_t          t = 0;

    /*
     *  timezone を求める (UTC とローカル時間の時差を求める)
     */
    lm = localtime( &t );
#ifdef	UNIX
# ifndef	SYSV
    /* BSD系のUNIXでは、以下の処理が必要
     *  (ANSI C 登場以前の UNIX では、BSD系でない場合でも、別途対応が必要
     *   であると思われる)
     */
    if ( (lm->tm_isdst != 0) && (lm->tm_isdst != 1) ) {
        lm->tm_isdst  = 0;
        lm->tm_gmtoff = 9 * 60 * 60;
        lm->tm_zone   = "JST";
    }
    _tzname[lm->tm_isdst] = lm->tm_zone;
    _timezone = -(lm->tm_gmtoff);
# endif
#else	/* !UNIX */
# ifdef	WIN32
    {
        OSVERSIONINFO   osverInfo;
        BOOL            ret;

        osverInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
        if ( ret = GetVersionEx( &osverInfo ) ) {
            if ( (osverInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ||
                 (osverInfo.dwPlatformId == VER_PLATFORM_WIN32s       )    ) {
                /* Windows 3.x (Win32S環境), Windows95, Windows98 の場合は、
                 * 以下の処理が必要
                 */
                lm->tm_isdst = 0;
                _tzname[lm->tm_isdst] = "JST";
                _timezone = -(9 * 60 * 60);
            }
        }
    }
# endif
#endif

    /*
     *  ローカル時間で指定された年月日時分秒を UTC に変換する
     */
    t1 = ((((double)absoluteFromGregorian( _dd, _mm, _yy ) * 24.0 +
            (double)_hh) * 60.0) + (double)_mmm) * 60.0 +
            (double)_ss + (double)_timezone;
    tt = (_hh * 60 + _mmm) * 60 + _ss + _timezone;
    uyy  = _yy;
    umm  = _mm;
    udd  = _dd;
    uhh  = _hh;
    ummm = _mmm;
    uss  = _ss;
    if ( tt < 0 ) {
        gregorianFromAbsolute( absoluteFromGregorian( _dd, _mm, _yy ) - 1,
                               &__d, &__m, &__y );
        uyy = __y;
        umm = __m;
        udd = __d;
    }
    else if ( tt > 24 * 60 * 60 ) {
        gregorianFromAbsolute( absoluteFromGregorian( _dd, _mm, _yy ) + 1,
                               &__d, &__m, &__y );
        uyy = __y;
        umm = __m;
        udd = __d;
    }
    uhh = ((uhh * 60 * 60 + _timezone) / (60 * 60)) % 24;
    if ( uhh < 0 )
        uhh += 24;
    ummm = ((ummm * 60 + _timezone) / 60) % 60;
    if ( ummm < 0 )
        ummm += 60;
    uss = (uss + _timezone) % 60;
    if ( uss < 0 )
        uss += 60;

    /*
     *  UTC をユリウス日に変換する
     */
    jd = jtime( uyy, umm, udd, uhh, ummm, uss );

    /*
     *  当該ユリウス日の直前の朔の日時を求める
     */
    yy = 0;
    (void)phase( jd + 1, &cphase, &aom, &cdist, &cangdia, &csund, &csuang );
    phasehunt( jd, phasar );
    lptime   = phasar[0];
    lunation = (long)(floor(((lptime + 7.0) - lunatbase) / synmonth) + 1.0);
    jyear( lptime, &yy, &mm, &dd );
    jhms( lptime, &hh, &mmm, &ss );

    /*
     *  朔の日時(ユリウス日)を UTC に変換する
     */
    t2 = ((((double)absoluteFromGregorian( dd, mm, yy ) * 24.0 +
            (double)hh) * 60.0) + (double)mmm) * 60.0 + (double)ss;

    /*
     * 2つの UTC の差分を元に月齢を求める
     */
    aom = qpom3( t1, t2 );
    if ( aom < 0.0 )
        aom += synmonth;

    /*
     *  結果を出力する
     */
    if ( flag ) {
        printf( "<TABLE BORDER=\"0\" SUMMARY=\"月齢\">\n<TR><TD>月齢" );
    }
    else {
	    if ( !strncmp( _tzname[lm->tm_isdst], "東京", 4 ) )
	        printf( "%d年%02d月%02d日 %02d時%02d分%02d秒(JST)現在の月齢",
                    _yy, _mm, _dd, _hh, _mmm, _ss );
	    else if ( _tzname[lm->tm_isdst][0] )
	        printf( "%d年%02d月%02d日 %02d時%02d分%02d秒(%s)現在の月齢",
                    _yy, _mm, _dd, _hh, _mmm, _ss, _tzname[lm->tm_isdst] );
        else
	        printf( "%d年%02d月%02d日 %02d時%02d分%02d秒現在の月齢",
                    _yy, _mm, _dd, _hh, _mmm, _ss );
    }

    printf( "%s%.1f (%02d日%02d時%02d分)",
            flag ? "</TD><TD>" : ":\n                 ",
            aom /*+ 0.05*/,
            (int) aom, ((int) (24 * (aom - floor(aom)))),
            ((int) (1440 * (aom - floor(aom)))) % 60 );

    printf( " %s[輝度: %.1f%%]",
	        flag ? "<BR>" : " ",
          (1.0 - cos((2.0 * PI * aom) / (LPERIOD / 86400.0))) / 2.0 * 100.0 );

    if ( flag ) {
        printf( "</TD>\n<TD ROWSPAN=5><IMG SRC=" );
        printf( 
#ifdef  RIMNET
                "\"/~tsupo/qpom/image/moon%2.2d.gif\"",
#else
                "\"qpom/image/moon%2.2d.gif\"",
#endif
                (int)(100.0 * (aom /*+ 0.05*/) / (LPERIOD / 86400.0)) );
        printf( " WIDTH=\"110\" HEIGHT=\"110\"" );
        printf( " ALIGN=\"LEFT\" BORDER=2 ALT=\"[%1d day old Moon]\">\n",
                (long)(aom /*+ 0.05*/));
        printf( "</TD></TR>\n<TR><TD>" );
    }
    else {
        putchar( '\n' );
    }

    printf( "地球-月の距離%s%ldkm%s(地球赤道半径の%.1f倍)\n",
            flag ? "</TD><TD>" : ":   ",
            (long) cdist,
            flag ? "<BR>" : " ",
            cdist / earthrad );

    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );
    printf( "月の視差%s%.4f度\n",
            flag ? "</TD><TD>" : ":        ",
            cangdia );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );
    printf( "地球-太陽の距離%s%.0fkm%s(%.3f天文単位)\n",
            flag ? "</TD><TD>" : ": ",
            csund,
            flag ? "<BR>" : " ",
            csund / sunsmax );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );
    printf( "太陽の視差%s%.4f度\n",
            flag ? "</TD><TD>" : ":      ",
            csuang );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );

    printf( "朔%s%ld年%02ld月%02ld日 %02ld時%02ld分 UTC ",
            flag ? "</TD><TD COLSPAN=2>" : ":              ",
            yy, mm, dd, hh, mmm );
    printf( "(Lunation %ld)\n", lunation );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );

    lptime = phasar[1];
    jyear( lptime, &yy, &mm, &dd );
    jhms( lptime, &hh, &mmm, &ss );
    printf( "上弦%s%ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
            flag ? "</TD><TD COLSPAN=2>" : ":            ",
            yy, mm, dd, hh, mmm );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );

    lptime = phasar[2];
    jyear( lptime, &yy, &mm, &dd );
    jhms( lptime, &hh, &mmm, &ss );
    printf( "望%s%ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
            flag ? "</TD><TD COLSPAN=2>" : ":              ",
            yy, mm, dd, hh, mmm );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );

    lptime = phasar[3];
    jyear( lptime, &yy, &mm, &dd );
    jhms( lptime, &hh, &mmm, &ss );
    printf( "下弦%s%ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
            flag ? "</TD><TD COLSPAN=2>" : ":            ",
            yy, mm, dd, hh, mmm );
    if ( flag )
        printf( "</TD></TR>\n<TR><TD>" );

    nptime = phasar[4];
    jyear( nptime, &yy, &mm, &dd );
    jhms( nptime, &hh, &mmm, &ss );
    printf( "次の朔%s%ld年%02ld月%02ld日 %02ld時%02ld分 UTC ",
            flag ? "</TD><TD COLSPAN=2>" : ":          ",
            yy, mm, dd, hh, mmm );
    printf( "(Lunation %ld)\n", lunation + 1 );
    if ( flag )
        printf( "</TD></TR>\n</TABLE>\n" );

#ifdef  __TEST_20030507__
    if ( !flag ) {
        double  target = 0.0;

        lptime   = phasar[0];
        jyear( lptime, &yy, &mm, &dd );
        jhms( lptime, &hh, &mmm, &ss );
        printf( "  月齢 %f : %ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
                target, yy, mm, dd, hh, mmm );
        target += 1.0;

        do {
            jyear( lptime, &yy, &mm, &dd );
            jhms( lptime, &hh, &mmm, &ss );
            /*
            t1 = ((((double)absoluteFromGregorian( dd, mm, yy ) * 24.0 +
                    (double)hh) * 60.0) + (double)mmm) * 60.0 +
                    (double)ss;
         // aom = qpom3( t1, t2 );
            */

            jd = jtime( yy, mm, dd, hh, mmm, ss );
            phase( jd + 1, &cphase, &aom, &cdist, &cangdia, &csund, &csuang );

            /*
            if ( aom < 0.0 )
                aom += synmonth;
            */
         // printf( "aom = %f\n", aom );
            /*
                jyear( lptime, &yy, &mm, &dd );
                jhms( lptime, &hh, &mmm, &ss );
                printf( "  月齢 %f : %ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
                        aom, yy, mm, dd, hh, mmm );
            */
         // if ( aom > 1.0 )
         //     break;
            if ( floor(target * 100.0) == floor(aom * 100.00) ) {
                printf( "  月齢 %f : %ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
                        target - 1.0, yy, mm, dd, hh, mmm );
                target += 1.0;
            }
            lptime += 1.0 / (24.0 * 3600.0);
         /* lptime += 0.001; */
        } while ( floor(aom * 100.00) != 0.0 );

        lptime = phasar[4];
        jyear( lptime, &yy, &mm, &dd );
        jhms( lptime, &hh, &mmm, &ss );
        printf( "  月齢 %f : %ld年%02ld月%02ld日 %02ld時%02ld分 UTC\n",
                target, yy, mm, dd, hh, mmm );
    }
#endif  /* __TEST_20030507__ */
}