mirror of
https://github.com/infinet/lunar-calendar.git
synced 2026-01-12 21:17:00 +08:00
change arg of g2jd, deltaT from struct to seperated param
This commit is contained in:
@@ -110,11 +110,8 @@ double solarterm(int year, double angle)
|
|||||||
double ERROR, r, est_vejd, x0, x1;
|
double ERROR, r, est_vejd, x0, x1;
|
||||||
ERROR = 0.000000005;
|
ERROR = 0.000000005;
|
||||||
|
|
||||||
GregorianDate ve; /* estimated date of Vernal Equinox, March 20.5 UTC0 */
|
/* estimated date of Vernal Equinox, March 20.5 UTC0 */
|
||||||
ve.year = year;
|
est_vejd = g2jd(year, 3, 20.5);
|
||||||
ve.month = 3;
|
|
||||||
ve.day = 20.5;
|
|
||||||
est_vejd = g2jd(ve);
|
|
||||||
|
|
||||||
/* negative angle means search backward from Vernal Equinox.
|
/* negative angle means search backward from Vernal Equinox.
|
||||||
* Initialize x0 to the day which apparent Sun longitude close to the
|
* Initialize x0 to the day which apparent Sun longitude close to the
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ double jdptime(char *isodt, char *fmt, double tz, int isut);
|
|||||||
|
|
||||||
size_t jdftime(char *isodt, double jd, char *fmt, double tz, int isut);
|
size_t jdftime(char *isodt, double jd, char *fmt, double tz, int isut);
|
||||||
|
|
||||||
double g2jd(GregorianDate d);
|
double g2jd(int year, int month, double day);
|
||||||
|
|
||||||
double deltaT(GregorianDate g);
|
double deltaT(int year, int month);
|
||||||
|
|
||||||
double apparentsun(double jd, int ignorenutation);
|
double apparentsun(double jd, int ignorenutation);
|
||||||
|
|
||||||
|
|||||||
34
c/julian.c
34
c/julian.c
@@ -9,28 +9,28 @@
|
|||||||
#include "astro.h"
|
#include "astro.h"
|
||||||
|
|
||||||
/* convert a Gregorian date to JD from AA, p61 */
|
/* convert a Gregorian date to JD from AA, p61 */
|
||||||
double g2jd(GregorianDate d)
|
double g2jd(int year, int month, double day)
|
||||||
{
|
{
|
||||||
if (d.month <= 2) {
|
if (month <= 2) {
|
||||||
d.year -= 1;
|
year -= 1;
|
||||||
d.month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a, b, isjulian;
|
int a, b, isjulian;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
a = (int) (d.year / 100);
|
a = (int) (year / 100);
|
||||||
isjulian = 0;
|
isjulian = 0;
|
||||||
if (d.year < 1582) {
|
if (year < 1582) {
|
||||||
isjulian = 1;
|
isjulian = 1;
|
||||||
} else if (d.year == 1582) {
|
} else if (year == 1582) {
|
||||||
if (d.month < 10)
|
if (month < 10)
|
||||||
isjulian = 1;
|
isjulian = 1;
|
||||||
|
|
||||||
if (d.month == 10 && d.day <= 5)
|
if (month == 10 && day <= 5.0)
|
||||||
isjulian = 1;
|
isjulian = 1;
|
||||||
|
|
||||||
if (d.month == 10 && d.day > 5 && d.day < 15)
|
if (month == 10 && day > 5.0 && day < 15.0)
|
||||||
return 2299160.5;
|
return 2299160.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +40,8 @@ double g2jd(GregorianDate d)
|
|||||||
b = 2 - a + (int) (a / 4);
|
b = 2 - a + (int) (a / 4);
|
||||||
|
|
||||||
/* 30.6001 is a hack Meeus suggested */
|
/* 30.6001 is a hack Meeus suggested */
|
||||||
jd = (int) (365.25 * (d.year + 4716)) + (int) (30.6001 * (d.month + 1))
|
jd = (int) (365.25 * (year + 4716)) + (int) (30.6001 * (month + 1))
|
||||||
+ d.day + b - 1524.5;
|
+ day + b - 1524.5;
|
||||||
return jd;
|
return jd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ double jdptime(char *isodt, char *fmt, double tz, int isut)
|
|||||||
d += (hour * 3600.0 + minute * 60.0 + sec) / 86400.0;
|
d += (hour * 3600.0 + minute * 60.0 + sec) / 86400.0;
|
||||||
g.day = d;
|
g.day = d;
|
||||||
|
|
||||||
return g2jd(g);
|
return g2jd(g.year, g.month, g.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* format a Julian Day to ISO format datetime
|
/* format a Julian Day to ISO format datetime
|
||||||
@@ -164,7 +164,7 @@ size_t jdftime(char *isodt, double jd, char *fmt, double tz, int isut)
|
|||||||
/* char isodt[ISODTLEN]; */
|
/* char isodt[ISODTLEN]; */
|
||||||
g = jd2g(jd);
|
g = jd2g(jd);
|
||||||
|
|
||||||
deltat = isut ? deltaT(g) : 0;
|
deltat = isut ? deltaT(g.year, g.month) : 0;
|
||||||
|
|
||||||
/* convert jd to seconds, then adjust deltat */
|
/* convert jd to seconds, then adjust deltat */
|
||||||
utsec = jd * 86400.0 + tz * 3600.0 - deltat;
|
utsec = jd * 86400.0 + tz * 3600.0 - deltat;
|
||||||
@@ -266,11 +266,9 @@ size_t jdftime(char *isodt, double jd, char *fmt, double tz, int isut)
|
|||||||
Horizon
|
Horizon
|
||||||
|
|
||||||
*/
|
*/
|
||||||
double deltaT(GregorianDate g) {
|
double deltaT(int year, int month) {
|
||||||
int year;
|
|
||||||
double y, m, u;
|
double y, m, u;
|
||||||
year = g.year;
|
m = (double) month;
|
||||||
m = (double) g.month;
|
|
||||||
y = year + (m - 0.5) / 12.0;
|
y = year + (m - 0.5) / 12.0;
|
||||||
if (year < -500) {
|
if (year < -500) {
|
||||||
u = (year - 1820) / 100.0;
|
u = (year - 1820) / 100.0;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ static char *CN_SOLARTERM[] = {
|
|||||||
|
|
||||||
static double newmoons[MAX_NEWMOONS];
|
static double newmoons[MAX_NEWMOONS];
|
||||||
static double solarterms[MAX_SOLARTERMS];
|
static double solarterms[MAX_SOLARTERMS];
|
||||||
static struct lunarcal *lcs[MAX_DAYS];
|
|
||||||
static int firstnm_offset;
|
static int firstnm_offset;
|
||||||
|
|
||||||
static int cached_year[CACHESIZE]; /* caches intermedia lunar cal*/
|
static int cached_year[CACHESIZE]; /* caches intermedia lunar cal*/
|
||||||
@@ -46,7 +45,7 @@ double normjd(double jd, double tz)
|
|||||||
double deltat, tmp, jd_i, jd_f;
|
double deltat, tmp, jd_i, jd_f;
|
||||||
GregorianDate g;
|
GregorianDate g;
|
||||||
g = jd2g(jd);
|
g = jd2g(jd);
|
||||||
deltat = deltaT(g);
|
deltat = deltaT(g.year, g.month);
|
||||||
tmp = jd + (tz * 3600.0 - deltat) / 86400.0;
|
tmp = jd + (tz * 3600.0 - deltat) / 86400.0;
|
||||||
g = jd2g(tmp);
|
g = jd2g(tmp);
|
||||||
jd_f = modf(tmp, &jd_i);
|
jd_f = modf(tmp, &jd_i);
|
||||||
@@ -68,15 +67,11 @@ void cn_lunarcal(int year)
|
|||||||
len1 = get_cached_lc(thisyear, year);
|
len1 = get_cached_lc(thisyear, year);
|
||||||
len2 = get_cached_lc(nextyear, year + 1);
|
len2 = get_cached_lc(nextyear, year + 1);
|
||||||
|
|
||||||
/* zip */
|
/* combine lunar calendars from this and next year. Leapmonth close to the
|
||||||
GregorianDate g;
|
* end of Gregorian year can only be found by compute Lunar calendar of the
|
||||||
g.year = year;
|
* next year */
|
||||||
g.month = 1;
|
ystart = g2jd(year, 1, 1.0);
|
||||||
g.day = 1;
|
yend = g2jd(year, 12, 31.0);
|
||||||
ystart = g2jd(g);
|
|
||||||
g.month = 12;
|
|
||||||
g.day = 31;
|
|
||||||
yend = g2jd(g);
|
|
||||||
k = 0;
|
k = 0;
|
||||||
|
|
||||||
for (i = 0; i < MAX_DAYS; output[i++] = NULL)
|
for (i = 0; i < MAX_DAYS; output[i++] = NULL)
|
||||||
@@ -113,7 +108,7 @@ int get_cached_lc(struct lunarcal *p[], int year)
|
|||||||
|
|
||||||
if ((k = get_cache_index(year)) > -1) {
|
if ((k = get_cache_index(year)) > -1) {
|
||||||
for (i = 0; i < MAX_DAYS; i++) {
|
for (i = 0; i < MAX_DAYS; i++) {
|
||||||
if (cached_lcs[k][i] ==NULL)
|
if (cached_lcs[k][i] == NULL)
|
||||||
break;
|
break;
|
||||||
p[i] = cached_lcs[k][i];
|
p[i] = cached_lcs[k][i];
|
||||||
}
|
}
|
||||||
@@ -133,12 +128,11 @@ int get_cached_lc(struct lunarcal *p[], int year)
|
|||||||
est_nm = jd_nm + SYNODIC_MONTH;
|
est_nm = jd_nm + SYNODIC_MONTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = mark_month_day();
|
len = mark_month_day(p);
|
||||||
for (i = 0; i < MAX_DAYS; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (cachep > CACHESIZE)
|
if (cachep > CACHESIZE)
|
||||||
cachep = 0;
|
cachep = 0;
|
||||||
cached_lcs[cachep][i] = lcs[i];
|
cached_lcs[cachep][i] = p[i];
|
||||||
p[i] = lcs[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add to cache */
|
/* add to cache */
|
||||||
@@ -148,7 +142,7 @@ int get_cached_lc(struct lunarcal *p[], int year)
|
|||||||
|
|
||||||
|
|
||||||
/* mark month and day number, solarterms */
|
/* mark month and day number, solarterms */
|
||||||
int mark_month_day(void)
|
int mark_month_day(struct lunarcal *lcs[])
|
||||||
{
|
{
|
||||||
int i, k, len;
|
int i, k, len;
|
||||||
int leapmonth, month;
|
int leapmonth, month;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ double normjd(double jd, double tz);
|
|||||||
|
|
||||||
int find_leap(void);
|
int find_leap(void);
|
||||||
|
|
||||||
int mark_month_day(void);
|
int mark_month_day(struct lunarcal *lcs[]);
|
||||||
|
|
||||||
struct lunarcal *lcalloc(double jd);
|
struct lunarcal *lcalloc(double jd);
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,9 @@ double jd2year(double jd);
|
|||||||
double jd2year(double jd)
|
double jd2year(double jd)
|
||||||
{
|
{
|
||||||
double fyear, jdyearstart;
|
double fyear, jdyearstart;
|
||||||
GregorianDate tmp, yearstart ;
|
GregorianDate tmp;
|
||||||
tmp = jd2g(jd);
|
tmp = jd2g(jd);
|
||||||
yearstart.year = tmp.year;
|
jdyearstart = g2jd(tmp.year, 1, 1.0);
|
||||||
yearstart.month = 1;
|
|
||||||
yearstart.day = 1;
|
|
||||||
jdyearstart = g2jd(yearstart);
|
|
||||||
|
|
||||||
fyear = (double) tmp.year + (jd - jdyearstart) / 365.0;
|
fyear = (double) tmp.year + (jd - jdyearstart) / 365.0;
|
||||||
return fyear;
|
return fyear;
|
||||||
@@ -46,16 +43,12 @@ void testdeltat()
|
|||||||
jdftime(strout, jd, "%y-%m-%d %H:%M", 0, 0);
|
jdftime(strout, jd, "%y-%m-%d %H:%M", 0, 0);
|
||||||
printf("jdftime output = %s\n", strout);
|
printf("jdftime output = %s\n", strout);
|
||||||
|
|
||||||
GregorianDate g;
|
|
||||||
int i,year;
|
int i,year;
|
||||||
double deltat;
|
double deltat;
|
||||||
year = -500;
|
year = -500;
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
g.year = year;
|
deltat = deltaT(year, 1);
|
||||||
g.month = 1;
|
printf("%d = %.2f\n", year, deltat);
|
||||||
g.day = 0;
|
|
||||||
deltat = deltaT(g);
|
|
||||||
printf("%d = %.2f\n", g.year, deltat);
|
|
||||||
year += 100;
|
year += 100;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -67,16 +60,12 @@ void testnewmoon_solarterm(void)
|
|||||||
double newmoons[NMCOUNT];
|
double newmoons[NMCOUNT];
|
||||||
double jd;
|
double jd;
|
||||||
//jd = jdptime("2014-01-01 18:00", "%y-%m-%d %H:%M", 0, 0);
|
//jd = jdptime("2014-01-01 18:00", "%y-%m-%d %H:%M", 0, 0);
|
||||||
GregorianDate g;
|
|
||||||
int year = 2000;
|
int year = 2000;
|
||||||
int n;
|
int n;
|
||||||
char isodt[30];
|
char isodt[30];
|
||||||
int i;
|
int i;
|
||||||
for (n = 0; n < 5; n++) {
|
for (n = 0; n < 5; n++) {
|
||||||
g.year = year;
|
jd = g2jd(year, 1, 1.0);
|
||||||
g.month = 1;
|
|
||||||
g.day = 1;
|
|
||||||
jd = g2jd(g);
|
|
||||||
findnewmoons(newmoons, NMCOUNT, jd);
|
findnewmoons(newmoons, NMCOUNT, jd);
|
||||||
year += 1;
|
year += 1;
|
||||||
}
|
}
|
||||||
@@ -179,7 +168,7 @@ void verify_apparent_sun_moon(void)
|
|||||||
|
|
||||||
lensun = parsejplhorizon("jpl_sun.txt", jplsun);
|
lensun = parsejplhorizon("jpl_sun.txt", jplsun);
|
||||||
lenmoon = parsejplhorizon("jpl_moon.txt", jplmoon);
|
lenmoon = parsejplhorizon("jpl_moon.txt", jplmoon);
|
||||||
step = 50;
|
step = 1;
|
||||||
i = 0;
|
i = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
delta_sun_n = 0;
|
delta_sun_n = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user