change arg of g2jd, deltaT from struct to seperated param

This commit is contained in:
Chen Wei
2014-03-31 07:43:49 +08:00
parent eb7acb8c21
commit 1e62e81c23
6 changed files with 38 additions and 60 deletions

View File

@@ -110,11 +110,8 @@ double solarterm(int year, double angle)
double ERROR, r, est_vejd, x0, x1;
ERROR = 0.000000005;
GregorianDate ve; /* estimated date of Vernal Equinox, March 20.5 UTC0 */
ve.year = year;
ve.month = 3;
ve.day = 20.5;
est_vejd = g2jd(ve);
/* estimated date of Vernal Equinox, March 20.5 UTC0 */
est_vejd = g2jd(year, 3, 20.5);
/* negative angle means search backward from Vernal Equinox.
* Initialize x0 to the day which apparent Sun longitude close to the

View File

@@ -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);
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);

View File

@@ -9,28 +9,28 @@
#include "astro.h"
/* 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) {
d.year -= 1;
d.month += 12;
if (month <= 2) {
year -= 1;
month += 12;
}
int a, b, isjulian;
double jd;
a = (int) (d.year / 100);
a = (int) (year / 100);
isjulian = 0;
if (d.year < 1582) {
if (year < 1582) {
isjulian = 1;
} else if (d.year == 1582) {
if (d.month < 10)
} else if (year == 1582) {
if (month < 10)
isjulian = 1;
if (d.month == 10 && d.day <= 5)
if (month == 10 && day <= 5.0)
isjulian = 1;
if (d.month == 10 && d.day > 5 && d.day < 15)
if (month == 10 && day > 5.0 && day < 15.0)
return 2299160.5;
}
@@ -40,8 +40,8 @@ double g2jd(GregorianDate d)
b = 2 - a + (int) (a / 4);
/* 30.6001 is a hack Meeus suggested */
jd = (int) (365.25 * (d.year + 4716)) + (int) (30.6001 * (d.month + 1))
+ d.day + b - 1524.5;
jd = (int) (365.25 * (year + 4716)) + (int) (30.6001 * (month + 1))
+ day + b - 1524.5;
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;
g.day = d;
return g2jd(g);
return g2jd(g.year, g.month, g.day);
}
/* 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]; */
g = jd2g(jd);
deltat = isut ? deltaT(g) : 0;
deltat = isut ? deltaT(g.year, g.month) : 0;
/* convert jd to seconds, then adjust 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
*/
double deltaT(GregorianDate g) {
int year;
double deltaT(int year, int month) {
double y, m, u;
year = g.year;
m = (double) g.month;
m = (double) month;
y = year + (m - 0.5) / 12.0;
if (year < -500) {
u = (year - 1820) / 100.0;

View File

@@ -32,7 +32,6 @@ static char *CN_SOLARTERM[] = {
static double newmoons[MAX_NEWMOONS];
static double solarterms[MAX_SOLARTERMS];
static struct lunarcal *lcs[MAX_DAYS];
static int firstnm_offset;
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;
GregorianDate g;
g = jd2g(jd);
deltat = deltaT(g);
deltat = deltaT(g.year, g.month);
tmp = jd + (tz * 3600.0 - deltat) / 86400.0;
g = jd2g(tmp);
jd_f = modf(tmp, &jd_i);
@@ -68,15 +67,11 @@ void cn_lunarcal(int year)
len1 = get_cached_lc(thisyear, year);
len2 = get_cached_lc(nextyear, year + 1);
/* zip */
GregorianDate g;
g.year = year;
g.month = 1;
g.day = 1;
ystart = g2jd(g);
g.month = 12;
g.day = 31;
yend = g2jd(g);
/* combine lunar calendars from this and next year. Leapmonth close to the
* end of Gregorian year can only be found by compute Lunar calendar of the
* next year */
ystart = g2jd(year, 1, 1.0);
yend = g2jd(year, 12, 31.0);
k = 0;
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) {
for (i = 0; i < MAX_DAYS; i++) {
if (cached_lcs[k][i] ==NULL)
if (cached_lcs[k][i] == NULL)
break;
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;
}
len = mark_month_day();
for (i = 0; i < MAX_DAYS; i++) {
len = mark_month_day(p);
for (i = 0; i < len; i++) {
if (cachep > CACHESIZE)
cachep = 0;
cached_lcs[cachep][i] = lcs[i];
p[i] = lcs[i];
cached_lcs[cachep][i] = p[i];
}
/* add to cache */
@@ -148,7 +142,7 @@ int get_cached_lc(struct lunarcal *p[], int year)
/* mark month and day number, solarterms */
int mark_month_day(void)
int mark_month_day(struct lunarcal *lcs[])
{
int i, k, len;
int leapmonth, month;

View File

@@ -19,7 +19,7 @@ double normjd(double jd, double tz);
int find_leap(void);
int mark_month_day(void);
int mark_month_day(struct lunarcal *lcs[]);
struct lunarcal *lcalloc(double jd);

View File

@@ -22,12 +22,9 @@ double jd2year(double jd);
double jd2year(double jd)
{
double fyear, jdyearstart;
GregorianDate tmp, yearstart ;
GregorianDate tmp;
tmp = jd2g(jd);
yearstart.year = tmp.year;
yearstart.month = 1;
yearstart.day = 1;
jdyearstart = g2jd(yearstart);
jdyearstart = g2jd(tmp.year, 1, 1.0);
fyear = (double) tmp.year + (jd - jdyearstart) / 365.0;
return fyear;
@@ -46,16 +43,12 @@ void testdeltat()
jdftime(strout, jd, "%y-%m-%d %H:%M", 0, 0);
printf("jdftime output = %s\n", strout);
GregorianDate g;
int i,year;
double deltat;
year = -500;
for (i = 0; i < 20; i++) {
g.year = year;
g.month = 1;
g.day = 0;
deltat = deltaT(g);
printf("%d = %.2f\n", g.year, deltat);
deltat = deltaT(year, 1);
printf("%d = %.2f\n", year, deltat);
year += 100;
}
return;
@@ -67,16 +60,12 @@ void testnewmoon_solarterm(void)
double newmoons[NMCOUNT];
double jd;
//jd = jdptime("2014-01-01 18:00", "%y-%m-%d %H:%M", 0, 0);
GregorianDate g;
int year = 2000;
int n;
char isodt[30];
int i;
for (n = 0; n < 5; n++) {
g.year = year;
g.month = 1;
g.day = 1;
jd = g2jd(g);
jd = g2jd(year, 1, 1.0);
findnewmoons(newmoons, NMCOUNT, jd);
year += 1;
}
@@ -179,7 +168,7 @@ void verify_apparent_sun_moon(void)
lensun = parsejplhorizon("jpl_sun.txt", jplsun);
lenmoon = parsejplhorizon("jpl_moon.txt", jplmoon);
step = 50;
step = 1;
i = 0;
count = 0;
delta_sun_n = 0;