-
Notifications
You must be signed in to change notification settings - Fork 4
/
super.c
1436 lines (1311 loc) · 54.6 KB
/
super.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
863
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
*
* @date Created on Aug 24, 2024
* @author Attila Kovacs
*
* SuperNOVAS only functions, which are not integral to the functionality of novas.c, and thus
* can live in a separate, more manageably sized, module.
*/
// We'll use gcc major version as a proxy for the glibc library to decide which feature macro to use.
// gcc 5.1 was released 2015-04-22...
#ifndef __GNUC__
# define _DEFAULT_SOURCE ///< strcasecmp() feature macro starting glibc 2.20 (2014-09-08)
#elif __GNUC__ >= 5
# define _DEFAULT_SOURCE ///< strcasecmp() feature macro starting glibc 2.20 (2014-09-08)
#else
# define _BSD_SOURCE ///< strcasecmp() feature macro for glibc <= 2.19
#endif
#include <math.h>
#include <errno.h>
#include <string.h>
/// \cond PRIVATE
#define __NOVAS_INTERNAL_API__ ///< Use definitions meant for internal use by SuperNOVAS only
#include "novas.h"
/// \endcond
/**
* Returns the difference between Terrestrial Time (TT) and Universal Coordinated Time (UTC)
*
* @param leap_seconds [s] The current leap seconds (see IERS Bulletins)
* @return [s] The TT - UTC time difference
*
* @sa get_ut1_to_tt()
* @sa julian_date()
*
* @since 1.0
* @author Attila Kovacs
*/
double get_utc_to_tt(int leap_seconds) {
return leap_seconds NOVAS_TAI_TO_TT;
}
/**
* Returns the TT - UT1 time difference given the leap seconds and the actual UT1 - UTC time
* difference as measured and published by IERS.
*
* NOTES:
* <ol>
* <li>The current UT1 - UTC time difference, and polar offsets, historical data and near-term
* projections are published in the
<a href="https://www.iers.org/IERS/EN/Publications/Bulletins/bulletins.html>IERS Bulletins</a>
* </li>
* </ol>
*
* @param leap_seconds [s] Leap seconds at the time of observations
* @param dut1 [s] UT1 - UTC time difference [-0.5:0.5]
* @return [s] The TT - UT1 time difference that is suitable for used with all
* calls in this library that require a <code>ut1_to_tt</code> argument.
*
* @sa get_utc_to_tt()
* @sa place()
* @sa cel_pole()
*
* @since 1.0
* @author Attila Kovacs
*/
double get_ut1_to_tt(int leap_seconds, double dut1) {
return get_utc_to_tt(leap_seconds) dut1;
}
/**
* 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;
}
/**
* Convert ecliptic longitude and latitude to right ascension and declination. To convert
* GCRS ecliptic coordinates (mean ecliptic and equinox of J2000.0), set 'coord_sys' to
* NOVAS_GCRS_EQUATOR(2); in this case the value of 'jd_tt' can be set to anything, since
* J2000.0 is assumed. Otherwise, all input coordinates are dynamical at'jd_tt'.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date. (Unused if 'coord_sys'
* is NOVAS_GCRS_EQUATOR[2])
* @param coord_sys The astrometric reference system of the coordinates. If 'coord_sys' is
* NOVAS_GCRS_EQUATOR(2), the input GCRS coordinates are converted to
* J2000 ecliptic coordinates.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param elon [deg] Ecliptic longitude in degrees, referred to specified ecliptic and
* equinox of date.
* @param elat [deg] Ecliptic latitude in degrees, referred to specified ecliptic and
* equinox of date.
* @param[out] ra [h] Right ascension in hours, referred to specified equator and equinox
* of date.
* @param[out] dec [deg] Declination in degrees, referred to specified equator and equinox
* of date.
* @return 0 if successful, or else 1 if the value of 'coord_sys' is invalid.
*
* @sa ecl2equ_vec()
* @sa equ2ecl()
*
* @since 1.0
* @author Attila Kovacs
*/
int ecl2equ(double jd_tt, enum novas_equator_type coord_sys, enum novas_accuracy accuracy, double elon, double elat, double *ra,
double *dec) {
static const char *fn = "ecl2equ";
double coslat, pos[3], xyproj;
if(!ra || !dec)
return novas_error(-1, EINVAL, fn, "NULL output pointer: ra=%p, dec=%p", ra, dec);
// Form position vector in equatorial system from input coordinates.
elon *= DEGREE;
elat *= DEGREE;
coslat = cos(elat);
pos[0] = coslat * cos(elon);
pos[1] = coslat * sin(elon);
pos[2] = sin(elat);
// Convert the vector from equatorial to ecliptic system.
prop_error(fn, ecl2equ_vec(jd_tt, coord_sys, accuracy, pos, pos), 0);
// Decompose ecliptic vector into ecliptic longitude and latitude.
xyproj = sqrt(pos[0] * pos[0] pos[1] * pos[1]);
*ra = xyproj ? atan2(pos[1], pos[0]) / HOURANGLE : 0.0;
if(*ra < 0.0)
*ra = DAY_HOURS;
*dec = atan2(pos[2], xyproj) / DEGREE;
return 0;
}
/**
* Converts galactic longitude and latitude to ICRS right ascension and declination.
*
* REFERENCES:
* <ol>
* <li>Hipparcos and Tycho Catalogues, Vol. 1, Section 1.5.3.</li>
* </ol>
*
* @param glon [deg] Galactic longitude in degrees.
* @param glat [deg] Galactic latitude in degrees.
* @param[out] ra [h] ICRS right ascension in hours.
* @param[out] dec [deg] ICRS declination in degrees.
*
* @return 0 if successful, or -1 if either of the output pointer arguments
* are NULL.
*
* @sa equ2gal()
*
* @since 1.0
* @author Attila Kovacs
*/
int gal2equ(double glon, double glat, double *ra, double *dec) {
double pos1[3], pos2[3], xyproj, coslat;
// Rotation matrix A_g from Hipparcos documentation eq. 1.5.11.
// AK: Transposed compared to NOVAS C 3.1 for dot product handling.
static const double ag[3][3] = { //
{ -0.0548755604, 0.4941094279, -0.8676661490 }, //
{ -0.8734370902, -0.4448296300, -0.1980763734 }, //
{ -0.4838350155, 0.7469822445, 0.4559837762 } };
if(!ra || !dec)
return novas_error(-1, EINVAL, "gal2equ", "NULL output pointer: ra=%p, dec=%p", ra, dec);
// Form position vector in equatorial system from input coordinates
glon *= DEGREE;
glat *= DEGREE;
coslat = cos(glat);
pos1[0] = coslat * cos(glon);
pos1[1] = coslat * sin(glon);
pos1[2] = sin(glat);
// Rotate position vector to galactic system, using Hipparcos documentation eq. 1.5.13.
pos2[0] = novas_vdot(ag[0], pos1);
pos2[1] = novas_vdot(ag[1], pos1);
pos2[2] = novas_vdot(ag[2], pos1);
// Decompose galactic vector into longitude and latitude.
xyproj = sqrt(pos2[0] * pos2[0] pos2[1] * pos2[1]);
*ra = xyproj ? atan2(pos2[1], pos2[0]) / HOURANGLE : 0.0;
if(*ra < 0.0)
*ra = DAY_HOURS;
*dec = atan2(pos2[2], xyproj) / DEGREE;
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 j2000_to_tod()
* @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;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from the Celestial Intermediate
* Reference System (CIRS) at the given epoch to the True of Date (TOD) reference
* system.
*
* @param jd_tt [day] Terrestrial 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 CIRS Input (x, y, z) position or velocity vector
* @param[out] out Output position or velocity 3-vector in the True of Date (TOD) 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 10 the error from cio_location(), or
* else 20 the error from cio_basis().
*
* @sa tod_to_cirs()
* @sa cirs_to_app_ra()
* @sa cirs_to_gcrs()
* @sa cirs_to_itrs()
*
*
* @since 1.1
* @author Attila Kovacs
*/
int cirs_to_tod(double jd_tt, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "cirs_to_tod";
double ra_cio; // [h] R.A. of the CIO (from the true equinox) we'll calculate
// Obtain the R.A. [h] of the CIO at the given date
prop_error(fn, cio_ra(jd_tt, accuracy, &ra_cio), 0);
prop_error(fn, spin(-15.0 * ra_cio, in, out), 0);
return 0;
}
/**
* Transforms a rectangular equatorial (x, y, z) vector from the True of Date (TOD) reference
* system to the Celestial Intermediate Reference System (CIRS) at the given epoch to the .
*
* @param jd_tt [day] Terrestrial 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 CIRS Input (x, y, z) position or velocity vector
* @param[out] out Output position or velocity 3-vector in the True of Date (TOD) 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 10 the error from cio_location(), or
* else 20 the error from cio_basis().
*
* @sa cirs_to_tod()
* @sa app_to_cirs_ra()
* @sa tod_to_gcrs()
* @sa tod_to_j2000()
* @sa tod_to_itrs()
*
*
* @since 1.1
* @author Attila Kovacs
*/
int tod_to_cirs(double jd_tt, enum novas_accuracy accuracy, const double *in, double *out) {
static const char *fn = "tod_to_cirs";
double ra_cio; // [h] R.A. of the CIO (from the true equinox) we'll calculate
// Obtain the R.A. [h] of the CIO at the given date
prop_error(fn, cio_ra(jd_tt, accuracy, &ra_cio), 0);
prop_error(fn, spin(15.0 * ra_cio, in, out), 0);
return 0;
}
/**
* Converts a position vector in the Earth-fixed ITRS frame to astrometric (unrefracted) azimuth
* and zenith angles at the specified observer location.
*
* @param location Observer location on Earth
* @param itrs 3-vector position in Earth-fixed ITRS frame
* @param[out] az [deg] astrometric azimuth angle at observer location [0:360]. It may be
* NULL if not required.
* @param[out] za [deg] astrometric zenith angle at observer location [0:180]. It may be NULL
* if not required.
* @return 0 if successful, or else -1 if the location or the input vector is NULL.
*
* @sa hor_to_itrs()
* @sa cirs_to_itrs()
* @sa tod_to_itrs()
* @sa refract_astro()
*
* @since 1.0
* @author Attila Kovacs
*/
int itrs_to_hor(const on_surface *location, const double *itrs, double *az, double *za) {
double uze[3], une[3], uwe[3];
double lat, lon, coslat, sinlat, coslon, sinlon;
double pn, pw, pz, proj;
// Default output values in case of error return.
if(az)
*az = NAN;
if(za)
*za = NAN;
if(!location || !itrs)
return novas_error(-1, EINVAL, "itrs_to_hor", "NULL input location=%p or ITRS pos=%p", location, itrs);
lat = location->latitude * DEGREE;
lon = location->longitude * DEGREE;
coslat = cos(lat);
sinlat = sin(lat);
coslon = cos(lon);
sinlon = sin(lon);
// Define vector toward local north in Earth-fixed system (x axis).
une[0] = -sinlat * coslon;
une[1] = -sinlat * sinlon;
une[2] = coslat;
// Define vector toward local west in Earth-fixed system (y axis).
uwe[0] = sinlon;
uwe[1] = -coslon;
uwe[2] = 0.0;
// Define vector toward local zenith in Earth-fixed system (z axis).
uze[0] = coslat * coslon;
uze[1] = coslat * sinlon;
uze[2] = sinlat;
// Obtain vectors in celestial system.
// Compute coordinates of object w.r.t orthonormal basis.
// Compute components of 'p' - projections of 'p' onto rotated
// Earth-fixed basis vectors.
pn = novas_vdot(itrs, une);
pw = novas_vdot(itrs, uwe);
pz = novas_vdot(itrs, uze);
// Compute azimuth and zenith distance.
proj = sqrt(pn * pn pw * pw);
if(az) {
*az = proj > 0.0 ? -atan2(pw, pn) / DEGREE : 0.0;
if(*az < 0.0)
*az = DEG360;
}
if(za)
*za = atan2(proj, pz) / DEGREE;
return 0;
}
/**
* Converts astrometric (unrefracted) azimuth and zenith angles at the specified observer location to a
* unit position vector in the Earth-fixed ITRS frame.
*
* @param location Observer location on Earth
* @param az [deg] astrometric azimuth angle at observer location [0:360]. It may be
* NULL if not required.
* @param za [deg] astrometric zenith angle at observer location [0:180]. It may be NULL
* if not required.
* @param[out] itrs Unit 3-vector direction in Earth-fixed ITRS frame
* @return 0 if successful, or else -1 if the location or the input vector is NULL.
*
* @sa itrs_to_hor()
* @sa itrs_to_cirs()
* @sa itrs_to_tod()
* @sa refract()
*
* @since 1.0
* @author Attila Kovacs
*/
int hor_to_itrs(const on_surface *location, double az, double za, double *itrs) {
double in[3], uze[3], une[3], uwe[3];
double sinza;
double lat, lon, coslat, sinlat, coslon, sinlon;
if(!location || !itrs)
return novas_error(-1, EINVAL, "hor_to_itrs", "NULL input location=%p or output itrs=%p position", location, itrs);
az *= -DEGREE;
za *= DEGREE;
sinza = sin(za);
in[0] = sinza * cos(az);
in[1] = sinza * sin(az);
in[2] = cos(za);
lat = location->latitude * DEGREE;
lon = location->longitude * DEGREE;
coslat = cos(lat);
sinlat = sin(lat);
coslon = cos(lon);
sinlon = sin(lon);
// Define vector toward local zenith in Earth-fixed system (z axis).
uze[0] = coslat * coslon;
uze[1] = coslat * sinlon;
uze[2] = sinlat;
// Define vector toward local north in Earth-fixed system (x axis).
une[0] = -sinlat * coslon;
une[1] = -sinlat * sinlon;
une[2] = coslat;
// Define vector toward local west in Earth-fixed system (y axis).
uwe[0] = sinlon;
uwe[1] = -coslon;
uwe[2] = 0.0;
// Calculate ITRS positions from NWZ components at ITRS origin
itrs[0] = une[0] * in[0] uwe[0] * in[1] uze[0] * in[2];
itrs[1] = une[1] * in[0] uwe[1] * in[1] uze[1] * in[2];
itrs[2] = une[2] * in[0] uwe[2] * in[1] uze[2] * in[2];
return 0;
}
/**
* Converts a CIRS right ascension coordinate (measured from the CIO) to an apparent R.A.
* measured from the true equinox of date.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param ra [h] The CIRS right ascension coordinate, measured from the CIO.
* @return [h] the apparent R.A. coordinate measured from the true equinox of date [0:24],
* or NAN if the accuracy is invalid, or if there wan an error from cio_ra().
*
* @sa app_to_cirs_ra()
* @sa cirs_to_tod()
*
* @since 1.0.1
* @author Attila Kovacs
*/
double cirs_to_app_ra(double jd_tt, enum novas_accuracy accuracy, double ra) {
double ra_cio; // [h] R.A. of the CIO (from the true equinox) we'll calculate
// Obtain the R.A. [h] of the CIO at the given date
int stat = cio_ra(jd_tt, accuracy, &ra_cio);
if(stat)
return novas_trace_nan("cirs_to_app_ra");
// Convert CIRS R.A. to true apparent R.A., keeping the result in the [0:24] h range
ra = remainder(ra ra_cio, 24.0);
if(ra < 0.0)
ra = 24.0;
return ra;
}
/**
* Converts an apparent right ascension coordinate (measured from the true equinox of date) to a
* CIRS R.A., measured from the CIO.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian date
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param ra [h] the apparent R.A. coordinate measured from the true equinox of date.
* @return [h] The CIRS right ascension coordinate, measured from the CIO [0:24],
* or NAN if the accuracy is invalid, or if there wan an error from cio_ra().
*
* @sa cirs_to_app_ra()
* @sa tod_to_cirs()
*
* @since 1.0.1
* @author Attila Kovacs
*/
double app_to_cirs_ra(double jd_tt, enum novas_accuracy accuracy, double ra) {
double ra_cio; // [h] R.A. of the CIO (from the true equinox) we'll calculate
// Obtain the R.A. [h] of the CIO at the given date
int stat = cio_ra(jd_tt, accuracy, &ra_cio);
if(stat)
return novas_trace_nan("app_to_cirs_ra");
// Convert CIRS R.A. to true apparent R.A., keeping the result in the [0:24] h range
ra = remainder(ra - ra_cio, 24.0);
if(ra < 0.0)
ra = 24.0;
return ra;
}
/**
* Rotates a position vector from the Earth-fixed ITRS frame to the dynamical CIRS frame of
* date (IAU 2000 standard method).
*
* If both 'xp' and 'yp' are set to 0 no polar motion is included in the transformation.
*
* If extreme (sub-microarcsecond) accuracy is not required, you can use UT1-based Julian date
* instead of the TT-based Julian date and set the 'ut1_to_tt' argument to 0.0. and you can
* use UTC-based Julian date the same way.for arcsec-level precision also.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU
* XXV Joint Discussion 16.</li>
* </ol>
*
* @param jd_tt_high [day] High-order part of Terrestrial Time (TT) based Julian date.
* @param jd_tt_low [day] Low-order part of Terrestrial Time (TT) based Julian date.
* @param ut1_to_tt [s] TT - UT1 Time difference in seconds
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param xp [arcsec] Conventionally-defined X coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param yp [arcsec] Conventionally-defined Y coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param in Position vector, geocentric equatorial rectangular coordinates,
* referred to ITRS axes (terrestrial system)
* @param[out] out Position vector, geocentric equatorial rectangular coordinates,
* referred to CIRS axes (celestial system).
* @return 0 if successful, -1 if either of the vector arguments is NULL, 1 if
* 'accuracy' is invalid, or else 10 the error from cio_location(), or
* 20 error from cio_basis().
*
* @sa itrs_to_tod()
* @sa cirs_to_itrs()
* @sa cirs_to_gcrs()
*
* @since 1.0
* @author Attila Kovacs
*/
int itrs_to_cirs(double jd_tt_high, double jd_tt_low, double ut1_to_tt, enum novas_accuracy accuracy, double xp, double yp,
const double *in, double *out) {
prop_error("itrs_to_cirs",
ter2cel(jd_tt_high, jd_tt_low - ut1_to_tt / DAY, ut1_to_tt, EROT_ERA, accuracy, NOVAS_DYNAMICAL_CLASS, xp, yp, in, out), 0);
return 0;
}
/**
* Rotates a position vector from the Earth-fixed ITRS frame to the dynamical True of Date
* (TOD) frame of date (pre IAU 2000 method).
*
* If both 'xp' and 'yp' are set to 0 no polar motion is included in the transformation.
*
* If extreme (sub-microarcsecond) accuracy is not required, you can use UT1-based Julian date
* instead of the TT-based Julian date and set the 'ut1_to_tt' argument to 0.0. and you can
* use UTC-based Julian date the same way.for arcsec-level precision also.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU
* XXV Joint Discussion 16.</li>
* </ol>
*
* @param jd_tt_high [day] High-order part of Terrestrial Time (TT) based Julian date.
* @param jd_tt_low [day] Low-order part of Terrestrial Time (TT) based Julian date.
* @param ut1_to_tt [s] TT - UT1 Time difference in seconds
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param xp [arcsec] Conventionally-defined X coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param yp [arcsec] Conventionally-defined Y coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param in Position vector, geocentric equatorial rectangular coordinates,
* referred to ITRS axes (terrestrial system)
* @param[out] out Position vector, geocentric equatorial rectangular coordinates,
* referred to True of Date (TOD) axes (celestial system)
* @return 0 if successful, -1 if either of the vector arguments is NULL, 1 if
* 'accuracy' is invalid, or else 10 the error from cio_location(), or
* 20 error from cio_basis().
*
* @sa itrs_to_cirs()
* @sa tod_to_itrs()
* @sa tod_to_j2000()
*
* @since 1.0
* @author Attila Kovacs
*/
int itrs_to_tod(double jd_tt_high, double jd_tt_low, double ut1_to_tt, enum novas_accuracy accuracy, double xp, double yp, const double *in,
double *out) {
prop_error("itrs_to_tod",
ter2cel(jd_tt_high, jd_tt_low - ut1_to_tt / DAY, ut1_to_tt, EROT_GST, accuracy, NOVAS_DYNAMICAL_CLASS, xp, yp, in, out), 0);
return 0;
}
/**
* Rotates a position vector from the dynamical CIRS frame of date to the Earth-fixed ITRS frame
* (IAU 2000 standard method).
*
* If both 'xp' and 'yp' are set to 0 no polar motion is included in the transformation.
*
* If extreme (sub-microarcsecond) accuracy is not required, you can use UT1-based Julian date
* instead of the TT-based Julian date and set the 'ut1_to_tt' argument to 0.0. and you can
* use UTC-based Julian date the same way.for arcsec-level precision also.
*
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU XXV
* Joint Discussion 16.</li>
* </ol>
*
* @param jd_tt_high [day] High-order part of Terrestrial Time (TT) based Julian date.
* @param jd_tt_low [day] Low-order part of Terrestrial Time (TT) based Julian date.
* @param ut1_to_tt [s] TT - UT1 Time difference in seconds
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param xp [arcsec] Conventionally-defined X coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param yp [arcsec] Conventionally-defined Y coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param in Position vector, geocentric equatorial rectangular coordinates,
* referred to CIRS axes (celestial system).
* @param[out] out Position vector, geocentric equatorial rectangular coordinates,
* referred to ITRS axes (terrestrial system).
* @return 0 if successful, -1 if either of the vector arguments is NULL, 1 if
* 'accuracy' is invalid, 2 if 'method' is invalid 10--20, 3 if the method
* and option are mutually incompatible, or else 10 the error from
* cio_location(), or 20 error from cio_basis().
*
* @sa tod_to_itrs()
* @sa itrs_to_cirs()
* @sa gcrs_to_cirs()
* @sa cirs_to_gcrs()
* @sa cirs_to_tod()
*
* @since 1.0
* @author Attila Kovacs
*/
int cirs_to_itrs(double jd_tt_high, double jd_tt_low, double ut1_to_tt, enum novas_accuracy accuracy, double xp, double yp,
const double *in, double *out) {
prop_error("cirs_to_itrs",
cel2ter(jd_tt_high, jd_tt_low - ut1_to_tt / DAY, ut1_to_tt, EROT_ERA, accuracy, NOVAS_DYNAMICAL_CLASS, xp, yp, in, out), 0);
return 0;
}
/**
* Rotates a position vector from the dynamical True of Date (TOD) frame of date the Earth-fixed
* ITRS frame (pre IAU 2000 method).
*
* If both 'xp' and 'yp' are set to 0 no polar motion is included in the transformation.
*
* If extreme (sub-microarcsecond) accuracy is not required, you can use UT1-based Julian date
* instead of the TT-based Julian date and set the 'ut1_to_tt' argument to 0.0. and you can
* use UTC-based Julian date the same way.for arcsec-level precision also.
*
* REFERENCES:
* <ol>
* <li>Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210.</li>
* <li>Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU XXV
* Joint Discussion 16.</li>
* </ol>
*
* @param jd_tt_high [day] High-order part of Terrestrial Time (TT) based Julian date.
* @param jd_tt_low [day] Low-order part of Terrestrial Time (TT) based Julian date.
* @param ut1_to_tt [s] TT - UT1 Time difference in seconds.
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param xp [arcsec] Conventionally-defined X coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param yp [arcsec] Conventionally-defined Y coordinate of celestial intermediate
* pole with respect to ITRS pole, in arcseconds.
* @param in Position vector, geocentric equatorial rectangular coordinates,
* referred to True of Date (TOD) axes (celestial system).
* @param[out] out Position vector, geocentric equatorial rectangular coordinates,
* referred to ITRS axes (terrestrial system).
* @return 0 if successful, -1 if either of the vector arguments is NULL, 1 if
* 'accuracy' is invalid, 2 if 'method' is invalid 10--20, 3 if the method
* and option are mutually incompatible, or else 10 the error from
* cio_location(), or 20 error from cio_basis().
*
* @sa cirs_to_itrs()
* @sa itrs_to_tod()
* @sa j2000_to_tod()
* @sa tod_to_gcrs()
* @sa tod_to_j2000()
* @sa tod_to_cirs()
*
* @since 1.0
* @author Attila Kovacs
*/
int tod_to_itrs(double jd_tt_high, double jd_tt_low, double ut1_to_tt, enum novas_accuracy accuracy, double xp, double yp, const double *in,
double *out) {
prop_error("tod_to_itrs",
cel2ter(jd_tt_high, jd_tt_low - ut1_to_tt / DAY, ut1_to_tt, EROT_GST, accuracy, NOVAS_DYNAMICAL_CLASS, xp, yp, in, out), 0);
return 0;
}
/**
* Computes the gravitationally undeflected position of an observed source position due to the
* specified Solar-system bodies.
*
* REFERENCES:
* <ol>
* <li>Klioner, S. (2003), Astronomical Journal 125, 1580-1597, Section 6.</li>
* </ol>
*
* @param pos_app [AU] Apparent position 3-vector of observed object, with respect to origin at
* observer (or the geocenter), referred to ICRS axes, components
* in AU.
* @param pos_obs [AU] Position 3-vector of observer (or the geocenter), with respect to
* origin at solar system barycenter, referred to ICRS axes,
* components in AU.
* @param planets Apparent planet data containing positions and velocities for the major
* gravitating bodies in the solar-system.
* @param[out] out [AU] Nominal position vector of observed object, with respect to origin at
* observer (or the geocenter), referred to ICRS axes, without gravitational
* deflection, components in AU. It can be the same vector as the input, but not
* the same as pos_obs.
* @return 0 if successful, -1 if any of the pointer arguments is NULL.
*
* @sa obs_planets()
* @sa grav_planets()
* @sa novas_app_to_geom()
*
* @since 1.1
* @author Attila Kovacs
*/
int grav_undo_planets(const double *pos_app, const double *pos_obs, const novas_planet_bundle *planets, double *out) {
static const char *fn = "grav_undo_planets";
const double tol = 1e-13;
double pos_def[3] = {0}, pos0[3] = {0};
double l;
int i;
if(!pos_app || !pos_obs)
return novas_error(-1, EINVAL, fn, "NULL input 3-vector: pos_app=%p, pos_obs=%p", pos_app, pos_obs);
if(!planets)
return novas_error(-1, EINVAL, fn, "NULL input planet data");
if(!out)
return novas_error(-1, EINVAL, fn, "NULL output 3-vector: out=%p", out);
l = novas_vlen(pos_app);
if(l == 0.0) {
if(out != pos_app)
memcpy(out, pos_app, XYZ_VECTOR_SIZE);
return 0; // Source is same as observer. No deflection.
}
memcpy(pos0, pos_app, sizeof(pos0));
for(i = 0; i < novas_inv_max_iter; i ) {
int j;
prop_error(fn, grav_planets(pos0, pos_obs, planets, pos_def), 0);
if(novas_vdist(pos_def, pos_app) / l < tol) {
memcpy(out, pos0, sizeof(pos0));
return 0;
}
for(j = 3; --j >= 0;)
pos0[j] -= pos_def[j] - pos_app[j];
}
return novas_error(-1, ECANCELED, fn, "failed to converge");
}
/**
* Computes the gravitationally undeflected position of an observed source position due to the
* major gravitating bodies in the solar system. This function valid for an observed body within
* the solar system as well as for a star.
*
* If 'accuracy' is set to zero (full accuracy), three bodies (Sun, Jupiter, and Saturn) are
* used in the calculation. If the reduced-accuracy option is set, only the Sun is used in
* the calculation. In both cases, if the observer is not at the geocenter, the deflection
* due to the Earth is included.
*
* The number of bodies used at full and reduced accuracy can be set by making a change to
* the code in this function as indicated in the comments.
*
* REFERENCES:
* <ol>
* <li>Klioner, S. (2003), Astronomical Journal 125, 1580-1597, Section 6.</li>
* </ol>
*
* @param jd_tdb [day] Barycentric Dynamical Time (TDB) based Julian date
* @param accuracy NOVAS_FULL_ACCURACY (0) or NOVAS_REDUCED_ACCURACY (1)
* @param pos_app [AU] Apparent position 3-vector of observed object, with respect to origin at
* observer (or the geocenter), referred to ICRS axes, components
* in AU.
* @param pos_obs [AU] Position 3-vector of observer (or the geocenter), with respect to
* origin at solar system barycenter, referred to ICRS axes,
* components in AU.
* @param[out] out [AU] Nominal position vector of observed object, with respect to origin at
* observer (or the geocenter), referred to ICRS axes, without gravitational
* deflection, components in AU. It can be the same vector as the input, but not
* the same as pos_obs.
* @return 0 if successful, -1 if any of the pointer arguments is NULL (errno = EINVAL)
* or if the result did not converge (errno = ECANCELED), or else an error from
* obs_planets().
*
* @sa grav_def()
* @sa novas_app_to_geom()
* @sa set_planet_provider()
* @sa set_planet_provider_hp()
* @sa grav_bodies_full_accuracy
* @sa grav_bodies_reduced_accuracy
*
* @since 1.1
* @author Attila Kovacs
*/
int grav_undef(double jd_tdb, enum novas_accuracy accuracy, const double *pos_app, const double *pos_obs, double *out) {
static const char *fn = "grav_undef";
novas_planet_bundle planets = {0};
int pl_mask = (accuracy == NOVAS_FULL_ACCURACY) ? grav_bodies_full_accuracy : grav_bodies_reduced_accuracy;
if(!pos_app || !out)
return novas_error(-1, EINVAL, fn, "NULL source position 3-vector: pos_app=%p, out=%p", pos_app, out);
prop_error(fn, obs_planets(jd_tdb, accuracy, pos_obs, pl_mask, &planets), 0);
prop_error(fn, grav_undo_planets(pos_app, pos_obs, &planets, out), 0);
return 0;
}
/**
* Populates and object data structure with the data for a catalog source.
*
* @param star Pointer to structure to populate with the catalog data for a celestial
* object located outside the solar system.
* @param[out] source Pointer to the celestial object data structure to be populated.
* @return 0 if successful, or -1 if 'cel_obj' is NULL or when type is
* NOVAS_CATALOG_OBJECT and 'star' is NULL, or else 1 if 'type' is
* invalid, 2 if 'number' is out of legal range or 5 if 'name' is too long.
*
* @sa make_cat_entry()
* @sa make_planet()
* @sa make_ephem_object()
* @sa novas_geom_posvel()
* @sa place()
*
* @since 1.1
* @author Attila Kovacs
*