Exemplo n.º 1
0
        /// <summary>
        ///  to RINEX String,自动采用观测文件内容更新时间。
        /// </summary>
        /// <param name="obsFile"></param>
        /// <param name="minIntervalSeconds">最小采样率</param>
        public string GetRinexString(RinexObsFile obsFile, double version, int minIntervalSeconds = 0)
        {
            if (obsFile == null || obsFile.Count == 0)
            {
                return("");
            }

            this.Header = obsFile.Header;
            obsFile.Header.StartTime = obsFile[0].ReceiverTime;
            if (obsFile.Count > 1)
            {
                obsFile.Header.EndTime  = obsFile[obsFile.Count - 1].ReceiverTime;
                obsFile.Header.Interval = (obsFile[1].ReceiverTime - obsFile[0].ReceiverTime);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(ObsHeaderToRinexString(obsFile.Header, version));
            //更新采样率
            if (obsFile.Header.Interval < minIntervalSeconds)
            {
                obsFile.Header.Interval = minIntervalSeconds;
            }

            RinexEpochObservation prevEpochObs = null;
            int i = 0;

            foreach (var item in obsFile.ToArray())
            {
                if (item.Count == 0)
                {
                    continue;
                }

                if (prevEpochObs == null)
                {
                    prevEpochObs = item;
                }                                                 //第一次

                var differ = item.ReceiverTime - prevEpochObs.ReceiverTime;
                if (differ >= minIntervalSeconds || i == 0)
                {
                    if (version >= 3)
                    {
                        sb.Append(GetRecordStringV3(item));
                    }
                    else
                    {
                        sb.Append(GetRecordStringV2(item));
                    }

                    prevEpochObs = item;//roll
                }
                i++;
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 写一个观测历元
        /// </summary>
        /// <param name="epochObs"></param>
        public void WriteEpochObservation(RinexEpochObservation epochObs)
        {
            string rinex = null;

            if (Version >= 3)
            {
                rinex = GetRecordStringV3(epochObs);
            }
            else
            {
                rinex = GetRecordStringV2(epochObs);
            }

            Writer.Write(rinex);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 一个历元观测量
        /// </summary>
        /// <param name="epochObs"></param>
        /// <returns></returns>
        public string GetRecordStringV3(RinexEpochObservation epochObs)
        {
            if (epochObs.Count == 0)
            {
                return("");
            }

            var prns = GetOutputPrns(epochObs);

            StringBuilder sb            = new StringBuilder();
            var           OneBlankSpace = " ";

            sb.Append("> ");
            var epoch     = epochObs.ReceiverTime;
            var firstLine = epoch.Year.ToString("0000")  //四位数的年
                            + OneBlankSpace + epoch.Month.ToString("00")
                            + OneBlankSpace + epoch.Day.ToString("00")
                            + OneBlankSpace + epoch.Hour.ToString("00")
                            + OneBlankSpace + epoch.Minute.ToString("00")
                            + OneBlankSpace + epoch.Seconds.ToString("00.0000000")//F11.7
                            + StringUtil.FillSpaceLeft(epochObs.EpochFlag + "", 3)
                            + StringUtil.FillSpaceLeft(prns.Count + "", 3)
                            + StringUtil.FillSpaceLeft("", 6)
                            + StringUtil.FillSpaceLeft(epochObs.ReceiverClockOffset.ToString("0.000000000000"), 15)
            ;

            sb.AppendLine(firstLine);

            foreach (var prn in prns)
            {
                var sat = epochObs[prn];
                sb.Append(prn.ToString());//PRN可能有三位?
                if (sat != null)
                {
                    var obstypes   = ObsCodes[prn.SatelliteType];
                    int emptyCount = 0;
                    foreach (var type in obstypes)
                    {
                        var val = sat.TryGetObsValue(type);

                        #region 简明输出处理逻辑
                        if (IsConcise)       //简明输出
                        {
                            if (val == null) //若为空,则跳过,记录次数
                            {
                                emptyCount++;
                                continue;
                            }
                            else//若不是空,则补足前期数据。
                            {
                                for (int i = 0; i < emptyCount; i++)
                                {
                                    sb.Append(Utils.StringUtil.FillSpace("  ", 16));
                                }
                                emptyCount = 0;
                            }
                        }
                        #endregion

                        if (val != null && (Double.IsNaN(val.Value) || Double.IsInfinity(val.Value)))
                        {
                            val.Value = 0;
                        }
                        sb.Append(ToRinexValueString(val));
                    }
                }

                sb.AppendLine();
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取将要输出的卫星列表
 /// </summary>
 /// <param name="epochObs"></param>
 /// <returns></returns>
 public List <SatelliteNumber> GetOutputPrns(RinexEpochObservation epochObs)
 {
     return(epochObs.Prns.Where(m => ObsCodes.Keys.Contains(m.SatelliteType)).ToList());
 }
Exemplo n.º 5
0
        /// <summary>
        /// 一个历元观测量
        /// </summary>
        /// <param name="epochObs"></param>
        /// <returns></returns>
        public string GetRecordStringV2(RinexEpochObservation epochObs)
        {
            if (epochObs.Count == 0)
            {
                return("");
            }

            var           prns          = GetOutputPrns(epochObs);
            StringBuilder sb            = new StringBuilder();
            var           OneBlankSpace = " ";

            sb.Append(OneBlankSpace);                    //第一个为空格
            var epoch     = epochObs.ReceiverTime;
            var firstLine = epoch.SubYear.ToString("00") //两位数的年
                            + OneBlankSpace + epoch.Month.ToString("00")
                            + OneBlankSpace + epoch.Day.ToString("00")
                            + OneBlankSpace + epoch.Hour.ToString("00")
                            + OneBlankSpace + epoch.Minute.ToString("00")
                            + OneBlankSpace + epoch.Seconds.ToString("00.0000000")//F11.7
                            + StringUtil.FillSpaceLeft(epochObs.EpochFlag + "", 3)
                            + StringUtil.FillSpaceLeft(prns.Count + "", 3);

            sb.Append(firstLine);

            var firstEnd = StringUtil.FillSpaceLeft(epochObs.ReceiverClockOffset.ToString("0.000000000"), 12);
            //卫星列表
            int satIndex = 0;
            //var prns = epochObs.Prns;
            int           satCount          = prns.Count;
            int           maxSatCountInLine = 12;
            StringBuilder line = new StringBuilder();

            foreach (var item in prns)
            {
                line.Append(item.ToString());
                satIndex++;

                //卫星数量小于maxSatCountInLine个,且到最后一个时。
                if (satIndex == satCount && satCount < maxSatCountInLine)
                {
                    AppendObsFirstEnd(sb, firstEnd, line);
                }

                //卫星数量大于等于12,且到了12的倍数个时
                if (satIndex % maxSatCountInLine == 0)
                {
                    if (satIndex / maxSatCountInLine == 1)//第一行
                    {
                        AppendObsFirstEnd(sb, firstEnd, line);
                    }
                    else//第 1 行以后
                    {
                        AppendToString(sb, line);
                    }

                    //如果后面还有卫星,则应该换行继续。
                    if (satIndex < satCount)
                    {
                        sb.AppendLine();
                        sb.Append(StringUtil.Fill("", 32));
                    }
                }

                //最后一颗卫星,全部上缴
                if (satIndex == satCount)
                {
                    AppendToString(sb, line);
                }
            }
            //结束行
            sb.AppendLine();

            //内容部分
            var obsCodes = Header.GetObsCodesV2();

            foreach (var prn in prns)//遍历每一颗卫星
            {
                var obs = epochObs[prn];
                //一行只能记录5个,超出后换行
                int index     = 0;
                int leftCount = obsCodes.Count;
                foreach (var type in obsCodes)//遍历每一个类型 如 C1,L1
                {
                    var val = obs.TryGetObsValue(type);
                    if ((val == null || val.Value == 0) && IsUseXCodeAsPLWhenEmpty)
                    {
                        if (type == "L2")
                        {
                            val = obs.PhaseB;
                        }
                        else if (type == "P2")
                        {
                            val = obs.RangeB;
                        }
                    }


                    var str = ToRinexValueString(val);

                    sb.Append(str);
                    index++;
                    leftCount--;
                    if (index >= 5 && leftCount > 0)
                    {
                        sb.AppendLine();
                        index = 0;
                    }
                }

                sb.AppendLine();
            }

            return(sb.ToString());
        }