Exemple #1
0
        public void TestGetPlanetName_Asteroid_WithFile()
        {
            using (var swe = new Sweph())
            {
                swe.OnLoadFile += (s, e) => {
                    if (e.FileName == "seasnam.txt")
                    {
                        string fileContent = @"
# Asteroid names
000001  Ceres
(000002)  Pallas
 [3]  Juno
Invalid line
{ 004  } Vesta
000430  Hybris
000431  Nephele
000432  Pythia
000433  Eros
   487  Venetia
";
                        e.File = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(fileContent));
                    }
                };

                Assert.AreEqual("0: not found", swe.Planet.GetPlanetName(Planet.FirstAsteroid));
                Assert.AreEqual("Ceres", swe.Planet.GetPlanetName(Planet.Ceres));
                Assert.AreEqual("Pallas", swe.Planet.GetPlanetName(Planet.Pallas));
                Assert.AreEqual("Juno", swe.Planet.GetPlanetName(Planet.Juno));
                Assert.AreEqual("Vesta", swe.Planet.GetPlanetName(Planet.Vesta));
                Assert.AreEqual("Hybris", swe.Planet.GetPlanetName(Planet.FirstAsteroid + 430));
                Assert.AreEqual("Eros", swe.Planet.GetPlanetName(Planet.FirstAsteroid + 433));
                Assert.AreEqual("450: not found", swe.Planet.GetPlanetName(Planet.FirstAsteroid + 450));
            }
        }
Exemple #2
0
        public void TestDeltaTRecordFile()
        {
            using (var swe = new Sweph())
            {
                swe.OnLoadFile += (s, e) => {
                    if (e.FileName == "sedeltat.txt")
                    {
                        e.File = new MemoryStream(System.Text.Encoding.Default.GetBytes(@"
# Head

2000 30.0
    2001    31.25    
; 2002   30.0
2000-30.0

"));
                    }
                };

                var file    = swe.Dependencies.Create <SwephNet.Date.DeltaTRecordFile>();
                var records = file.GetRecords().ToArray();
                Assert.AreEqual(2, records.Length);
                Assert.AreEqual(2000, records[0].Year);
                Assert.AreEqual(30.0, records[0].Value);
                Assert.AreEqual(2001, records[1].Year);
                Assert.AreEqual(31.25, records[1].Value);
            }
        }
Exemple #3
0
 public void TestGetDependencies()
 {
     using (var swe = new Sweph())
     {
         Assert.IsNotNull(swe.Dependencies);
     }
 }
Exemple #4
0
 public void TestGetTidAcc()
 {
     using (var swe = new Sweph())
     {
         Assert.AreEqual(-25.82, swe.Date.TidalAcceleration);
     }
 }
Exemple #5
0
        public void TestDeltaTWithoutEspenakMeeus2006()
        {
            using (var swe = new Sweph())
            {
                swe.Date.UseEspenakMeeus2006 = false;
                double deltaPrec = 0.000000000001;

                Assert.AreEqual(1.5716511059188, swe.Date.DeltaT(0.0), deltaPrec);

                Assert.AreEqual(0.294436185639733, swe.Date.DeltaT(swe.JulianDay(-1010, 2, 2, 12.5)), deltaPrec);

                Assert.AreEqual(0.0375610997366034, swe.Date.DeltaT(2000000.0), deltaPrec);
                Assert.AreEqual(0.0375610327085927, swe.Date.DeltaT(2000000.25), deltaPrec);
                Assert.AreEqual(0.0375609656805818, swe.Date.DeltaT(2000000.5), deltaPrec);
                Assert.AreEqual(0.0375608986525707, swe.Date.DeltaT(2000000.75), deltaPrec);
                Assert.AreEqual(0.000848297829347124, swe.Date.DeltaT(2317746.13090277789), deltaPrec);

                var tjd = SweDate.J2000 + (365.25 * (1610 - 2000.0));
                Assert.AreEqual(0.00138947083317893, swe.Date.DeltaT(tjd), deltaPrec);


                Assert.AreEqual(0.101230433035332, swe.Date.DeltaT(3000000), deltaPrec);
                Assert.AreEqual(0.101230598229371, swe.Date.DeltaT(3000000.5), deltaPrec);
                Assert.AreEqual(0.101230680826441, swe.Date.DeltaT(3000000.75), deltaPrec);

                Assert.AreEqual(0.000828297529544201, swe.Date.DeltaT(swe.JulianDay(2020, 1, 1, 10.5)), deltaPrec);
            }
        }
Exemple #6
0
 public void TestGetPlanetName_Fictitious()
 {
     using (var swe = new Sweph()) {
         Assert.AreEqual("Cupido", swe.Planets.GetPlanetName(Planet.FirstFictitious));
         Assert.AreEqual("name not found", swe.Planets.GetPlanetName(Planet.FirstFictitious + 200));
     }
 }
Exemple #7
0
 public void TestGetPlanetName_Asteroid()
 {
     using (var swe = new Sweph()) {
         Assert.AreEqual("0: not found", swe.Planets.GetPlanetName(Planet.FirstAsteroid));
         Assert.AreEqual("433: not found", swe.Planets.GetPlanetName(Planet.FirstAsteroid + 433));
     }
 }
Exemple #8
0
 public void TestResolve_FailedType()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Resolve(typeof(Type1));
     }
 }
        /// <summary>
        /// Conversion d'une date Julien en temps universel
        /// </summary>
        public DateTime ToUniversalTime(JulianDay jDay)
        {
            int year = 0, month = 0, day = 0, hour = 0, minute = 0; double second = 0;

            Sweph.swe_jdet_to_utc(jDay.Value, ToCalendar(jDay.Calendar), ref year, ref month, ref day, ref hour, ref minute, ref second);
            return(new DateTime(year, month, day, hour, minute, (int)second, DateTimeKind.Utc));
        }
 /// <summary>
 /// Internal release resources
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         Sweph.Dispose();
     }
 }
Exemple #11
0
 public void TestResolve_FailedGenericType()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Resolve <Type1>();
     }
 }
Exemple #12
0
        public void TestDeltaT_without_ESPENAK_MEEUS_2006()
        {
            var conf = new SweConfig()
            {
                UseEspenakMeeusDeltaT = false
            };

            using (var swe = new Sweph(conf)) {
                double deltaPrec = 0.000000000001;

                Assert.AreEqual(1.5716511059188, swe.Date.DeltaT(0.0), deltaPrec);

                Assert.AreEqual(0.0375610997366034, swe.Date.DeltaT(2000000.0), deltaPrec);
                Assert.AreEqual(0.0375610327085927, swe.Date.DeltaT(2000000.25), deltaPrec);
                Assert.AreEqual(0.0375609656805818, swe.Date.DeltaT(2000000.5), deltaPrec);
                Assert.AreEqual(0.0375608986525707, swe.Date.DeltaT(2000000.75), deltaPrec);
                Assert.AreEqual(0.000848297829347124, swe.Date.DeltaT(2317746.13090277789), deltaPrec);

                var tjd = SwissEph.J2000 + (365.25 * (1610 - 2000.0));
                Assert.AreEqual(0.00138947083317893, swe.Date.DeltaT(tjd), deltaPrec);


                Assert.AreEqual(0.101230433035332, swe.Date.DeltaT(3000000), deltaPrec);
                Assert.AreEqual(0.101230598229371, swe.Date.DeltaT(3000000.5), deltaPrec);
                Assert.AreEqual(0.101230680826441, swe.Date.DeltaT(3000000.75), deltaPrec);
            }
        }
Exemple #13
0
 public void TestCreateTypeWithoutConstructor()
 {
     using (var swe = new Sweph())
     {
         var t = swe.Dependencies.Create <Type3>();
         Assert.IsNull(t);
     }
 }
Exemple #14
0
 public void TestCreateValueType()
 {
     using (var swe = new Sweph())
     {
         var t = swe.Dependencies.Create <IDisposable>();
         Assert.IsNull(t);
     }
 }
Exemple #15
0
 public void TestEphemerisTime()
 {
     using (var swe = new Sweph())
     {
         double prec = 0.00000001;
         Assert.AreEqual(1.5716511059188, swe.EphemerisTime(new JulianDay()), prec);
         Assert.AreEqual(2442275.52135549, swe.EphemerisTime(new JulianDay(new UniversalTime(1974, 8, 16, 0.5))), prec);
     }
 }
        PlanetValues InternalCalcPlanet(Planet planet, EphemerisTime time, double?armc = null, Longitude?longitude = null, double?trueEclipticObliquity = null)
        {
            CheckInitialized();
            String serr = null;

            Double[] x    = new double[24];
            String   star = String.Empty;
            int      iflgret;
            var      result = new PlanetValues()
            {
                Planet = planet
            };

            if (planet == Planet.FixedStar)
            {
                iflgret           = Sweph.swe_fixstar(star, time, _SwephFlag, x, ref serr);
                result.PlanetName = star;
            }
            else
            {
                iflgret           = Sweph.swe_calc(time, planet, _SwephFlag, x, ref serr);
                result.PlanetName = Sweph.swe_get_planet_name(planet);
                if (planet.IsAsteroid)
                {
                    result.PlanetName = String.Format("#{0}", planet - Planet.FirstAsteroid);
                }
            }
            if (iflgret >= 0)
            {
                result.Longitude      = x[0];
                result.Latitude       = x[1];
                result.Distance       = x[2];
                result.LongitudeSpeed = x[3];
                result.LatitudeSpeed  = x[4];
                result.DistanceSpeed  = x[5];
                if (armc.HasValue && longitude.HasValue && trueEclipticObliquity.HasValue)
                {
                    result.HousePosition = Sweph.swe_house_pos(armc.Value, longitude.Value, trueEclipticObliquity.Value, HouseSystemToChar(_HouseSystem), x, ref serr);
                    if (result.HousePosition == 0)
                    {
                        iflgret = SwissEph.ERR;
                    }
                }
            }
            if (iflgret < 0)
            {
                if (!String.IsNullOrEmpty(serr))
                {
                    result.ErrorMessage = serr;
                }
            }
            else if (!String.IsNullOrEmpty(serr) && String.IsNullOrEmpty(result.WarnMessage))
            {
                result.WarnMessage = serr;
            }
            return(result);
        }
Exemple #17
0
 public void TestCreateFromResolver()
 {
     using (var swe = new Sweph())
     {
         var t = swe.Dependencies.Create <Type1>();
         Assert.AreEqual(0, t.Value);
         Assert.AreEqual(false, t.IsDisposed);
     }
 }
Exemple #18
0
        public void TestJulianDayToDate()
        {
            using (var swe = new Sweph()) {
                int y = 0, m = 0, d = 0, h, mi, s;

                SweDate.JulianDayToDate(0, DateCalendar.Gregorian, out y, out m, out d, out h, out mi, out s);
                Assert.AreEqual(-4713, y);
                Assert.AreEqual(11, m);
                Assert.AreEqual(24, d);
                Assert.AreEqual(12, h);
                Assert.AreEqual(0, mi);
                Assert.AreEqual(0, s);

                SweDate.JulianDayToDate(0, DateCalendar.Julian, out y, out m, out d, out h, out mi, out s);
                Assert.AreEqual(-4712, y);
                Assert.AreEqual(1, m);
                Assert.AreEqual(1, d);
                Assert.AreEqual(12, h);
                Assert.AreEqual(0, mi);
                Assert.AreEqual(0, s);

                SweDate.JulianDayToDate(2000000, DateCalendar.Gregorian, out y, out m, out d, out h, out mi, out s);
                Assert.AreEqual(763, y);
                Assert.AreEqual(9, m);
                Assert.AreEqual(18, d);
                Assert.AreEqual(12, h);
                Assert.AreEqual(0, mi);
                Assert.AreEqual(0, s);

                SweDate.JulianDayToDate(2000000, DateCalendar.Julian, out y, out m, out d, out h, out mi, out s);
                Assert.AreEqual(763, y);
                Assert.AreEqual(9, m);
                Assert.AreEqual(14, d);
                Assert.AreEqual(12, h);
                Assert.AreEqual(0, mi);
                Assert.AreEqual(0, s);

                var date = SweDate.JulianDayToDate(2000000, DateCalendar.Julian);
                Assert.AreEqual(763, date.Year);
                Assert.AreEqual(9, date.Month);
                Assert.AreEqual(14, date.Day);
                Assert.AreEqual(12, date.Hours);
                Assert.AreEqual(0, date.Minutes);
                Assert.AreEqual(0, date.Seconds);

                date = SweDate.JulianDayToDate(2000000);
                Assert.AreEqual(763, date.Year);
                Assert.AreEqual(9, date.Month);
                Assert.AreEqual(14, date.Day);
                Assert.AreEqual(12, date.Hours);
                Assert.AreEqual(0, date.Minutes);
                Assert.AreEqual(0, date.Seconds);
            }
        }
Exemple #19
0
 public void TestResolve()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         }, true);
         var t = swe.Dependencies.Resolve <Type1>();
         Assert.AreEqual(123, t.Value);
     }
 }
Exemple #20
0
 public void TestCreateBasicType()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         });
         var t = swe.Dependencies.Create <Type1>();
         Assert.AreEqual(123, t.Value);
         Assert.AreEqual(false, t.IsDisposed);
     }
 }
        /// <summary>
        /// Recalculate the swisseph flag and parameters
        /// </summary>
        protected void RecalcSwephState()
        {
            _SwephFlag = SwissEph.SEFLG_SPEED;
            // Ephemeris type
            switch (Ephemeris)
            {
            case EphemerisMode.Moshier:
                _SwephFlag |= SwissEph.SEFLG_MOSEPH;
                break;

            case EphemerisMode.JPL:
                _SwephFlag |= SwissEph.SEFLG_JPLEPH;
                break;

            case EphemerisMode.SwissEphemeris:
            default:
                _SwephFlag |= SwissEph.SEFLG_SWIEPH;
                break;
            }
            // Position center
            var sidmode = SwissEph.SE_SIDM_FAGAN_BRADLEY;

            switch (PositionCenter)
            {
            case PositionCenter.Topocentric:
                _SwephFlag |= SwissEph.SEFLG_TOPOCTR;
                break;

            case PositionCenter.Heliocentric:
                _SwephFlag |= SwissEph.SEFLG_HELCTR;
                break;

            case PositionCenter.Barycentric:
                _SwephFlag |= SwissEph.SEFLG_BARYCTR;
                break;

            case PositionCenter.SiderealFagan:
                _SwephFlag |= SwissEph.SEFLG_SIDEREAL;
                sidmode     = SwissEph.SE_SIDM_FAGAN_BRADLEY;
                break;

            case PositionCenter.SiderealLahiri:
                _SwephFlag |= SwissEph.SEFLG_SIDEREAL;
                sidmode     = SwissEph.SE_SIDM_LAHIRI;
                break;

            case PositionCenter.Geocentric:
            default:
                break;
            }
            Sweph.swe_set_sid_mode(sidmode, 0, 0);
        }
Exemple #22
0
 public void TestRegisterInstance()
 {
     using (var swe = new Sweph())
     {
         var t1 = new Type1()
         {
             Value = 9876
         };
         swe.Dependencies.RegisterInstance(t1);
         var t2 = swe.Dependencies.Resolve <Type1>();
         Assert.AreSame(t1, t2);
     }
 }
Exemple #23
0
 public void TestRegisterByCreatorAsNotSingleton()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         }, false);
         var t1 = swe.Dependencies.Resolve <Type1>();
         Assert.IsNotNull(t1);
         var t2 = swe.Dependencies.Resolve <Type1>();
         Assert.AreNotSame(t1, t2);
     }
 }
        /// <summary>
        /// Conversion d'un datetimeoffset en date julien
        /// </summary>
        public JulianDay ToJulianDay(DateTimeOffset date, DateCalendar calendar = DateCalendar.Gregorian)
        {
            var utc = date.ToUniversalTime();

            return(new JulianDay(
                       Sweph.swe_julday(
                           utc.Year,
                           utc.Month,
                           utc.Day,
                           utc.TimeOfDay.TotalHours,
                           ToCalendar(calendar)
                           ),
                       calendar));
        }
Exemple #25
0
        public void TestDateUT()
        {
            using (var swe = new Sweph())
            {
                // From JulianDay
                Assert.AreEqual(new UniversalTime(-4712, 1, 1, 12.0), swe.DateUT(new JulianDay()));
                Assert.AreEqual(new UniversalTime(-4712, 1, 1, 12.0), swe.DateUT(new JulianDay(0)));
                Assert.AreEqual(new UniversalTime(-4713, 11, 24, 12, 0, 0), swe.DateUT(new JulianDay(0, DateCalendar.Gregorian)));
                Assert.AreEqual(new UniversalTime(-4712, 1, 1, 12.0), swe.DateUT(new JulianDay(0, DateCalendar.Julian)));

                // From EphemerisTime
                Assert.AreEqual(new UniversalTime(-4712, 1, 1, 12.0), swe.DateUT(new EphemerisTime()));
                Assert.AreEqual(new UniversalTime(-4712, 1, 1, 12.0), swe.DateUT(new EphemerisTime(new JulianDay(), 0)));
            }
        }
Exemple #26
0
 public void TestTryToResolve()
 {
     using (var swe = new Sweph())
     {
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         }, true);
         Type1 t1 = null;
         Assert.IsTrue(swe.Dependencies.TryToResolve(out t1));
         Assert.AreEqual(123, t1.Value);
         Type2 t2 = null;
         Assert.IsFalse(swe.Dependencies.TryToResolve(out t2));
         Assert.IsNotNull(t2);
     }
 }
        /// <summary>
        /// Calcul des nutations écliptiques
        /// </summary>
        public EclipticNutationValues CalcEclipticNutation(EphemerisTime time)
        {
            CheckInitialized();
            String serr = null;

            Double[] x       = new double[24];
            var      iflgret = Sweph.swe_calc(time, SwissEph.SE_ECL_NUT, _SwephFlag, x, ref serr);

            return(new EclipticNutationValues {
                TrueEclipticObliquity = x[0],
                MeanEclipticObliquity = x[1],
                NutationLongitude = x[2],
                NutationObliquity = x[3]
            });
        }
Exemple #28
0
        public void TestJulianDay()
        {
            using (var swe = new Sweph()) {
                Assert.AreEqual(0.0, swe.JulianDay(new DateUT(-4713, 11, 24, 12, 0, 0), DateCalendar.Gregorian).Value);
                Assert.AreEqual(0.0, swe.JulianDay(-4713, 11, 24, 12, 0, 0, DateCalendar.Gregorian).Value);
                Assert.AreEqual(0.0, swe.JulianDay(-4713, 11, 24, 12.0, DateCalendar.Gregorian).Value);
                Assert.AreEqual(0.0, swe.JulianDay(-4712, 1, 1, 12.0, DateCalendar.Julian).Value);

                Assert.AreEqual(2000000.0, swe.JulianDay(763, 9, 18, 12.0, DateCalendar.Gregorian).Value);
                Assert.AreEqual(2000000.0, swe.JulianDay(763, 9, 14, 12.0, DateCalendar.Julian).Value);

                Assert.AreEqual(1063884.0, swe.JulianDay(-1800, 9, 18, 12.0, DateCalendar.Gregorian).Value);
                Assert.AreEqual(1063865.0, swe.JulianDay(-1800, 9, 14, 12.0, DateCalendar.Julian).Value);
            }
        }
Exemple #29
0
 public void TestGetPlanetName()
 {
     using (var swe = new Sweph()) {
         Assert.AreEqual("Soleil", swe.Planet.GetPlanetName(Planet.Sun));
         Assert.AreEqual("Lune", swe.Planet.GetPlanetName(Planet.Moon));
         Assert.AreEqual("Mercure", swe.Planet.GetPlanetName(Planet.Mercury));
         Assert.AreEqual("Vénus", swe.Planet.GetPlanetName(Planet.Venus));
         Assert.AreEqual("Terre", swe.Planet.GetPlanetName(Planet.Earth));
         Assert.AreEqual("Mars", swe.Planet.GetPlanetName(Planet.Mars));
         Assert.AreEqual("Jupiter", swe.Planet.GetPlanetName(Planet.Jupiter));
         Assert.AreEqual("Saturne", swe.Planet.GetPlanetName(Planet.Saturn));
         Assert.AreEqual("Uranus", swe.Planet.GetPlanetName(Planet.Uranus));
         Assert.AreEqual("Neptune", swe.Planet.GetPlanetName(Planet.Neptune));
     }
 }
Exemple #30
0
 public void TestCanResolve()
 {
     using (var swe = new Sweph())
     {
         Assert.IsFalse(swe.Dependencies.CanResolve(null));
         Assert.IsFalse(DependencyExtensions.CanResolve <Type1>(null));
         Assert.IsFalse(swe.Dependencies.CanResolve(typeof(Type1)));
         Assert.IsFalse(swe.Dependencies.CanResolve <Type1>());
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         }, true);
         Assert.IsFalse(swe.Dependencies.CanResolve(null));
         Assert.IsFalse(DependencyExtensions.CanResolve <Type1>(null));
         Assert.IsTrue(swe.Dependencies.CanResolve(typeof(Type1)));
         Assert.IsTrue(swe.Dependencies.CanResolve <Type1>());
     }
 }