Ejemplo n.º 1
0
        public void TestRoundTripDefaultConstructed()
        {
            GregorianDate gd  = new GregorianDate();
            GregorianDate gd2 = new GregorianDate(gd.ToJulianDate());

            Assert.AreEqual(gd, gd2);
        }
Ejemplo n.º 2
0
        public void TestRoundTripDefaultConstructed()
        {
            GregorianDate gregorianDate1 = new GregorianDate();
            GregorianDate gregorianDate2 = new GregorianDate(gregorianDate1.ToJulianDate());

            Assert.AreEqual(gregorianDate1, gregorianDate2);
        }
Ejemplo n.º 3
0
        public void CanConvertToJulianDate()
        {
            {
                GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 23, 59, 59.999);

                JulianDate julianDate = gregorianDate.ToJulianDate();

                GregorianDate newGregorianDate = new GregorianDate(julianDate);

                Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year);
                Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month);
                Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day);
                Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour);
                Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute);
                Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11);
            }

            {
                GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 01, 01, 01);

                JulianDate julianDate = gregorianDate.ToJulianDate();

                GregorianDate newGregorianDate = new GregorianDate(julianDate);

                Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year);
                Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month);
                Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day);
                Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour);
                Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute);
                Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a <see cref="JulianDate"/> from a <see cref="GregorianDate"/> where the <see cref="GregorianDate"/>
        /// is expressed in the given <see cref="TimeStandard"/>.  If the date is during a leap second, the
        /// <see cref="JulianDate"/> will be expressed in <see cref="TimeStandard.InternationalAtomicTime"/> (TAI).
        /// </summary>
        /// <param name="gregorianDate">The <see cref="GregorianDate"/>.</param>
        /// <param name="standard">
        /// The time standard in which the <paramref name="gregorianDate"/> is expressed.
        /// </param>
        public JulianDate(GregorianDate gregorianDate, TimeStandard standard)
        {
            JulianDate converted = gregorianDate.ToJulianDate(standard);

            m_day          = converted.m_day;
            m_secondsOfDay = converted.m_secondsOfDay;
            m_timeStandard = converted.Standard;
        }
Ejemplo n.º 5
0
        public void TestConversionToJulianDate()
        {
            GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 0);

            JulianDate julianDate = date.ToJulianDate();

            GregorianDate oneSecondLater  = new GregorianDate(2008, 12, 31, 23, 59, 1);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 58, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(julianDate).Seconds);
            Assert.AreEqual(1, julianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
Ejemplo n.º 6
0
        public void CanConvertGregorianDateRepresentingLeapSecondToJulianDate()
        {
            GregorianDate leapSecondGregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 60);
            JulianDate    leapSecondJulianDate    = leapSecondGregorianDate.ToJulianDate();

            Assert.AreEqual(leapSecondGregorianDate, leapSecondJulianDate.ToGregorianDate());

            GregorianDate oneSecondLater  = new GregorianDate(2009, 1, 1, 0, 0, 0);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 59, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(leapSecondJulianDate).Seconds);
            Assert.AreEqual(1, leapSecondJulianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
Ejemplo n.º 7
0
        public void TestNonStandardTimeStandard()
        {
            GregorianDate gregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 40);

            JulianDate julianDate = gregorianDate.ToJulianDate(TimeStandard.InternationalAtomicTime);

            Assert.AreEqual(TimeStandard.InternationalAtomicTime, julianDate.Standard);

            GregorianDate roundTrip = julianDate.ToGregorianDate(TimeStandard.InternationalAtomicTime);

            Assert.AreEqual(gregorianDate, roundTrip);

            roundTrip = new GregorianDate(julianDate);
            Assert.AreNotEqual(gregorianDate, roundTrip);

            double expectedDifference = LeapSeconds.Instance.GetTaiMinusUtc(julianDate);

            Assert.AreEqual(expectedDifference, gregorianDate.Second - roundTrip.Second);
        }
Ejemplo n.º 8
0
        public void TestRoundTripDefaultConstructed()
        {
            GregorianDate gd = new GregorianDate();
            GregorianDate gd2 = new GregorianDate(gd.ToJulianDate());

            Assert.AreEqual(gd, gd2);
        }
Ejemplo n.º 9
0
        public void TestNonStandardTimeStandard()
        {
            GregorianDate gregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 40);

            JulianDate jd = gregorianDate.ToJulianDate(TimeStandard.InternationalAtomicTime);
            Assert.AreEqual(TimeStandard.InternationalAtomicTime, jd.Standard);

            GregorianDate roundTrip1 = jd.ToGregorianDate(TimeStandard.InternationalAtomicTime);
            Assert.AreEqual(gregorianDate, roundTrip1);

            GregorianDate roundTrip = new GregorianDate(jd);
            Assert.AreNotEqual(gregorianDate, roundTrip);

            double expectedDifference = LeapSeconds.Instance.GetTaiMinusUtc(jd);
            Assert.AreEqual(expectedDifference, gregorianDate.Second - roundTrip.Second);
        }
Ejemplo n.º 10
0
        public void CanConvertGregorianDateRepresentingLeapSecondToJulianDate()
        {
            GregorianDate leapSecondGregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 60);
            JulianDate leapSecondJulianDate = leapSecondGregorianDate.ToJulianDate();

            Assert.AreEqual(leapSecondGregorianDate, leapSecondJulianDate.ToGregorianDate());

            GregorianDate oneSecondLater = new GregorianDate(2009, 1, 1, 0, 0, 0);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 59, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(leapSecondJulianDate).Seconds);
            Assert.AreEqual(1, leapSecondJulianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
Ejemplo n.º 11
0
        public void TestConversionToJulianDate()
        {
            GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 0);

            JulianDate julianDate = date.ToJulianDate();

            GregorianDate oneSecondLater = new GregorianDate(2008, 12, 31, 23, 59, 1);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 58, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(julianDate).Seconds);
            Assert.AreEqual(1, julianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
Ejemplo n.º 12
0
        public void CanConvertToJulianDate()
        {
            {
                GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 23, 59, 59.999);

                JulianDate julianDate = gregorianDate.ToJulianDate();

                GregorianDate newGregorianDate = new GregorianDate(julianDate);

                Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year);
                Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month);
                Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day);
                Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour);
                Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute);
                Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11);
            }

            {
                GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 01, 01, 01);

                JulianDate julianDate = gregorianDate.ToJulianDate();

                GregorianDate newGregorianDate = new GregorianDate(julianDate);

                Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year);
                Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month);
                Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day);
                Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour);
                Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute);
                Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11);
            }
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            // use a fixed seed so repeated invocations use the same colors
            var rng = new Random(0);

            var files = new[]
            {
                @"ISS11_07_image_data.csv",
                @"ISS11_11_image_data.csv",
                @"ISS12_01_image_data.csv",
                @"ISS12_07_2_image_data.csv",
                @"ISS12_11_image_data.csv",
                @"ISS13_01_image_data.csv",
                @"ISS11_04_image_data.csv"
            };

            List <KeyValuePair <string, string> > missions = new List <KeyValuePair <string, string> >();

            foreach (var fileName in files)
            {
                string   csvFile = Path.Combine(AssetsDirectory, "CSV", fileName);
                string[] lines   = File.ReadAllLines(csvFile);

                string czmlFile = Path.Combine(AssetsDirectory, "CZML", Path.ChangeExtension(fileName, ".czml"));
                string jsonFile = Path.Combine(AssetsDirectory, "JSON", Path.ChangeExtension(fileName, ".json"));

                using (StreamWriter czmlWriter = new StreamWriter(czmlFile))
                    using (StreamWriter jsonWriter = new StreamWriter(jsonFile))
                        using (CesiumOutputStream czmlOutputStream = new CesiumOutputStream(czmlWriter))
                        {
                            czmlOutputStream.PrettyFormatting = false;
                            czmlOutputStream.WriteStartSequence();

                            List <string> ID          = new List <string>();
                            List <string> Time        = new List <string>();
                            List <string> School      = new List <string>();
                            List <string> ImageUrl    = new List <string>();
                            List <string> LensSize    = new List <string>();
                            List <string> OrbitNumber = new List <string>();
                            List <string> FrameWidth  = new List <string>();
                            List <string> FrameHeight = new List <string>();
                            List <string> Page        = new List <string>();
                            List <string> CZML        = new List <string>();

                            GregorianDate start = new GregorianDate();
                            for (int i = 1; i < lines.Length; i++)
                            {
                                string   line   = lines[i];
                                string[] tokens = line.Split(',');
                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Trim('"').Trim();
                                }

                                if (i == 1)
                                {
                                    start = GregorianDate.Parse(tokens[17]);
                                    missions.Add(new KeyValuePair <string, string>(Path.ChangeExtension(fileName, null), tokens[18]));
                                }
                                else if (i == lines.Length - 1)
                                {
                                    Console.WriteLine(Path.GetFileNameWithoutExtension(fileName));
                                    Console.WriteLine(start.ToJulianDate().TotalDays + " JDate");
                                    var stop = GregorianDate.Parse(tokens[17]);
                                    Console.WriteLine(stop.ToJulianDate().TotalDays + " JDate");
                                    Console.WriteLine();
                                    //Console.WriteLine((stop.ToJulianDate() - start.ToJulianDate()).TotalDays);
                                }

                                var writer = new CesiumStreamWriter();
                                using (var packet = writer.OpenPacket(czmlOutputStream))
                                {
                                    packet.WriteId(tokens[0]);
                                    using (var vertexPositions = packet.OpenVertexPositionsProperty())
                                    {
                                        var points = new Cartographic[] {
                                            new Cartographic(double.Parse(tokens[5]), double.Parse(tokens[6]), 0),
                                            new Cartographic(double.Parse(tokens[7]), double.Parse(tokens[8]), 0),
                                            new Cartographic(double.Parse(tokens[9]), double.Parse(tokens[10]), 0),
                                            new Cartographic(double.Parse(tokens[11]), double.Parse(tokens[12]), 0)
                                        };
                                        vertexPositions.WriteCartographicDegrees(points);
                                    }
                                    using (var polygon = packet.OpenPolygonProperty())
                                    {
                                        polygon.WriteShowProperty(true);
                                        using (var material = polygon.OpenMaterialProperty())
                                        {
                                            using (var color = material.OpenSolidColorProperty())
                                            {
                                                color.WriteColorProperty(Color.FromArgb(255, (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255)));
                                            }
                                        }
                                    }
                                }

                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Replace("\"", "\\\"");
                                }

                                ID.Add(tokens[0]);
                                Time.Add(GregorianDate.Parse(tokens[17]).ToIso8601String(Iso8601Format.Compact));
                                School.Add(tokens[23]);
                                ImageUrl.Add(tokens[21].Split(new[] { '=' })[2]);
                                LensSize.Add(tokens[14]);
                                OrbitNumber.Add(tokens[19]);
                                FrameWidth.Add(tokens[15]);
                                FrameHeight.Add(tokens[16]);
                                Page.Add(tokens[20].Split(new[] { '=' })[1]);
                            }

                            czmlOutputStream.WriteEndSequence();

                            jsonWriter.WriteLine("{");
                            writeJsonArray(jsonWriter, "ID", ID);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Time", Time);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "School", School);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "ImageUrl", ImageUrl);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "LensSize", LensSize);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "OrbitNumber", OrbitNumber);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameWidth", FrameWidth);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameHeight", FrameHeight);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Page", Page);
                            jsonWriter.WriteLine();
                            jsonWriter.WriteLine("}");
                        }
            }

            using (StreamWriter missionsJsonWriter = new StreamWriter(Path.Combine(AssetsDirectory, "missions.json")))
            {
                missionsJsonWriter.Write("[");
                for (int i = 0; i < missions.Count; ++i)
                {
                    missionsJsonWriter.Write("{{\"file\":\"{0}\",\"name\":\"{1}\"}}", missions[i].Key, missions[i].Value);
                    if (i != missions.Count - 1)
                    {
                        missionsJsonWriter.Write(",");
                    }
                }
                missionsJsonWriter.Write("]");
            }
        }
        public static void Main(string[] args)
        {
            // use a fixed seed so repeated invocations use the same colors
            var rng = new Random(0);

            var files = new[]
            {
                @"ISS11_07_image_data.csv",
                @"ISS11_11_image_data.csv",
                @"ISS12_01_image_data.csv",
                @"ISS12_07_2_image_data.csv",
                @"ISS12_11_image_data.csv",
                @"ISS13_01_image_data.csv",
                @"ISS11_04_image_data.csv"
            };

            List<KeyValuePair<string, string>> missions = new List<KeyValuePair<string,string>>();

            foreach (var fileName in files)
            {
                string csvFile = Path.Combine(AssetsDirectory, "CSV", fileName);
                string[] lines = File.ReadAllLines(csvFile);

                string czmlFile = Path.Combine(AssetsDirectory, "CZML", Path.ChangeExtension(fileName, ".czml"));
                string jsonFile = Path.Combine(AssetsDirectory, "JSON", Path.ChangeExtension(fileName, ".json"));

                using (StreamWriter czmlWriter = new StreamWriter(czmlFile))
                using (StreamWriter jsonWriter = new StreamWriter(jsonFile))
                using (CesiumOutputStream czmlOutputStream = new CesiumOutputStream(czmlWriter))
                {
                    czmlOutputStream.PrettyFormatting = false;
                    czmlOutputStream.WriteStartSequence();

                    List<string> ID = new List<string>();
                    List<string> Time = new List<string>();
                    List<string> School = new List<string>();
                    List<string> ImageUrl = new List<string>();
                    List<string> LensSize = new List<string>();
                    List<string> OrbitNumber = new List<string>();
                    List<string> FrameWidth = new List<string>();
                    List<string> FrameHeight = new List<string>();
                    List<string> Page = new List<string>();
                    List<string> CZML = new List<string>();

                    GregorianDate start = new GregorianDate();
                    for (int i = 1; i < lines.Length; i++)
                    {
                        string line = lines[i];
                        string[] tokens = line.Split(',');
                        for (int q = 0; q < tokens.Length; q++)
                        {
                            tokens[q] = tokens[q].Trim('"').Trim();
                        }

                        if (i == 1)
                        {
                            start = GregorianDate.Parse(tokens[17]);
                            missions.Add(new KeyValuePair<string, string>(Path.ChangeExtension(fileName, null), tokens[18]));
                        }
                        else if (i == lines.Length - 1)
                        {
                            Console.WriteLine(Path.GetFileNameWithoutExtension(fileName));
                            Console.WriteLine(start.ToJulianDate().TotalDays + " JDate");
                            var stop = GregorianDate.Parse(tokens[17]);
                            Console.WriteLine(stop.ToJulianDate().TotalDays + " JDate");
                            Console.WriteLine();
                            //Console.WriteLine((stop.ToJulianDate() - start.ToJulianDate()).TotalDays);
                        }

                        var writer = new CesiumStreamWriter();
                        using (var packet = writer.OpenPacket(czmlOutputStream))
                        {
                            packet.WriteId(tokens[0]);
                            using (var vertexPositions = packet.OpenVertexPositionsProperty())
                            {
                                var points = new Cartographic[] {
                                    new Cartographic(double.Parse(tokens[5]), double.Parse(tokens[6]), 0),
                                    new Cartographic(double.Parse(tokens[7]), double.Parse(tokens[8]), 0),
                                    new Cartographic(double.Parse(tokens[9]), double.Parse(tokens[10]), 0),
                                    new Cartographic(double.Parse(tokens[11]), double.Parse(tokens[12]), 0)
                                };
                                vertexPositions.WriteCartographicDegrees(points);
                            }
                            using (var polygon = packet.OpenPolygonProperty())
                            {
                                polygon.WriteShowProperty(true);
                                using (var material = polygon.OpenMaterialProperty())
                                {
                                    using (var color = material.OpenSolidColorProperty())
                                    {
                                        color.WriteColorProperty(Color.FromArgb(255, (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255)));
                                    }
                                }
                            }
                        }

                        for (int q = 0; q < tokens.Length; q++)
                        {
                            tokens[q] = tokens[q].Replace("\"", "\\\"");
                        }

                        ID.Add(tokens[0]);
                        Time.Add(GregorianDate.Parse(tokens[17]).ToIso8601String(Iso8601Format.Compact));
                        School.Add(tokens[23]);
                        ImageUrl.Add(tokens[21].Split(new[] { '=' })[2]);
                        LensSize.Add(tokens[14]);
                        OrbitNumber.Add(tokens[19]);
                        FrameWidth.Add(tokens[15]);
                        FrameHeight.Add(tokens[16]);
                        Page.Add(tokens[20].Split(new[] { '=' })[1]);
                    }

                    czmlOutputStream.WriteEndSequence();

                    jsonWriter.WriteLine("{");
                    writeJsonArray(jsonWriter, "ID", ID);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "Time", Time);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "School", School);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "ImageUrl", ImageUrl);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "LensSize", LensSize);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "OrbitNumber", OrbitNumber);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "FrameWidth", FrameWidth);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "FrameHeight", FrameHeight);
                    jsonWriter.WriteLine(",");
                    writeJsonArray(jsonWriter, "Page", Page);
                    jsonWriter.WriteLine();
                    jsonWriter.WriteLine("}");
                }
            }

            using (StreamWriter missionsJsonWriter = new StreamWriter(Path.Combine(AssetsDirectory, "missions.json")))
            {
                missionsJsonWriter.Write("[");
                for (int i = 0; i < missions.Count; ++i)
                {
                    missionsJsonWriter.Write("{{\"file\":\"{0}\",\"name\":\"{1}\"}}", missions[i].Key, missions[i].Value);
                    if (i != missions.Count - 1)
                        missionsJsonWriter.Write(",");
                }
                missionsJsonWriter.Write("]");
            }
        }