public void ReplaceHeader(RinexObsFileHeader header, string outPath) { using (StreamWriter writer = new StreamWriter(outPath)) { var headerStr = RinexObsFileWriter.ObsHeaderToRinexString(header, header.Version); writer.WriteLine(headerStr); using (StreamReader reader = new StreamReader(FilePath)) { string line = null; bool isContent = false; while (((line = reader.ReadLine()) != null)) { if (line.Contains(RinexHeaderLabel.END_OF_HEADER)) { isContent = true; continue; } if (isContent) { writer.WriteLine(line); } } } } }
private static void BuildCoordInfoText(RinexObsFileHeader header, StringBuilder sb) { if (header.ApproxXyz != null) { var xyz = header.ApproxXyz; var rinexApproxXyzLine = BuildApproxXyzLine(xyz); sb.AppendLine(rinexApproxXyzLine); } if (header.Hen != null) { sb.AppendLine(StringUtil.FillSpace( StringUtil.FillSpaceLeft(header.Hen.H.ToString("0.0000"), 14) + StringUtil.FillSpaceLeft(header.Hen.E.ToString("0.0000"), 14) + StringUtil.FillSpaceLeft(header.Hen.N.ToString("0.0000"), 14), 60 ) + RinexHeaderLabel.ANTENNA_DELTA_H_E_N); } if (header.AntDeltaXyz != null) { sb.AppendLine(StringUtil.FillSpace( StringUtil.FillSpaceLeft(header.AntDeltaXyz.X.ToString("0.0000"), 14) + StringUtil.FillSpaceLeft(header.AntDeltaXyz.Y.ToString("0.0000"), 14) + StringUtil.FillSpaceLeft(header.AntDeltaXyz.Z.ToString("0.0000"), 14), 60 ) + RinexHeaderLabel.ANTENNA_DELTA_XYZ); } }
private static void BuildDateTimeInfo(RinexObsFileHeader header, StringBuilder sb) { sb.AppendLine( StringUtil.FillSpace( StringUtil.FillSpaceLeft(header.StartTime.Year.ToString(), 6) + StringUtil.FillSpaceLeft(header.StartTime.Month.ToString(), 6) + StringUtil.FillSpaceLeft(header.StartTime.Day.ToString(), 6) + StringUtil.FillSpaceLeft(header.StartTime.Hour.ToString(), 6) + StringUtil.FillSpaceLeft(header.StartTime.Minute.ToString(), 6) + StringUtil.FillSpaceLeft(header.StartTime.Seconds.ToString("0.0000000"), 13) + StringUtil.FillSpaceLeft(header.TimeSystem, 8), 60) + RinexHeaderLabel.TIME_OF_FIRST_OBS); if (header.EndTime > header.StartTime && header.EndTime != Time.Default && header.EndTime != Time.MaxValue && header.EndTime != Time.MinValue) { sb.AppendLine( StringUtil.FillSpace( StringUtil.FillSpaceLeft(header.EndTime.Year.ToString(), 6) + StringUtil.FillSpaceLeft(header.EndTime.Month.ToString(), 6) + StringUtil.FillSpaceLeft(header.EndTime.Day.ToString(), 6) + StringUtil.FillSpaceLeft(header.EndTime.Hour.ToString(), 6) + StringUtil.FillSpaceLeft(header.EndTime.Minute.ToString(), 6) + StringUtil.FillSpaceLeft(header.EndTime.Seconds.ToString("0.0000000"), 13) + StringUtil.FillSpaceLeft(header.TimeSystem, 8), 60) + RinexHeaderLabel.TIME_OF_LAST_OBS); } sb.AppendLine(StringUtil.FillSpace(StringUtil.FillSpaceLeft(header.LeapSeconds, 6), 60) + RinexHeaderLabel.LEAP_SECONDS); }
private static void BuildHeaderLine(RinexObsFileHeader header, double version, StringBuilder sb) { // HeaderLabel.RINEX_VERSION_TYPE: sb.Append(StringUtil.FillSpace(StringUtil.FillSpaceLeft(version, 9), 20)); sb.Append(StringUtil.FillSpace("OBSERVATION DATA", 20)); sb.Append(StringUtil.FillSpace(header.GetSatTypeMarker().ToString(), 20)); sb.AppendLine(RinexHeaderLabel.RINEX_VERSION_TYPE); }
/// <summary> /// 写头部文件 /// </summary> /// <param name="header"></param> public void WriteHeader(RinexObsFileHeader header) { if (header == null) { return; } this.Header = header; var str = ObsHeaderToRinexString(header, Version); this.Writer.Write(str); }
private static void BuildSystemPhaseShiftText(RinexObsFileHeader header, StringBuilder sb) { var sameTypePrns = header.GetCodeSatTypedPrns(); foreach (var typeKv in sameTypePrns) { foreach (var prnKv in typeKv.Value) { var satType = typeKv.Key; int satCount = prnKv.Value.Count; var code = prnKv.Key; var val = header.GetSystemPhaseShift(prnKv.Value[0], code); StringBuilder ssb = new StringBuilder(); ssb.Append(satType); ssb.Append(" "); ssb.Append(code); ssb.Append(" "); var valStr = StringUtil.FillSpaceLeft(val.ToString("0.00000"), 8); ssb.Append(valStr); ssb.Append(" "); var satCountStr = StringUtil.FillSpaceLeft(satCount, 3); ssb.Append(satCountStr); int i = -1; foreach (var prn in prnKv.Value) { i++; if (i % 10 == 0 && i != 0) { var line = StringUtil.FillSpace(ssb.ToString(), 60) + RinexHeaderLabel.SYS_PHASE_SHIFT; sb.AppendLine(line); ssb.Clear(); ssb.Append(StringUtil.FillSpaceLeft(0, 18)); } ssb.Append(" "); ssb.Append(prn); } if (ssb.Length > 0) { var line = StringUtil.FillSpace(ssb.ToString(), 60) + RinexHeaderLabel.SYS_PHASE_SHIFT; sb.AppendLine(line); ssb.Clear(); ssb.Append(StringUtil.FillSpaceLeft(0, 18)); } } } }
/// <summary> /// 重写头部信息 /// </summary> /// <param name="header"></param> public void ReWriteHeader(RinexObsFileHeader header) { this.Dispose(); //读取 RinexObsFile obsFile = null; using (RinexObsFileReader reader = new RinexObsFileReader(this.FilePath)) { obsFile = reader.ReadObsFile(); header.ObsCodes = obsFile.Header.ObsCodes; obsFile.Header = header; } //重写 this.Writer = new StreamWriter(FilePath, false, Encoding.ASCII); this.Write(obsFile); }
public string Build(RinexObsFileHeader header) { this.StationName = header.MarkerName; this.TimeResolution = TimeUnit.Hour; this.RinexFileType = Rinex.RinexFileType.O; ContryCode = header.CountryCode; DataSource = "R"; Period = GetPeriodCode(header.TimePeriod.TimeSpan); Interval = header.Interval.ToString("00") + "S"; ContentType = header.SatTypeMarker + "O"; FileFormat = "rnx"; Compression = "crx"; IsCompression = false; return(Build(header.StartTime)); }
/// <summary> /// 获取 RINEX2.0 形式的观测码文本行。多系统情况下还需要解决。!!2015.10.28 /// </summary> /// <param name="header"></param> /// <param name="sb"></param> private static void BuildObsCodeLineRinexV2(RinexObsFileHeader header, StringBuilder sb) { List <string> obsTypes = header.GetObsCodesV2();// new List<string>(); int allSatCount = obsTypes.Count; ////每一类型卫星遍历 //foreach (var satType in header.SatelliteTypes) //{ // var types = header.GetOrInitObsCodes(satType); // obsTypes.AddRange(types); // allSatCount += types.Count; //} //第一行 StringBuilder lineSb = new StringBuilder(); lineSb.Append(StringUtil.FillSpaceRight("", 3)); //3个空格 lineSb.Append(StringUtil.FillSpaceLeft(allSatCount + "", 3)); //3 个字符 //一行最多13个 int i = 0; foreach (var valType in obsTypes) { //此处还需要做转换 var val = valType; if (val.Length == 3) { val = val.Substring(0, 2); } lineSb.Append(StringUtil.FillSpaceLeft(val, 6)); if (i % 8 == 0 && i != 0) //换行 { sb.AppendLine(StringUtil.FillSpaceRight(lineSb.ToString(), 60) + RinexHeaderLabel.TYPES_OF_OBSERV); lineSb.Clear(); lineSb.Append(StringUtil.FillSpaceLeft("", 6)); } i++; } if (lineSb.Length != 0) { sb.AppendLine(StringUtil.FillSpaceRight(lineSb.ToString(), 60) + RinexHeaderLabel.TYPES_OF_OBSERV); lineSb.Clear(); } }
private static void BuildReceiverAntennaInfoText(RinexObsFileHeader header, StringBuilder sb) { //HeaderLabel.MARKER_NAME: sb.AppendLine(StringUtil.FillSpace(header.SiteInfo.SiteName, 60) + RinexHeaderLabel.MARKER_NAME); sb.AppendLine(StringUtil.FillSpace(header.SiteInfo.MarkerNumber, 60) + RinexHeaderLabel.MARKER_NUMBER); if (header.MarkerType != null) { sb.AppendLine(StringUtil.FillSpace(header.MarkerType, 60) + RinexHeaderLabel.MARKER_TYPE); } sb.AppendLine(StringUtil.FillSpace(header.ObsInfo.ObserverAgence, 60) + RinexHeaderLabel.OBSERVER_AGENCY); sb.Append(StringUtil.FillSpace(header.SiteInfo.ReceiverNumber, 20)); sb.Append(StringUtil.FillSpace(header.SiteInfo.ReceiverType, 20)); sb.AppendLine(StringUtil.FillSpace(header.SiteInfo.ReceiverVersion, 20) + RinexHeaderLabel.REC_NUM_TYPE_VERS); sb.Append(StringUtil.FillSpace(header.SiteInfo.AntennaNumber, 20)); sb.AppendLine(StringUtil.FillSpace(header.SiteInfo.AntennaType, 40) + RinexHeaderLabel.ANT_NUM_TYPE); }
private static void BuildGlonassCodePhaseBiasText(RinexObsFileHeader header, StringBuilder sb) { int length = header.GlonassCodePhaseBias.Count; string line = ""; int i = 0; foreach (var kv in header.GlonassCodePhaseBias) { if (i % 4 == 0 && i != 0) { sb.AppendLine(StringUtil.FillSpace(line, 60) + RinexHeaderLabel.GLONASS_COD_PHS_BIS); line = ""; } line += " " + kv.Key + " " + Utils.StringUtil.FillSpaceLeft(kv.Value.ToString("0.000"), 8); i++; } if (line.Length > 1) //最后检查一次 { sb.AppendLine(StringUtil.FillSpace(line, 60) + RinexHeaderLabel.GLONASS_COD_PHS_BIS); } }
private static void BuildGlonassSlotFreqNumsText(RinexObsFileHeader header, StringBuilder sb) { int length = header.GlonassSlotFreqNums.Count; string line = Utils.StringUtil.FillSpaceLeft(length + "", 3) + " "; int i = 0; foreach (var kv in header.GlonassSlotFreqNums) { if (i % 8 == 0 && i != 0) { sb.AppendLine(StringUtil.FillSpace(line, 60) + RinexHeaderLabel.GLONASS_SLOT_FRQ); line = " "; } line += kv.Key + " " + Utils.StringUtil.FillSpaceLeft(kv.Value, 2) + " ";//3 + 1 + 2 + 1 i++; } if (line.Length > 4)//最后检查一次 { sb.AppendLine(StringUtil.FillSpace(line, 60) + RinexHeaderLabel.GLONASS_SLOT_FRQ); } }
private static void BuildObsCodeLineRinexV3(RinexObsFileHeader header, StringBuilder sb) { //每一类型卫星遍历 foreach (var satType in header.SatelliteTypes) { //第一行 var types = header.GetOrInitObsCodes(satType); StringBuilder lineSb = new StringBuilder(); lineSb.Append(StringUtil.FillSpaceRight(satType.ToString(), 3)); var count = types.Count; lineSb.Append(StringUtil.FillSpaceLeft(count + "", 3)); double lineCount = Math.Ceiling(count / 13.0d); //一行最多13个 int i = 0; foreach (var valType in types) { //此处还需要做转换 var val = new ObservationCode(valType).GetRinexCode(3); lineSb.Append(StringUtil.FillSpaceLeft(val, 4)); i++; if (i % 13 == 0 && i != 0) { sb.AppendLine(StringUtil.FillSpaceRight(lineSb.ToString(), 60) + RinexHeaderLabel.SYS_OBS_TYPES); lineSb.Clear(); lineSb.Append(StringUtil.FillSpaceLeft("", 6)); } } if (lineSb.Length != 0) { sb.AppendLine(StringUtil.FillSpaceRight(lineSb.ToString(), 60) + RinexHeaderLabel.SYS_OBS_TYPES); lineSb.Clear(); } } }
/// <summary> /// RINEX文件的头文件。 /// </summary> /// <param name="header">头部文件</param> /// <param name="version">版本</param> /// <returns></returns> public static string ObsHeaderToRinexString(RinexObsFileHeader header, double version) { StringBuilder sb = new StringBuilder(); BuildHeaderLine(header, version, sb); // return ""; // HeaderLabel.PGM_RUN_BY_DATE: BuildProgramRunByDateLine(sb); // HeaderLabel.COMMENT: sb.AppendLine(BuildGnsserCommentLines()); foreach (var item in header.Comments) { if (item.Contains("Gnsser")) { continue; } //不重复写Gnsser信息。 if (String.IsNullOrWhiteSpace(item)) { continue; } sb.AppendLine(StringUtil.FillSpace(item, 60) + RinexHeaderLabel.COMMENT); } BuildReceiverAntennaInfoText(header, sb); BuildCoordInfoText(header, sb); if (version >= 3) { BuildObsCodeLineRinexV3(header, sb); } else { BuildObsCodeLineRinexV2(header, sb); } sb.AppendLine(StringUtil.FillSpace( StringUtil.FillSpaceLeft(header.Interval.ToString("0.000"), 10), 60) + RinexHeaderLabel.INTERVAL); BuildDateTimeInfo(header, sb); //SYS / PHASE SHIFT if (header.SystemPhaseShift != null && header.SystemPhaseShift.Count > 0) { BuildSystemPhaseShiftText(header, sb); } //RINEX 3.3 if (header.GlonassSlotFreqNums != null && header.GlonassSlotFreqNums.Count > 0) { BuildGlonassSlotFreqNumsText(header, sb); } //GLONASS_COD_PHS_BIS // C1C 0.000 C1P 0.000 C2C 0.000 C2P 0.000 GLONASS COD/PHS/BIS if (header.GlonassCodePhaseBias != null && header.GlonassCodePhaseBias.Count > 0) { BuildGlonassCodePhaseBiasText(header, sb); } //end header sb.AppendLine(StringUtil.FillSpace("", 60) + RinexHeaderLabel.END_OF_HEADER); return(sb.ToString()); }