예제 #1
0
        /// <summary>
        /// 读取 SP3
        /// </summary>
        /// <param name="header"></param>
        /// <param name="r"></param>
        /// <param name="firstLine"></param>
        /// <param name="satNum">是否读取指定卫星的值</param>
        /// <param name="availableOnly">是否只返回可用的记录</param>
        /// <returns></returns>
        public static Sp3Section ReadSection(Sp3Header header, StreamReader r, string firstLine, SatelliteNumber satNum, bool availableOnly = true)
        {
            Sp3Section sec = new Sp3Section();

            sec.Time = ParseTime(firstLine);


            //if (header.OrbitType == SatelliteType.C)//如果是历元,需要转换为北斗时间来计算。
            {
                //  time = time + 14;
            }
            int satLineCount = 1;

            for (int i = 0; i < header.NumberOfSatellites * satLineCount; i++)
            {
                firstLine = r.ReadLine();
                if (firstLine == "EOF")
                {
                    break;
                }
                var firstChar    = firstLine.Substring(0, 1);
                var firstTwoChar = firstLine.Substring(0, 2);
                //判断是否内容
                if (firstTwoChar == RecordHeadSymbol)
                {
                    return(ReadSection(header, r, firstLine, satNum, availableOnly));
                }

                //解析卫星编号
                var prn = SatelliteNumber.Parse(firstLine.Substring(1, 3));
                if (satNum != SatelliteNumber.Default && !satNum.Equals(prn))
                {
                    continue;
                }                                                                            //过滤指定卫星否

                if (!sec.Contains(prn))
                {
                    sec[prn] = new Ephemeris(prn, sec.Time)
                    {
                        Source = header.SourceName
                    };
                }
                var rec = sec[prn];

                if (firstChar == PositionClockSymbol || firstTwoChar == EphemerisPosition)
                {
                    double clock;
                    var    xyz = ParseLine(firstLine, out clock);
                    //单位转换为米
                    rec.XYZ = xyz * 1000.0;
                    if (clock == 999999.999999) //continue;
                    {
                        clock = GnssConst.MaxClockError;
                        if (availableOnly)
                        {
                            sec.Remove(prn); continue;
                        }
                    } //????????????是否该标记卫星状态糟糕   //崔阳,修改,应直接去除该卫星,不能使用。
                    rec.ClockBias = clock * 1e-6;

                    if (firstLine.Length > 70)
                    {
                        ParsePosStd(firstLine, rec);
                    }
                }
                else if (firstChar == VelocityClockSymbol || firstTwoChar == EphemerisVelocity)
                {
                    satLineCount = 2;
                    double dclock;
                    var    xyz = ParseLine(firstLine, out dclock);
                    rec.XyzDot     = xyz * 0.1;
                    rec.ClockDrift = dclock * 1e-10;
                }
            }
            return(sec);
        }
예제 #2
0
        /// <summary>
        /// 读取 SP3
        /// </summary>
        /// <param name="header"></param>
        /// <param name="r"></param>
        /// <param name="satNum">是否读取指定卫星的值</param>
        /// <param name="availableOnly">是否只返回可用的记录</param>
        /// <returns></returns>
        public static Sp3Section ReadSection(Sp3Header header, StreamReader r, string firstLine, SatelliteNumber satNum, bool availableOnly = true)
        {
            return(Sp3Reader.ReadSection(header, r, firstLine, satNum, availableOnly));


            Sp3Section s = new Sp3Section();

            //try
            {
                //读取第一行,头部。
                // if (line.Substring(0, 2) != RecordHeadSymbol) throw new Exception("SP3文件不合法");

                var time = ParseTime(firstLine);
                s.Time = time;

                //if (header.OrbitType == SatelliteType.C)//如果是历元,需要转换为北斗时间来计算。
                {
                    //  time = time + 14;
                }


                for (int i = 0; i < header.NumberOfSatellites; i++)
                {
                    firstLine = r.ReadLine();
                    if (firstLine == "EOF")
                    {
                        break;
                    }
                    var firstChar    = firstLine.Substring(0, 1);
                    var firstTwoChar = firstLine.Substring(0, 2);
                    if (firstChar != PositionClockSymbol)
                    {
                        if (firstTwoChar == RecordHeadSymbol)
                        {
                            return(ReadSection(header, r, firstLine, satNum));
                        }
                        throw new Exception("SP3文件不合法,行首字母为 " + firstChar + ", 非 " + PositionClockSymbol);
                    }
                    if (firstLine == "PC01     -0.000476     -0.005825      0.005830    -22.363000")
                    {
                    }
                    if (firstLine == "PC01     -0.000475     -0.005827      0.005829    -22.366667")
                    {
                    }
                    if (firstLine == "PC01     -0.000467     -0.005845      0.005817    -22.317333")
                    {
                    }
                    SatelliteNumber prn = SatelliteNumber.Parse(firstLine.Substring(1, 3));
                    //过滤指定卫星否
                    if (satNum != SatelliteNumber.Default && !satNum.Equals(prn))
                    {
                        continue;
                    }

                    Ephemeris rec = new Ephemeris();
                    rec.Time = s.Time;
                    rec.Prn  = prn;
                    double x = double.Parse(firstLine.Substring(4, 14)) * 1000.0;
                    double y = double.Parse(firstLine.Substring(18, 14)) * 1000.0;
                    double z = double.Parse(firstLine.Substring(32, 14)) * 1000.0;
                    rec.XYZ = new XYZ(x, y, z);

                    double clock = double.Parse(firstLine.Substring(46, 14));

                    rec.ClockBias = clock * 1e-6;

                    if (firstLine.Length > 70)
                    {
                        //读取精度估值stdv
                        //Columns 62-63       x-sdev (b**n mm)   18                  I2
                        //Column  64          Unused             _                   blank
                        //Columns 65-66       y-sdev (b**n mm)   18                  I2
                        //Column  67          Unused             _                   blank
                        //Columns 68-69       z-sdev (b**n mm)   18                  I2
                        //Column  70          Unused             _                   blank
                        //Columns 71-73       c-sdev (b**n psec) 219                 I3


                        double sdevX = 0.0, sdevY = 0.0, sdevZ = 0.0;
                        string tmp = firstLine.Substring(61, 2);
                        if (tmp != "  ")
                        {
                            sdevX = double.Parse(tmp) * 0.001;
                        }                                      //保留为米
                        tmp = firstLine.Substring(64, 2);
                        if (tmp != "  ")
                        {
                            sdevY = double.Parse(tmp) * 0.001;
                        }
                        tmp = firstLine.Substring(67, 2);
                        if (tmp != "  ")
                        {
                            sdevZ = double.Parse(tmp) * 0.001;
                        }


                        rec.Rms = new XYZ(sdevX, sdevY, sdevZ);

                        double sdevClock = 0.0;
                        tmp = firstLine.Substring(70, 3); //保留了皮秒单位,因为10-12次方太小
                        if (tmp != "   ")
                        {
                            sdevClock = double.Parse(tmp);
                        }



                        rec.ClockBiasRms = sdevClock;
                    }
                    else
                    {
                        rec.Rms = new XYZ(0.0, 0.0, 0.0);

                        rec.ClockBiasRms = 0.0;
                    }

                    //读取速度
                    if (header.P_V_ModeFlag == VelocityClockSymbol)
                    {
                        firstLine = r.ReadLine();
                        firstChar = firstLine.Substring(0, 2);
                        if (firstChar != EphemerisPosition)
                        {
                            throw new Exception("SP3文件不合法,‘#cV’格式星历第2行前两字符为 " + firstChar + ", 非 " + EphemerisPosition);
                        }
                        //double xsdev = double.Parse(firstLine.Substring(4, 4)) * 0.0001;
                        //double ysdev = double.Parse(firstLine.Substring(9, 4)) * 0.0001;
                        //double zsdev = double.Parse(firstLine.Substring(14, 4)) * 0.0001;
                        //rec.XyzSdev = new XYZ(xsdev, ysdev, zsdev);
                        //rec.ClockSdev = double.Parse(firstLine.Substring(19, 7)) * 1E-12;

                        firstLine = r.ReadLine();
                        firstChar = firstLine.Substring(0, 1);
                        if (firstChar != VelocityClockSymbol)
                        {
                            throw new Exception("SP3文件不合法,行首字母为 " + firstChar + ", 非 " + VelocityClockSymbol);
                        }

                        rec.Prn = SatelliteNumber.Parse(firstLine.Substring(1, 3));
                        //分米每秒
                        double xdot = double.Parse(firstLine.Substring(4, 14)) * 1e-1;
                        double ydot = double.Parse(firstLine.Substring(18, 14)) * 1e-1;
                        double zdot = double.Parse(firstLine.Substring(32, 14)) * 1e-1;
                        rec.XyzDot = new XYZ(xdot, ydot, zdot);
                        //(10e-4 msec/sec) = 10e-4 * 1e-6 ??
                        rec.ClockDrift = double.Parse(firstLine.Substring(46, 14)) * 1e-10;


                        firstLine = r.ReadLine();
                        firstChar = firstLine.Substring(0, 2);
                        if (firstChar != EphemerisVelocity)
                        {
                            throw new Exception("SP3文件不合法,‘#cV’格式星历第4行前两字符为 " + firstChar + ", 非 " + EphemerisVelocity);
                        }
                        //double xVsdev = double.Parse(firstLine.Substring(4, 4)) * 0.0001;
                        //double yVsdev = double.Parse(firstLine.Substring(9, 4)) * 0.0001;
                        //double zVsdev = double.Parse(firstLine.Substring(14, 4)) * 0.0001;
                        //rec.XyzDotSdev = new XYZ(xVsdev, yVsdev, zVsdev);
                    }

                    s.Add(rec.Prn, rec);
                }
            }
            //catch (Exception ex)
            //{
            //    throw new ArgumentException("解析行“" + line + "”时出错!\r\north" + ex.Message);
            //}
            return(s);
        }