Skip to content

Commit 56f6b3a

Browse files
committed
More fixes, more tests
1 parent 531f6d4 commit 56f6b3a

13 files changed

+223
-20
lines changed

include/novas.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,20 @@ enum novas_reference_system {
234234
* Constants that determine the type of equator to be used for the coordinate system.
235235
*/
236236
enum novas_equator_type {
237-
NOVAS_MEAN_EQUATOR = 0, ///< True equinox Of Date (TOD): dynamical system of the true equator, with its origin at the true equinox (pre IAU 2006 system).
238-
NOVAS_CIRS_EQUATOR, ///< Celestial Intermediate Reference System (CIRS): dynamical system of the true equator, with its origin at the CIO (preferred since IAU 2006)
237+
NOVAS_MEAN_EQUATOR = 0, ///< Mean equator without nutation (pre IAU 2006 system).
238+
NOVAS_TRUE_EQUATOR, ///< True equator (pre IAU 2006 system).
239239
NOVAS_ICRS_EQUATOR ///< International Celestiual Reference system (ICRS). The equatorial system fixed to the frame of distant quasars.
240240
};
241241

242+
/**
243+
* Constants that determine the type of dynamical system type for gcrs2equ()
244+
*/
245+
enum novas_dynamical_type {
246+
NOVAS_DYNAMICAL_MOD = 0, ///< Mean equinox Of Date (TOD): dynamical system not including nutation (pre IAU 2006 system).
247+
NOVAS_DYNAMICAL_TOD, ///< True equinox Of Date (TOD): dynamical system of the true equator, with its origin at the true equinox (pre IAU 2006 system).
248+
NOVAS_DYNAMICAL_CIRS ///< Celestial Intermediate Reference System (CIRS): dynamical system of the true equator, with its origin at the CIO (preferred since IAU 2006)
249+
};
250+
242251
#define NOVAS_REFERENCE_SYSTEMS (NOVAS_ICRS + 1) ///< The number of basic coordinate reference systems in NOVAS.
243252

244253
/**
@@ -603,7 +612,7 @@ short ecl2equ_vec(double jd_tt, enum novas_equator_type coord_sys, enum novas_ac
603612
int equ2hor(double jd_ut1, double ut1_to_tt, enum novas_accuracy accuracy, double xp, double yp, const on_surface *location, double ra,
604613
double dec, enum novas_refraction_model ref_option, double *zd, double *az, double *rar, double *decr);
605614

606-
short gcrs2equ(double jd_tt, enum novas_equator_type coord_sys, enum novas_accuracy accuracy, double rag, double decg, double *ra,
615+
short gcrs2equ(double jd_tt, enum novas_dynamical_type coord_sys, enum novas_accuracy accuracy, double rag, double decg, double *ra,
607616
double *dec);
608617

609618
short sidereal_time(double jd_high, double jd_low, double ut1_to_tt, enum novas_equinox_type gst_type,

src/novas.c

+22-12
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ short equ2ecl_vec(double jd_tt, enum novas_equator_type coord_sys, enum novas_ac
14801480
// Get obliquity, depending upon the "system" of the input coordinates.
14811481
switch(coord_sys) {
14821482
case NOVAS_MEAN_EQUATOR: // Input: mean equator and equinox of date
1483-
case NOVAS_CIRS_EQUATOR: // Input: true equator and equinox of date
1483+
case NOVAS_TRUE_EQUATOR: // Input: true equator and equinox of date
14841484
memcpy(pos0, pos1, sizeof(pos0));
14851485

14861486
if(!time_equals(jd_tt, t_last) || accuracy != acc_last) {
@@ -1545,7 +1545,7 @@ short ecl2equ_vec(double jd_tt, enum novas_equator_type coord_sys, enum novas_ac
15451545
// Get obliquity, depending upon the "system" of the input coordinates.
15461546
switch(coord_sys) {
15471547
case NOVAS_MEAN_EQUATOR: // Output: mean equator and equinox of date
1548-
case NOVAS_CIRS_EQUATOR: // Output: true equator and equinox of date
1548+
case NOVAS_TRUE_EQUATOR: // Output: true equator and equinox of date
15491549
if(!time_equals(jd_tt, t_last) || accuracy != acc_last) {
15501550
e_tilt(jd_tdb, accuracy, &oblm, &oblt, NULL, NULL, NULL);
15511551
t_last = jd_tt;
@@ -1810,11 +1810,12 @@ int cirs_to_hor(double jd_ut1, double ut1_to_tt, enum novas_accuracy accuracy, d
18101810
* @param decg [deg] GCRS declination in degrees.
18111811
* @param[out] ra [h] Right ascension in hours, referred to specified equator and right ascension origin of date.
18121812
* @param[out] dec [deg] Declination in degrees, referred to specified equator of date.
1813-
* @return 0 if successful, or -1 with errno set to EINVAL if the output pointers are NULL, otherwise
1813+
* @return 0 if successful, or -1 with errno set to EINVAL if the output pointers are NULL or the
1814+
* coord_sys is invalid, otherwise
18141815
* <0 if an error from vector2radec(), 10--20 error is 10 + error cio_location(); or else
18151816
* 20 + error from cio_basis()
18161817
*/
1817-
short gcrs2equ(double jd_tt, enum novas_equator_type coord_sys, enum novas_accuracy accuracy, double rag, double decg, double *ra,
1818+
short gcrs2equ(double jd_tt, enum novas_dynamical_type coord_sys, enum novas_accuracy accuracy, double rag, double decg, double *ra,
18181819
double *dec) {
18191820
double t1, r, d, pos1[3], pos2[3];
18201821
int error = 0;
@@ -1835,24 +1836,32 @@ short gcrs2equ(double jd_tt, enum novas_equator_type coord_sys, enum novas_accur
18351836
pos1[1] = cos(d) * sin(r);
18361837
pos1[2] = sin(d);
18371838

1839+
18381840
// Transform the position vector based on the value of 'coord_sys'.
1839-
if(coord_sys <= 1) {
1841+
switch(coord_sys) {
18401842
// Transform the position vector from GCRS to mean equator and equinox
18411843
// of date.
18421844

18431845
// If requested, transform further to true equator and equinox of date.
1844-
if(coord_sys == NOVAS_CIRS_EQUATOR) {
1846+
case NOVAS_DYNAMICAL_TOD:
18451847
gcrs_to_tod(t1, accuracy, pos1, pos2);
1846-
}
1847-
else {
1848+
break;
1849+
1850+
case NOVAS_DYNAMICAL_MOD: {
18481851
double pos3[3];
18491852
frame_tie(pos1, TIE_ICRS_TO_J2000, pos3);
18501853
precession(JD_J2000, pos3, t1, pos2);
1854+
break;
18511855
}
1852-
}
1853-
else {
1854-
error = gcrs_to_cirs(t1, accuracy, pos1, pos2);
1855-
if(error) return 10 + error;
1856+
1857+
case NOVAS_DYNAMICAL_CIRS:
1858+
error = gcrs_to_cirs(t1, accuracy, pos1, pos2);
1859+
if(error) return 10 + error;
1860+
break;
1861+
1862+
default:
1863+
errno = EINVAL;
1864+
return -1;
18561865
}
18571866

18581867
// Convert the position vector to equatorial spherical coordinates.
@@ -1864,6 +1873,7 @@ short gcrs2equ(double jd_tt, enum novas_equator_type coord_sys, enum novas_accur
18641873
}
18651874

18661875
return 0;
1876+
18671877
}
18681878

18691879
/**

test/novasc3.1/cal_date.out

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-10000.0 A0: 1972 08 15 12.000000
2+
0.0 A0: 2000 01 01 12.000000
3+
10000.0 A0: 2027 05 19 12.000000
4+
10000.0 A0: 2027 05 19 12.000000

test/novasc3.1/gcrs2equ.out

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
0.0 22+20 S2 O0 A0: mean 22.000000 19.999997
3+
4+
0.0 22+20 S2 O0 A0: true 21.999816 19.999465
5+
6+
0.0 22+20 S2 O0 A0: cirs 22.000052 19.999465
7+
8+
0.0 16-20 S2 O0 A0: mean 16.000000 -19.999996
9+
10+
0.0 16-20 S2 O0 A0: true 15.999751 -19.997838
11+
12+
0.0 16-20 S2 O0 A0: cirs 15.999987 -19.997838
13+
14+
0.0 22+20 S2 O0 A1: mean 22.000000 19.999997
15+
16+
0.0 22+20 S2 O0 A1: true 21.999816 19.999465
17+
18+
0.0 22+20 S2 O0 A1: cirs 22.000052 19.999465
19+
20+
0.0 16-20 S2 O0 A1: mean 16.000000 -19.999996
21+
22+
0.0 16-20 S2 O0 A1: true 15.999751 -19.997838
23+
24+
0.0 16-20 S2 O0 A1: cirs 15.999987 -19.997838

test/novasc3.1/make_observer.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
G1 0
2+
G2 0
3+
E1 1 1.000 2.000 3.000 4.0 5.0
4+
E2 1 1.000 2.000 3.000 4.0 5.0
5+
S1 2 100.000 200.000 300.000 -10.000 -20.000 -30.000
6+
S2 2 100.000 200.000 300.000 -10.000 -20.000 -30.000

test/novasc3.1/mean_star.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 0.000000 0.000000
2+
2 0.000000 0.000000
3+
3 0.000000 0.000000

test/novasc3.1/tbd2tt.out

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-10000.0 A0: -0.001101
2+
0.0 A0: -0.000096
3+
10000.0 A0: 0.001169
4+
10000.0 A0: 0.001169
5+
-10000.0 A1: -0.001101
6+
0.0 A1: -0.000096
7+
10000.0 A1: 0.001169
8+
10000.0 A1: 0.001169

test/reference/cal_date.out

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-10000.0 A0: 1972 08 15 12.000000
2+
0.0 A0: 2000 01 01 12.000000
3+
10000.0 A0: 2027 05 19 12.000000
4+
10000.0 A0: 2027 05 19 12.000000

test/reference/gcrs2equ.out

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
0.0 22+20 S2 O0 A0: mean 22.000000 20.000003
3+
4+
0.0 22+20 S2 O0 A0: true 21.999815 19.999471
5+
6+
0.0 22+20 S2 O0 A0: cirs 22.000052 19.999471
7+
8+
0.0 16-20 S2 O0 A0: mean 16.000000 -20.000004
9+
10+
0.0 16-20 S2 O0 A0: true 15.999750 -19.997846
11+
12+
0.0 16-20 S2 O0 A0: cirs 15.999987 -19.997846
13+
14+
0.0 22+20 S2 O0 A1: mean 22.000000 20.000003
15+
16+
0.0 22+20 S2 O0 A1: true 21.999815 19.999471
17+
18+
0.0 22+20 S2 O0 A1: cirs 22.000052 19.999471
19+
20+
0.0 16-20 S2 O0 A1: mean 16.000000 -20.000004
21+
22+
0.0 16-20 S2 O0 A1: true 15.999750 -19.997846
23+
24+
0.0 16-20 S2 O0 A1: cirs 15.999987 -19.997846

test/reference/make_observer.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
G1 0
2+
G2 0
3+
E1 1 1.000 2.000 3.000 4.0 5.0
4+
E2 0 1.000 2.000 3.000 4.0 5.0
5+
S1 2 100.000 200.000 300.000 -10.000 -20.000 -30.000
6+
S2 0 100.000 200.000 300.000 -10.000 -20.000 -30.000

test/reference/mean_star.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 0.000000 0.000000
2+
2 0.000000 0.000000
3+
3 0.000000 0.000000

test/reference/tbd2tt.out

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-10000.0 A0: -0.001101
2+
0.0 A0: -0.000096
3+
10000.0 A0: 0.001169
4+
10000.0 A0: 0.001169
5+
-10000.0 A1: -0.001101
6+
0.0 A1: -0.000096
7+
10000.0 A1: 0.001169
8+
10000.0 A1: 0.001169

test/src/test.c

+99-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ static int idx = -1;
3333

3434
static char *header;
3535

36-
// make_observer
37-
// cal_date
3836
// transform_cat
3937
// transform_hip
40-
// cio_array, cio_location (same time), cio_ra, tbd2tt
38+
// cio_array, cio_location (same time), cio_ra
4139
// cel_pole
42-
// gcrs2equ
4340
// ecl2equ_vec
44-
// mean_star
4541

4642
static void newline() {
4743
fprintf(fp, "\n%8.1f %-10s S%d O%d A%d: ", (tdb - J2000), source.name, source.type, obs.where, accuracy);
@@ -123,6 +119,42 @@ static void test_make_object() {
123119
}
124120

125121

122+
static void test_make_observer() {
123+
observer obs, earth, space;
124+
double pos[3] = {100.0, 200.0, 300.0};
125+
double vel[3] = {-10.0, -20.0, -30.0};
126+
on_surface *on = &earth.on_surf;
127+
in_space *in = &space.near_earth;
128+
129+
openfile("make_observer");
130+
make_observer(0, NULL, NULL, &obs);
131+
fprintf(fp, "G1 %d ", obs.where);
132+
133+
openfile("make_observer");
134+
make_observer_at_geocenter(&obs);
135+
fprintf(fp, "G2 %d ", obs.where);
136+
137+
openfile("make_observer");
138+
make_observer_on_surface(1.0, 2.0, 3.0, 4.0, 5.0, &earth);
139+
fprintf(fp, "E1 %d %8.3f %8.3f %8.3f %5.1f %5.1f ", earth.where, on->latitude, on->longitude, on->height, on->temperature, on->pressure);
140+
141+
openfile("make_observer");
142+
make_observer(1, on, NULL, &obs);
143+
on = &obs.on_surf;
144+
fprintf(fp, "E2 %d %8.3f %8.3f %8.3f %5.1f %5.1f ", obs.where, on->latitude, on->longitude, on->height, on->temperature, on->pressure);
145+
146+
openfile("make_observer");
147+
make_observer_in_space(pos, vel, &space);
148+
fprintf(fp, "S1 %d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f ", space.where, in->sc_pos[0], in->sc_pos[1], in->sc_pos[2], in->sc_vel[0], in->sc_vel[1], in->sc_vel[2]);
149+
150+
openfile("make_observer");
151+
make_observer(2, NULL, in, &obs);
152+
in = &obs.near_earth;
153+
fprintf(fp, "S2 %d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f ", obs.where, in->sc_pos[0], in->sc_pos[1], in->sc_pos[2], in->sc_vel[0], in->sc_vel[1], in->sc_vel[2]);
154+
}
155+
156+
157+
126158
static void test_refract() {
127159
on_surface surf;
128160

@@ -132,23 +164,60 @@ static void test_refract() {
132164
fprintf(fp, "%12.6f %12.6f ", refract(&surf, 1, 89.0), refract(&surf, 2, 89.0));
133165
}
134166

167+
static void test_mean_star() {
168+
double ra, dec;
169+
170+
mean_star(2433282.42345905, 10.0, -40.0, 0, &ra, &dec);
171+
openfile("mean_star");
172+
fprintf(fp, "1 %12.6f %12.6f ", ra, dec);
173+
174+
mean_star(2433282.42345905, 19.0, 30.0, 0, &ra, &dec);
175+
openfile("mean_star");
176+
fprintf(fp, "2 %12.6f %12.6f ", ra, dec);
177+
178+
mean_star(2433282.42345905, 2.7, 68.3, 0, &ra, &dec);
179+
openfile("mean_star");
180+
fprintf(fp, "3 %12.6f %12.6f ", ra, dec);
181+
}
135182

136183

137184
static void test_basics() {
138185
idx = -1;
139186
test_make_cat_entry();
140187
test_make_object();
188+
test_make_observer();
141189
test_refract();
190+
test_mean_star();
142191
}
143192

144193

145194

146195

147196

197+
148198
// ======================================================================================
149199
// Time specific
150200
// ======================================================================================
151201

202+
static void test_cal_date() {
203+
short y, m, d;
204+
double h;
205+
206+
if(accuracy != 0) return;
207+
208+
cal_date(tdb, &y, &m, &d, &h);
209+
openfile("cal_date");
210+
fprintf(fp, "%5d %02d %02d %10.6f ", y, m, d, h);
211+
}
212+
213+
214+
static void test_tdb2tt() {
215+
double tt, dt;
216+
openfile("tbd2tt");
217+
tdb2tt(tdb, &tt, &dt);
218+
fprintf(fp, "%12.6f ", dt);
219+
}
220+
152221
static void test_ephemeris() {
153222
double pos1[3], vel1[3], tdb2[2] = {tdb};
154223
object body[2];
@@ -286,13 +355,17 @@ static void test_geo_posvel() {
286355
}
287356
}
288357

358+
359+
289360
static void test_time_specific() {
290361
static char th[40] = { };
291362

292363
idx = -1;
293364
sprintf(th, "%8.1f A%d: ", (tdb - J2000), accuracy);
294365
header = th;
295366

367+
test_cal_date();
368+
test_tdb2tt();
296369
test_ephemeris();
297370
test_era();
298371
test_ee_ct();
@@ -633,6 +706,24 @@ static void test_equ2ecl() {
633706
fprintf(fp, "%12.6f %12.6f ", elon, elat);
634707
}
635708

709+
static void test_gcrs2equ() {
710+
double ra, dec;
711+
712+
if(source.type != 2 || obs.where != 0 || tdb != J2000) return;
713+
714+
openfile("gcrs2equ");
715+
if(is_ok(gcrs2equ(tdb, 0, accuracy, source.star.ra, source.star.dec, &ra, &dec)))
716+
fprintf(fp, "mean %12.6f %12.6f ", ra, dec);
717+
718+
openfile("gcrs2equ");
719+
if(is_ok(gcrs2equ(tdb, 1, accuracy, source.star.ra, source.star.dec, &ra, &dec)))
720+
fprintf(fp, "true %12.6f %12.6f ", ra, dec);
721+
722+
openfile("gcrs2equ");
723+
if(is_ok(gcrs2equ(tdb, 2, accuracy, source.star.ra, source.star.dec, &ra, &dec)))
724+
fprintf(fp, "cirs %12.6f %12.6f ", ra, dec);
725+
}
726+
636727
static int test_source() {
637728
openfile("init");
638729

@@ -655,6 +746,7 @@ static int test_source() {
655746
test_ter2cel();
656747
test_equ2gal();
657748
test_equ2ecl();
749+
test_gcrs2equ();
658750
}
659751

660752
if(obs.where == 1) {
@@ -711,6 +803,8 @@ static int test_sources() {
711803
return 0;
712804
}
713805

806+
807+
714808
static int test_dates() {
715809
double offsets[] = {-10000.0, 0.0, 10000.0, 10000.0 };
716810
int i;

0 commit comments

Comments
 (0)