Example #1
0
 private void rinexToEphToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         string fileName = dialog.FileName;
         int length = fileName.LastIndexOf('.');
         fileName.Substring(0, length);
         string path = fileName.Substring(0, length) + ".ai3eph";
         StreamWriter writer = new StreamWriter(path);
         try
         {
             RinexFile file = new RinexFile();
             file.Read(fileName);
             int year = file.Year;
             int month = file.Month;
             int day = file.Day;
             int hour = file.Hour;
             int minute = file.Minute;
             int second = file.Second;
             for (int i = 0; i < 0x18; i += 2)
             {
                 DateTime inTime = new DateTime(year, month, day, i, 0, 0);
                 GPSDateTime time2 = new GPSDateTime();
                 time2.SetUTCOffset(0);
                 time2.SetTime(inTime);
                 int gPSTOW = (int) time2.GetGPSTOW();
                 int num7 = gPSTOW + (time2.GetGPSWeek() * 0x93a80);
                 string str3 = string.Format("// Hour {0:D2}-{1:D2}\r\n", i, i + 2) + "// Ephemeris Collection Time(UTC): ";
                 string str4 = string.Format("{0:ddd MMM dd HH:mm:ss yyyy}", inTime);
                 str3 = str3 + str4 + "\r\n*********** Ephemeris Data at GPS time: ";
                 string str5 = num7.ToString();
                 str3 = str3 + str5 + "***********\r\n//\r\n//";
                 writer.WriteLine(str3);
                 for (byte j = 1; j <= 0x20; j = (byte) (j + 1))
                 {
                     RinexEph eph = file.SearchRinexArrayList(j, gPSTOW + file.UTCOffset);
                     if (eph != null)
                     {
                         string str6 = string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23},", new object[] {
                             eph.svid, eph.ura_ind, (byte) eph.iode, (short) (eph.Crs * Math.Pow(2.0, 5.0)), (short) (eph.deltan * Math.Pow(2.0, 43.0)), (int) (eph.m0 * Math.Pow(2.0, 31.0)), (short) (eph.Cuc * Math.Pow(2.0, 29.0)), (uint) (eph.ecc * Math.Pow(2.0, 33.0)), (short) (eph.Cus * Math.Pow(2.0, 29.0)), (uint) (eph.sqrta * Math.Pow(2.0, 19.0)), (ushort) (eph.toe * Math.Pow(2.0, -4.0)), (short) (eph.Cic * Math.Pow(2.0, 29.0)), (int) (eph.omega0 * Math.Pow(2.0, 31.0)), (short) (eph.Cis * Math.Pow(2.0, 29.0)), (int) (eph.i0 * Math.Pow(2.0, 31.0)), (short) (eph.Crc * Math.Pow(2.0, 5.0)),
                             (int) (eph.omega * Math.Pow(2.0, 31.0)), (int) (eph.omegaDot * Math.Pow(2.0, 43.0)), (short) (eph.idot * Math.Pow(2.0, 43.0)), (ushort) (eph.toc * Math.Pow(2.0, -4.0)), (sbyte) (eph.tgd * Math.Pow(2.0, 31.0)), (sbyte) (eph.af2 * Math.Pow(2.0, 55.0)), (short) (eph.af1 * Math.Pow(2.0, 43.0)), (int) (eph.af0 * Math.Pow(2.0, 31.0))
                          });
                         writer.WriteLine(str6);
                     }
                 }
                 writer.WriteLine("");
             }
             writer.Close();
             MessageBox.Show("Conversion is complete and file saved as: " + path, "File Conversion Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         catch (Exception exception)
         {
             MessageBox.Show("Exception in Rinex to ai3eph file conversion: " + exception.ToString());
         }
     }
 }