Пример #1
0
        public void GetCoordinates()
        {
            double jd = 2448724.5;

            // geocentrical coordinates
            CrdsEcliptical ecl = LunarMotion.GetCoordinates(jd);

            Assert.AreEqual(133.162655, ecl.Lambda, 1e-6);
            Assert.AreEqual(-3.229126, ecl.Beta, 1e-6);
            Assert.AreEqual(368409.7, ecl.Distance, 1e-1);

            // get nutation elements
            var nutation = Nutation.NutationElements(jd);

            // apparent geocentrical ecliptical coordinates
            ecl += Nutation.NutationEffect(nutation.deltaPsi);

            // true obliquity of the Earth orbit
            double epsilon = Date.TrueObliquity(jd, nutation.deltaEpsilon);

            // equatorial geocentrical coordinates
            CrdsEquatorial eq = ecl.ToEquatorial(epsilon);

            // Max error in Right Ascention is 0.1" of time
            double errAlpha = new HMS("0h 0m 00.1s").ToDecimalAngle();

            // Max error in Declination is 1" of arc
            double errDelta = new DMS("0* 0' 01''").ToDecimalAngle();

            Assert.AreEqual(new HMS("8h 58m 45.2s").ToDecimalAngle(), eq.Alpha, errAlpha);
            Assert.AreEqual(new DMS("+13* 46' 06''").ToDecimalAngle(), eq.Delta, errDelta);
        }
Пример #2
0
        public void HMS_Implicit_Hours_ReturnsTrue()
        {
            HMS   hms = new HMS(6, 30, 0);
            Hours hrs = hms;

            Assert.IsTrue(Math.Abs(hrs.Angle - 6.5) < tolerance, "Kut u satima: " + hrs.Angle.ToString());
        }
Пример #3
0
        public void HMS_Implicit_Radians_ReturnsTrue()
        {
            HMS     hms = new HMS(12, 0, 0);
            Radians rad = hms;

            Assert.IsTrue(rad.Angle == Math.PI, rad.Angle.ToString());
        }
Пример #4
0
        public void HMS_Arithmetic_promjenaPredznaka_ReturnsTrue()
        {
            HMS a = new HMS(1, 34, 5.5);

            HMS b = -a;

            Assert.IsTrue(b.Sign < 0, "Predznak: " + b.Sign);
        }
Пример #5
0
        public void Hours_Implicit_HMS_ReturnsTrue()
        {
            HMS   hms = new HMS(5, 30, 30);
            Hours deg = hms;

            double razlika = 5.5083333333333333 - deg.Angle;

            Assert.IsTrue(Math.Abs(razlika) < tolerance, "Kut u satima: " + hms + " " + deg);
        }
Пример #6
0
        public void HMS_Constructor_Gradians_ReturnsTrue()
        {
            HMS kut     = new HMS(3, 0, 0);
            HMS kutTest = new HMS(new Gradians(50));

            Assert.IsTrue((kut - kutTest).Hours == 0);
            Assert.IsTrue((kut - kutTest).Minutes == 0);
            Assert.IsTrue((kut - kutTest).Seconds < tolerance);
        }
Пример #7
0
        public void HMS_Constructor_Degrees_ReturnsTrue()
        {
            HMS kut     = new HMS(3, 0, 0);
            HMS kutTest = new HMS(new Degrees(45));

            Assert.IsTrue((kut - kutTest).Hours == 0);
            Assert.IsTrue((kut - kutTest).Minutes == 0);
            Assert.IsTrue((kut - kutTest).Seconds < tolerance);
        }
Пример #8
0
        public void ToHMS_12h0m0s_ReturnsTrue()
        {
            Radians kutRadijani = new Radians(Math.PI);

            HMS kutZaProvjeru = new HMS(12, 0, 0);

            Assert.IsTrue(kutRadijani.ToHMS().Hours == kutZaProvjeru.Hours);
            Assert.IsTrue(kutRadijani.ToHMS().Minutes == kutZaProvjeru.Minutes);
            Assert.IsTrue(kutRadijani.ToHMS().Seconds == kutZaProvjeru.Seconds);
        }
Пример #9
0
        public void HMS_Veci_Manji_VeciJednako_ManjiJednako2_test_ReturnsTrue()
        {
            HMS a = new HMS(-1, 34, 5.5);
            HMS b = new HMS(1, -33, 3);
            HMS c = new HMS(1, 33, -3);


            Assert.IsTrue(a > b);
            Assert.IsTrue(b < a);
            Assert.IsTrue(b >= c);
            Assert.IsTrue(c <= b);
            Assert.IsTrue(a >= c);
            Assert.IsTrue(c <= a);
        }
Пример #10
0
                public static bool FromValue(double value, out HMS hms)
                {
                    hms = new HMS();

                    if (double.IsNaN(value) || value < 0 || 24 < value)
                    {
                        return(false);
                    }

                    hms.Hour   = (int)Math.Floor(value); value -= hms.Hour; value *= 60;
                    hms.Minute = (int)Math.Floor(value); value -= hms.Minute; value *= 60;
                    hms.Second = value;

                    return(true);
                }
Пример #11
0
                public static bool TryParse(string s, out HMS hms)
                {
                    hms = new HMS(); Match match = Regex.Match(s, @"(?<Hour>\d+)\+(?<Minute>\d+(\.\d+)?)");

                    if (!match.Success || !int.TryParse(match.Groups["Hour"].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out int hour) || hour < 0 || /*23 < hour ||*/
                        !double.TryParse(match.Groups["Minute"].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out double minute) || minute < 0 || 60 <= minute)
                    {
                        return(false);
                    }

                    hms.Hour   = hour;
                    hms.Minute = (int)Math.Floor(minute);
                    hms.Second = (minute - hms.Minute) * 60;

                    return(true);
                }
Пример #12
0
        public void ShowFunctionParams(HMSItem item, int nParam, IWin32Window window, Point p)
        {
            string title      = item.ToolTipTitle;
            string parameters = title;
            string activparam = "";
            string paramtype  = "";
            string paramHelp  = item.Help;

            if ((nParam > 0) && (nParam <= item.Params.Count))
            {
                paramHelp = item.Params[nParam - 1];
            }
            Match m = regexFunctionParams.Match(title);

            if (m.Success)
            {
                parameters = m.Groups[1].Value;
            }
            string[] prmtrs = regexSplitFuncParam.Split(parameters);
            if ((nParam > 0) && (nParam <= prmtrs.Length))
            {
                activparam = prmtrs[nParam - 1];
            }
            if (activparam.Length > 0)
            {
                int ind = parameters.IndexOf(activparam);
                paramtype = HMS.GetType(parameters.Substring(ind));
            }
            HMS.CurrentParamType = paramtype.ToLower();
            if (activparam.Length > 0)
            {
                title = title.Replace(activparam, "<b>" + activparam + "</b>");
            }
            if (paramHelp.Length == 0)
            {
                paramHelp = " ";
            }
            Help         = paramHelp;
            ToolTipTitle = title;
            if (!Visible)
            {
                Show(" ", window, p);
            }
        }
Пример #13
0
        public void ToTopocentric()
        {
            // Geocentric coordinates of Mars
            CrdsEquatorial eq = new CrdsEquatorial(339.530208, -15.771083);

            // Palomar Observatory coordinates, see example 11.a
            CrdsGeographical geo = new CrdsGeographical(new HMS("7h 47m 27s").ToDecimalAngle(), new DMS("+33* 21' 22''").ToDecimalAngle(), 1706);

            // Equatoria horizontal parallax
            double pi = 23.592 / 3600;

            // Apparent sidereal time at Greenwich
            double theta0 = new HMS("1h 40m 45s").ToDecimalAngle();

            // Equatorial topocentric coordinates of Mars
            CrdsEquatorial topo = eq.ToTopocentric(geo, theta0, pi);

            Assert.AreEqual(new HMS("22h 38m 08.54s").ToDecimalAngle(), topo.Alpha, errorInHMS);
            Assert.AreEqual(new DMS("-15* 46' 30.04''").ToDecimalAngle(), topo.Delta, errorInDMS);
        }
Пример #14
0
        public void Hours_Constructors_ReturnsTrue()
        {
            Hours kut = new Hours(3);

            Hours h   = new Hours(3);
            HMS   hms = new HMS(3, 0, 0);

            Degrees d   = new Degrees(45);
            DMS     dms = new DMS(45, 0, 0);
            Seconds s   = new Seconds(45 * 180 * 60 * 60 / Math.PI);

            Gradians g = new Gradians(50);


            Assert.IsTrue((kut - h).Angle < tolerance, "Hours");
            Assert.IsTrue((kut - hms).Angle < tolerance, "HMS");

            Assert.IsTrue((kut - d).Angle < tolerance, "Degrees");
            Assert.IsTrue((kut - dms).Angle < tolerance, "DMS");
            Assert.IsTrue((kut - s).Angle < tolerance, "Seconds");

            Assert.IsTrue((kut - g).Angle < tolerance, "Gradians");
        }
Пример #15
0
        private void DoAutocomplete(AutocompleteItem item, Range fragment)
        {
            string newText = item.GetTextForReplace();

            //replace text of fragment
            var tb = fragment.tb;

            // < By WendyH ---------------------------
            if (tb.ToolTip4Function.Visible)
            {
                Menu.AfterComplete = true;
            }
            if (fragment.CharBeforeStart == '=')
            {
                newText = " " + newText;
            }
            int     iLine   = fragment.Start.iLine;
            int     iChar   = fragment.Start.iChar;
            HMSItem hmsItem = item as HMSItem;

            if ((hmsItem != null) && ((hmsItem.Kind == DefKind.Property) || (hmsItem.Kind == DefKind.Variable)) && !HMS.TypeIsClass(hmsItem.Type))
            {
                Range  fwords = fragment.GetFragmentLookedLeft();
                var    f      = new Range(tb, new Place(0, iLine), new Place(fwords.Start.iChar, iLine));
                string line   = f.Text.Trim();
                if (line.Length == 0)
                {
                    newText += (tb.Language == Language.PascalScript) ? " := " : " = ";
                }
            }

            // > By WendyH ---------------------------

            tb.BeginAutoUndo();
            tb.TextSource.Manager.ExecuteCommand(new SelectCommand(tb.TextSource));
            if (tb.Selection.ColumnSelectionMode)
            {
                var start = tb.Selection.Start;
                var end   = tb.Selection.End;
                start.iChar        = fragment.Start.iChar;
                end.iChar          = fragment.End.iChar;
                tb.Selection.Start = start;
                tb.Selection.End   = end;
            }
            else
            {
                tb.Selection.Start = fragment.Start;
                tb.Selection.End   = fragment.End;
            }
            tb.InsertText(newText);
            tb.TextSource.Manager.ExecuteCommand(new SelectCommand(tb.TextSource));
            tb.EndAutoUndo();
            tb.Focus();
        }
Пример #16
0
        // < By WendyH ------------------------------------------
        public HMSItem GetHMSItemByText(string text, out string partAfterDot, bool returnItemBeforeDot = false)
        {
            HMSItem      item = null;
            HMSClassInfo info = new HMSClassInfo();

            string[] names = text.ToLower().Split('.');
            int      count = 0; partAfterDot = "";

            foreach (string word in names)
            {
                string name = HMS.GetTextWithoutBrackets(word);
                count++; partAfterDot = name;
                if (returnItemBeforeDot && (count >= names.Length))
                {
                    break;                                                                 // return last item before the dot
                }
                if (info.Name.Length > 0)
                {
                    // search in class members
                    item = info.MemberItems.GetItemOrNull(name);
                    if (item == null)
                    {
                        item = info.StaticItems.GetItemOrNull(name);
                    }
                    if (item != null)
                    {
                        info = HMS.HmsClasses[item.Type];
                    }
                }
                else
                {
                    // try get variabe
                    if (item == null)
                    {
                        item = Menu.Items.VisibleLocalVars.GetItemOrNull(name);                                   // try visible known variables
                    }
                    if (item == null)
                    {
                        item = Menu.Items.VisibleVariables.GetItemOrNull(name);                                   // try visible known variables
                    }
                    if (item == null)
                    {
                        item = Menu.Items.VisibleFunctions.GetItemOrNull(name);                                   // try functions in script
                    }
                    if (item == null)
                    {
                        item = HMS.ItemsVariable.GetItemOrNull(name);                                   // try internal variables
                    }
                    if (item == null)
                    {
                        item = HMS.ItemsConstant.GetItemOrNull(name);                                   // try internal constants
                    }
                    if (item == null)
                    {
                        item = HMS.ItemsFunction.GetItemOrNull(name);                                   // try internal functions
                    }
                    if (item == null)
                    {
                        item = HMS.ItemsClass.GetItemOrNull(name);                                   // try internal classes
                    }
                    if (count < names.Length)
                    {
                        if (item != null)
                        {
                            info = HMS.HmsClasses[item.Type];
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(item);
        }
Пример #17
0
        public void HMS_Parse_ToString_true()
        {
            HMS h = new HMS(2, 56, 45.4);

            Assert.IsTrue(h == HMS.Parse(h.ToString()));
        }
Пример #18
0
        public override void Initialize()
        {
            // Load NGC/IC catalogs data
            using (var reader = new StreamReader(NGCIC_FILE))
            {
                short recordNumber = 0;

                while (!reader.EndOfStream)
                {
                    recordNumber++;
                    string line = reader.ReadLine();

                    string strStatus = line.Substring(10, 2).Trim();
                    if (strStatus == "")
                    {
                        continue;
                    }

                    DeepSkyStatus status = (DeepSkyStatus)(Convert.ToInt32(strStatus) % 10);
                    if (status == DeepSkyStatus.Duplicate ||
                        status == DeepSkyStatus.DuplicateIC)
                    {
                        continue;
                    }

                    var ra = new HMS(
                        uint.Parse(line.Substring(20, 2)),
                        uint.Parse(line.Substring(23, 2)),
                        double.Parse(line.Substring(26, 4), CultureInfo.InvariantCulture))
                             .ToDecimalAngle();

                    var dec =
                        (line[31] == '-' ? -1 : 1) * new DMS(
                            uint.Parse(line.Substring(32, 2)),
                            uint.Parse(line.Substring(35, 2)),
                            uint.Parse(line.Substring(38, 2)))
                        .ToDecimalAngle();

                    string mag     = line.Substring(50, 4).Trim();
                    string sizeA   = line.Substring(61, 7).Trim();
                    string sizeB   = line.Substring(67, 6).Trim();
                    string PA      = line.Substring(74, 3).Trim();
                    string id1     = line.Substring(96, 16).Trim();
                    byte   messier = 0;
                    if (id1.StartsWith("M "))
                    {
                        messier = (byte)Convert.ToInt32(id1.Substring(2));
                    }

                    var ds = new DeepSky()
                    {
                        RecordNumber = recordNumber,
                        Number       = Convert.ToUInt16(line.Substring(0, 4).Trim()),
                        Letter       = line.Substring(4, 1)[0],
                        Component    = line.Substring(5, 1)[0],
                        Equatorial0  = new CrdsEquatorial(ra, dec),
                        Status       = status,
                        Mag          = string.IsNullOrWhiteSpace(mag) ? (float?)null : float.Parse(mag, CultureInfo.InvariantCulture),
                        SizeA        = float.Parse(string.IsNullOrWhiteSpace(sizeA) ? "0" : sizeA, CultureInfo.InvariantCulture),
                        SizeB        = float.Parse(string.IsNullOrWhiteSpace(sizeB) ? "0" : sizeB, CultureInfo.InvariantCulture),
                        PA           = short.Parse(string.IsNullOrWhiteSpace(PA) ? "0" : PA),
                        Messier      = messier,
                    };

                    DeepSkies.Add(ds);
                }

                RecordLength = (long)Math.Round(reader.BaseStream.Length / (double)recordNumber);
            }

            // Load proper names of deep sky objects and assign them
            using (var reader = new StreamReader(NAMES_FILE))
            {
                while (!reader.EndOfStream)
                {
                    string[] line = reader.ReadLine().Split(';');
                    var      ds   = DeepSkies.FirstOrDefault(d => d.CatalogName.Replace(" ", "").Equals(line[0].Replace(" ", "")));
                    if (ds != null)
                    {
                        ds.ProperName = line[1].Trim();
                    }
                }
            }

            // Load deep sky object outlines
            using (var reader = new StreamReader(OUTLINES_FILE))
            {
                List <CelestialPoint> outline = new List <CelestialPoint>();

                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // End previos outline and begin a new one
                    if (line.StartsWith("//"))
                    {
                        outline = new List <CelestialPoint>();

                        string name = line.Substring(2).Trim().ToUpper();
                        var    ds   = DeepSkies.FirstOrDefault(d => d.Names.Any(n => n.Replace(" ", "").Equals(name)));
                        if (ds != null && ds.Status != DeepSkyStatus.Galaxy)
                        {
                            ds.Outline = outline;
                        }

                        continue;
                    }

                    // Process outline points
                    uint           raH  = Convert.ToUInt32(line.Substring(0, 2).Trim());
                    uint           raM  = Convert.ToUInt32(line.Substring(3, 2).Trim());
                    double         raS  = Convert.ToDouble(line.Substring(6, 7).Trim(), CultureInfo.InvariantCulture);
                    uint           decD = Convert.ToUInt32(line.Substring(15, 2).Trim());
                    uint           decM = Convert.ToUInt32(line.Substring(18, 2).Trim());
                    double         decS = Convert.ToDouble(line.Substring(21).Trim(), CultureInfo.InvariantCulture);
                    CelestialPoint cp   = new CelestialPoint();
                    cp.Equatorial0.Alpha = new HMS(raH, raM, raS).ToDecimalAngle();
                    cp.Equatorial0.Delta = new DMS(decD, decM, decS).ToDecimalAngle() * (line[14] == '-' ? -1 : 1);

                    outline.Add(cp);
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Move the mount to specitfied celestial coordinate. [*NOTE*] This command is invalid in INIT state.
 /// </summary>
 /// <param name="ra">Right Ascension which is formatted as [HH]+[MM.M]</param>
 /// <param name="dec">Declination which is formatted as [S][DDD]+[MM]</param>
 /// <returns>Response string: OK or ERROR:%</returns>
 ///
 public Response Goto(HMS ra, DMS dec)
 {
     return(this.Handshake(string.Format(CultureInfo.InvariantCulture, "GOTORADEC?RA={0}&DEC={1}", ra, dec)));
 }
 void OnGUI()
 {
     clock = new HMS(0, 0, Time.time - starttime);
     timetextstyle.fontSize = Screen.width / 100;
     GUI.Label(new Rect(Screen.width, 0f, 0f, 0f), "time: " + clock.ToString() /*,string.Format("time: {0}:{1:00}:{2:00}", clock.hours, clock.minutes, clock.seconds)*/, timetextstyle);
 }
Пример #21
0
            /// <summary>
            /// Get status of the mount.
            /// </summary>
            /// <param name="status">
            /// Status which contains the following fields:
            /// [*] RA: Right Ascension which is formatted as [HH]+[MM.M]
            /// [*] DEC: Declination which is formatted as [S][DDD]+[MM]
            /// [*] STATE: State of starbook
            ///     [+] INIT (Power Up)
            ///     [+] GUIDE (?)
            ///     [+] SCOPE (User Presses OK or START)
            ///     [+] CHART (User Presses CHART)
            ///     [+] USER (User Presses MENU)
            /// [*] GOTO: Slewing (1) or Not Slewing (0)
            /// </param>
            /// <returns>Response string: OK or ERROR:%</returns>
            ///
            public Response GetStatus(out Status status)
            {
                status = new Status(); Response response = this.Handshake("GETSTATUS", out Dictionary <string, string> dictionary);

                if (response == Response.ErrorUnknown)
                {
                    bool statusRA = false, statusDEC = false, statusState = false, statusGoto = false;

                    foreach (KeyValuePair <string, string> item in dictionary)
                    {
                        switch (item.Key)
                        {
                        case "RA":
                        {
                            if (HMS.TryParse(item.Value, out HMS ra))
                            {
                                status.RA = ra; statusRA = true;
                            }
                            break;
                        }

                        case "DEC":
                        {
                            if (DMS.TryParse(item.Value, out DMS dec))
                            {
                                status.Dec = dec; statusDEC = true;
                            }
                            break;
                        }

                        case "STATE":
                        {
                            State state = this.ParseState(item.Value);
                            if (state != State.Unknown)
                            {
                                status.State = state; statusState = true;
                            }
                            break;
                        }

                        case "GOTO":
                        {
                            if (item.Value == "1")
                            {
                                status.Goto = true; statusGoto = true;
                            }
                            else if (item.Value == "0")
                            {
                                status.Goto = false; statusGoto = true;
                            }
                            break;
                        }
                        }
                    }

                    if (statusRA && statusDEC && statusState && statusGoto)
                    {
                        response.Assign(Response.OK);
                    }
                }

                return(response);
            }
Пример #22
0
 /// <summary>
 /// Align/Sync the mount with the specified celesctial coordinate. [*NOTE*] This command is invalid in INIT state.
 /// </summary>
 /// <param name="ra">Right Ascension which is formatted as [HH]+[MM.M]</param>
 /// <param name="dec">Declination which is formatted as [S][DDD]+[MM]</param>
 /// <returns>Response string: OK or ERROR:%</returns>
 public Response Align(HMS ra, DMS dec)
 {
     return(this.Handshake(string.Format(CultureInfo.InvariantCulture, "ALIGN?RA={0}&DEC={1}", ra, dec)));
 }