Skip to content

Commit

Permalink
More error tracing fixes in timescale.c
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 17, 2024
1 parent 1652350 commit f79dc77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/timescale.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ double novas_get_time(const novas_timespec *time, enum novas_timescale timescale
* @param[out] ijd [day] The integer part of the Julian date in the requested timescale. It may
* be NULL if not required.
* @return [day] The fractional part of the Julian date in the requested timescale or
* NAN is the time argument is NULL.
* NAN is the time argument is NULL (ijd will be set to -1 also).
*
* @sa novas_set_split_time()
* @sa novas_get_time()
Expand All @@ -265,6 +265,8 @@ double novas_get_split_time(const novas_timespec *time, enum novas_timescale tim
static const char *fn = "novas_get_split_time";
double f;

if(ijd) *ijd = -1;

if(!time) {
novas_error(-1, EINVAL, fn, "NULL input time specification");
return NAN;
Expand Down Expand Up @@ -443,7 +445,7 @@ int novas_set_unix_time(time_t unix_time, long nanos, int leap, double dut1, nov
*
* @param time Pointer to the astronomical time specification data structure.
* @param[out] nanos [ns] UTC sub-second component. It may be NULL if not required.
* @return [s] The integer UNIX time
* @return [s] The integer UNIX time, or -1 if the input time is NULL.
*
* @sa novas_set_unix_time()
* @sa novas_get_time()
Expand All @@ -457,8 +459,11 @@ time_t novas_get_unix_time(const novas_timespec *time, long *nanos) {
time_t seconds;

sod = novas_get_split_time(time, NOVAS_UTC, &ijd) * DAY;
if(isnan(sod))
return novas_trace_nan("novas_get_unix_time");
if(isnan(sod)) {
static const char *fn = "novas_get_unix_time";
if(nanos) *nanos = novas_trace_nan(fn);
return novas_trace(fn, -1, 0);
}

isod = (long) floor(sod);
seconds = UNIX_J2000 + (ijd - IJD_J2000) * IDAY + isod;
Expand Down
15 changes: 14 additions & 1 deletion test/src/test-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ static int test_obs_posvel() {
static int test_time() {
novas_timespec time = {};
int n = 0;
long ijd = 0;

if(check("time:set:time", -1, novas_set_time(NOVAS_TT, NOVAS_JD_J2000, 37, 0.11, NULL))) n++;
if(check("time:set:scale:-1", -1, novas_set_time(-1, NOVAS_JD_J2000, 37, 0.11, &time))) n++;
Expand All @@ -1025,6 +1026,9 @@ static int test_time() {
if(check_nan("time:get:scale:-1", novas_get_time(&time, -1))) n++;
if(check_nan("time:get:scale:hi", novas_get_time(&time, NOVAS_TIMESCALES))) n++;

if(check("time:get_unix_time:time", -1, novas_get_unix_time(NULL, &ijd))) n++;
if(check("time:get_unix_time:time+ijd", -1, novas_get_unix_time(NULL, NULL))) n++;

if(check("time:offset:time", -1, novas_offset_time(NULL, 0.1, &time))) n++;
if(check("time:offset:out", -1, novas_offset_time(&time, 0.1, NULL))) n++;
if(check("time:offset:both", -1, novas_offset_time(NULL, 0.1, NULL))) n++;
Expand All @@ -1033,6 +1037,15 @@ static int test_time() {
if(check_nan("time:diff:t2", novas_diff_time(&time, NULL))) n++;
if(check_nan("time:diff:both", novas_diff_time(NULL, NULL))) n++;

if(check_nan("time:diff_tcg:t1", novas_diff_tcg(NULL, &time))) n++;
if(check_nan("time:diff_tcg:t2", novas_diff_tcg(&time, NULL))) n++;
if(check_nan("time:diff_tcg:both", novas_diff_tcg(NULL, NULL))) n++;

if(check_nan("time:diff_tcb:t1", novas_diff_tcb(NULL, &time))) n++;
if(check_nan("time:diff_tcb:t2", novas_diff_tcb(&time, NULL))) n++;
if(check_nan("time:diff_tcb:both", novas_diff_tcb(NULL, NULL))) n++;


return n;
}

Expand Down Expand Up @@ -1065,7 +1078,7 @@ static int test_refraction() {
if(check_nan("inv_refract:conv", novas_inv_refract(switching_refraction, NOVAS_JD_J2000, NULL, NOVAS_REFRACT_OBSERVED, 10.0))) n++;
else if(check("inv_refract:conv:errno", ECANCELED, errno)) n++;

fprintf(stderr, ">>> Expecting an eror and trace...\n");
fprintf(stderr, ">>> Expecting an error and trace...\n");
novas_debug(1);
novas_optical_refraction(NOVAS_JD_J2000, NULL, NOVAS_REFRACT_OBSERVED, 10.0);
novas_debug(0);
Expand Down

0 comments on commit f79dc77

Please sign in to comment.