Example #1
0
        /// <summary>
        /// 读取一个历元的数据
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="lineNum"></param>
        /// <returns></returns>
        public SP3Epoch DecodeEpoch(string[] lines, ref int lineNum)
        {
            SP3Epoch epoch = new SP3Epoch();

            epoch.Epoch = GPST.Decode(lines[lineNum].Substring(1));

            Dictionary <string, SP3Sat> allSat = new Dictionary <string, SP3Sat>();

            int i = lineNum + 1;

            for (; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("*"))
                {
                    break;
                }
                else if (lines[i].StartsWith("EOF"))
                {
                    break;
                }

                SP3Sat sat = DecodeSat(lines[i]);

                epoch.AllSat.Add(sat.Prn, sat);
            }
            lineNum = i;

            return(epoch);
        }
Example #2
0
        /// <summary>
        /// 计算卫星位置
        /// </summary>
        /// <param name="oEpo"></param>
        public void GetSatPos(ref OEpoch oEpo)
        {
            if (oEpo is null || oEpo.SatNum == 0)
            {
                return;
            }

            double pRange = 0d;

            foreach (var sat in oEpo.AllSat.Values)
            {
                if (!sat.SatPRN.StartsWith("G"))
                {
                    continue;
                }
                pRange = sat["P2"];
                if (pRange == 0d)
                {
                    pRange = sat["P1"];
                }
                if (pRange == 0d)
                {
                    pRange = sat["C1"];
                }
                if (pRange == 0d)
                {
                    continue;
                }

                GPST t0 = new GPST(oEpo.Epoch);
                t0.AddSeconds(-pRange / Common.C0);
                double[] satPos = GetSatPos(t0, sat.SatPRN);
                sat.SatCoor = satPos;
            }
        }
Example #3
0
        public bool Merge(SP3File file)
        {
            if (Files is null)
            {
                Files = new List <SP3File>();
            }

            bool flag = false;

            if (Files.Count < 1)
            {
                Files.Add(file);
                flag = true;
            }

            for (int i = 0; i < Files.Count; i++)
            {
                if (file.Week < Files[i].Week)
                {
                    Files.Insert(i, file);
                    flag = true;
                }
                else if (file.Week == Files[i].Week)
                {
                    if (file.Day < Files[i].Day)
                    {
                        Files.Insert(i, file);
                        flag = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (flag)
            {
                startTime = Files[0].StartTime;
                endTime   = Files.Last().AllEpoch.Last().Epoch;
            }

            return(flag);
        }
Example #4
0
 public Coor3 GetSatCoor(GPST time)
 {
     return(new Coor3());
 }
Example #5
0
        /// <summary>
        /// 获取某颗卫星的位置
        /// </summary>
        /// <param name="t0"></param>
        /// <param name="prn"></param>
        /// <returns></returns>
        public double[] GetSatPos(GPST t0, string prn)
        {
            double[] p = { 0, 0, 0 };

            // 00:00:00之前,无法插值
            if (t0 - StartTime + 1e-13 < 0)
            {
                return(p);
            }
            // 00:00:00之后,无法插值
            if (t0 - StartTime > 24 * 3600)
            {
                return(p);
            }

            // 10阶插值
            double[] t = new double[10];
            double[] x = new double[10];
            double[] y = new double[10];
            double[] z = new double[10];

            GPST ts = StartTime;

            int index = (int)System.Math.Floor((t0 - ts) / Interval);

            // Console.WriteLine("index:{0}", index);

            // 刚好落在采样点上
            if (Math.Abs(ts - t0 + Interval * index) < 1e-13)
            {
                p[0] = AllEpoch[index][prn].X;
                p[1] = AllEpoch[index][prn].Y;
                p[2] = AllEpoch[index][prn].Z;
                return(p);
            }
            else if (Math.Abs(ts - t0 + Interval * index + Interval) < 1e-13)
            {
                p[0] = AllEpoch[index + 1][prn].X;
                p[1] = AllEpoch[index + 1][prn].Y;
                p[2] = AllEpoch[index + 1][prn].Z;
                return(p);
            }

            // 在开始的几个历元内
            if (index < 4)
            {
                for (int i = 0; i < 10; i++)
                {
                    x[i] = AllEpoch[i][prn].X;
                    y[i] = AllEpoch[i][prn].Y;
                    z[i] = AllEpoch[i][prn].Z;

                    t[i] = AllEpoch[i].Epoch.TotalSeconds;
                }
            }
            // 在结束的几个历元内
            else if (EpochNum - index < 6)
            {
                for (int i = 0; i < 10; i++)
                {
                    x[i] = AllEpoch[EpochNum - 10 + i][prn].X;
                    y[i] = AllEpoch[EpochNum - 10 + i][prn].Y;
                    z[i] = AllEpoch[EpochNum - 10 + i][prn].Z;

                    t[i] = AllEpoch[EpochNum - 10 + i].Epoch.TotalSeconds;
                }
            }
            // 在中间
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    x[i] = AllEpoch[index - 4 + i][prn].X;
                    y[i] = AllEpoch[index - 4 + i][prn].Y;
                    z[i] = AllEpoch[index - 4 + i][prn].Z;

                    t[i] = AllEpoch[index - 4 + i].Epoch.TotalSeconds;
                }
            }

            p[0] = Interp.GetValueLagrange(10, t, x, t0.TotalSeconds);
            p[1] = Interp.GetValueLagrange(10, t, y, t0.TotalSeconds);
            p[2] = Interp.GetValueLagrange(10, t, z, t0.TotalSeconds);
            return(p);
        }
Example #6
0
        /// <summary>
        /// 尝试读取数据
        /// </summary>
        /// <returns></returns>
        public bool TryRead()
        {
            if (!File.Exists(Path))
            {
                return(false);
            }

            string[] lines;
            try
            {
                lines = File.ReadAllLines(Path);
            }
            catch (Exception ex)
            {
                return(false);
            }

            if (Header is null)
            {
                Header = new SP3Header();
            }

            //// Line1
            Header.Version  = lines[0].Substring(0, 2);
            Header.P_V_Flag = lines[0][2].ToString();

            Header.StartTime = GPST.Decode(lines[0].Substring(3, 23));

            Header.EpochNum       = Int32.Parse(lines[0].Substring(32, 7).Trim());//读完数据之后会更改此值
            Header.Data_Used      = lines[0].Substring(40, 5).Trim();
            Header.Coordinate_Sys = lines[0].Substring(46, 5).Trim();
            Header.OrbitType      = lines[0].Substring(52, 3).Trim();
            Header.Agency         = lines[0].Substring(56, 4).Trim();

            //// Line2
            int    weeks;
            double seconds;

            weeks                 = Convert.ToInt32(lines[1].Substring(3, 4).Trim());
            seconds               = Convert.ToDouble(Math.Floor(Double.Parse(lines[1].Substring(8, 15).Trim())));
            Header.StartGPSTime   = new GPST(weeks, seconds);
            Header.Epoch_Interval = Double.Parse(lines[1].Substring(24, 14).Trim());

            //读取卫星PRN号,3-7行
            Header.Num_Sats = Int32.Parse(lines[2].Substring(4, 2).Trim());
            Header.SatPRN   = new List <string>();
            for (int ii = 0; ii < 5; ii++)
            {
                int j = 10;
                for (j = 10; j < 59; j = j + 3)
                {
                    if (lines[2 + ii].Substring(j - 1, 3).Trim() != "0")
                    {
                        Header.SatPRN.Add(lines[2 + ii].Substring(j - 1, 3).Trim());
                    }
                }
            }

            //读取卫星精度,8-12行
            Header.SatAccuracy = new List <string>();
            int i = 0;

            for (int ii = 0; ii < 5; ii++)
            {
                int j = 10;
                if (i < Header.Num_Sats)
                {
                    for (j = 10; j < 59; j = j + 3)
                    {
                        Header.SatAccuracy.Add(lines[7 + ii].Substring(j - 1, 3).Trim());
                        i = i + 1;
                        if (i >= Header.Num_Sats)
                        {
                            break;
                        }
                    }
                }
            }

            for (i = 22; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("EOF"))
                {
                    break;
                }

                if (lines[i].StartsWith("*"))
                {
                    SP3Epoch epoch = DecodeEpoch(lines, ref i);
                    i--;

                    AllEpoch.Add(epoch);
                }
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// 每几个历元输出一张图
        /// </summary>
        /// <param name="epoNum"></param>
        public void WriteTECMap(string outFolder, int epoNum = 10)
        {
            List <int> startIndex = new List <int>();

            GPST startTime = Stations.Min(s => s.StartTime);

            for (int i = 0; i < Stations.Count; i++)
            {
                OStation sta   = Stations[i];
                int      index = (int)Math.Floor(sta.StartTime.TotalSeconds - startTime.TotalSeconds + 0.1d);
                startIndex.Add(index);
            }

            GPST curStartTime = new GPST(startTime);
            GPST curEndTime   = new GPST(startTime);

            curEndTime.AddSeconds(epoNum * Interval);
            double          p4 = 0d;
            int             start = 0, end = epoNum;
            List <string[]> data = new List <string[]>();

            do
            {
                data = new List <string[]>();
                for (int i = 0; i < Stations.Count; i++)
                {
                    var sta = Stations[i];
                    if (startIndex[i] >= end)
                    {
                        continue;
                    }
                    if (startIndex[i] + sta.EpochNum <= start)
                    {
                        continue;
                    }

                    int epoNum1 = startIndex[i] < start ? start - startIndex[i] : 0;
                    int epoNum2 = end - startIndex[i];
                    for (int j = epoNum1; j < epoNum2; j++)
                    {
                        foreach (var sat in sta.Epoches[j].AllSat.Values)
                        {
                            p4 = sat["SP4"];
                            if (Math.Abs(p4) < 1e-10)
                            {
                                continue;
                            }

                            data.Add(new string[]
                            {
                                (sat.IPP[1] * Angle.R2D).ToString("#.##########"),
                                (sat.IPP[0] * Angle.R2D).ToString("#.##########"),
                                p4.ToString("f4")
                            });
                        }
                    }
                }

                // 写入文件
                //if (data.Count > 0)
                {
                    string fileName = string.Format("{0}{1:0#}{2:0#}{3:0#}{4:0#}{5:##.#}.{6}{7:0#}{8:0#}{9:0#}{10:0#}{11:##.#}.tec",
                                                    curStartTime.CommonT.Year,
                                                    curStartTime.CommonT.Month,
                                                    curStartTime.CommonT.Day,
                                                    curStartTime.CommonT.Hour,
                                                    curStartTime.CommonT.Minute,
                                                    curStartTime.CommonT.Second,
                                                    curEndTime.CommonT.Year,
                                                    curEndTime.CommonT.Month,
                                                    curEndTime.CommonT.Day,
                                                    curEndTime.CommonT.Hour,
                                                    curEndTime.CommonT.Minute,
                                                    curEndTime.CommonT.Second
                                                    );

                    string filePath = Path.Combine(outFolder, fileName);
                    FileHelper.WriteLines(filePath, data, ',');

                    curStartTime.AddSeconds(epoNum * Interval);
                    curEndTime.AddSeconds(epoNum * Interval);
                }

                start += epoNum;
                end   += epoNum;
            }while (data.Count > 0);
        }
Example #8
0
        public void WriteMeas(string folder, int epoNum)
        {
            // start time(st)
            GPST st = new GPST(Epoches[0].Epoch);
            // end time(et)
            GPST et = new GPST(Epoches[0].Epoch);

            // start index(si) end index(ei)
            int si = 0, ei = si;

            while (si < EpochNum)
            {
                ei = si + epoNum;
                if (ei >= EpochNum)
                {
                    ei = EpochNum - 1;
                }

                st = Epoches[si].Epoch;
                et = Epoches[ei].Epoch;

                List <string[]> lines = new List <string[]>();
                for (int i = 0; i < ei; i++)
                {
                    foreach (var sat in Epoches[i].AllSat.Values)
                    {
                        if (Math.Abs(sat["SP4"]) < 1e-10)
                        {
                            continue;
                        }

                        lines.Add(new string[]
                        {
                            sat.SatPRN,
                            (sat.IPP[1] * Angle.R2D).ToString("#.##########"),
                            (sat.IPP[0] * Angle.R2D).ToString("#.##########"),
                            sat["vtec"].ToString("f4")
                        });
                    }
                }

                string fileName = Name + string.Format(".{0}{1:0#}{2:0#}{3:0#}{4:0#}{5:##.#}.{6}{7:0#}{8:0#}{9:0#}{10:0#}{11:##.#}.tec",
                                                       st.CommonT.Year,
                                                       st.CommonT.Month,
                                                       st.CommonT.Day,
                                                       st.CommonT.Hour,
                                                       st.CommonT.Minute,
                                                       st.CommonT.Second,
                                                       et.CommonT.Year,
                                                       et.CommonT.Month,
                                                       et.CommonT.Day,
                                                       et.CommonT.Hour,
                                                       et.CommonT.Minute,
                                                       et.CommonT.Second
                                                       );
                string filePath = Path.Combine(folder, fileName);
                FileHelper.WriteLines(filePath, lines, ',');

                si += epoNum;
            }
        }