Skip to content

Commit fe69122

Browse files
committed
Yest more tests and some tweaks
1 parent 3325598 commit fe69122

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

src/novas.c

+24-22
Original file line numberDiff line numberDiff line change
@@ -1226,23 +1226,19 @@ short mean_star(double jd_tt, double ra, double dec, enum novas_accuracy accurac
12261226
prop_error(app_star(jd_tt, &star, accuracy, &ra1, &dec1), 20);
12271227

12281228
// If within tolerance, we are done
1229-
if(fabs(ra - ra1) < 1.0e-12 && fabs(dec - dec1) < 1.0e-11)
1230-
break;
1229+
if(fabs(ra - ra1) < 1.0e-12 && fabs(dec - dec1) < 1.0e-11) {
1230+
*ira = star.ra < 0.0 ? star.ra + DAY_HOURS : star.ra;
1231+
*idec = star.dec;
1232+
return 0;
1233+
}
12311234

12321235
// Correct for overshoot
12331236
star.ra = remainder(star.ra + (ra - ra1), DAY_HOURS);
12341237
star.dec = remainder(star.dec + (dec - dec1), DEG360);
12351238
}
12361239

1237-
*ira = star.ra < 0.0 ? star.ra + DAY_HOURS : star.ra;
1238-
*idec = star.dec;
1239-
1240-
if(iter < 0) {
1241-
errno = ECANCELED;
1242-
return 1;
1243-
}
1244-
1245-
return 0;
1240+
errno = ECANCELED;
1241+
return 1;
12461242
}
12471243

12481244
/**
@@ -1932,11 +1928,13 @@ int itrs_to_hor(const on_surface *location, const double *in, double *az, double
19321928
double lat, lon, coslat, sinlat, coslon, sinlon;
19331929
double pn, pw, pz, proj;
19341930

1931+
// Default output values in case of error return.
1932+
if(az)
1933+
*az = NAN;
1934+
if(za)
1935+
*za = NAN;
1936+
19351937
if(!location || !in) {
1936-
if(az)
1937-
*az = NAN;
1938-
if(za)
1939-
*za = NAN;
19401938
errno = EINVAL;
19411939
return -1;
19421940
}
@@ -2123,16 +2121,21 @@ int equ2hor(double jd_ut1, double ut1_to_tt, enum novas_accuracy accuracy, doubl
21232121
double uze[3], une[3], uwe[3], uz[3], un[3], uw[3], p[3];
21242122
double pz, pn, pw, proj, pr[3];
21252123

2126-
if(!location || !zd || !az) {
2127-
errno = EINVAL;
2128-
return -1;
2129-
}
2130-
2124+
// Default output values in case of error return;
2125+
if(az)
2126+
*az = NAN;
2127+
if(zd)
2128+
*zd = NAN;
21312129
if(rar)
21322130
*rar = ra;
21332131
if(decr)
21342132
*decr = dec;
21352133

2134+
if(!location || !zd || !az) {
2135+
errno = EINVAL;
2136+
return -1;
2137+
}
2138+
21362139
lon = location->longitude * DEGREE;
21372140
lat = location->latitude * DEGREE;
21382141

@@ -2219,8 +2222,7 @@ int equ2hor(double jd_ut1, double ut1_to_tt, enum novas_accuracy accuracy, doubl
22192222
proj = sqrt(pr[0] * pr[0] + pr[1] * pr[1]);
22202223

22212224
if(rar) {
2222-
if(proj > 0.0)
2223-
*rar = atan2(pr[1], pr[0]) / HOURANGLE;
2225+
*rar = proj ? atan2(pr[1], pr[0]) / HOURANGLE : 0.0;
22242226
if(*rar < 0.0)
22252227
*rar += DAY_HOURS;
22262228
}

test/src/test-errors.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ static int test_place() {
272272

273273
static int test_radec_planet() {
274274
object o;
275-
observer loc;
275+
observer loc = {};
276276
double ra, dec, dis, rv;
277277

278278
o.type = NOVAS_CATALOG_OBJECT;
279+
if(check("radec_planet:cat", -1, radec_planet(NOVAS_JD_J2000, &o, &loc, 0.0, NOVAS_GCRS, NOVAS_REDUCED_ACCURACY, &ra, &dec, &dis, &rv))) return 1;
279280

280-
if(check("radec_planet", -1, radec_planet(0.0, &o, &loc, 0.0, NOVAS_GCRS, NOVAS_FULL_ACCURACY, &ra, &dec, &dis, &rv))) return 1;
281281
return 0;
282282
}
283283

test/src/test-super.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,16 @@ static int test_itrs_hor_itrs() {
139139
}
140140

141141
static int test_equ2hor() {
142-
double az, za, ra, dec, rar, decr;
142+
int a;
143143

144144
if(obs.where != NOVAS_OBSERVER_ON_EARTH) return 0;
145145

146-
vector2radec(pos0, &ra, &dec);
146+
for(a = 0; a < 24.0; a += 3) {
147+
double ra = a, dec = 0.0, az, za, rar, decr;
147148

148-
if(!is_ok("itrs_to_hor:rar:null", equ2hor(tdb, 0.0, NOVAS_FULL_ACCURACY, 0.0, 0.0, &obs.on_surf, NOVAS_STANDARD_ATMOSPHERE, ra, dec, &az, &za, NULL, &decr))) return 1;
149-
if(!is_ok("itrs_to_hor:decr:null", equ2hor(tdb, 0.0, NOVAS_FULL_ACCURACY, 0.0, 0.0, &obs.on_surf, NOVAS_STANDARD_ATMOSPHERE, ra, dec, &az, &za, &rar, NULL))) return 1;
149+
if(!is_ok("itrs_to_hor:rar:null", equ2hor(tdb, 0.0, NOVAS_REDUCED_ACCURACY, 0.0, 0.0, &obs.on_surf, NOVAS_STANDARD_ATMOSPHERE, ra, dec, &az, &za, NULL, &decr))) return 1;
150+
if(!is_ok("itrs_to_hor:decr:null", equ2hor(tdb, 0.0, NOVAS_REDUCED_ACCURACY, 0.0, 0.0, &obs.on_surf, NOVAS_STANDARD_ATMOSPHERE, ra, dec, &az, &za, &rar, NULL))) return 1;
151+
}
150152

151153
return 0;
152154
}
@@ -745,8 +747,8 @@ static int test_iau2000a() {
745747
static int test_iau2000b() {
746748
double dpsi, deps;
747749

748-
if(!is_ok("iau2000a:dspi:null", iau2000a(tdb, 0.0, NULL, &deps))) return 1;
749-
if(!is_ok("iau2000a:deps:null", iau2000a(tdb, 0.0, &dpsi, NULL))) return 1;
750+
if(!is_ok("iau2000a:dspi:null", iau2000b(tdb, 0.0, NULL, &deps))) return 1;
751+
if(!is_ok("iau2000a:deps:null", iau2000b(tdb, 0.0, &dpsi, NULL))) return 1;
750752

751753
return 0;
752754
}

0 commit comments

Comments
 (0)