source: trunk/MagicSoft/Cosy/catalog/Slalib.cc@ 3957

Last change on this file since 3957 was 3897, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1#include "Slalib.h"
2
3#include <time.h>
4#include <iostream.h> // cout
5
6#include "coord.h"
7
8#include "slalib.h"
9
10ClassImp(Slalib);
11
12Slalib::Slalib(MObservatory::LocationName_t key) : MObservatory(key)
13{
14}
15
16Double_t Slalib::Trunc(Double_t val)
17{
18 /* dint(A) - truncate to nearest whole number towards zero (double) */
19 return val<0 ? TMath::Ceil(val) : TMath::Floor(val);
20}
21
22Double_t Slalib::Round(Double_t val)
23{
24 /* dnint(A) - round to nearest whole number (double) */
25 return val<0 ? TMath::Ceil(val-0.5) : TMath::Floor(val+0.5);
26}
27
28void Slalib::SetMjd(double mjd)
29{
30 fTime.SetMjd(mjd);
31
32 fAlpha = slaGmst(GetMjd()) + GetElong();
33}
34
35void Slalib::Now(double offset)
36{
37 fTime.Now();
38 SetMjd(fTime.GetMjd()+offset/(24*60*60));
39}
40
41
42ZdAz Slalib::XYZ2ZdAz(double coord[3]) const
43{
44 //
45 // -- xyz to spherical coordinates --
46 //
47 double ra, dec;
48 slaDcc2s(coord, &ra, &dec);
49
50 //
51 // radec[rad] -> hadec[rad]
52 //
53 const double ha = fAlpha-ra;
54
55 //
56 // hadec[rad] -> altaz[rad]
57 //
58 double alt, az;
59 slaDe2h(ha, dec, GetPhi(), &az, &alt);
60
61 return ZdAz(kPiDiv2-alt, az);
62}
63/*
64Double_t Slalib::Hms2Sec(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
65{
66 const Double_t rc = TMath::Sign((60.0 * (60.0 * (Double_t)TMath::Abs(deg) + (Double_t)min) + sec), (Double_t)deg);
67 return sgn=='-' ? -rc : rc;
68}
69
70Double_t Slalib::Dms2Rad(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
71{
72 // pi/(180*3600): arcseconds to radians
73#define DAS2R 4.8481368110953599358991410235794797595635330237270e-6
74 return Hms2Sec(deg, min, sec, sgn)*DAS2R;
75}
76
77Double_t Slalib::Hms2Rad(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
78{
79 // pi/(12*3600): seconds of time to radians
80#define DS2R 7.2722052166430399038487115353692196393452995355905e-5
81 return Hms2Sec(hor, min, sec, sgn)*DS2R;
82}
83
84Double_t Slalib::Dms2Deg(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
85{
86 return Hms2Sec(deg, min, sec, sgn)/3600.;
87}
88
89Double_t Slalib::Hms2Deg(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
90{
91 return Hms2Sec(hor, min, sec, sgn)/240.;
92}
93
94Double_t Slalib::Dms2Hor(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
95{
96 return Hms2Sec(deg, min, sec, sgn)/15.;
97}
98
99Double_t Slalib::Hms2Hor(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
100{
101 return Hms2Sec(hor, min, sec, sgn)/3600.;
102}
103
104void Slalib::Day2Hms(Double_t day, Char_t &sgn, UShort_t &hor, UShort_t &min, UShort_t &sec)
105{
106 // Handle sign
107 sgn = day<0?'-':'+';
108
109 // Round interval and express in smallest units required
110 Double_t a = Round(86400. * TMath::Abs(day)); // Days to seconds
111
112 // Separate into fields
113 const Double_t ah = Trunc(a/3600.);
114 a -= ah * 3600.;
115 const Double_t am = Trunc(a/60.);
116 a -= am * 60.;
117 const Double_t as = Trunc(a);
118
119 // Return results
120 hor = (UShort_t)ah;
121 min = (UShort_t)am;
122 sec = (UShort_t)as;
123}
124
125void Slalib::Rad2Hms(Double_t rad, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
126{
127 Day2Hms(rad/(TMath::Pi()*2), sgn, deg, min, sec);
128}
129
130void Slalib::Rad2Dms(Double_t rad, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
131{
132 Rad2Hms(rad*15, sgn, deg, min, sec);
133}
134
135void Slalib::Deg2Dms(Double_t d, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
136{
137 Day2Hms(d/24, sgn, deg, min, sec);
138}
139
140void Slalib::Deg2Hms(Double_t d, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
141{
142 Rad2Hms(d/360, sgn, deg, min, sec);
143}
144
145void Slalib::Hor2Dms(Double_t h, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
146{
147 Day2Hms(h*15/24, sgn, deg, min, sec);
148}
149
150void Slalib::Hor2Hms(Double_t h, Char_t &sgn, UShort_t &deg, UShort_t &min, UShort_t &sec)
151{
152 Day2Hms(h/24, sgn, deg, min, sec);
153}
154
155void Slalib::Day2Hm(Double_t day, Char_t &sgn, UShort_t &hor, Double_t &min)
156{
157 // Handle sign
158 sgn = day<0?'-':'+';
159
160 // Round interval and express in smallest units required
161 Double_t a = Round(86400. * TMath::Abs(day)); // Days to seconds
162
163 // Separate into fields
164 const Double_t ah = Trunc(a/3600.);
165 a -= ah * 3600.;
166
167 // Return results
168 hor = (UShort_t)ah;
169 min = a/60.;
170}
171
172void Slalib::Rad2Hm(Double_t rad, Char_t &sgn, UShort_t &deg, Double_t &min)
173{
174 Day2Hm(rad/(TMath::Pi()*2), sgn, deg, min);
175}
176
177void Slalib::Rad2Dm(Double_t rad, Char_t &sgn, UShort_t &deg, Double_t &min)
178{
179 Rad2Hm(rad*15, sgn, deg, min);
180}
181
182void Slalib::Deg2Dm(Double_t d, Char_t &sgn, UShort_t &deg, Double_t &min)
183{
184 Day2Hm(d/24, sgn, deg, min);
185}
186
187void Slalib::Deg2Hm(Double_t d, Char_t &sgn, UShort_t &deg, Double_t &min)
188{
189 Rad2Hm(d/360, sgn, deg, min);
190}
191
192void Slalib::Hor2Dm(Double_t h, Char_t &sgn, UShort_t &deg, Double_t &min)
193{
194 Day2Hm(h*15/24, sgn, deg, min);
195}
196
197void Slalib::Hor2Hm(Double_t h, Char_t &sgn, UShort_t &deg, Double_t &min)
198{
199 Day2Hm(h/24, sgn, deg, min);
200}
201
202*/
Note: See TracBrowser for help on using the repository browser.