Satellite Observers Workbench. NOT yet complete, just published for forum posters to \"cherry pick\" pieces of code as requiered as an example.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sgp4sdp4.h Source File

sgp4sdp4.h

00001 /*
00002  *  kelso.h     April 9 2001
00003  *
00004  *  Header file for kelso
00005  */
00006 
00007 #ifndef KELSO_H
00008 #define KELSO_H 1
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013     
00014 #include <math.h>
00015 #include <stdio.h>
00016 #include <string.h>
00017 #include <stdlib.h>
00018 #include <time.h>
00019 /* #include <unistd.h> */
00020 
00021 /* from David Kaelbling <drk@sgi.com> */
00022 #define select duplicate_select
00023 //#include <unistd.h>
00024 #undef select
00025 
00026 
00027 
00028 /** Type definitions **/
00029 
00030 /* Two-line-element satellite orbital data */
00031 typedef struct
00032 {
00033   double
00034     epoch, xndt2o, xndd6o, bstar, 
00035     xincl, xnodeo, eo, omegao, xmo, xno;
00036   int
00037     catnr,  /* Catalogue Number  */
00038     elset,  /* Element Set       */
00039     revnum; /* Revolution Number */
00040   char
00041     sat_name[25], /* Satellite name string    */
00042     idesg[9];     /* International Designator */
00043   /* values needed for squint calculations */
00044   double xincl1, xnodeo1, omegao1;
00045 } tle_t; 
00046 
00047 
00048 /* Geodetic position structure */
00049 typedef struct
00050 {
00051   double
00052   lat, lon, alt, theta;
00053 } geodetic_t;
00054 
00055 /* General three-dimensional vector structure */
00056 typedef struct
00057 {
00058   double
00059   x, y, z, w;
00060 } vector_t;
00061 
00062 /* Common arguments between deep-space functions */
00063 typedef struct
00064 {
00065   /* Used by dpinit part of Deep() */
00066   double
00067     eosq,sinio,cosio,betao,aodp,theta2,sing,cosg,
00068     betao2,xmdot,omgdot,xnodot,xnodp;
00069   /* Used by dpsec and dpper parts of Deep() */
00070   double
00071     xll,omgadf,xnode,em,xinc,xn,t;
00072   /* Used by thetg and Deep() */
00073   double
00074     ds50;
00075 } deep_arg_t;
00076 
00077 /** Table of constant values **/
00078 #define de2ra    1.74532925E-2   /* Degrees to Radians */
00079 #define pi       3.1415926535898 /* Pi */
00080 #define pio2     1.5707963267949 /* Pi/2 */
00081 #define x3pio2   4.71238898      /* 3*Pi/2 */
00082 #define twopi    6.2831853071796 /* 2*Pi  */
00083 #define e6a      1.0E-6
00084 #define tothrd   6.6666667E-1    /* 2/3 */
00085 #define xj2      1.0826158E-3    /* J2 Harmonic */
00086 #define xj3     -2.53881E-6      /* J3 Harmonic */   
00087 #define xj4     -1.65597E-6      /* J4 Harmonic */
00088 #define xke      7.43669161E-2
00089 #define xkmper   6.378135E3      /* Earth radius km */
00090 #define xmnpda   1.44E3          /* Minutes per day */
00091 #define ae       1.0
00092 #define ck2      5.413079E-4
00093 #define ck4      6.209887E-7
00094 #define __f      3.352779E-3
00095 #define ge       3.986008E5 
00096 #define __s__    1.012229
00097 #define qoms2t   1.880279E-09
00098 #define secday   8.6400E4        /* Seconds per day */
00099 #define omega_E  1.0027379
00100 #define omega_ER 6.3003879
00101 #define zns      1.19459E-5
00102 #define c1ss     2.9864797E-6
00103 #define zes      1.675E-2
00104 #define znl      1.5835218E-4
00105 #define c1l      4.7968065E-7
00106 #define zel      5.490E-2
00107 #define zcosis   9.1744867E-1
00108 #define zsinis   3.9785416E-1
00109 #define zsings  -9.8088458E-1
00110 #define zcosgs   1.945905E-1
00111 #define zcoshs   1
00112 #define zsinhs   0
00113 #define q22      1.7891679E-6
00114 #define q31      2.1460748E-6
00115 #define q33      2.2123015E-7
00116 #define g22      5.7686396
00117 #define g32      9.5240898E-1
00118 #define g44      1.8014998
00119 #define g52      1.0508330
00120 #define g54      4.4108898
00121 #define root22   1.7891679E-6
00122 #define root32   3.7393792E-7
00123 #define root44   7.3636953E-9
00124 #define root52   1.1428639E-7
00125 #define root54   2.1765803E-9
00126 #define thdt     4.3752691E-3
00127 #define rho      1.5696615E-1
00128 #define mfactor  7.292115E-5
00129 #define __sr__       6.96000E5      /*Solar radius - kilometers (IAU 76)*/
00130 #define SGPAU       1.49597870E8   /*Astronomical unit - kilometers (IAU 76)*/
00131 
00132 /* Entry points of Deep() */
00133 #define dpinit   1 /* Deep-space initialization code */
00134 #define dpsec    2 /* Deep-space secular code        */
00135 #define dpper    3 /* Deep-space periodic code       */
00136 
00137 /* Carriage return and line feed */
00138 #define CR  0x0A
00139 #define LF  0x0D
00140 
00141 /* Flow control flag definitions */
00142 #define ALL_FLAGS              -1
00143 #define  SGP_INITIALIZED_FLAG  0x000001
00144 #define SGP4_INITIALIZED_FLAG  0x000002
00145 #define SDP4_INITIALIZED_FLAG  0x000004
00146 #define SGP8_INITIALIZED_FLAG  0x000008
00147 #define SDP8_INITIALIZED_FLAG  0x000010
00148 #define SIMPLE_FLAG            0x000020
00149 #define DEEP_SPACE_EPHEM_FLAG  0x000040
00150 #define LUNAR_TERMS_DONE_FLAG  0x000080
00151 #define NEW_EPHEMERIS_FLAG     0x000100
00152 #define DO_LOOP_FLAG           0x000200
00153 #define RESONANCE_FLAG         0x000400
00154 #define SYNCHRONOUS_FLAG       0x000800
00155 #define EPOCH_RESTART_FLAG     0x001000
00156 #define VISIBLE_FLAG           0x002000
00157 #define SAT_ECLIPSED_FLAG      0x004000
00158 
00159 
00160 /** Funtion prototypes **/
00161 
00162 /* main.c */
00163 /* int     main(void); */
00164 /* sgp4sdp4.c */
00165 void    SGP4(double tsince, tle_t *tle, vector_t *pos, vector_t *vel, double* phase);
00166 void    SDP4(double tsince, tle_t *tle, vector_t *pos, vector_t *vel, double* phase);
00167 void    Deep(int ientry, tle_t *tle, deep_arg_t *deep_arg);
00168 int     isFlagSet(int flag);
00169 int     isFlagClear(int flag);
00170 void    SetFlag(int flag);
00171 void    ClearFlag(int flag);
00172 /* sgp_in.c */
00173 int     Checksum_Good(char *tle_set);
00174 int     Good_Elements(char *tle_set);
00175 void    Convert_Satellite_Data(char *tle_set, tle_t *tle);
00176 int     Get_Next_Tle_Set( char lines[3][80], tle_t *tle );
00177 void    select_ephemeris(tle_t *tle);
00178 /* sgp_math.c */
00179 int     Sign(double arg);
00180 double  Sqr(double arg);
00181 double  Cube(double arg);
00182 double  Radians(double arg);
00183 double  Degrees(double arg);
00184 double  ArcSin(double arg);
00185 double  ArcCos(double arg);
00186 void    SgpMagnitude(vector_t *v);
00187 void    Vec_Add(vector_t *v1, vector_t *v2, vector_t *v3);
00188 void    Vec_Sub(vector_t *v1, vector_t *v2, vector_t *v3);
00189 void    Scalar_Multiply(double k, vector_t *v1, vector_t *v2);
00190 void    Scale_Vector(double k, vector_t *v);
00191 double  Dot(vector_t *v1, vector_t *v2);
00192 double  Angle(vector_t *v1, vector_t *v2);
00193 void    Cross(vector_t *v1, vector_t *v2, vector_t *v3);
00194 void    Normalize(vector_t *v);
00195 double  AcTan(double sinx, double cosx);
00196 double  FMod2p(double x);
00197 double  Modulus(double arg1, double arg2);
00198 double  Frac(double arg);
00199 int     Round(double arg);
00200 double  Int(double arg);
00201 void    Convert_Sat_State(vector_t *pos, vector_t *vel);
00202 /* sgp_obs.c */
00203 void    Calculate_User_PosVel(double _time, geodetic_t *geodetic,
00204                               vector_t *obs_pos, vector_t *obs_vel);
00205 void    Calculate_LatLonAlt(double _time, vector_t *pos, geodetic_t *geodetic);
00206 void    Calculate_Obs(double _time, vector_t *pos, vector_t *vel,
00207                       geodetic_t *geodetic, vector_t *obs_set);
00208 void    Calculate_RADec(double _time, vector_t *pos, vector_t *vel,
00209                         geodetic_t *geodetic, vector_t *obs_set);
00210 /* sgp_time.c */
00211 double  Julian_Date_of_Epoch(double epoch);
00212 double  Epoch_Time(double jd);
00213 int     DOY(int yr, int mo, int dy);
00214 double  Fraction_of_Day(int hr, int mi, int se);
00215 void    Calendar_Date(double jd, struct tm *cdate);
00216 void    Time_of_Day(double jd, struct tm *cdate);
00217 double  Julian_Date(struct tm *cdate);
00218 void    Date_Time(double jd, struct tm *cdate);
00219 int     Check_Date(struct tm *cdate);
00220 struct tm Time_to_UTC(struct tm *cdate);
00221 struct tm Time_from_UTC(struct tm *cdate);
00222 double  JD_to_UTC(double jt);
00223 double  JD_from_UTC(double jt);
00224 double  Delta_ET(double year);
00225 double  Julian_Date_of_Year(double year);
00226 double  ThetaG(double epoch, deep_arg_t *deep_arg);
00227 double  ThetaG_JD(double jd);
00228 void    UTC_Calendar_Now(struct tm *cdate);
00229 /* solar.c */
00230 void    Calculate_Solar_Position(double _time, vector_t *solar_vector);
00231 int     Sat_Eclipsed(vector_t *pos, vector_t *sol, double *depth);
00232 
00233 #ifdef __cplusplus
00234 }
00235 #endif
00236 
00237 #endif