-
Notifications
You must be signed in to change notification settings - Fork 2
/
novas.c
7130 lines (6270 loc) · 267 KB
/
novas.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
*
* @author G. Kaplan and A. Kovacs
* @version 1.0.1
*
* SuperNOVAS astrometry softwate based on the Naval Observatory Vector Astrometry Software (NOVAS).
* It has been modified to fix outstanding issues and to make it easier to use.
*
* Based on the NOVAS C Edition, Version 3.1, U. S. Naval Observatory
* Astronomical Applications Dept.
* Washington, DC
* <a href="http://www.usno.navy.mil/USNO/astronomical-applications">http://www.usno.navy.mil/USNO/astronomical-applications</a>
*
*/
#if !COMPAT
# include <stdio.h>
# include <stdlib.h>
# include <ctype.h>
#endif
#include <string.h>
#include <math.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
/// \cond PRIVATE
#define __NOVAS_INTERNAL_API__ ///< Use definitions meant for internal use by SuperNOVAS only
#include "novas.h"
#define CIO_INTERP_POINTS 6 ///< Number of points to load from CIO interpolation table at once.
// On some older platform NAN may not be defined, so define it here if need be
#ifndef NAN
# define NAN (0.0/0.0)
#endif
#ifndef DEFAULT_SOLSYS
/// Will use solarsystem() and solarsystem_hp() that is linked with application
# define DEFAULT_SOLSYS 0
#endif
#if !DEFAULT_SOLSYS
novas_planet_provider planet_call = (novas_planet_provider) solarsystem;
novas_planet_provider_hp planet_call_hp = (novas_planet_provider_hp) solarsystem_hp;
#endif
/// \endcond
/**
* Celestial pole offset ψ for high-precision applications.
*
* @sa EPS_COR
* @sa cel_pole()
*/
double PSI_COR = 0.0;
/**
* Celestial pole offset ε for high-precision applications.
*
* @sa PSI_COR
* @sa cel_pole()
*/
double EPS_COR = 0.0;
/// Current debugging state for reporting errors and traces to stderr.
static enum novas_debug_mode novas_debug_state = 0;
///< Opened CIO locator data file, or NULL.
static FILE *cio_file;
/// function to use for reading ephemeris data for all types of solar system sources
static novas_ephem_provider readeph2_call = NULL;
/// Function to use for reduced-precision calculations. (The full IAU 2000A model is used
/// always for high-precision calculations)
static novas_nutation_provider nutate_lp = nu2000k;
static int is_case_sensitive = 0; ///< (boolean) whether object names are case-sensitive.
/// \cond PRIVATE
/**
* (<i>for internal use</i>) Propagates an error (if any) with an offset. If the error is
* non-zero, it returns with the offset error value. Otherwise it keeps going as if it weren't
* even there...
*
* @param loc Function [:location] where error was produced.
* @param n error code that was received.
* @param offset Offset to add to error code (if <0) to return.
*
* @sa novas_print_error()
*/
int novas_trace(const char *loc, int n, int offset) {
if(n != 0) {
n = n < 0 ? -1 : n + offset;
if(novas_get_debug_mode() != NOVAS_DEBUG_OFF)
fprintf(stderr, " @ %s [=> %d]\n", loc, n);
}
return n;
}
/**
* (<i>for internal use</i>) Sets an errno and report errors to the standard error, depending
* on the current debug mode.
*
* @param en {int} UNIX error number (see errno.h)
* @param from {string} Function (:location) where error originated
* @param desc {string} Description of error, with information to convey to user.
*
* @sa novas_print_error()
* @sa novas_debug()
*
* @since 1.0
* @author Attil Kovacs
*/
void novas_set_errno(int en, const char *from, const char *desc, ...) {
va_list varg;
va_start(varg, desc);
if(novas_get_debug_mode() != NOVAS_DEBUG_OFF) {
fprintf(stderr, "\n ERROR! %s: ", from);
vfprintf(stderr, desc, varg);
fprintf(stderr, "\n");
}
va_end(varg);
errno = en;
}
/**
* (<i>for internal use</i>) Sets errno and reports errors to the standard error, depending
* on the current debug mode, before returning the supplied return code.
*
* @param ret return value
* @param en UNIX error code (see errno.h)
* @param from function (:location) where error originated
* @param desc description of error, with information to convey to user.
*
* @sa novas_set_errno()
* @sa novas_trace()
*
* @since 1.0
* @author Attila Kovacs
*/
int novas_error(int ret, int en, const char *from, const char *desc, ...) {
va_list varg;
va_start(varg, desc);
if(novas_get_debug_mode() != NOVAS_DEBUG_OFF) {
fprintf(stderr, "\n ERROR! %s: ", from);
vfprintf(stderr, desc, varg);
fprintf(stderr, " [=> %d]\n", ret);
}
va_end(varg);
errno = en;
return ret;
}
/// \endcond
/**
* Enables or disables reporting errors and traces to the standard error stream.
*
* @param mode NOVAS_DEBUG_OFF (0; or <0), NOVAS_DEBUG_ON (1), or NOVAS_DEBUG_EXTRA (2; or >2).
*
* @since 1.0
* @author Attila Kovacs
*
* @sa novas_get_debug_mode()
*/
void novas_debug(enum novas_debug_mode mode) {
if(mode < 0 || mode > NOVAS_DEBUG_EXTRA)
mode = NOVAS_DEBUG_EXTRA;
novas_debug_state = mode;
}
/**
* Returns the current, thread-local, mode for reporting errors encountered (and traces).
*
* @return The current debug mode in the calling thread.
*
* @since 1.0
* @author Attila Kovacs
*
* @sa novas_debug()
*/
enum novas_debug_mode novas_get_debug_mode() {
return novas_debug_state;
}
/// \cond PRIVATE
/**
* Calculates the length of a 3-vector
*
* @param v Pointer to a 3-component (x, y, z) vector. The argument cannot be NULL
* @return the length of the vector
*
* @sa vdot()
* @sa vdist()
*
* @since 1.0
* @author Attila Kovacs
*/
double novas_vlen(const double *v) {
return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
}
/**
* Calculates the distance between two 3-vectors.
*
* @param v1 Pointer to a 3-component (x, y, z) vector. The argument cannot be NULL
* @param v2 Pointer to another 3-component (x, y, z) vector. The argument cannot
* be NULL
* @return The distance between the two vectors
*
* @sa vlen()
* @sa vdot()
*
* @since 1.0
* @author Attila Kovacs
*/
double novas_vdist(const double *v1, const double *v2) {
double d2 = 0.0;
int i;
for(i = 3; --i >= 0;) {
const double d = v1[i] - v2[i];
d2 += d * d;
}
return sqrt(d2);
}
/**
* Calculates the dot product between two 3-vectors.
*
* @param v1 Pointer to a 3-component (x, y, z) vector. The argument cannot be NULL
* @param v2 Pointer to another 3-component (x, y, z) vector. The argument cannot
* be NULL
* @return The dot product between the two vectors.
*
* @sa vlen()
* @sa vdist()
*
* @since 1.0
* @author Attila Kovacs
*/
double novas_vdot(const double *v1, const double *v2) {
return (v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2]);
}
/// \endcond
/**
* Computationally efficient implementation of 3D rotation with small angles.
*
* @param in 3D vector to rotate
* @param ax (rad) rotation angle around x
* @param ax (rad) rotation angle around x
* @param ax (rad) rotation angle around x
* @param[out] out Rotated vector. It can be the same as the input.
*
*/
static void tiny_rotate(const double *in, double ax, double ay, double az, double *out) {
const double x = in[0], y = in[1], z = in[2];
const double A[3] = { ax * ax, ay * ay, az * az };
out[0] = x - 0.5 * (A[1] + A[2]) * x - az * y + ay * z;
out[1] = y - 0.5 * (A[0] + A[2]) * y + az * x - ax * z;
out[2] = z - 0.5 * (A[0] + A[1]) * z - ay * x + ax * y;
}
/**
* Checks if two Julian dates are equals under the precision that can be handled by this
* library. In practive two dates are considered equal if they agree within 10<sup>-8</sup>
* days (or about 1 ms) of each other.
*
*
* @param jd1 [day] a Julian date (in any time measure)
* @param jd2 [day] a Julian date in the same time measure as the first argument
* @return TRUE (1) if the two dates are effectively the same at the precision of
* comparison, or else FALSE (0) if they differ by more than the allowed
* tolerance.
*/
static int time_equals(double jd1, double jd2) {
return fabs(jd1 - jd2) <= 1.0e-8;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from J2000 coordinates to the
* True of Date (TOD) reference frame at the given epoch
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date that defines
* the output epoch. Typically it does not require much precision, and
* Julian dates in other time measures will be unlikely to affect the
* result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in Input (x, y, z) position or velocity vector in rectangular equatorial
* coordinates at J2000
* @param[out] out Output position or velocity 3-vector in the True equinox of Date
* coordinate frame. It can be the same vector as the input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL or the
* accuracy is invalid.
*
* @sa j2000_to_gcrs()
* @sa tod_to_j2000()
* @sa gcrs_to_j2000()
*
* @since 1.0
* @author Attila Kovacs
*/
int j2000_to_tod(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "j2000_to_tod";
if(!in || !out)
return novas_error(-1, EINVAL, fn, "NULL input or output 3-vector: in=%p, out=%p", in, out);
if(accuracy != NOVAS_FULL_ACCURACY && accuracy != NOVAS_REDUCED_ACCURACY)
return novas_error(-1, EINVAL, fn, "invalid accuracy: %d", accuracy);
precession(JD_J2000, in, jd_tdb, out);
nutation(jd_tdb, NUTATE_MEAN_TO_TRUE, accuracy, out, out);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from True of Date (TOD) reference frame
* at the given epoch to the J2000 coordinates.
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date that defines the
* input epoch. Typically it does not require much precision, and Julian dates
* in other time measures will be unlikely to affect the result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in Input (x, y, z) position or velocity 3-vector in the True equinox of Date
* coordinate frame.
* @param[out] out Output position or velocity vector in rectangular equatorial coordinates at
* J2000. It can be the same vector as the input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL or the
* 'accuracy' is invalid.
*
* @sa j2000_to_tod()
* @sa j2000_to_gcrs()
*
* @since 1.0
* @author Attila Kovacs
*/
int tod_to_j2000(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "tod_to_j2000";
if(!in || !out)
return novas_error(-1, EINVAL, fn, "NULL input or output 3-vector: in=%p, out=%p", in, out);
if(accuracy != NOVAS_FULL_ACCURACY && accuracy != NOVAS_REDUCED_ACCURACY)
return novas_error(-1, EINVAL, fn, "invalid accuracy: %d", accuracy);
nutation(jd_tdb, NUTATE_TRUE_TO_MEAN, accuracy, in, out);
precession(jd_tdb, out, JD_J2000, out);
return 0;
}
/**
* Change J2000 coordinates to GCRS coordinates. Same as frame_tie() called with J2000_TO_ICRS
*
* @param in J2000 input 3-vector
* @param[out] out GCRS output 3-vector
* @return 0 if successful, or else an error from frame_tie()
*
* @sa gcrs_to_j2000()
*
* @since 1.0
* @author Attila Kovacs
*/
int j2000_to_gcrs(const double *in, double *out) {
prop_error("j2000_to_gcrs", frame_tie(in, J2000_TO_ICRS, out), 0);
return 0;
}
/**
* Change GCRS coordinates to J2000 coordinates. Same as frame_tie() called with ICRS_TO_J2000
*
* @param in GCRS input 3-vector
* @param[out] out J2000 output 3-vector
* @return 0 if successful, or else an error from frame_tie()
*
* @sa j2000_to_gcrs()
*
* @since 1.0
* @author Attila Kovacs
*/
int gcrs_to_j2000(const double *in, double *out) {
prop_error("gcrs_to_j2000", frame_tie(in, ICRS_TO_J2000, out), 0);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from the Geocentric Celestial
* Reference System (GCRS) to the True of Date (TOD) reference frame at the given epoch
*
* @param jd_tdb [day] Barycentric Dynamical Time (TT) based Julian date that defines the
* output epoch. Typically it does not require much precision, and Julian
* dates in other time measures will be unlikely to affect the result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in GCRS Input (x, y, z) position or velocity vector
* @param[out] out Output position or velocity 3-vector in the True equinox of Date coordinate
* frame. It can be the same vector as the input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL.
*
* @sa gcrs_to_cirs()
* @sa tod_to_gcrs()
* @sa j2000_to_tod()
*
* @since 1.0
* @author Attila Kovacs
*/
static int gcrs_to_tod(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "gcrs_to_tod [internal]";
prop_error(fn, frame_tie(in, ICRS_TO_J2000, out), 0);
prop_error(fn, j2000_to_tod(jd_tdb, accuracy, out, out), 0);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from True of Date (TOD) reference
* frame at the given epoch to the Geocentric Celestial Reference System(GCRS)
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date that defines the
* input epoch. Typically it does not require much precision, and Julian dates
* in other time measures will be unlikely to affect the result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in Input (x, y, z) position or velocity 3-vector in the True equinox of Date
* coordinate frame.
* @param[out] out Output GCRS position or velocity vector. It can be the same vector as the
* input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL.
*
* @sa j2000_to_tod()
* @sa tod_to_gcrs()
*
* @since 1.0
* @author Attila Kovacs
*/
static int tod_to_gcrs(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "tod_to_gcrs [internal]";
prop_error(fn, tod_to_j2000(jd_tdb, accuracy, in, out), 0);
prop_error(fn, frame_tie(out, J2000_TO_ICRS, out), 0);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from the Geocentric Celestial Reference
* System (GCRS) to the Celestial Intermediate Reference System (CIRS) frame at the given epoch
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date that defines the
* output epoch. Typically it does not require much precision, and Julian dates
* in other time measures will be unlikely to affect the result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in GCRS Input (x, y, z) position or velocity vector
* @param[out] out Output position or velocity 3-vector in the True equinox of Date coordinate
* frame. It can be the same vector as the input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL or the
* accuracy is invalid, or an error from cio_location(), or
* else 10 + the error from cio_basis().
*
* @sa gcrs_to_j2000()
* @sa cirs_to_gcrs()
*
*
* @since 1.0
* @author Attila Kovacs
*/
int gcrs_to_cirs(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "gcrs_to_cirs";
double r_cio, v[3], x[3], y[3], z[3];
short sys;
if(!in || !out)
return novas_error(-1, EINVAL, fn, "NULL input or output 3-vector: in=%p, out=%p", in, out);
memcpy(v, in, sizeof(v));
// Obtain the basis vectors, in the GCRS, of the celestial intermediate
// system.
prop_error(fn, cio_location(jd_tdb, accuracy, &r_cio, &sys), 0);
prop_error(fn, cio_basis(jd_tdb, r_cio, sys, accuracy, x, y, z), 10);
// Transform position vector to celestial intermediate system.
out[0] = novas_vdot(x, v);
out[1] = novas_vdot(y, v);
out[2] = novas_vdot(z, v);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from the Celestial Intermediate
* Reference System (CIRS) frame at the given epoch to the Geocentric Celestial Reference
* System (GCRS).
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date that defines
* the output epoch. Typically it does not require much precision, and
* Julian dates in other time measures will be unlikely to affect the
* result
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param in CIRS Input (x, y, z) position or velocity vector
* @param[out] out Output position or velocity 3-vector in the GCRS coordinate frame.
* It can be the same vector as the input.
* @return 0 if successful, or -1 if either of the vector arguments is NULL
* or the accuracy is invalid, or an error from cio_location(), or else
* 10 + the error from cio_basis().
*
* @sa tod_to_gcrs()
* @sa gcrs_to_cirs()
*
*
* @since 1.0
* @author Attila Kovacs
*/
int cirs_to_gcrs(double jd_tdb, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "cirs_to_gcrs";
double r_cio, vx[3], vy[3], vz[4], x, y, z;
short sys;
int i;
if(!in || !out)
return novas_error(-1, EINVAL, fn, "NULL input or output 3-vector: in=%p, out=%p", in, out);
// Obtain the basis vectors, in the GCRS, of the celestial intermediate
// system.
prop_error(fn, cio_location(jd_tdb, accuracy, &r_cio, &sys), 0);
prop_error(fn, cio_basis(jd_tdb, r_cio, sys, accuracy, vx, vy, vz), 10);
x = in[0];
y = in[1];
z = in[2];
// Transform position vector to GCRS system.
for(i = 3; --i >= 0;) {
out[i] = x * vx[i] + y * vy[i] + z * vz[i];
}
return 0;
}
/**
* Set a custom function to use for regular precision (see NOVAS_REDUCED_ACCURACY)
* ephemeris calculations instead of the default solarsystem() routine.
*
* @param func The function to use for solar system position/velocity calculations.
* See solarsystem() for further details on what is required of this
* function.
*
* @author Attila Kovacs
* @since 1.0
*
* @sa set_planet_provider_hp()
* @sa solarsystem()
* @sa NOVAS_REDUCED_ACCURACY
*/
int set_planet_provider(novas_planet_provider func) {
if(!func)
return novas_error(-1, EINVAL, "set_planet_provider", "NULL 'func' parameter");
planet_call = func;
return 0;
}
/**
* Set a custom function to use for high precision (see NOVAS_FULL_ACCURACY) ephemeris
* calculations instead of the default solarsystem_hp() routine.
*
* @param func The function to use for solar system position/velocity calculations.
* See solarsystem_hp() for further details on what is required of this
* function.
*
* @author Attila Kovacs
* @since 1.0
*
* @sa set_planet_provider()
* @sa solarsystem_hp()
* @sa NOVAS_FULL_ACCURACY
*/
int set_planet_provider_hp(novas_planet_provider_hp func) {
if(!func)
return novas_error(-1, EINVAL, "set_planet_provider_hp", "NULL 'func' parameter");
planet_call_hp = func;
return 0;
}
/**
* Computes the apparent place of a star, referenced to dynamical equator at date 'jd_tt',
* given its catalog mean place, proper motion, parallax, and radial velocity. See `place()`
* for more information.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Explanatory Supplement to the Astronomical Almanac (1992),Chapter 3.</li>
* </ol>
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date.
* @param star Pointer to catalog entry structure containing catalog data for
* the object in the ICRS.
* @param obs Observer location (can be NULL if not relevant)
* @param ut1_to_tt [s] Difference TT-UT1 at 'jd_tt', in seconds of time.
* @param system The type of coordinate reference system in which coordinates are to
* be returned.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos The position and radial velocity of of the catalog source in the
* specified coordinate system and relative to the specified observer
* location (if applicable)
* @return 0 if successful, or -1 if one of the required arguments is NULL, or
* else 1 if the observer location is invalid, or an error code from
* place().
*
* @sa get_ut1_to_tt()
*
* @author Attila Kovacs
* @since 1.0
*/
int place_star(double jd_tt, const cat_entry *star, const observer *obs, double ut1_to_tt, enum novas_reference_system system,
enum novas_accuracy accuracy, sky_pos *pos) {
static const char *fn = "place_star";
object source = { };
if(!star || !pos)
return novas_error(-1, EINVAL, fn, "NULL input star=%p or output pos=%p pointer", star, pos);
source.type = NOVAS_CATALOG_OBJECT;
source.star = *star;
prop_error(fn, place(jd_tt, &source, obs, ut1_to_tt, system, accuracy, pos), 0);
return 0;
}
/**
* Computes the International Celestial Reference System (ICRS) position of a source.
* (from the geocenter). Unlike `place_gcrs()`, this version does not include
* aberration or gravitational deflection corrections.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated geocentric ICRS position
* data (Unlike place_gcrs(), the calculated coordinates do not account
* for aberration or gravitational deflection).
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_gcrs()
* @sa place_cirs()
* @sa place_tod()
* @sa mean_star()
*
* @since 1.0
* @author Attila Kovacs
*/
int place_icrs(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_icrs", place(jd_tt, source, NULL, 0.0, NOVAS_ICRS, accuracy, pos), 0);
return 0;
}
/**
* Computes the Geocentric Celestial Reference System (GCRS) position of a source (as 'seen'
* from the geocenter) at the given time of observation. Unlike `place_icrs()`, this includes
* aberration for the moving frame of the geocenter as well as gravitational deflections
* calculated for a virtual observer located at the geocenter. See `place()` for more information.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated GCRS position data
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_icrs()
* @sa place_cirs()
* @sa place_tod()
* @sa virtual_star()
* @sa virtual_planet()
*
* @since 1.0
* @author Attila Kovacs
*/
int place_gcrs(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_gcrs", place(jd_tt, source, NULL, 0.0, NOVAS_GCRS, accuracy, pos), 0);
return 0;
}
/**
* Computes the Celestial Intermediate Reference System (CIRS) dynamical position
* position of a source as 'seen' from the geocenter at the given time of observation. See
* `place()` for more information.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated CIRS position data
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_tod()
* @sa place_gcrs()
*
* @since 1.0
* @author Attila Kovacs
*
*/
int place_cirs(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_cirs", place(jd_tt, source, NULL, 0.0, NOVAS_CIRS, accuracy, pos), 0);
return 0;
}
/**
* Computes the True of Date (TOD) dynamical position position of a source as 'seen' from the
* geocenter at the given time of observation. See `place()` for more information.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated CIRS position data
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_cirs()
* @sa place_gcrs()
* @sa app_star()
* @sa app_planet()
*
* @since 1.0
* @author Attila Kovacs
*
*/
int place_tod(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_tod", place(jd_tt, source, NULL, 0.0, NOVAS_TOD, accuracy, pos), 0);
return 0;
}
/**
* Computes the Mean of Date (MOD) dynamical position position of a source as 'seen' from the
* geocenter at the given time of observation. See `place()` for more information.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated CIRS position data
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_cirs()
* @sa place_gcrs()
* @sa app_star()
* @sa app_planet()
*
* @since 1.1
* @author Attila Kovacs
*
*/
int place_mod(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_mod", place(jd_tt, source, NULL, 0.0, NOVAS_MOD, accuracy, pos), 0);
return 0;
}
/**
* Computes the J2000 dynamical position position of a source as 'seen' from the
* geocenter at the given time of observation. See `place()` for more information.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date of observation.
* @param source Catalog source or solar_system body.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] pos Structure to populate with the calculated CIRS position data
* @return 0 if successful, or -1 if any of the input pointer arguments is NULL,
* or else an error from place().
*
* @sa place_cirs()
* @sa place_gcrs()
* @sa app_star()
* @sa app_planet()
*
* @since 1.1
* @author Attila Kovacs
*
*/
int place_j2000(double jd_tt, const object *source, enum novas_accuracy accuracy, sky_pos *pos) {
prop_error("place_j2000", place(jd_tt, source, NULL, 0.0, NOVAS_J2000, accuracy, pos), 0);
return 0;
}
/**
* Computes the place of a star at date 'jd_tt', for an observer in the specified coordinate
* system, given the star's ICRS catalog place, proper motion, parallax, and radial velocity.
*
* Notwithstanding the different set of return values, this is the same as calling place_star()
* with the same arguments.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3.</li>
* </ol>
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date.
* @param star Pointer to catalog entry structure containing catalog data for the object
* in the ICRS.
* @param obs Observer location. It may be NULL if not relevant.
* @param ut1_to_tt [s] Difference TT-UT1 at 'jd_tt', in seconds of time.
* @param sys Coordinate reference system in which to produce output values
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] ra [h] Topocentric right ascension in hours, referred to true equator and
* equinox of date 'jd_tt' or NAN when returning with an error code.
* (It may be NULL if not required)
* @param[out] dec [deg] Topocentric declination in degrees, referred to true equator and
* equinox of date 'jd_tt' or NAN when returning with an error code.
* (It may be NULL if not required)
* @param[out] rv [AU/day] radial velocity relative ot observer, or NAN when returning with
* an error code. (It may be NULL if not required)
* @return 0 if successful, -1 if a required pointer argument is NULL, or else
* 20 + the error code from place_star().
*
* @sa radec_planet()
*
* @since 1.0
* @author Attila Kovacs
*/
int radec_star(double jd_tt, const cat_entry *star, const observer *obs, double ut1_to_tt, enum novas_reference_system sys,
enum novas_accuracy accuracy, double *ra, double *dec, double *rv) {
sky_pos output = { };
// Default return values in case of error.
if(ra)
*ra = NAN;
if(dec)
*dec = NAN;
if(rv)
*rv = NAN;
prop_error("radec_star", place_star(jd_tt, star, obs, ut1_to_tt, sys, accuracy, &output), 20);
if(ra)
*ra = output.ra;
if(dec)
*dec = output.dec;
if(rv)
*rv = output.rv;
return 0;
}
/**
* Computes the place of a solar system body at the specified time for an observer in the
* specified coordinate system. This is the same as calling place() with the same arguments,
* except the different set of return values used.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Explanatory Supplement to the Astronomical Almanac (1992),Chapter 3.</li>
* </ol>
*
* @param jd_tt [day] Terretrial Time (TT) based Julian date.
* @param ss_body Pointer to structure containing the body designation for the solar
* system body.
* @param obs Observer location. It may be NULL if not relevant.
* @param ut1_to_tt [s] Difference TT-UT1 at 'jd_tt', in seconds of time.
* @param sys Coordinate reference system in which to produce output values
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] ra [h] Topocentric apparent right ascension in hours, referred to the
* true equator and equinox of date, or NAN when returning with an error
* code. (It may be NULL if not required)
* @param[out] dec [deg] Topocentric apparent declination in degrees referred to the
* true equator and equinox of date, or NAN when returning with an error
* code. (It may be NULL if not required)
* @param[out] dis [AU] True distance from Earth to the body at 'jd_tt' in AU, or NAN when
* returning with an error code. (It may be NULL if not needed).
* @param[out] rv [AU/day] radial velocity relative ot observer, or NAN when returning with
* an error code. (It may be NULL if not required)
* @return 0 if successful, or -1 if the object argument is NULL or if
* the value of 'where' in structure 'location' is invalid, or 10 + the
* error code from place().
*
* @sa radec_star()
*
* @since 1.0
* @author Attila Kovacs
*/
int radec_planet(double jd_tt, const object *ss_body, const observer *obs, double ut1_to_tt, enum novas_reference_system sys,
enum novas_accuracy accuracy, double *ra, double *dec, double *dis, double *rv) {
static const char *fn = "radec_planet";
sky_pos output = { };
// Default return values in case of error.
if(ra)
*ra = NAN;
if(dec)
*dec = NAN;
if(dis)
*dis = NAN;
if(rv)
*rv = NAN;
if(ss_body->type != NOVAS_PLANET && ss_body->type != NOVAS_EPHEM_OBJECT)
return novas_error(-1, EINVAL, fn, "object is not solar-system type: type=%d", ss_body->type);
prop_error(fn, place(jd_tt, ss_body, obs, ut1_to_tt, sys, accuracy, &output), 10);
if(ra)
*ra = output.ra;
if(dec)
*dec = output.dec;
if(dis)
*dis = output.dis;
if(rv)
*rv = output.rv;
return 0;
}
/**
* Computes the apparent place of a star, referenced to dynamical equator at date 'jd_tt',
* given its catalog mean place, proper motion, parallax, and radial velocity.
*
* Notwithstanding the different set of return values, this is the same as calling
* place_star() with a NULL observer location and NOVAS_TOD as the system for an object that
* specifies the star.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Explanatory Supplement to the Astronomical Almanac (1992),Chapter 3.</li>
* </ol>
*
* @deprecated Use place_cirs() is now preferred, especially for high accuracy calculations.
*
* @param jd_tt [day] Terretrial Time (TT) based Julian date.
* @param star Pointer to catalog entry structure containing catalog data for
* the object in the ICRS.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] ra [h] Apparent right ascension in hours, referred to true equator and
* equinox of date 'jd_tt' (it may be NULL if not required).
* @param[out] dec [deg] Apparent declination in degrees, referred to true equator and
* equinox of date 'jd_tt' (it may be NULL if not required).
* @return 0 if successful, -1 if a required pointer argument is NULL, or else an
* the error from make_object(), or 20 + the error from place().
*
* @sa place_tod()
* @sa place_star()
* @sa astro_star()
* @sa local_star()
* @sa topo_star()
* @sa virtual_star()
* @sa app_planet()
*/
short app_star(double jd_tt, const cat_entry *star, enum novas_accuracy accuracy, double *ra, double *dec) {
prop_error("app_star", radec_star(jd_tt, star, NULL, 0.0, NOVAS_TOD, accuracy, ra, dec, NULL), 0);
return 0;
}
/**
* Computes the virtual place of a star, referenced to GCRS, at date 'jd_tt', given its
* catalog mean place, proper motion, parallax, and radial velocity.
*
* Notwithstanding the different set of return values, this is the same as calling
* place_star() with a NULL observer location and NOVAS_GCRS as the system, or place_gcrs()
* for an object that specifies the star.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3.</li>
* </ol>
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date.
* @param star Pointer to catalog entry structure containing catalog data for
* the object in the ICRS.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param[out] ra [h] Virtual right ascension in hours, referred to the GCRS
* (it may be NULL if not required).
* @param[out] dec [deg] Virtual declination in degrees, referred to the GCRS
* (it may be NULL if not required).
* @return 0 if successful, or -1 if a required pointer argument is NULL, or
* 20 + the error from place().
*
* @sa place_star()
* @sa place_gcrs()
* @sa app_star()
* @sa astro_star()
* @sa local_star()
* @sa topo_star()
* @sa virtual_planet()
*/
short virtual_star(double jd_tt, const cat_entry *star, enum novas_accuracy accuracy, double *ra, double *dec) {
prop_error("virtual_star", radec_star(jd_tt, star, NULL, 0.0, NOVAS_GCRS, accuracy, ra, dec, NULL), 0);
return 0;