Пример #1
0
        /// <summary>
        /// 构建头部字符串。
        /// </summary>
        /// <param name="header"></param>
        /// <returns></returns>
        public static string BuildHeaderString(NavFileHeader header)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(StringUtil.FillSpace("3.01", 9, false));
            sb.Append(StringUtil.FillSpace("", 11));
            sb.Append("G");
            sb.Append(StringUtil.FillSpace("", 19));
            sb.Append(header.SatelliteType);
            sb.Append(StringUtil.FillSpace("", 19));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.RINEX_VERSION_TYPE, 20, true));
            sb.AppendLine();

            sb.Append(StringUtil.FillSpace("Gnsser Workgroup", 20, true));
            sb.Append(StringUtil.FillSpace("Gnsser", 20, true));
            sb.Append(StringUtil.FillSpace(DateTime.UtcNow.ToString("yyyyMMdd hhmmss UTC"), 20, true));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.PGM_RUN_BY_DATE, 20, true));
            sb.AppendLine();
            header.Comments.Add("this file is generated by Gnsser " + DateTime.Now.Year);


            string line = StringUtil.FillSpace(header.LeapSeconds + "", 6, false);

            sb.Append(StringUtil.FillSpace(line, 60, true));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.LEAP_SECONDS, 20, true));
            sb.AppendLine();
            sb.AppendLine(StringUtil.FillSpace("", 60, true) + "END OF HEADER");

            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// RINEX 3.0 记录读取。
        /// </summary>
        /// <param name="sr">数据流</param>
        /// <param name="header">头部信息</param>
        /// <returns></returns>
        public static GlonassNavRecord ReadRecordV3(StreamReader sr, NavFileHeader header)
        {
            GlonassNavRecord record = new GlonassNavRecord();
            string           line   = sr.ReadLine();

            GlonassNaviFileReader.ParseFirstLineV3(line, record);

            return(ReadRecordBodyV3(sr, record));
        }
Пример #3
0
        /// <summary>
        /// 分解第一行。V2
        /// </summary>
        /// <param name="line">行</param>
        /// <param name="header">头部</param>
        /// <param name="record">钟差</param>
        public static void ParseFirstLineV2(string line, NavFileHeader header, GlonassNavRecord record)
        {
            line        = line.Replace('D', 'E');
            record.Prn  = SatelliteNumber.Parse(line.Substring(0, 2), header.SatelliteType);
            record.Time = Time.Parse(line.Substring(2, 20));
            string val = line.Substring(22, 19);

            record.ClockBias             = double.Parse(val);
            record.RelativeFrequencyBias = double.Parse(line.Substring(41, 19));
            record.MessageTime           = double.Parse(line.Substring(60, 19));
        }
Пример #4
0
        /// <summary>
        /// 分解第一行。
        /// </summary>
        /// <param name="line"></param>
        /// <param name="header"></param>
        /// <param name="record"></param>
        public static void ParseFirstLineV2(string line, NavFileHeader header, SatClockBias record)
        {
            line        = line.Replace('D', 'E');
            record.Prn  = SatelliteNumber.Parse(line.Substring(0, 2), header.SatelliteType);
            record.Time = Time.Parse(line.Substring(2, 20));
            string val = line.Substring(22, 19);

            record.ClockBias  = double.Parse(val);
            record.ClockDrift = double.Parse(line.Substring(41, 19));
            record.DriftRate  = double.Parse(line.Substring(60, 19));
        }
Пример #5
0
        /// <summary>
        /// 分解第一行。
        /// </summary>
        /// <param name="line"></param>
        /// <param name="header"></param>
        /// <param name="record"></param>
        public static SatClockBias ParseFirstLineV3(string line, NavFileHeader header)
        {
            SatClockBias record = new SatClockBias();

            line        = line.Replace('D', 'E');
            record.Prn  = SatelliteNumber.Parse(line.Substring(0, 3), header.SatelliteType);
            record.Time = Time.Parse(line.Substring(4, 19));
            string val = line.Substring(23, 19);

            record.ClockBias  = double.Parse(val);
            record.ClockDrift = double.Parse(line.Substring(42, 19));
            record.DriftRate  = double.Parse(line.Substring(61, 19));
            return(record);
        }
Пример #6
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="filePath">文件路径</param>
 /// <param name="NavFileHeader">头部信息</param>
 public GlonassNavFileWriter(string filePath, NavFileHeader NavFileHeader = null)
 {
     this.FilePath      = filePath;
     this.NavFileHeader = NavFileHeader;
     if (NavFileHeader == null)
     {
         this.NavFileHeader = new NavFileHeader
         {
             CreationDate    = DateTime.Now.ToString(),
             FileType        = RinexFileType.G,
             SatelliteType   = SatelliteType.R,
             LeapSeconds     = 0,//???2015.05.07
             Version         = 3.02,
             CreationAgence  = "Gnsser",
             CreationProgram = "Gnsser"
         };
     }
     this.StringBuilder = new StringBuilder();
     this.StringBuilder.Append(BuildHeaderString(this.NavFileHeader));
     this.LatestNavEphDic = new Dictionary <SatelliteNumber, Time>();
 }
Пример #7
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="filePath">文件路径</param>
 /// <param name="NavFileHeader">头部信息</param>
 public ParamNavFileWriter(string filePath, NavFileHeader NavFileHeader = null)
 {
     Geo.Utils.FileUtil.CheckOrCreateDirectory(System.IO.Path.GetDirectoryName(filePath));
     this.FilePath      = filePath;
     this.NavFileHeader = NavFileHeader;
     if (NavFileHeader == null)
     {
         this.NavFileHeader = new NavFileHeader
         {
             CreationDate    = DateTime.UtcNow.ToString() + "/UTC",
             FileType        = RinexFileType.N,
             SatelliteType   = SatelliteType.G,
             LeapSeconds     = 0,//???2015.05.07
             Version         = 3.02,
             CreationAgence  = "Gnsser",
             CreationProgram = "Gnsser"
         };
     }
     this.StringBuilder = new StringBuilder();
     this.StringBuilder.Append(BuildHeaderString(this.NavFileHeader));
     this.LatestNavEphDic = new Dictionary <SatelliteNumber, Time>();
 }
Пример #8
0
        /// <summary>
        /// 构建头部字符串。
        /// </summary>
        /// <param name="header"></param>
        /// <returns></returns>
        public static string BuildHeaderString(NavFileHeader header)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(StringUtil.FillSpace(header.Version.ToString("0.0#"), 9, false));
            sb.Append(StringUtil.FillSpace("", 11));
            sb.Append("N");
            sb.Append(StringUtil.FillSpace("", 19));
            sb.Append(header.SatelliteType);
            sb.Append(StringUtil.FillSpace("", 19));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.RINEX_VERSION_TYPE, 20, true));
            sb.AppendLine();

            sb.Append(StringUtil.FillSpace("Gnsser Workgroup", 20, true));
            sb.Append(StringUtil.FillSpace("Gnsser", 20, true));
            sb.Append(StringUtil.FillSpace(DateTime.UtcNow.ToString("yyyyMMdd hhmmss UTC"), 20, true));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.PGM_RUN_BY_DATE, 20, true));
            sb.AppendLine();
            header.Comments.Add("this file is generated by Gnsser " + DateTime.Now.Year);
            foreach (var item in header.Comments)
            {
                if (item.Trim().Length == 0)
                {
                    continue;
                }
                sb.Append(StringUtil.FillSpace(item, 60, true));
                sb.Append(StringUtil.FillSpace(RinexHeaderLabel.COMMENT, 20, true));
                sb.AppendLine();
            }

            string line = StringUtil.FillSpace(header.LeapSeconds + "", 6, false);

            sb.Append(StringUtil.FillSpace(line, 60, true));
            sb.Append(StringUtil.FillSpace(RinexHeaderLabel.LEAP_SECONDS, 20, true));
            sb.AppendLine();
            sb.AppendLine(StringUtil.FillSpace("", 60, true) + "END OF HEADER");

            return(sb.ToString());
        }
Пример #9
0
        /// <summary>
        /// 读取记录
        /// </summary>
        /// <param name="sr">数据流读取器</param>
        /// <param name="header">头部信息</param>
        /// <returns></returns>
        public static GlonassNavRecord ReadRecordV2(StreamReader sr, NavFileHeader header)
        {
            GlonassNavRecord record = new GlonassNavRecord();
            string           line   = sr.ReadLine();

            GlonassNaviFileReader.ParseFirstLineV2(line, header, record);

            line = sr.ReadLine();
            line = line.Replace('D', 'E');
            double x   = double.Parse(line.Substring(3, 19));
            double vx  = double.Parse(line.Substring(22, 19));
            double vvx = double.Parse(line.Substring(41, 19));

            record.Health = double.Parse(line.Substring(60, 19));

            line = sr.ReadLine();
            line = line.Replace('D', 'E');
            double y   = double.Parse(line.Substring(3, 19));
            double vy  = double.Parse(line.Substring(22, 19));
            double vvy = double.Parse(line.Substring(41, 19));

            record.FrequencyNumber = double.Parse(line.Substring(60, 19));

            line = sr.ReadLine();
            line = line.Replace('D', 'E');
            double z   = double.Parse(line.Substring(3, 19));
            double vz  = double.Parse(line.Substring(22, 19));
            double vvz = double.Parse(line.Substring(41, 19));

            record.FrequencyNumber = double.Parse(line.Substring(60, 19));
            record.AgeOfOper       = double.Parse(line.Substring(60, 19));

            record.XYZ             = new XYZ(x, y, z) * 1000.0;       // km -> m
            record.XyzVelocity     = new XYZ(vx, vy, vz) * 1000.0;    // km -> m
            record.XyzAcceleration = new XYZ(vvx, vvy, vvz) * 1000.0; // km -> m
            return(record);
        }
Пример #10
0
 public void SetHeader(NavFileHeader Header)
 {
     this.Header = Header; this.ParamNavFile.Header = Header; this.GlonassNavFile.Header = Header;
 }
Пример #11
0
        /// <summary>
        /// 读取RINEX文件的头文件。
        /// </summary>
        /// <param name="rinexFileName">文件路径</param>
        /// <returns></returns>
        public static NavFileHeader ReadHeader(string RinexFileName)
        {
            NavFileHeader header = new NavFileHeader();

            header.Name = Path.GetFileName(RinexFileName);
            using (StreamReader r = new StreamReader(RinexFileName, Encoding.UTF8))
            {
                string line        = null;
                string headerLabel = null;
                while ((line = r.ReadLine()) != null && headerLabel != RinexHeaderLabel.END_OF_HEADER)
                {
                    //中文字符支持
                    int nonAscCount = StringUtil.GetNonAscCount(line.Substring(0, 60 > line.Length ? line.Length : 60));
                    headerLabel = line.Substring(60 - nonAscCount).TrimEnd();//header label 61-80
                    if (headerLabel.Contains(RinexHeaderLabel.END_OF_HEADER))
                    {
                        break;
                    }
                    switch (headerLabel)
                    {
                    /**
                     *  +--------------------+------------------------------------------+------------+
                     | HEADER LABEL | DESCRIPTION | FORMAT |
                     | (Columns 61-80) | | |
                     +--------------------+------------------------------------------+------------+
                     |RINEX VERSION / TYPE| - Format version : 3.00 | F9.2,11X, |
                     | | - File type: O for Observation Data | A1,19X, |
                     | | - Satellite System: G: GPS | A1,19X |
                     | | R: GLONASS | |
                     | | E: Galileo | |
                     | | S: SBAS payload | |
                     | | M: Mixed | |
                     +--------------------+------------------------------------------+------------+
                     *
                     */
                    case RinexHeaderLabel.RINEX_VERSION_TYPE:
                        header.Version  = double.Parse(line.Substring(0, 9));
                        header.FileType = (RinexFileType)Enum.Parse(typeof(RinexFileType), line.Substring(20, 1));
                        if (line.Substring(40, 1) == " ")
                        {
                            header.SatelliteType = RinexUtil.GetSatelliteType(header.FileType);
                        }
                        else
                        {
                            header.SatelliteType = (SatelliteType)Enum.Parse(typeof(SatelliteType), line.Substring(40, 1));
                        }
                        break;

                    case RinexHeaderLabel.PGM_RUN_BY_DATE:
                        header.CreationProgram = line.Substring(0, 20).TrimEnd();
                        header.CreationAgence  = line.Substring(20, 20).Trim();
                        header.CreationDate    = line.Substring(40, 20).TrimEnd();
                        break;

                    case RinexHeaderLabel.COMMENT:
                        if (header.Comments == null)
                        {
                            header.Comments = new List <string>();
                        }
                        header.Comments.Add(line.Substring(0, 60 - nonAscCount).Trim());
                        break;

                    case RinexHeaderLabel.RCV_CLOCK_OFFS_APPL:

                        break;

                    case RinexHeaderLabel.LEAP_SECONDS:
                        header.LeapSeconds = int.Parse(line.Substring(0, 6));
                        break;

                    case RinexHeaderLabel.NUM_OF_SATELLITES:
                        break;

                    case RinexHeaderLabel.PRN_NUM_OF_OBS:
                        break;

                    //2X,4D12.4
                    case RinexHeaderLabel.ION_ALPHA:
                        line = line.Replace('D', 'E');
                        header.IonParam.AlfaA0 = double.Parse(line.Substring(2, 12));
                        header.IonParam.AlfaA1 = double.Parse(line.Substring(14, 12));
                        header.IonParam.AlfaA2 = double.Parse(line.Substring(26, 12));
                        header.IonParam.AlfaA3 = double.Parse(line.Substring(38, 12));
                        break;

                    case RinexHeaderLabel.ION_BETA:
                        line = line.Replace('D', 'E');
                        header.IonParam.BetaB0 = double.Parse(line.Substring(2, 12));
                        header.IonParam.BetaB1 = double.Parse(line.Substring(14, 12));
                        header.IonParam.BetaB2 = double.Parse(line.Substring(26, 12));
                        header.IonParam.BetaB3 = double.Parse(line.Substring(38, 12));
                        break;

                    //3X,2D19.12,2I9
                    case RinexHeaderLabel.DELTA_UTC_A0_A1_T_W:
                        line = line.Replace('D', 'E');
                        header.UtcDeltaA0 = double.Parse(line.Substring(3, 19));
                        header.UtcDeltaA1 = double.Parse(line.Substring(22, 19));
                        header.UtcDeltaT  = double.Parse(line.Substring(41, 9));
                        header.UtcDeltaW  = double.Parse(line.Substring(50, 9));
                        break;

                    case RinexHeaderLabel.PRN_LIST:
                        if (header.PrnList == null)
                        {
                            header.PrnList = new List <SatelliteNumber>();
                        }
                        string[] prnStrs = line.Substring(0, 60).Trim().Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string prn in prnStrs)
                        {
                            header.PrnList.Add(SatelliteNumber.Parse(prn));
                        }

                        break;

                    //rinex 3.0 nav
                    case RinexHeaderLabel.TIME_SYSTEM_CORR:

                        break;

                    //rinex 3.0 nav
                    case RinexHeaderLabel.IONOSPHERIC_CORR:

                        break;

                    case RinexHeaderLabel.END_OF_HEADER:
                    default: break;
                    }
                }
            }
            return(header);
        }
Пример #12
0
        /// <summary>
        /// 读取 RINEX 2.0s GPS导航文件。
        /// </summary>
        /// <param name="sr"></param>
        /// <param name="header"></param>
        /// <returns></returns>
        public static EphemerisParam ReadRecordV2(StreamReader sr, NavFileHeader header)
        {
            EphemerisParam record = new EphemerisParam();

            string line = sr.ReadLine();

            ParseFirstLineV2(line, header, record);

            line               = sr.ReadLine();
            line               = line.Replace('D', 'E');
            record.IODE        = double.Parse(line.Substring(3, 19));
            record.Crs         = double.Parse(line.Substring(22, 19));
            record.DeltaN      = double.Parse(line.Substring(41, 19));
            record.MeanAnomaly = double.Parse(line.Substring(60, 19));

            line                = sr.ReadLine();
            line                = line.Replace('D', 'E');
            record.Cuc          = double.Parse(line.Substring(3, 19));
            record.Eccentricity = double.Parse(line.Substring(22, 19));
            record.Cus          = double.Parse(line.Substring(41, 19));
            record.SqrtA        = double.Parse(line.Substring(60, 19));

            line                   = sr.ReadLine();
            line                   = line.Replace('D', 'E');
            record.Toe             = double.Parse(line.Substring(3, 19));
            record.Cic             = double.Parse(line.Substring(22, 19));
            record.LongOfAscension = double.Parse(line.Substring(41, 19));
            record.Cis             = double.Parse(line.Substring(60, 19));

            line = sr.ReadLine();
            line = line.Replace('D', 'E');
            record.Inclination       = double.Parse(line.Substring(3, 19));
            record.Crc               = double.Parse(line.Substring(22, 19));
            record.ArgumentOfPerigee = double.Parse(line.Substring(41, 19));
            record.OmegaDot          = double.Parse(line.Substring(60, 19));

            line               = sr.ReadLine();
            line               = line.Replace('D', 'E');
            record.EyeDot      = double.Parse(line.Substring(3, 19));
            record.CodesL2     = double.Parse(line.Substring(22, 19));
            record.GPSWeeks    = (int)double.Parse(line.Substring(41, 19));
            record.L2PDataFlag = double.Parse(line.Substring(60, 19)) == 1;

            line = sr.ReadLine();
            line = line.Replace('D', 'E');
            record.SVAccuracy = double.Parse(line.Substring(3, 19));
            record.SVHealth   = double.Parse(line.Substring(22, 19));
            record.TGD        = double.Parse(line.Substring(41, 19));
            record.IODC       = double.Parse(line.Substring(60, 19));

            if (header.Version == 1.0)
            {
                return(record);
            }

            line       = sr.ReadLine();
            line       = line.Replace('D', 'E');
            record.TTM = double.Parse(line.Substring(3, 19));

            return(record);
        }