1 /*
2  *  kelso.h     April 9 2001
3  *
4  *  Header file for kelso
5  */
6 
7 #ifndef KELSO_H
8 #define KELSO_H 1
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <math.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdlib.h>
18 #include <time.h>
19 /* #include <unistd.h> */
20 
21 /* from David Kaelbling <drk@sgi.com> */
22 #define select duplicate_select
23 #include <unistd.h>
24 #undef select
25 
26 
27 
28 /** Type definitions **/
29 
30 /* Two-line-element satellite orbital data */
31 typedef struct
32 {
33   double
34     epoch, xndt2o, xndd6o, bstar,
35     xincl, xnodeo, eo, omegao, xmo, xno;
36   int
37     catnr,  /* Catalogue Number  */
38     elset,  /* Element Set       */
39     revnum; /* Revolution Number */
40   char
41     sat_name[25], /* Satellite name string    */
42     idesg[9];     /* International Designator */
43 } tle_t;
44 
45 /* Geodetic position structure */
46 typedef struct
47 {
48   double
49   lat, lon, alt, theta;
50 } geodetic_t;
51 
52 /* General three-dimensional vector structure */
53 typedef struct
54 {
55   double
56   x, y, z, w;
57 } vector_t;
58 
59 /* Common arguments between deep-space functions */
60 typedef struct
61 {
62   /* Used by dpinit part of Deep() */
63   double
64     eosq,sinio,cosio,betao,aodp,theta2,sing,cosg,
65     betao2,xmdot,omgdot,xnodot,xnodp;
66   /* Used by dpsec and dpper parts of Deep() */
67   double
68     xll,omgadf,xnode,em,xinc,xn,t;
69   /* Used by thetg and Deep() */
70   double
71     ds50;
72 } deep_arg_t;
73 
74 /** Table of constant values **/
75 #define de2ra    1.74532925E-2   /* Degrees to Radians */
76 #define pi       3.1415926535898 /* Pi */
77 #define pio2     1.5707963267949 /* Pi/2 */
78 #define x3pio2   4.71238898      /* 3*Pi/2 */
79 #define twopi    6.2831853071796 /* 2*Pi  */
80 #define e6a      1.0E-6
81 #define tothrd   6.6666667E-1    /* 2/3 */
82 #define xj2      1.0826158E-3    /* J2 Harmonic */
83 #define xj3     -2.53881E-6      /* J3 Harmonic */
84 #define xj4     -1.65597E-6      /* J4 Harmonic */
85 #define xke      7.43669161E-2
86 #define xkmper   6.378135E3      /* Earth radius km */
87 #define xmnpda   1.44E3          /* Minutes per day */
88 #define ae       1.0
89 #define ck2      5.413079E-4
90 #define ck4      6.209887E-7
91 #define f        3.352779E-3
92 #define ge       3.986008E5
93 #define s        1.012229
94 #define qoms2t   1.880279E-09
95 #define secday   8.6400E4        /* Seconds per day */
96 #define omega_E  1.0027379
97 #define omega_ER 6.3003879
98 #define zns      1.19459E-5
99 #define c1ss     2.9864797E-6
100 #define zes      1.675E-2
101 #define znl      1.5835218E-4
102 #define c1l      4.7968065E-7
103 #define zel      5.490E-2
104 #define zcosis   9.1744867E-1
105 #define zsinis   3.9785416E-1
106 #define zsings  -9.8088458E-1
107 #define zcosgs   1.945905E-1
108 #define zcoshs   1
109 #define zsinhs   0
110 #define q22      1.7891679E-6
111 #define q31      2.1460748E-6
112 #define q33      2.2123015E-7
113 #define g22      5.7686396
114 #define g32      9.5240898E-1
115 #define g44      1.8014998
116 #define g52      1.0508330
117 #define g54      4.4108898
118 #define root22   1.7891679E-6
119 #define root32   3.7393792E-7
120 #define root44   7.3636953E-9
121 #define root52   1.1428639E-7
122 #define root54   2.1765803E-9
123 #define thdt     4.3752691E-3
124 #define rho      1.5696615E-1
125 #define mfactor  7.292115E-5
126 #define sr       6.96000E5      /*Solar radius - kilometers (IAU 76)*/
127 #define AU       1.49597870E8   /*Astronomical unit - kilometers (IAU 76)*/
128 
129 /* Entry points of Deep() */
130 #define dpinit   1 /* Deep-space initialization code */
131 #define dpsec    2 /* Deep-space secular code        */
132 #define dpper    3 /* Deep-space periodic code       */
133 
134 /* Carriage return and line feed */
135 #define CR  0x0A
136 #define LF  0x0D
137 
138 /* Flow control flag definitions */
139 #define ALL_FLAGS              -1
140 #define  SGP_INITIALIZED_FLAG  0x000001
141 #define SGP4_INITIALIZED_FLAG  0x000002
142 #define SDP4_INITIALIZED_FLAG  0x000004
143 #define SGP8_INITIALIZED_FLAG  0x000008
144 #define SDP8_INITIALIZED_FLAG  0x000010
145 #define SIMPLE_FLAG            0x000020
146 #define DEEP_SPACE_EPHEM_FLAG  0x000040
147 #define LUNAR_TERMS_DONE_FLAG  0x000080
148 #define NEW_EPHEMERIS_FLAG     0x000100
149 #define DO_LOOP_FLAG           0x000200
150 #define RESONANCE_FLAG         0x000400
151 #define SYNCHRONOUS_FLAG       0x000800
152 #define EPOCH_RESTART_FLAG     0x001000
153 #define VISIBLE_FLAG           0x002000
154 #define SAT_ECLIPSED_FLAG      0x004000
155 
156 
157 /** Funtion prototypes **/
158 
159 /* main.c */
160 /* int     main(void); */
161 /* sgp4sdp4.c */
162 void    SGP4(double tsince, tle_t *tle, vector_t *pos, vector_t *vel);
163 void    SDP4(double tsince, tle_t *tle, vector_t *pos, vector_t *vel);
164 void    Deep(int ientry, tle_t *tle, deep_arg_t *deep_arg);
165 int     isFlagSet(int flag);
166 int     isFlagClear(int flag);
167 void    SetFlag(int flag);
168 void    ClearFlag(int flag);
169 /* sgp_in.c */
170 int     Checksum_Good(char *tle_set);
171 int     Good_Elements(char *tle_set);
172 void    Convert_Satellite_Data(char *tle_set, tle_t *tle);
173 int     Get_Next_Tle_Set( char lines[3][80], tle_t *tle );
174 void    select_ephemeris(tle_t *tle);
175 /* sgp_math.c */
176 int     Sign(double arg);
177 double  Sqr(double arg);
178 double  Cube(double arg);
179 double  Radians(double arg);
180 double  Degrees(double arg);
181 double  ArcSin(double arg);
182 double  ArcCos(double arg);
183 void    Magnitude(vector_t *v);
184 void    Vec_Add(vector_t *v1, vector_t *v2, vector_t *v3);
185 void    Vec_Sub(vector_t *v1, vector_t *v2, vector_t *v3);
186 void    Scalar_Multiply(double k, vector_t *v1, vector_t *v2);
187 void    Scale_Vector(double k, vector_t *v);
188 double  Dot(vector_t *v1, vector_t *v2);
189 double  Angle(vector_t *v1, vector_t *v2);
190 void    Cross(vector_t *v1, vector_t *v2, vector_t *v3);
191 void    Normalize(vector_t *v);
192 double  AcTan(double sinx, double cosx);
193 double  FMod2p(double x);
194 double  Modulus(double arg1, double arg2);
195 double  Frac(double arg);
196 int     Round(double arg);
197 double  Int(double arg);
198 void    Convert_Sat_State(vector_t *pos, vector_t *vel);
199 /* sgp_obs.c */
200 void    Calculate_User_PosVel(double time, geodetic_t *geodetic,
201                               vector_t *obs_pos, vector_t *obs_vel);
202 void    Calculate_LatLonAlt(double time, vector_t *pos, geodetic_t *geodetic);
203 void    Calculate_Obs(double time, vector_t *pos, vector_t *vel,
204                       geodetic_t *geodetic, vector_t *obs_set);
205 void    Calculate_RADec(double time, vector_t *pos, vector_t *vel,
206                         geodetic_t *geodetic, vector_t *obs_set);
207 /* sgp_time.c */
208 double  Julian_Date_of_Epoch(double epoch);
209 double  Epoch_Time(double jd);
210 int     DOY(int yr, int mo, int dy);
211 double  Fraction_of_Day(int hr, int mi, int se);
212 void    Calendar_Date(double jd, struct tm *cdate);
213 void    Time_of_Day(double jd, struct tm *cdate);
214 double  Julian_Date(struct tm *cdate);
215 void    Date_Time(double jd, struct tm *cdate);
216 int     Check_Date(struct tm *cdate);
217 struct tm Time_to_UTC(struct tm *cdate);
218 struct tm Time_from_UTC(struct tm *cdate);
219 double  JD_to_UTC(double jt);
220 double  JD_from_UTC(double jt);
221 double  Delta_ET(double year);
222 double  Julian_Date_of_Year(double year);
223 double  ThetaG(double epoch, deep_arg_t *deep_arg);
224 double  ThetaG_JD(double jd);
225 void    UTC_Calendar_Now(struct tm *cdate);
226 /* solar.c */
227 void    Calculate_Solar_Position(double time, vector_t *solar_vector);
228 int     Sat_Eclipsed(vector_t *pos, vector_t *sol, double *depth);
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 #endif
235