Skip to content

Commit d711a1f

Browse files
committed
Fix tod_to_itrs() and more tests
1 parent c3eec1a commit d711a1f

File tree

2 files changed

+30
-44
lines changed

2 files changed

+30
-44
lines changed

src/frames.c

+7-23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <math.h>
2121
#include "novas.h"
2222

23+
#define XI0 (-0.0166170 * ARCSEC) ///< Frame bias term &xi;<sub>0</sub>
24+
#define ETA0 (-0.0068192 * ARCSEC) ///< Frame bias term &eta;<sub>0</sub>
25+
#define DA0 (-0.01460 * ARCSEC) ///< Frame bias term da<sub>0</sub>
26+
2327
/// \cond PRIVATE
2428
#define FRAME_DEFAULT 0 ///< frame.state value we set to indicate the frame is not configured
2529
#define FRAME_INITIALIZED 0xdeadbeadcafeba5e ///< frame.state for a properly initialized frame.
@@ -44,21 +48,6 @@ static int cmp_sys(enum novas_reference_system a, enum novas_reference_system b)
4448
return index[a] < index[b] ? -1 : 1;
4549
}
4650

47-
int print_matrix(const char *prefix, const novas_matrix *matrix) {
48-
int i;
49-
for(i = 0; i < 3; i++) {
50-
int j;
51-
52-
printf(prefix);
53-
for(j = 0; j < 3; j++)
54-
printf(" %.12f", matrix->M[i][j]);
55-
printf("\n");
56-
}
57-
printf("\n");
58-
59-
return 0;
60-
}
61-
6251
static int matrix_transform(const double *in, const novas_matrix *matrix, double *out) {
6352
double v[3];
6453
int i;
@@ -112,11 +101,6 @@ static int invert_matrix(const novas_matrix *A, novas_matrix *I) {
112101
return 0;
113102
}
114103

115-
#define XI0 (-0.0166170 * ARCSEC)
116-
#define ETA0 (-0.0068192 * ARCSEC)
117-
#define DA0 (-0.01460 * ARCSEC)
118-
119-
120104
static int set_frame_tie(novas_frame *frame) {
121105
// 'xi0', 'eta0', and 'da0' are ICRS frame biases in arcseconds taken
122106
// from IERS (2003) Conventions, Chapter 5.
@@ -684,7 +668,7 @@ int novas_app_to_hor(const novas_frame *frame, enum novas_reference_system sys,
684668
if(!is_frame_initialized(frame))
685669
return novas_error(-1, EINVAL, fn, "frame at %p not initialized", frame);
686670

687-
if(frame->observer.where != NOVAS_OBSERVER_ON_EARTH) {
671+
if(frame->observer.where != NOVAS_OBSERVER_ON_EARTH && frame->observer.where != NOVAS_AIRBORNE_OBSERVER) {
688672
return novas_error(-1, EINVAL, fn, "observer not on Earth: where=%d", frame->observer.where);
689673
}
690674

@@ -772,7 +756,7 @@ int novas_hor_to_app(const novas_frame *frame, double az, double el, RefractionM
772756
if(!is_frame_initialized(frame))
773757
return novas_error(-1, EINVAL, fn, "frame at %p not initialized", frame);
774758

775-
if(frame->observer.where != NOVAS_OBSERVER_ON_EARTH) {
759+
if(frame->observer.where != NOVAS_OBSERVER_ON_EARTH && frame->observer.where != NOVAS_AIRBORNE_OBSERVER) {
776760
return novas_error(-1, EINVAL, fn, "observer not on Earth: where=%d", frame->observer.where);
777761
}
778762

@@ -798,7 +782,7 @@ int novas_hor_to_app(const novas_frame *frame, double az, double el, RefractionM
798782
prop_error(fn, itrs_to_cirs(time->ijd_tt, time->fjd_tt, time->ut1_to_tt, frame->accuracy, frame->dx, frame->dy, pos, pos), 0);
799783
}
800784

801-
// Continue to convert to output system....
785+
// Continue to convert TOD / CIRS to output system....
802786
switch(sys) {
803787
case NOVAS_TOD:
804788
break;

test/src/test-super.c

+23-21
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int is_ok(const char *func, int error) {
8080
static int is_equal(const char *func, double v1, double v2, double prec) {
8181
if(fabs(v1 - v2) < prec) return 1;
8282

83-
fprintf(stderr, "ERROR! %s (%.9g != %.9g)\n", func, v1, v2);
83+
fprintf(stderr, "ERROR! %s (%.12g != %.12g)\n", func, v1, v2);
8484
return 0;
8585
}
8686

@@ -93,7 +93,7 @@ static int test_gcrs_j2000_gcrs() {
9393

9494
if(!is_ok("gcrs_to_j2000", gcrs_to_j2000(pos0, pos1))) return 1;
9595
if(!is_ok("j2000_to_gcrs", j2000_to_gcrs(pos1, pos1))) return 1;
96-
if(!is_ok("gcrs_j2000_gcrs", check_equal_pos(pos0, pos1, 1e-9 * vlen(pos0)))) return 1;
96+
if(!is_ok("gcrs_j2000_gcrs", check_equal_pos(pos0, pos1, 1e-12 * vlen(pos0)))) return 1;
9797
return 0;
9898
}
9999

@@ -102,7 +102,7 @@ static int test_j2000_tod_j2000() {
102102

103103
if(!is_ok("j2000_to_tod", j2000_to_tod(tdb, 0, pos0, pos1))) return 1;
104104
if(!is_ok("tod_to_j2000", tod_to_j2000(tdb, 0, pos1, pos1))) return 1;
105-
if(!is_ok("j2000_tod_j2000", check_equal_pos(pos0, pos1, 1e-9 * vlen(pos0)))) return 1;
105+
if(!is_ok("j2000_tod_j2000", check_equal_pos(pos0, pos1, 1e-12 * vlen(pos0)))) return 1;
106106
return 0;
107107
}
108108

@@ -111,7 +111,7 @@ static int test_tod_itrs_tod() {
111111

112112
if(!is_ok("tod_to_itrs", tod_to_itrs(tdb, 0.0, ut12tt, 0, xp, yp, pos0, pos1))) return 1;
113113
if(!is_ok("itrs_to_tod", itrs_to_tod(tdb, 0.0, ut12tt, 0, xp, yp, pos1, pos1))) return 1;
114-
if(!is_ok("tod_itrs_tod", check_equal_pos(pos0, pos1, 1e-9 * vlen(pos0)))) return 1;
114+
if(!is_ok("tod_itrs_tod", check_equal_pos(pos0, pos1, 1e-12 * vlen(pos0)))) return 1;
115115
return 0;
116116
}
117117

@@ -120,7 +120,7 @@ static int test_gcrs_cirs_gcrs() {
120120

121121
if(!is_ok("gcrs_to_cirs", gcrs_to_cirs(tdb, 0, pos0, pos1))) return 1;
122122
if(!is_ok("cirs_to_gcrs", cirs_to_gcrs(tdb, 0, pos1, pos1))) return 1;
123-
if(!is_ok("gcrs_cirs_gcrs", check_equal_pos(pos0, pos1, 1e-9 * vlen(pos0)))) return 1;
123+
if(!is_ok("gcrs_cirs_gcrs", check_equal_pos(pos0, pos1, 1e-12 * vlen(pos0)))) return 1;
124124
return 0;
125125
}
126126

@@ -130,7 +130,7 @@ static int test_cirs_itrs_cirs() {
130130

131131
if(!is_ok("cirs_to_itrs", cirs_to_itrs(tdb, 0.0, ut12tt, 0, xp, yp, pos0, pos1))) return 1;
132132
if(!is_ok("itrs_to_cirs", itrs_to_cirs(tdb, 0.0, ut12tt, 0, xp, yp, pos1, pos1))) return 1;
133-
if(!is_ok("cirs_itrs_cirs", check_equal_pos(pos0, pos1, 1e-9 * vlen(pos0)))) return 1;
133+
if(!is_ok("cirs_itrs_cirs", check_equal_pos(pos0, pos1, 1e-12 * vlen(pos0)))) return 1;
134134
return 0;
135135
}
136136

@@ -147,7 +147,7 @@ static int test_itrs_hor_itrs() {
147147

148148
if(!is_ok("itrs_to_hor", itrs_to_hor(&obs.on_surf, p, &az, &za))) return 1;
149149
if(!is_ok("hor_to_itrs", hor_to_itrs(&obs.on_surf, az, za, pos1))) return 1;
150-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, pos1, 1e-9))) return 1;
150+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, pos1, 1e-12))) return 1;
151151

152152
if(!is_ok("itrs_to_hor:az:null", itrs_to_hor(&obs.on_surf, p, NULL, &za))) return 1;
153153
if(!is_ok("itrs_to_hor:za:null", itrs_to_hor(&obs.on_surf, p, &az, NULL))) return 1;
@@ -165,23 +165,23 @@ static int test_cel2ter2cel() {
165165

166166
if(!is_ok("cel2ter2cel:cel2ter:1", cel2ter(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 1.0, 0.0, p0, p))) return 1;
167167
if(!is_ok("cel2ter2cel:ter2cel:1", ter2cel(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 1.0, 0.0, p, p))) return 1;
168-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-9))) return 1;
168+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-12))) return 1;
169169

170170
if(!is_ok("cel2ter2cel:cel2ter:2", cel2ter(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 1.0, p0, p))) return 1;
171171
if(!is_ok("cel2ter2cel:ter2cel:2", ter2cel(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 1.0, p, p))) return 1;
172-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-9))) return 1;
172+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-12))) return 1;
173173

174174
if(!is_ok("cel2ter2cel:cel2ter:3", cel2ter(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 0.0, p0, p))) return 1;
175175
if(!is_ok("cel2ter2cel:ter2cel:3", ter2cel(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 0.0, p, p))) return 1;
176-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-9))) return 1;
176+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-12))) return 1;
177177

178178
if(!is_ok("cel2ter2cel:cel2ter:dyn", cel2ter(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_DYNAMICAL_CLASS, 0.0, 0.0, p0, p))) return 1;
179179
if(!is_ok("cel2ter2cel:ter2cel:dyn", ter2cel(tdb, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_DYNAMICAL_CLASS, 0.0, 0.0, p, p))) return 1;
180-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-9))) return 1;
180+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-12))) return 1;
181181

182182
if(!is_ok("cel2ter2cel:cel2ter:era", cel2ter(tdb, 0.0, 0.0, EROT_ERA, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 0.0, p0, p))) return 1;
183183
if(!is_ok("cel2ter2cel:ter2cel:era", ter2cel(tdb, 0.0, 0.0, EROT_ERA, NOVAS_FULL_ACCURACY, NOVAS_REFERENCE_CLASS, 0.0, 0.0, p, p))) return 1;
184-
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-9))) return 1;
184+
if(!is_ok("itrs_hor_itrs", check_equal_pos(p, p0, 1e-12))) return 1;
185185

186186
return 0;
187187
}
@@ -452,16 +452,16 @@ static int test_app_hor(enum novas_reference_system sys) {
452452
if(!is_ok("app_hor:app_to_hor", novas_app_to_hor(&frame, sys, ra, dec, NULL, &az, &el))) return 1;
453453
if(!is_ok("app_hor:hor_to_app", novas_hor_to_app(&frame, az, el, NULL, sys, &ra1, &dec1))) return 1;
454454

455-
if(!is_equal("app_hor:hor_to_app:ra", ra1, ra, 1e-8)) return 1;
456-
if(!is_equal("app_hor:hor_to_app:dec", dec1, dec, 1e-9)) return 1;
455+
if(!is_equal("app_hor:trip:ra", ra1, ra, 1e-7)) return 1;
456+
if(!is_equal("app_hor:trip:dec", dec1, dec, 1e-6)) return 1;
457457

458458
if(!is_ok("app_hor:app_to_hor:refract", novas_app_to_hor(&frame, sys, ra, dec, novas_standard_refraction, &az, &el))) return 1;
459459
if(!is_ok("app_hor:hor_to_app:refract", novas_hor_to_app(&frame, az, el, novas_standard_refraction, sys, &ra1, &dec1))) return 1;
460460

461461
// TODO check against cel2ter...
462462

463-
if(!is_equal("app_hor:hor_to_app:refract:ra", ra1, ra, 1e-8)) return 1;
464-
if(!is_equal("app_hor:hor_to_app:refract:dec", dec1, dec, 1e-9)) return 1;
463+
if(!is_equal("app_hor:refract:trip:ra", ra1, ra, 1e-7)) return 1;
464+
if(!is_equal("app_hor:refract:trip:dec", dec1, dec, 1e-6)) return 1;
465465

466466

467467
return 0;
@@ -496,7 +496,9 @@ static int test_source() {
496496

497497
if(test_geo_posvel()) n++;
498498

499-
//for(k = 0; k < NOVAS_REFERENCE_SYSTEMS; k++) if(test_app_hor(k)) n++;
499+
if(test_app_hor(1)) n++;
500+
501+
for(k = 0; k < NOVAS_REFERENCE_SYSTEMS; k++) if(test_app_hor(k)) n++;
500502

501503
return n;
502504
}
@@ -849,16 +851,16 @@ static int test_sky_pos(enum novas_reference_system sys) {
849851
if(!is_ok(label, novas_sky_pos(&source[i], &frame, sys, &p))) return 1;
850852

851853
sprintf(label, "sky_pos:sys=%d:source=%d:check:ra", sys, i);
852-
if(!is_equal(label, p.ra, pc.ra, 1e-9)) return 1;
854+
if(!is_equal(label, p.ra, pc.ra, 1e-10)) return 1;
853855

854856
sprintf(label, "sky_pos:sys=%d:source=%d:check:dec", sys, i);
855-
if(!is_equal(label, p.dec, pc.dec, 1e-10)) return 1;
857+
if(!is_equal(label, p.dec, pc.dec, 1e-9)) return 1;
856858

857859
sprintf(label, "sky_pos:sys=%d:source=%d:check:rv", sys, i);
858-
if(!is_equal(label, p.rv, pc.rv, 1e-12)) return 1;
860+
if(!is_equal(label, p.rv, pc.rv, 1e-9)) return 1;
859861

860862
sprintf(label, "sky_pos:sys=%d:source=%d:check:r_hat", sys, i);
861-
if(!is_ok(label, check_equal_pos(p.r_hat, pc.r_hat, 1e-9))) return 1;
863+
if(!is_ok(label, check_equal_pos(p.r_hat, pc.r_hat, 1e-12))) return 1;
862864
}
863865

864866
return 0;

0 commit comments

Comments
 (0)