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