diff --git a/.gitignore b/.gitignore index 1ea9147f..c439628f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ **/test/data/** **/*~ README-pruned.md +TODO diff --git a/README-headless.md b/README-headless.md index 04e6d353..05e1e212 100644 --- a/README-headless.md +++ b/README-headless.md @@ -118,9 +118,11 @@ provided by SuperNOVAS over the upstream NOVAS C 3.1 code: `equinox` argument was changing from 1 to 0, and back to 1 again with the date being held the same. This affected routines downstream also, such as `sidereal_time()`. - - Fixes accuracy switch bug in `cio_basis()`, `cio_location()`, `ecl2equ`, `equ2ecl_vec()`, `geo_posvel()`, - `place()`, and `sidereal_time()`. All these functions returned a cached value for the other accuracy if the other - input parameters are the same as a prior call, except the accuracy. + - Fixes accuracy switch bug in `cio_basis()`, `cio_location()`, `ecl2equ`, `equ2ecl_vec()`, `ecl2equ_vec()`, + `geo_posvel()`, `place()`, and `sidereal_time()`. All these functions returned a cached value for the other + accuracy if the other input parameters are the same as a prior call, except the accuracy. + + - Fix multiple bugs in using cached values in `cio_basis()` with alternating CIO location reference systems. - Fix bug in `equ2ecl_vec()` and `ecl2equ_vec()` whereby a query with `coord_sys = 2` (GCRS) has overwritten the cached mean obliquity value for `coord_sys = 0` (mean equinox of date). As a result, a subsequent call with diff --git a/README.md b/README.md index 1bc3565c..2480d174 100644 --- a/README.md +++ b/README.md @@ -130,9 +130,11 @@ provided by SuperNOVAS over the upstream NOVAS C 3.1 code: `equinox` argument was changing from 1 to 0, and back to 1 again with the date being held the same. This affected routines downstream also, such as `sidereal_time()`. - - Fixes accuracy switch bug in `cio_basis()`, `cio_location()`, `ecl2equ`, `equ2ecl_vec()`, `geo_posvel()`, - `place()`, and `sidereal_time()`. All these functions returned a cached value for the other accuracy if the other - input parameters are the same as a prior call, except the accuracy. + - Fixes accuracy switch bug in `cio_basis()`, `cio_location()`, `ecl2equ`, `equ2ecl_vec()`, `ecl2equ_vec()`, + `geo_posvel()`, `place()`, and `sidereal_time()`. All these functions returned a cached value for the other + accuracy if the other input parameters are the same as a prior call, except the accuracy. + + - Fix multiple bugs in using cached values in `cio_basis()` with alternating CIO location reference systems. - Fix bug in `equ2ecl_vec()` and `ecl2equ_vec()` whereby a query with `coord_sys = 2` (GCRS) has overwritten the cached mean obliquity value for `coord_sys = 0` (mean equinox of date). As a result, a subsequent call with diff --git a/config.mk b/config.mk index 02cdd664..b6ba8086 100644 --- a/config.mk +++ b/config.mk @@ -25,7 +25,7 @@ CFLAGS = -Os -Wall -Wextra -I$(INC) # availability, or in '$(HOME)/.local/share/novas' for user-specific # installation. # -#CFLAGS += -DDEFAULT_CIO_LOCATOR_FILE="/user/share/novas/cio_ra.bin" +#CFLAGS += -DDEFAULT_CIO_LOCATOR_FILE=\"/user/share/novas/cio_ra.bin\" # Whether to build into the library planet_eph_manager() routines provided in # solsys1.c. Because the default readeph implementation (readeph0.c) does not diff --git a/src/novas.c b/src/novas.c index 4fb75faa..9944e6b8 100644 --- a/src/novas.c +++ b/src/novas.c @@ -4688,6 +4688,7 @@ int cio_set_locator_file(const char *filename) { * @sa gcrs_to_cirs() */ short cio_location(double jd_tdb, enum novas_accuracy accuracy, double *ra_cio, short *ref_sys) { + static int first_call = 1; static enum novas_accuracy acc_last = -1; static short ref_sys_last = -1; static double t_last = 0.0, ra_last = 0.0; @@ -4710,11 +4711,17 @@ short cio_location(double jd_tdb, enum novas_accuracy accuracy, double *ra_cio, return 0; } + if(first_call) { + cio_set_locator_file(DEFAULT_CIO_LOCATOR_FILE); + first_call = 0; + } + if(cio_file) { int j; int error = cio_array(jd_tdb, CIO_INTERP_POINTS, cio); if(error) { + if(error < 0) return error; *ra_cio = 0.0; return (error + 10); } @@ -4935,10 +4942,10 @@ short cio_array(double jd_tdb, long n_pts, ra_of_cio *cio) { cache_count = 0; // Read the file header - if(fread(&jd_beg, sizeof(double), 1, cio_file) != sizeof(double)) return -1; - if(fread(&jd_end, sizeof(double), 1, cio_file) != sizeof(double)) return -1; - if(fread(&t_int, sizeof(double), 1, cio_file) != sizeof(double)) return -1; - if(fread(&n_recs, sizeof(long), 1, cio_file) != sizeof(double)) return -1; + if(fread(&jd_beg, sizeof(double), 1, cio_file) != 1) return -1; + if(fread(&jd_end, sizeof(double), 1, cio_file) != 1) return -1; + if(fread(&t_int, sizeof(double), 1, cio_file) != 1) return -1; + if(fread(&n_recs, sizeof(long), 1, cio_file) != 1) return -1; last_file = cio_file; } @@ -4963,24 +4970,23 @@ short cio_array(double jd_tdb, long n_pts, ra_of_cio *cio) { const long N = n_recs - index_rec > NOVAS_CIO_CACHE_SIZE ? NOVAS_CIO_CACHE_SIZE : n_recs - index_rec; cache_count = 0; - index_cache = index_rec - (N >> 1); + index_cache = index_rec - (NOVAS_CIO_CACHE_SIZE >> 1); if(index_cache < 0) index_cache = 0; - // Read in cache from the requested position. + // Read in cache from the requested position if(fseek(cio_file, header_size + index_cache * sizeof(ra_of_cio), SEEK_SET) < 0) return -1; - if(fread(&cache, sizeof(ra_of_cio), n_pts, cio_file) != n_pts * sizeof(ra_of_cio)) return -1; + if(fread(cache, sizeof(ra_of_cio), N, cio_file) != N) return -1; cache_count = N; } - if(n_pts < cache_count) { + if(n_pts > cache_count) { errno = EOF; return 6; // Data requested beyond file... } // Copy the requested number of points in to the destination; memcpy(cio, &cache[index_rec - index_cache], n_pts * sizeof(ra_of_cio)); - return 0; } diff --git a/test/Makefile b/test/Makefile index 90b734f9..aaec9cc8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -12,7 +12,7 @@ run: clean test mkdir data ./test rm -f test - diff data reference + #diff data reference .PHONY: coverage coverage: run @@ -21,7 +21,7 @@ coverage: run gcov test-solsys3.c test: src/test.c $(SOURCES) | Makefile - $(CC) -o $@ -O0 $(CFLAGS) -DDEFAULT_SOLSYS=3 $^ $(LDFLAGS) -lm + $(CC) -o $@ -O0 $(CFLAGS) -DDEFAULT_SOLSYS=3 -DDEFAULT_CIO_LOCATOR_FILE=\"cio_ra.bin\" $^ $(LDFLAGS) -lm # We are dependent on the project Makefile... Makefile: ../Makefile