Beispiel #1
0
/* -----------------------------------------------------------------------------
*
*                           procedure days2mdhms
*
*  this procedure converts the day of the year, days, to the equivalent month
*    day, hour, minute and second.
*
*  algorithm     : set up array for the number of days per month
*                  find leap year - use 1900 because 2000 is a leap year
*                  loop through a temp value while the value is < the days
*                  perform int conversions to the correct day and month
*                  convert remainder into h m s using type conversions
*
*  author        : david vallado                  719-573-2600    1 mar 2001
*
*  inputs          description                    range / units
*    year        - year                           1900 .. 2100
*    days        - julian day of the year         0.0  .. 366.0
*
*  outputs       :
*    mon         - month                          1 .. 12
*    day         - day                            1 .. 28,29,30,31
*    hr          - hour                           0 .. 23
*    min         - minute                         0 .. 59
*    sec         - second                         0.0 .. 59.999
*
*  locals        :
*    dayofyr     - day of year
*    temp        - temporary extended values
*    inttemp     - temporary int value
*    i           - index
*    lmonth[12]  - int array containing the number of days per month
*
*  coupling      :
*    none.
* --------------------------------------------------------------------------- */


        public MdhmsResult days2mdhms(int year, float days)
        {
            MdhmsResult mdhmsResult = new MdhmsResult();

            int feb = ((year % 4) == 0 ? 29 : 28); // Account for leap year

            int[]  lmonth  = new int[] { 31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            double dayofyr = Math.Floor(days);

            //  ----------------- find month and day of month ----------------
            int i       = 1;
            int inttemp = 0;

            while ((dayofyr > (inttemp + lmonth[i - 1])) && i < 12)
            {
                inttemp += lmonth[i - 1];
                i       += 1;
            }

            int    mon = i;
            double day = dayofyr - inttemp;

            //  ----------------- find hours minutes and seconds -------------
            double temp = (days - dayofyr) * 24.0;
            double hr   = Math.Floor(temp);

            temp = (temp - hr) * 60.0;
            double minute = Math.Floor(temp);
            double sec    = (temp - minute) * 60.0;


            // Set params in object and return

            mdhmsResult.mon    = mon;
            mdhmsResult.day    = day;
            mdhmsResult.hr     = hr;
            mdhmsResult.minute = minute;
            mdhmsResult.sec    = sec;

            // return {
            //   mon,
            //   day,
            //   hr,
            //   minute,
            //   sec,
            // };

            return(mdhmsResult);
        }
Beispiel #2
0
        public Satrec twoline2satrec(string longstr1, string longstr2)
        {
            Globals globals = new Globals();

            const char   opsmode = 'i';
            const double xpdotp  = 1440.0 / (2.0 * Math.PI); // 229.1831180523293;
            int          year    = 0;

            Satrec satrec = new Satrec();

            satrec.error = 0;
            // satrec.satnum =  longstr1.Substring(2, 7); // From satellite.js
            satrec.satnum = longstr1.Substring(2, 5); // 5 length

            // satrec.epochyr = parseInt(longstr1.substring(18, 20), 10);
            satrec.epochyr = Int32.Parse(longstr1.Substring(18, 2));
            // satrec.epochdays = parseFloat(longstr1.substring(20, 32));
            satrec.epochdays = float.Parse(longstr1.Substring(20, 12));
            // satrec.ndot = parseFloat(longstr1.substring(33, 43));
            satrec.ndot = double.Parse(longstr1.Substring(33, 10));
            // satrec.nddot = parseFloat(
            //   `.${parseInt(longstr1.substring(44, 50), 10)
            //   }E${longstr1.substring(50, 52)}`,
            // );

            // Get the exponetial from the TLE line
            string nddot = "." + longstr1.Substring(44, 6).Trim() + "E" + longstr1.Substring(50, 2);

            satrec.nddot = double.Parse(nddot);

            //  satrec.bstar = parseFloat(
            //   `${longstr1.substring(53, 54)
            //   }.${parseInt(longstr1.substring(54, 59), 10)
            //   }E${longstr1.substring(59, 61)}`,
            // );
            string bstar = longstr1.Substring(53, 1) + "." + longstr1.Substring(54, 5) + "E" + longstr1.Substring(59, 2);

            satrec.bstar = double.Parse(bstar);

            //  satrec.inclo = parseFloat(longstr2.substring(8, 16));
            satrec.inclo = double.Parse(longstr2.Substring(8, 8));
            // satrec.nodeo = parseFloat(longstr2.substring(17, 25));
            satrec.nodeo = double.Parse(longstr2.Substring(17, 8));
            // satrec.ecco = parseFloat(`.${longstr2.substring(26, 33)}`);
            string ecco = "." + longstr2.Substring(26, 7);

            satrec.ecco = double.Parse(ecco);
            // satrec.argpo = parseFloat(longstr2.substring(34, 42));
            satrec.argpo = double.Parse(longstr2.Substring(34, 8));
            // satrec.mo = parseFloat(longstr2.substring(43, 51));
            satrec.mo = double.Parse(longstr2.Substring(43, 8));
            // satrec.no = parseFloat(longstr2.substring(52, 63));
            satrec.no = double.Parse(longstr2.Substring(52, 11));

            // ---- find no, ndot, nddot ----
            satrec.no /= xpdotp; //   rad/min
            // satrec.nddot= satrec.nddot * Math.pow(10.0, nexp);
            // satrec.bstar= satrec.bstar * Math.pow(10.0, ibexp);

            // ---- convert to sgp4 units ----
            //  satrec.a = ((satrec.no * tumin) ** (-2.0 / 3.0));
            satrec.a      = Math.Pow((satrec.no * globals.tumin), (-2.0 / 3.0));
            satrec.ndot  /= (xpdotp * 1440.0); // ? * minperday
            satrec.nddot /= (xpdotp * 1440.0 * 1440);

            // ---- find standard orbital elements ----
            satrec.inclo *= globals.deg2rad;
            satrec.nodeo *= globals.deg2rad;
            satrec.argpo *= globals.deg2rad;
            satrec.mo    *= globals.deg2rad;

            satrec.alta = (satrec.a * (1.0 + satrec.ecco)) - 1.0;
            satrec.altp = (satrec.a * (1.0 - satrec.ecco)) - 1.0;

            // ----------------------------------------------------------------
            // find sgp4epoch time of element set
            // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
            // and minutes from the epoch (time)
            // ----------------------------------------------------------------

            // ---------------- temp fix for years from 1957-2056 -------------------
            // --------- correct fix will occur when year is 4-digit in tle ---------

            if (satrec.epochyr < 57)
            {
                year = satrec.epochyr + 2000;
            }
            else
            {
                year = satrec.epochyr + 1900;
            }

            // const mdhmsResult = days2mdhms(year, satrec.epochdays);
            Ext         ext         = new Ext();
            MdhmsResult mdhmsResult = ext.days2mdhms(year, satrec.epochdays);

            satrec.jdsatepoch = ext.jday(year, mdhmsResult.mon, mdhmsResult.day, mdhmsResult.hr, mdhmsResult.minute, mdhmsResult.sec);

            //  ---------------- initialize the orbit at sgp4epoch -------------------
            // sgp4init(satrec, {
            //   opsmode,
            //   satn: satrec.satnum,
            //   epoch: satrec.jdsatepoch - 2433281.5,
            //   xbstar: satrec.bstar,
            //   xecco: satrec.ecco,
            //   xargpo: satrec.argpo,
            //   xinclo: satrec.inclo,
            //   xmo: satrec.mo,
            //   xno: satrec.no,
            //   xnodeo: satrec.nodeo,
            // });

            Sgp4initOptions sgp4initOptions = new Sgp4initOptions();

            sgp4initOptions.opsmode = opsmode;
            sgp4initOptions.satn    = satrec.satnum;
            sgp4initOptions.epoch   = satrec.jdsatepoch - 2433281.5;
            sgp4initOptions.xbstar  = satrec.bstar;
            sgp4initOptions.xecco   = satrec.ecco;
            sgp4initOptions.xargpo  = satrec.argpo;
            sgp4initOptions.xinclo  = satrec.inclo;
            sgp4initOptions.xmo     = satrec.mo;
            sgp4initOptions.xno     = satrec.no;
            sgp4initOptions.xnodeo  = satrec.nodeo;

            Sgp4init sgp4init = new Sgp4init();

            sgp4init.sgp4init(satrec, sgp4initOptions);


            return(satrec);
        }