1. be able to calculate the sat pos of BDS & Galileo
2. be able to Single postiting by GPS & Galileo
This commit is contained in:
KenanZhu111 committed 2024-10-14 21:24:01 +08:00
1 parent f29614d834
commit aba6c009ab
13 files changed
+1725 -842

No files matched your search

+19 -26
View File
@@ -46,7 +46,7 @@ char nav_f[MAX_PATH] = { 0 };
char path[MAX_PATH]; char path[MAX_PATH];
const wchar_t wpath[MAX_PATH];//PROGRAM'S FOLDER const wchar_t wpath[MAX_PATH];//PROGRAM'S FOLDER
static void ProgressBar(HWND hwnd, int BEG, int DES) static void ProgressBar(HWND hwnd, int BEG, int DES)//PROGRESS BAR FUNCTION
{ {
PBRANGE range; PBRANGE range;
SendMessage(hwnd, PBM_SETRANGE, (WPARAM)FALSE, (LPARAM)(MAKELPARAM(0, 100))); SendMessage(hwnd, PBM_SETRANGE, (WPARAM)FALSE, (LPARAM)(MAKELPARAM(0, 100)));
@@ -200,6 +200,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
TCHAR* SATSYS[5] = { TEXT("GPS"),TEXT("GLO"),TEXT("BeiDou"),TEXT("Galileo"),TEXT("SBAS") }; TCHAR* SATSYS[5] = { TEXT("GPS"),TEXT("GLO"),TEXT("BeiDou"),TEXT("Galileo"),TEXT("SBAS") };
static HWND hwndPB; static HWND hwndPB;
static int cxchar, cychar; static int cxchar, cychar;
static int gnssencode;//GNSS SET STATE CODE
switch (msg) { switch (msg) {
@@ -216,8 +217,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
InitCommonControls(); InitCommonControls();
hwndPB = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE, hwndPB = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE,
0.5 * cxchar, 12.25 * cychar, 0.5 * cxchar, 12.5 * cychar,
47 * cxchar, 1 * cychar, 47 * cxchar, 3 * cychar/4,
hwnd, (HMENU)PROGRESS, ((LPCREATESTRUCT)lParam)->hInstance, NULL); hwnd, (HMENU)PROGRESS, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//CREATE THE BUTTONS //CREATE THE BUTTONS
@@ -305,7 +306,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
{ {
read_o_h(fp_obs, obs_h); read_o_h(fp_obs, obs_h);
ProgressBar(hwndPB, PBSTATENONE, PBSTATEHALF); ProgressBar(hwndPB, PBSTATENONE, PBSTATEHALF);
read_o_b(fp_obs, obs_e, obs_b, obs_h->obstypenum_gps, obs_h->obstypenum_bds); read_o_b(fp_obs, obs_e, obs_b, obs_h);
} }
fclose(fp_obs); fclose(fp_obs);
@@ -421,37 +422,29 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
int ALLSTATE = 0x0000; int ALLSTATE = 0x0000;
for (int i = 0; i < 5; i++){ALLSTATE += SendMessage(hwndb[i + 5], BM_GETCHECK, wParam, lParam);} for (int i = 0; i < 5; i++){ALLSTATE += SendMessage(hwndb[i + 5], BM_GETCHECK, wParam, lParam);}
if (ALLSTATE == 0x0000) if (ALLSTATE == 0x0000)
{ while (MessageBox(hwnd, TEXT("No GNSS is choosen\nPlease Retry"), TEXT("STOP"), MB_ICONERROR | MB_RETRYCANCEL) == IDRETRY)
{ {
while (MessageBox(hwnd, TEXT("No GNSS is choosen\nPlease Retry"), TEXT("STOP"), MB_ICONERROR | MB_RETRYCANCEL) == IDRETRY) break;}}
{
break;
}
}
else else
{ { FileSaveDialog(wres_file);
FileSaveDialog(wres_file);
wcstombs(res_file, wres_file, MAX_PATH); wcstombs(res_file, wres_file, MAX_PATH);
if (res_file[0] == '\0') if (res_file[0] == '\0')
{ { while (MessageBox(hwnd, TEXT("Failed to select a save path.\nThe data has been cleared !"), TEXT("WARNING"), MB_ICONWARNING | MB_OK) == IDOK)
while (MessageBox(hwnd, TEXT("Failed to select a save path.\nThe data has been cleared !"), TEXT("WARNING"), MB_ICONWARNING | MB_OK) == IDOK) { break;}}
{
break;
}
}
else
{
if (SendMessage(hwndb[5], BM_GETCHECK, wParam, lParam) == BST_CHECKED)
{
sat_gps_pos_clac(result_file, hwndPB, else
{ gnssencode = pow(GPS, SendMessage(hwndb[5], BM_GETCHECK, wParam, lParam))
* pow(GLO, SendMessage(hwndb[6], BM_GETCHECK, wParam, lParam))
* pow(BDS, SendMessage(hwndb[7], BM_GETCHECK, wParam, lParam))
* pow(GAL, SendMessage(hwndb[8], BM_GETCHECK, wParam, lParam))
* pow(SBAS, SendMessage(hwndb[9], BM_GETCHECK, wParam, lParam));
sat_pos_clac(result_file, hwndPB,
nav_b, obs_e, obs_b, obs_h, nav_b, obs_e, obs_b, obs_h,
o_epochnum, satnum, o_epochnum, satnum, gnssencode,
res_file, obs_f, nav_f, res_file, obs_f, nav_f,
ionoption, trooption); ionoption, trooption);
}
} }
free(obs_h); free(obs_e); free(obs_b); free(nav_h); free(nav_b); free(obs_h); free(obs_e); free(obs_b); free(nav_h); free(nav_b);
fp_nav = NULL; fp_obs = NULL; result_file = NULL; fp_nav = NULL; fp_obs = NULL; result_file = NULL;
+9 -9
View File
@@ -2,16 +2,16 @@
#define _2GPST_H_ #define _2GPST_H_
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将世界协调时转换为GPS周内秒 /// @brief convert UTC to GPS Second of week
/// @param y 年 /// @param y year
/// @param m 月 /// @param m month
/// @param d 日 /// @param d day
/// @param h 时 /// @param h hour
/// @param min 分 /// @param min minute
/// @param sec 秒 /// @param sec second
/// @return 返回GPS周内秒 /// @return return GPS Second of week
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
double Time2GPSsec(int y, int m, int d, double h, int min, double sec) double Time2Weeksec(int y, int m, int d, double h, int min, double sec)
{ {
if (m > 2) if (m > 2)
{ {
+8 -9
View File
@@ -10,16 +10,15 @@ typedef struct
double N; double N;
double U; double U;
}blh2enu; }blh2enu;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将大地高坐标转换为站心坐标 /// @brief convert BLH coordinates to ENU coordinates
/// @param blh2enu 自定义结构体类型用来传参 /// @param blh2enu parameter transfer structure
/// @param stationB 站心纬度 /// @param stationB latitude of receiver station
/// @param stationL 站心经度 /// @param stationL longitude of receiver station
/// @param deltax 卫星到站心的x坐标差值 /// @param deltax X-coordinate difference of satellite arrival center
/// @param deltay 卫星到站心的y坐标差值 /// @param deltay Y-coordinate difference of satellite arrival center
/// @param deltaz 卫星到站心的z坐标差值 /// @param deltaz Z-coordinate difference of satellite arrival center
/// @return 返回自定义结构体类型包含E, N, U成员 /// @return return type of structure contain E, N, U members
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
blh2enu BLH2ENU(blh2enu blh2enu, blh2enu BLH2ENU(blh2enu blh2enu,
double stationB, double stationL, double stationB, double stationL,
+343 -65
View File
@@ -17,59 +17,187 @@
#include"type2code.h" #include"type2code.h"
#include"select_epo.h" #include"select_epo.h"
/* ------------------------------- GPS卫星位置计算函数 ------------------------------ */ /* -------------------- GPS Satellite position calculate -------------------- */
pos_ts gps_pos(int sPRN, int best_epoch, double GPSsec, pos_ts gps_pos(int sPRN, int best_epoch, double GPSsec,
pnav_body nav_b, pobs_head obs_h, pos_ts pos_t) pnav_body nav_b, pobs_head obs_h, pos_ts pos_t)
{ { double T_S = GPSsec - pos_t.delta_t;
double T_S = GPSsec - pos_t.delta_t[sPRN];//计算信号发射时刻
double n_0 = sqrt(GM) / pow(nav_b[best_epoch].sqrtA,3); double n_0 = sqrt(GM) / pow(nav_b[best_epoch].sqrtA,3);
double n = n_0 + nav_b[best_epoch].deltan; //计算卫星运行平均角速度 double n = n_0 + nav_b[best_epoch].deltan;
double tk = T_S - nav_b[best_epoch].TOE;//计算归化时间 double tk = T_S - nav_b[best_epoch].TOE;
if (tk > 32400)tk -= 604800; if (tk > 32400)tk -= 604800;
else if (tk < -32400)tk += 604800;//归化时间改正 else if (tk < -32400)tk += 604800;
double Ms = nav_b[best_epoch].M0 + n * tk;//计算卫星发射时卫星的平近角M
double Es = Ms, E0;//迭代计算偏近点角 double Ms = nav_b[best_epoch].M0 + n * tk;
double Es = Ms, E0;
do do
{ {
E0 = Es; E0 = Es;
Es = Ms + nav_b[best_epoch].e * sin(Es); Es = Ms + nav_b[best_epoch].e * sin(Es);
} while (fabs(Es - E0) > 1.0e-5);//迭代计算偏近点角 } while (fabs(Es - E0) > 1.0e-10);
//计算真近点角
double cosfs = (cos(Es) - nav_b[best_epoch].e) / (1 - nav_b[best_epoch].e * cos(Es)); double cosfs = (cos(Es) - nav_b[best_epoch].e) / (1 - nav_b[best_epoch].e * cos(Es));
double sinfs = (sqrt(1 - pow(nav_b[best_epoch].e, 2)) * sin(Es)) / (1 - nav_b[best_epoch].e * cos(Es)); double sinfs = (sqrt(1 - pow(nav_b[best_epoch].e, 2)) * sin(Es)) / (1 - nav_b[best_epoch].e * cos(Es));
double fs = atan2(sinfs, cosfs); double fs = atan2(sinfs, cosfs);
double u0 = fs + nav_b[best_epoch].omega;//计算升交角距 double u0 = fs + nav_b[best_epoch].omega;
//计算摄动改正项
double epsilon_u = nav_b[best_epoch].Cus * sin(2 * u0) + nav_b[best_epoch].Cuc * cos(2 * u0); double epsilon_u = nav_b[best_epoch].Cus * sin(2 * u0) + nav_b[best_epoch].Cuc * cos(2 * u0);
double epsilon_r = nav_b[best_epoch].Crs * sin(2 * u0) + nav_b[best_epoch].Crc * cos(2 * u0); double epsilon_r = nav_b[best_epoch].Crs * sin(2 * u0) + nav_b[best_epoch].Crc * cos(2 * u0);
double epsilon_i = nav_b[best_epoch].Cis * sin(2 * u0) + nav_b[best_epoch].Cic * cos(2 * u0); double epsilon_i = nav_b[best_epoch].Cis * sin(2 * u0) + nav_b[best_epoch].Cic * cos(2 * u0);
double u = u0 + epsilon_u;//改正后的升交角距
double r = pow(nav_b[best_epoch].sqrtA, 2) * (1 - nav_b[best_epoch].e * cos(Es)) + epsilon_r;//改正后的轨道向径 double u = u0 + epsilon_u;
double i = nav_b[best_epoch].i0 + epsilon_i + nav_b[best_epoch].IDOT * tk;//改正后的轨道倾角 double r = pow(nav_b[best_epoch].sqrtA, 2) * (1 - nav_b[best_epoch].e * cos(Es)) + epsilon_r;
double i = nav_b[best_epoch].i0 + epsilon_i + nav_b[best_epoch].IDOT * tk;
double x = r * cos(u); double x = r * cos(u);
double y = r * sin(u);//卫星在轨道平面坐标系中的坐标 double y = r * sin(u);
double l = nav_b[best_epoch].OMEGA + (nav_b[best_epoch].deltaomega - Earth_e) * tk - Earth_e * nav_b[best_epoch].TOE; double l = nav_b[best_epoch].OMEGA + (nav_b[best_epoch].deltaomega - Earth_e) * tk - Earth_e * nav_b[best_epoch].TOE;
//计算升交点经度
double X = x * cos(l) - y * cos(i) * sin(l); double X = x * cos(l) - y * cos(i) * sin(l);
double Y = x * sin(l) + y * cos(i) * cos(l); double Y = x * sin(l) + y * cos(i) * cos(l);
double Z = y * sin(i);//卫星在地固系下的直角坐标 double Z = y * sin(i);
pos_t.X[sPRN] = cos(Earth_e * pos_t.delta_t[sPRN]) * X + sin(Earth_e * pos_t.delta_t[sPRN]) * Y;
pos_t.Y[sPRN] = -sin(Earth_e * pos_t.delta_t[sPRN]) * X + cos(Earth_e * pos_t.delta_t[sPRN]) * Y; pos_t.X = cos(Earth_e * pos_t.delta_t) * X + sin(Earth_e * pos_t.delta_t) * Y;
pos_t.Z[sPRN] = Z; pos_t.Y = -sin(Earth_e * pos_t.delta_t) * X + cos(Earth_e * pos_t.delta_t) * Y;
double R = sqrt(pow(pos_t.X[sPRN] - obs_h->apX, 2) + pow(pos_t.Y[sPRN] - obs_h->apY, 2) + pow(pos_t.Z[sPRN] - obs_h->apZ, 2)); pos_t.Z = Z;//Correction of earth rotation
pos_t.deltat[sPRN] = pos_t.delta_t[sPRN];
double rela = 2*sqrt(GM) * nav_b[best_epoch].e * nav_b[best_epoch].sqrtA * sin(Es)/pow(C_V,2); double R = sqrt(pow(pos_t.X - obs_h->apX, 2) + pow(pos_t.Y - obs_h->apY, 2) + pow(pos_t.Z - obs_h->apZ, 2));
pos_t.delta_clk[sPRN] = nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * tk + nav_b[best_epoch].sa2 * pow(tk,2) - rela; pos_t.deltat = pos_t.delta_t;
pos_t.delta_t[sPRN] = R / C_V + pos_t.delta_clk[sPRN]; double rela = 2*sqrt(GM) * nav_b[best_epoch].e * nav_b[best_epoch].sqrtA * sin(Es)/pow(C_V,2);//Relativistic effect
return pos_t; pos_t.delta_clk = nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * tk + nav_b[best_epoch].sa2 * pow(tk,2) - rela - nav_b[best_epoch].TGD;
} pos_t.delta_t = R / C_V + pos_t.delta_clk;
/* -------------------------------------------------------------------------- */
return pos_t;}
/* ------------------------------- GPS卫星位置计算&输出 ------------------------------ */ /* -------------------- GAL Satellite position calculate -------------------- */
void sat_gps_pos_clac(FILE* result_file,HWND hwndPB, pos_ts gal_pos(int sPRN, int best_epoch, double GALsec,
pnav_body nav_b, pobs_head obs_h, pos_ts pos_t)
{ double T_S = GALsec - pos_t.delta_t;
double n_0 = sqrt(GM) / pow(nav_b[best_epoch].sqrtA, 3);
double n = n_0 + nav_b[best_epoch].deltan;
double tk = T_S - nav_b[best_epoch].TOE;
if (tk > 32400)tk -= 604800;
else if (tk < -32400)tk += 604800;
double Ms = nav_b[best_epoch].M0 + n * tk;
double Es = Ms, E0;
do
{
E0 = Es;
Es = Ms + nav_b[best_epoch].e * sin(Es);
} while (fabs(Es - E0) > 1.0e-10);
double cosfs = (cos(Es) - nav_b[best_epoch].e) / (1 - nav_b[best_epoch].e * cos(Es));
double sinfs = (sqrt(1 - pow(nav_b[best_epoch].e, 2)) * sin(Es)) / (1 - nav_b[best_epoch].e * cos(Es));
double fs = atan2(sinfs, cosfs);
double u0 = fs + nav_b[best_epoch].omega;
double epsilon_u = nav_b[best_epoch].Cus * sin(2 * u0) + nav_b[best_epoch].Cuc * cos(2 * u0);
double epsilon_r = nav_b[best_epoch].Crs * sin(2 * u0) + nav_b[best_epoch].Crc * cos(2 * u0);
double epsilon_i = nav_b[best_epoch].Cis * sin(2 * u0) + nav_b[best_epoch].Cic * cos(2 * u0);
double u = u0 + epsilon_u;
double r = pow(nav_b[best_epoch].sqrtA, 2) * (1 - nav_b[best_epoch].e * cos(Es)) + epsilon_r;
double i = nav_b[best_epoch].i0 + epsilon_i + nav_b[best_epoch].IDOT * tk;
double x = r * cos(u);
double y = r * sin(u);
double l = nav_b[best_epoch].OMEGA + (nav_b[best_epoch].deltaomega - Earth_e) * tk - Earth_e * nav_b[best_epoch].TOE;
double X = x * cos(l) - y * cos(i) * sin(l);
double Y = x * sin(l) + y * cos(i) * cos(l);
double Z = y * sin(i);
pos_t.X = cos(Earth_e * pos_t.delta_t) * X + sin(Earth_e * pos_t.delta_t) * Y;
pos_t.Y = -sin(Earth_e * pos_t.delta_t) * X + cos(Earth_e * pos_t.delta_t) * Y;
pos_t.Z = Z;//Correction of earth rotation
double R = sqrt(pow(pos_t.X - obs_h->apX, 2) + pow(pos_t.Y - obs_h->apY, 2) + pow(pos_t.Z - obs_h->apZ, 2));
pos_t.deltat = pos_t.delta_t;
double rela = 2 * sqrt(GM) * nav_b[best_epoch].e * nav_b[best_epoch].sqrtA * sin(Es) / pow(C_V, 2);//Relativistic effect
pos_t.delta_clk = nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * tk + nav_b[best_epoch].sa2 * pow(tk, 2) - rela - nav_b[best_epoch].BGDa;
pos_t.delta_t = R / C_V + pos_t.delta_clk;
return pos_t;}
/* -------------------- BDS Satellite position calculate -------------------- */
pos_ts bds_pos(int sPRN, int best_epoch, double BDSsec,
pnav_body nav_b, pobs_head obs_h, pos_ts pos_t)
{ double T_S = BDSsec - pos_t.delta_t;
double n_0 = sqrt(GM) / pow(nav_b[best_epoch].sqrtA, 3);
double n = n_0 + nav_b[best_epoch].deltan;
double tk = T_S - nav_b[best_epoch].TOE - 14;
if (tk > 32400)tk -= 604800;
else if (tk < -32400)tk += 604800;
double Ms = nav_b[best_epoch].M0 + n * tk;
double Es = Ms, E0;
do
{
E0 = Es;
Es = Ms + nav_b[best_epoch].e * sin(Es);
} while (fabs(Es - E0) > 1.0e-10);
double cosfs = (cos(Es) - nav_b[best_epoch].e) / (1 - nav_b[best_epoch].e * cos(Es));
double sinfs = (sqrt(1 - pow(nav_b[best_epoch].e, 2)) * sin(Es)) / (1 - nav_b[best_epoch].e * cos(Es));
double fs = atan2(sinfs, cosfs);
double u0 = fs + nav_b[best_epoch].omega;
double epsilon_u = nav_b[best_epoch].Cus * sin(2 * u0) + nav_b[best_epoch].Cuc * cos(2 * u0);
double epsilon_r = nav_b[best_epoch].Crs * sin(2 * u0) + nav_b[best_epoch].Crc * cos(2 * u0);
double epsilon_i = nav_b[best_epoch].Cis * sin(2 * u0) + nav_b[best_epoch].Cic * cos(2 * u0);
double u = u0 + epsilon_u;
double r = pow(nav_b[best_epoch].sqrtA, 2) * (1 - nav_b[best_epoch].e * cos(Es)) + epsilon_r;
double i = nav_b[best_epoch].i0 + epsilon_i + nav_b[best_epoch].IDOT * tk;
double x = r * cos(u);
double y = r * sin(u);
double l, X, Y, Z;
if (sPRN > 5 && sPRN < 59) //BDS IGSO & MEO Satellites
{
l = nav_b[best_epoch].OMEGA + (nav_b[best_epoch].deltaomega - Earth_e) * tk - Earth_e * nav_b[best_epoch].TOE;
X = x * cos(l) - y * cos(i) * sin(l);
Y = x * sin(l) + y * cos(i) * cos(l);
Z = y * sin(i);}
else // BDS GEO Satellites
{
l = nav_b[best_epoch].OMEGA + nav_b[best_epoch].deltaomega * tk - Earth_e * nav_b[best_epoch].TOE;
X = x * cos(l) - y * cos(i) * sin(l);
Y = x * sin(l) + y * cos(i) * cos(l);
Z = y * sin(i);
double f = deg2rad(-5);
double p = Earth_e * tk;
X = X * cos(p) + Y * sin(p) * cos(f) + Z * sin(p) * sin(f);
Y = X * -sin(p) + Y * cos(p) * cos(f) + Z * cos(p) * sin(f);
Z = Y * -sin(f) + Z * cos(f);}
pos_t.X = cos(Earth_e * pos_t.delta_t) * X + sin(Earth_e * pos_t.delta_t) * Y;
pos_t.Y = -sin(Earth_e * pos_t.delta_t) * X + cos(Earth_e * pos_t.delta_t) * Y;
pos_t.Z = Z;//Correction of earth rotation
double rela = 2 * sqrt(GM) * nav_b[best_epoch].e * nav_b[best_epoch].sqrtA * sin(Es) / pow(C_V, 2);//Relativistic effect
pos_t.delta_clk = nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * tk + nav_b[best_epoch].sa2 * pow(tk, 2) - rela;
double R = sqrt(pow(pos_t.X - obs_h->apX, 2) + pow(pos_t.Y - obs_h->apY, 2) + pow(pos_t.Z - obs_h->apZ, 2));
pos_t.deltat = pos_t.delta_t;
pos_t.delta_t = R / C_V + pos_t.delta_clk;
return pos_t;}
/* -------------------------------- Satellite position calculate & Output -------------------------------- */
void sat_pos_clac(FILE* result_file,HWND hwndPB,
pnav_body nav_b, pobs_epoch obs_e, pobs_body obs_b,pobs_head obs_h, pnav_body nav_b, pobs_epoch obs_e, pobs_body obs_b,pobs_head obs_h,
int o_epochnum, int satnum, int o_epochnum, int satnum, int gnssdecode,
char res_file[MAX_PATH], char obs_file[MAX_PATH], char nav_file[MAX_PATH], char res_file[MAX_PATH], char obs_file[MAX_PATH], char nav_file[MAX_PATH],
int ionoption, int trooption) int ionoption, int trooption)
{ {
@@ -77,18 +205,16 @@ void sat_gps_pos_clac(FILE* result_file,HWND hwndPB,
SendMessage(hwndPB, PBM_SETRANGE, (WPARAM)FALSE, (LPARAM)(MAKELPARAM(0, 100))); SendMessage(hwndPB, PBM_SETRANGE, (WPARAM)FALSE, (LPARAM)(MAKELPARAM(0, 100)));
SendMessage(hwndPB, PBM_GETRANGE, (WPARAM)TRUE, (LPARAM)&range); SendMessage(hwndPB, PBM_GETRANGE, (WPARAM)TRUE, (LPARAM)&range);
time_t gen_time; time_t gen_time;time(&gen_time);stations station = { 0 };xyz2blh tem2 = { 0 };
time(&gen_time);
stations station = { 0 };
xyz2blh tem2 = { 0 };
tem2 = XYZ2BLH(tem2, obs_h->apX, obs_h->apY, obs_h->apZ); tem2 = XYZ2BLH(tem2, obs_h->apX, obs_h->apY, obs_h->apZ);
station.B = tem2.B; station.B = tem2.B;
station.L = tem2.L; station.L = tem2.L;
station.H = tem2.H; station.H = tem2.H;
result_file = fopen(res_file, "w"); result_file = fopen(res_file, "w");
fclose(result_file); fclose(result_file);
result_file = fopen(res_file, "a+"); result_file = fopen(res_file, "a+");
fprintf(result_file, "@ GENERATE PROGRAM : KNZ_Calculate v0.9.7\n"); fprintf(result_file, "@ GENERATE PROGRAM : KNZ_Calculate v1.2.2\n");
fprintf(result_file, "@ GENERATE TYPE : Satellite Position\n"); fprintf(result_file, "@ GENERATE TYPE : Satellite Position\n");
fprintf(result_file, "@ GENERATE TIME : %s", ctime(&gen_time)); fprintf(result_file, "@ GENERATE TIME : %s", ctime(&gen_time));
fprintf(result_file, "@ OBS FILE PATH : %s\n", obs_file); fprintf(result_file, "@ OBS FILE PATH : %s\n", obs_file);
@@ -100,18 +226,20 @@ void sat_gps_pos_clac(FILE* result_file,HWND hwndPB,
fprintf(result_file, "@ APPROX POSITION XYZ: %13.04f%13.04f%13.04f\n@ APPROX POSITION BLH: %12.07f %12.07f %12.07f\n" fprintf(result_file, "@ APPROX POSITION XYZ: %13.04f%13.04f%13.04f\n@ APPROX POSITION BLH: %12.07f %12.07f %12.07f\n"
, obs_h->apX, obs_h->apY, obs_h->apZ , obs_h->apX, obs_h->apY, obs_h->apZ
, station.B, station.L, station.H); , station.B, station.L, station.H);
if (ionoption == 0) { fprintf(result_file, "@ IONOS OPT : NULL\n"); } if (ionoption == 0) { fprintf(result_file, "@ IONOS OPT : NULL\n"); }
if (ionoption == 1) { fprintf(result_file, "@ IONOS OPT : DEFAULT\n"); } if (ionoption == 1) { fprintf(result_file, "@ IONOS OPT : DEFAULT\n"); }
if (trooption == 0) { fprintf(result_file, "@ TROPO OPT : NULL\n@\n\n"); } if (trooption == 0) { fprintf(result_file, "@ TROPO OPT : NULL\n@\n\n"); }
if (trooption == 1) { fprintf(result_file, "@ TROPO OPT : DEFAULT\n@\n\n"); } if (trooption == 1) { fprintf(result_file, "@ TROPO OPT : DEFAULT\n@\n\n"); }
fclose(result_file); fclose(result_file);
double beginsec = Time2GPSsec(obs_h->f_y, obs_h->f_m, obs_h->f_d, obs_h->f_h, obs_h->f_min, obs_h->f_sec); //the beginning second of observation
double endinsec = Time2GPSsec(obs_h->l_y, obs_h->l_m, obs_h->l_d, obs_h->l_h, obs_h->l_min, obs_h->l_sec); double beginsec = Time2Weeksec(obs_h->f_y, obs_h->f_m, obs_h->f_d, obs_h->f_h, obs_h->f_min, obs_h->f_sec);
//the ending second of observation
double endinsec = Time2Weeksec(obs_h->l_y, obs_h->l_m, obs_h->l_d, obs_h->l_h, obs_h->l_min, obs_h->l_sec);
for (int i = 0; i < o_epochnum; i++) for (int i = 0; i < o_epochnum; i++)
{ { int y = obs_e[i].y;
int y = obs_e[i].y;
int m = obs_e[i].m; int m = obs_e[i].m;
int d = obs_e[i].d; int d = obs_e[i].d;
double h = obs_e[i].h; double h = obs_e[i].h;
@@ -129,55 +257,60 @@ void sat_gps_pos_clac(FILE* result_file,HWND hwndPB,
rahs rah = { 0 }; rahs rah = { 0 };
pos_ts pos_t = { 0 }; pos_ts pos_t = { 0 };
double GPSsec = Time2GPSsec(y, m, d, h, min, sec);//转换为GPS周内秒 double Weeksec = Time2Weeksec(y, m, d, h, min, sec);
int epochsignal = round((GPSsec - beginsec) / obs_h->interval) + 1; int epochcount = round((Weeksec - beginsec) / obs_h->interval) + 1;
result_file = fopen(res_file, "a+"); result_file = fopen(res_file, "a+");
fprintf(result_file, "\n>%04d %04d %02d %02d %02d %02d %07.04f" fprintf(result_file, "\n>%04d %04d %02d %02d %02d %02d %07.04f"
, epochsignal, obs_e[i].y, obs_e[i].m, obs_e[i].d, obs_e[i].h, obs_e[i].min, obs_e[i].sec); , epochcount, obs_e[i].y, obs_e[i].m, obs_e[i].d, obs_e[i].h, obs_e[i].min, obs_e[i].sec);
fclose(result_file); fclose(result_file);
for (int j = 0; j < obs_e[i].gps_num; j++)//第j颗GPS卫星 if (gnssdecode % GPS == 0)//Be judged as GPS
{
for (int j = 0; j < obs_e[i].gps_num; j++)
{ {
int sPRN = obs_e[i].sPRN_GPS[j]; int sPRN = obs_e[i].sPRN_GPS[j];
int best_epoch = select_epoch(GPSsec, sPRN, nav_b, satnum, GPS); //遍历N文件GPS卫星数据块,寻找最佳历元 int best_epoch = select_epoch(Weeksec, sPRN, nav_b, satnum, GPS);
double detat_toc = GPSsec - nav_b[best_epoch].TOE;//观测时刻 - 参考时刻
//计算近似的信号传播时间,接收机钟差已初始化为0(伪距/光速-接收机钟差+卫星钟差)
pos_t.delta_t[sPRN] = (obs_b[i].obs_gps[j][Code2Type(C1C, obs_h->obstypenum_gps, obs_h->obscode_gps)] / C_V) - station.delta_TR + nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * detat_toc + nav_b[best_epoch].sa2 * pow(detat_toc, 2);
pos_t.deltat[sPRN] = 0.0;//判断收敛
while (fabs(pos_t.delta_t[sPRN] - pos_t.deltat[sPRN]) > 1.0e-9) {
pos_t = gps_pos(sPRN, best_epoch, GPSsec, nav_b, obs_h, pos_t); if (best_epoch == -1)//when the sPRN is not exist func will return -1
break;
double detat_toc = Weeksec - nav_b[best_epoch].TOE;
//Iterative approximate propagation time
pos_t.delta_t = (obs_b[i].obs_gps[j][Code2Type(C1C, obs_h->obstypenum_gps, obs_h->obscode_gps)] / C_V)
- station.delta_TR + nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * detat_toc + nav_b[best_epoch].sa2 * pow(detat_toc, 2);
pos_t.deltat = 0.0;
while (fabs(pos_t.delta_t - pos_t.deltat) > 1.0e-9)
{
pos_t = gps_pos(sPRN, best_epoch, Weeksec, nav_b, obs_h, pos_t);
} }
/* ----------------------------- 地固坐标系转经纬大地高坐标系 ----------------------------- */ tem1 = XYZ2BLH(tem1, pos_t.X, pos_t.Y, pos_t.Z);
tem1 = XYZ2BLH(tem1, pos_t.X[sPRN], pos_t.Y[sPRN], pos_t.Z[sPRN]);
blh.B = rad2deg(tem1.B); blh.B = rad2deg(tem1.B);
blh.L = rad2deg(tem1.L); blh.L = rad2deg(tem1.L);
blh.H = tem1.H; blh.H = tem1.H;
/* -------------------------------------------------------------------------- */
/* ----------------------------- 经纬大地高坐标系转站心坐标系 ----------------------------- */ double deltax = pos_t.X - obs_h->apX;
double deltax = pos_t.X[sPRN] - obs_h->apX; double deltay = pos_t.Y - obs_h->apY;
double deltay = pos_t.Y[sPRN] - obs_h->apY; double deltaz = pos_t.Z - obs_h->apZ;
double deltaz = pos_t.Z[sPRN] - obs_h->apZ;
tem3 = BLH2ENU(tem3, station.B, station.L, deltax, deltay, deltaz); tem3 = BLH2ENU(tem3, station.B, station.L, deltax, deltay, deltaz);
enu.E = tem3.E; enu.E = tem3.E;
enu.N = tem3.N; enu.N = tem3.N;
enu.U = tem3.U; enu.U = tem3.U;
/* -------------------------------------------------------------------------- */
/* ---------------------------- 卫星方位角a,高度角h,向径r计算 --------------------------- */ //Satellite altitude Angle calculation
tem4 = RAHCAL(tem4, enu.E, enu.N, enu.U); tem4 = RAHCAL(tem4, enu.E, enu.N, enu.U);
rah.R = tem4.R; rah.R = tem4.R;
rah.A = rad2deg(tem4.A); rah.A = rad2deg(tem4.A);
rah.H = rad2deg(tem4.H); rah.H = rad2deg(tem4.H);
/* -------------------------------------------------------------------------- */
if (blh.H < 0 || rah.H < 10 || nav_b[best_epoch].sHEA != 0) if (blh.H < 0 || rah.H < 10 || nav_b[best_epoch].sHEA != 0)
{ {
continue; continue;
} }
else else
{ {
temb = DEG2DMS(temb, blh.B); temb = DEG2DMS(temb, blh.B);
@@ -191,14 +324,159 @@ void sat_gps_pos_clac(FILE* result_file,HWND hwndPB,
blh.L_s = teml.S; blh.L_s = teml.S;
result_file = fopen(res_file, "a+"); result_file = fopen(res_file, "a+");
fprintf(result_file, "\nG%02d | %15.05f %15.05f %15.05f %15.05f %15.05f %15.05f %15.12f %16.13f" fprintf(result_file, "\nG %02d| %15.05f %15.05f %15.05f %15.05f %15.05f %15.05f %16.13f"
, sPRN, pos_t.X[sPRN], pos_t.Y[sPRN], pos_t.Z[sPRN] , sPRN, pos_t.X, pos_t.Y, pos_t.Z
, obs_b[i].obs_gps[j][Code2Type(C1C, obs_h->obstypenum_gps, obs_h->obscode_gps)] , obs_b[i].obs_gps[j][Code2Type(C1C, obs_h->obstypenum_gps, obs_h->obscode_gps)]
, obs_b[i].obs_gps[j][Code2Type(C2L, obs_h->obstypenum_gps, obs_h->obscode_gps)] , obs_b[i].obs_gps[j][Code2Type(C2L, obs_h->obstypenum_gps, obs_h->obscode_gps)]
, rah.H, nav_b[best_epoch].TGD, pos_t.delta_clk[sPRN]); , rah.H, pos_t.delta_clk);//GPS satellite
fclose(result_file); fclose(result_file);
} }
} }
}
if (gnssdecode % BDS == 0)//Be judged as BeiDou
{
for (int j = 0; j < obs_e[i].bds_num; j++)
{
int sPRN = obs_e[i].sPRN_BDS[j];
int best_epoch = select_epoch(Weeksec, sPRN, nav_b, satnum, BDS);
if (best_epoch == -1)//when the sPRN is not exist func will return -1
break;
double detat_toc = Weeksec - nav_b[best_epoch].TOE - 14;//BDST - GPST = 14s
//Iterative approximate propagation time
pos_t.delta_t = (obs_b[i].obs_bds[j][Code2Type(C2I, obs_h->obstypenum_bds, obs_h->obscode_bds)] / C_V)
- station.delta_TR + nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * detat_toc + nav_b[best_epoch].sa2 * pow(detat_toc, 2);
pos_t.deltat = 0.0;
while (fabs(pos_t.delta_t - pos_t.deltat) > 1.0e-9)
{
pos_t = bds_pos(sPRN, best_epoch, Weeksec, nav_b, obs_h, pos_t);
}
tem1 = XYZ2BLH(tem1, pos_t.X, pos_t.Y, pos_t.Z);
blh.B = rad2deg(tem1.B);
blh.L = rad2deg(tem1.L);
blh.H = tem1.H;
double deltax = pos_t.X - obs_h->apX;
double deltay = pos_t.Y - obs_h->apY;
double deltaz = pos_t.Z - obs_h->apZ;
tem3 = BLH2ENU(tem3, station.B, station.L, deltax, deltay, deltaz);
enu.E = tem3.E;
enu.N = tem3.N;
enu.U = tem3.U;
//Satellite altitude Angle calculation
tem4 = RAHCAL(tem4, enu.E, enu.N, enu.U);
rah.R = tem4.R;
rah.A = rad2deg(tem4.A);
rah.H = rad2deg(tem4.H);
if (blh.H < 0 || rah.H < 10 || nav_b[best_epoch].sHEA != 0){
continue;
}
else{
temb = DEG2DMS(temb, blh.B);
blh.B_d = temb.D;
blh.B_m = temb.M;
blh.B_s = temb.S;
teml = DEG2DMS(teml, blh.L);
blh.L_d = teml.D;
blh.L_m = teml.M;
blh.L_s = teml.S;
result_file = fopen(res_file, "a+");
if (sPRN >= 19) {
fprintf(result_file, "\nCC%02d| %15.05f %15.05f %15.05f %15.05f %15.05f %15.05f %16.13f"
, sPRN, pos_t.X, pos_t.Y, pos_t.Z
, obs_b[i].obs_bds[j][Code2Type(C2I, obs_h->obstypenum_bds, obs_h->obscode_bds)]
, obs_b[i].obs_bds[j][Code2Type(C7I, obs_h->obstypenum_bds, obs_h->obscode_bds)]
, rah.H, pos_t.delta_clk);//BDS-3 satellite
}
else {
fprintf(result_file, "\nCB%02d| %15.05f %15.05f %15.05f %15.05f %15.05f %15.05f %16.13f"
, sPRN, pos_t.X, pos_t.Y, pos_t.Z
, obs_b[i].obs_bds[j][Code2Type(C2I, obs_h->obstypenum_bds, obs_h->obscode_bds)]
, obs_b[i].obs_bds[j][Code2Type(C7I, obs_h->obstypenum_bds, obs_h->obscode_bds)]
, rah.H, pos_t.delta_clk);//BDS-2 satellite
}
fclose(result_file);
}
}
}
if (gnssdecode % GAL == 0)//Be judged as Galileo
{
for (int j = 0; j < obs_e[i].gal_num; j++)
{
int sPRN = obs_e[i].sPRN_GAL[j];
int best_epoch = select_epoch(Weeksec, sPRN, nav_b, satnum, GAL);
if (best_epoch == -1)//when the sPRN is not exist func will return -1
break;
double detat_toc = Weeksec - nav_b[best_epoch].TOE;
//Iterative approximate propagation time
pos_t.delta_t = (obs_b[i].obs_gal[j][Code2Type(C1C, obs_h->obstypenum_gal, obs_h->obscode_gal)] / C_V)
- station.delta_TR + nav_b[best_epoch].sa0 + nav_b[best_epoch].sa1 * detat_toc + nav_b[best_epoch].sa2 * pow(detat_toc, 2);
pos_t.deltat = 0.0;
while (fabs(pos_t.delta_t - pos_t.deltat) > 1.0e-9)
{
pos_t = gal_pos(sPRN, best_epoch, Weeksec, nav_b, obs_h, pos_t);
}
tem1 = XYZ2BLH(tem1, pos_t.X, pos_t.Y, pos_t.Z);
blh.B = rad2deg(tem1.B);
blh.L = rad2deg(tem1.L);
blh.H = tem1.H;
double deltax = pos_t.X - obs_h->apX;
double deltay = pos_t.Y - obs_h->apY;
double deltaz = pos_t.Z - obs_h->apZ;
tem3 = BLH2ENU(tem3, station.B, station.L, deltax, deltay, deltaz);
enu.E = tem3.E;
enu.N = tem3.N;
enu.U = tem3.U;
//Satellite altitude Angle calculation
tem4 = RAHCAL(tem4, enu.E, enu.N, enu.U);
rah.R = tem4.R;
rah.A = rad2deg(tem4.A);
rah.H = rad2deg(tem4.H);
if (blh.H < 0 || rah.H < 10 || nav_b[best_epoch].sHEA != 0)
{ continue;}
else
{
temb = DEG2DMS(temb, blh.B);
blh.B_d = temb.D;
blh.B_m = temb.M;
blh.B_s = temb.S;
teml = DEG2DMS(teml, blh.L);
blh.L_d = teml.D;
blh.L_m = teml.M;
blh.L_s = teml.S;
result_file = fopen(res_file, "a+");
fprintf(result_file, "\nE %02d| %15.05f %15.05f %15.05f %15.05f %15.05f %15.05f %16.13f"
, sPRN, pos_t.X, pos_t.Y, pos_t.Z
, obs_b[i].obs_gal[j][Code2Type(C1C, obs_h->obstypenum_gps, obs_h->obscode_gps)]
, obs_b[i].obs_gal[j][Code2Type(C6C, obs_h->obstypenum_gps, obs_h->obscode_gps)]
, rah.H, pos_t.delta_clk);//Galileo satellite
fclose(result_file);
}
}
}
result_file = fopen(res_file, "a+"); result_file = fopen(res_file, "a+");
fprintf(result_file, "\n"); fprintf(result_file, "\n");
fclose(result_file); fclose(result_file);
+8 -9
View File
@@ -10,20 +10,19 @@ typedef struct
double M; double M;
double S; double S;
}deg2dms; }deg2dms;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将十进制的度数转换为度分秒形式 /// @brief Converts decimal degrees to degree minutes and seconds
/// @param deg2dms 结构体传递参数 /// @param deg2dms Parameter transfer structure
/// @param D 要转换度数 /// @param D The number of degrees to convert
/// @return 返回自定义结构体包含度,分,秒成员 /// @return return structure contain degree minute second
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
deg2dms DEG2DMS(deg2dms deg2dms, deg2dms DEG2DMS(deg2dms deg2dms,
double D) double D)
{ {
int sig = D / fabs(D);//符号判断 int sig = D / fabs(D);//sign judgment
deg2dms.D = (int)(D);//转换为度分秒 deg2dms.D = (int)(D);//to degree
deg2dms.M = (int)((D - deg2dms.D) * 60);//分秒去除符号格式 deg2dms.M = (int)((D - deg2dms.D) * 60);//to minute
deg2dms.S = (int)(((D - deg2dms.D) * 60 - deg2dms.M) * 60); deg2dms.S = (int)(((D - deg2dms.D) * 60 - deg2dms.M) * 60);//to second
deg2dms.M = deg2dms.M * sig; deg2dms.M = deg2dms.M * sig;
deg2dms.S = deg2dms.S * sig; deg2dms.S = deg2dms.S * sig;
+4 -5
View File
@@ -2,11 +2,10 @@
#define _DEGRRAD_H_ #define _DEGRRAD_H_
#include"public.h" #include"public.h"
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 角度转弧度 /// @brief degree to radian
/// @param deg /// @param deg
/// @return 返回弧度 /// @return return radian
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
double deg2rad(double deg) double deg2rad(double deg)
{ {
@@ -15,9 +14,9 @@ double deg2rad(double deg)
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 弧度转角度 /// @brief radian to degree
/// @param rad /// @param rad
/// @return 返回角度 /// @return return degree
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
double rad2deg(double rad) double rad2deg(double rad)
{ {
+155 -128
View File
@@ -1,6 +1,7 @@
#ifndef _PUBLIC_H_ #ifndef _PUBLIC_H_
#define _PUBLIC_H_ #define _PUBLIC_H_
/*---------------------------------- FOR UI ----------------------------------*/
/* --------------------------------- FOR UI --------------------------------- */
//FILE SELECT DIALOGS //FILE SELECT DIALOGS
#define FILEEXOP TEXT("RINEX OBS(*.o*.*.*obs.*.*d)\0*.*o;*.*obs;*.*d\0"\ #define FILEEXOP TEXT("RINEX OBS(*.o*.*.*obs.*.*d)\0*.*o;*.*obs;*.*d\0"\
"All Files(*.*)\0*.*\0\0"); "All Files(*.*)\0*.*\0\0");
@@ -50,56 +51,78 @@
#define Earth_e 7.2921151467e-5 #define Earth_e 7.2921151467e-5
/* ----------------------------- GPS OBSERV TYPE ---------------------------- */ /* ----------------------------- GNSS OBSERV TYPE --------------------------- */
#define C1C 1 #define C1C 100
#define C1S 2 #define C1S 101
#define C1L 3 #define C1L 102
#define C1X 4 #define C1X 103
#define C1P 5 #define C1P 104
#define C1W 6 #define C1W 105
#define C1Y 7 #define C1Y 106
#define C1M 8 #define C1M 107
#define C1A 108
#define C1B 109
#define C1Z 110
#define C2C 9 #define C2C 200
#define C2S 10 #define C2S 201
#define C2L 11 #define C2L 202
#define C2X 12 #define C2X 203
#define C2P 13 #define C2P 204
#define C2W 14 #define C2W 205
#define C2Y 15 #define C2Y 206
#define C2M 16 #define C2M 207
#define C2I 208
#define C2Q 209
#define C2X 210
#define C5I 17 #define C5I 500
#define C5Q 18 #define C5Q 501
#define C5X 19 #define C5X 502
#define C6A 600
#define C6B 601
#define C6C 602
#define C6X 603
#define C6Z 604
#define C7I 700
#define C7Q 701
#define C7X 702
#define C7D 703
#define C7P 704
#define C7Z 705
#define C8I 800
#define C8Q 801
#define C8X 802
/* ------------------------------- GNSS CODE -------------------------------- */ /* ------------------------------- GNSS CODE -------------------------------- */
#define GPS 0 #define GPS 03
#define BDS 1 #define BDS 07
#define CAL 2 #define GAL 11
#define GLO 3 #define GLO 13
#define SBAS 4 #define SBAS 17
/* ------------------------------ FOR CALMOD.H ------------------------------ */ /* ------------------------------ FOR CALMOD.H ------------------------------ */
#define MAXRINEX 1000 #define MAXRINEX 1000
#define DAYSEC 86400 #define DAYSEC 86400
//卫星位置结构体 //satellite position & clock bias structure
typedef struct typedef struct
{ {
double X[36]; double X;
double Y[36]; double Y;
double Z[36]; double Z;
double deltat[36];//改正前的信号传播时间 double deltat;
double delta_t[36];//改正后的信号传播时间 double delta_t;
double delta_clk[36]; double delta_clk;
}pos_ts; }pos_ts;
//测站位置结构体 //receiver station position & clock bias structure
typedef struct typedef struct
{ {
double X; double X;
double Y; double Y;
double Z; double Z;
@@ -107,10 +130,11 @@
double L; double L;
double H; double H;
double delta_TR; double delta_TR;
}stations; }stations;
//经纬高结构体
typedef struct //longitude & latitude structure
{ typedef struct
{
double B; double B;
int B_d; int B_d;
int B_m; int B_m;
@@ -120,34 +144,37 @@
int L_m; int L_m;
int L_s; int L_s;
double H; double H;
}blhs; }blhs;
//东北天结构体
typedef struct //local Cartesian coordinates coordinate system structure
{ typedef struct
{
double E; double E;
double N; double N;
double U; double U;
}enus; }enus;
//高度方位角结构体
typedef struct //satellite azimuth angle structure
{ typedef struct
{
double R; double R;
double A; double A;
double H; double H;
}rahs; }rahs;
/* ------------------------------- FOR READ.H ------------------------------- */ /* ------------------------------- FOR READ.H ------------------------------- */
//导航头文件结构体
//header data of file of nav
typedef struct nav_head typedef struct nav_head
{ {
double ver;//rinex 版本号 double ver;//rinex
char type[20];//读取的数据类型 char type[20];
double ION_GPSA[4];//8个电离层参数 double ION_GPSA[4];
double ION_GPSB[4]; double ION_GPSB[4];
double ION_BDSA[4];//8个电离层参数 double ION_BDSA[4];
double ION_BDSB[4]; double ION_BDSB[4];
double ION_QZSA[4];//8个电离层参数 double ION_QZSA[4];
double ION_QZSB[4]; double ION_QZSB[4];
double ION_IRNA[4];//8个电离层参数 double ION_IRNA[4];
double ION_IRNB[4]; double ION_IRNB[4];
double GPUT[4]; double GPUT[4];
double GLUT[4]; double GLUT[4];
@@ -159,76 +186,76 @@ typedef struct nav_head
int leap; int leap;
}nav_head, *pnav_head; }nav_head, *pnav_head;
//导航数据结构体 //body data of file of nav: GPS BeiDou Galileo
typedef struct nav_body typedef struct nav_body
{ {
int sPRN_GPS; int sPRN_BDS; int sPRN_GAL;
int TOC_Y;
int TOC_M;
int TOC_D;
int TOC_H;
int TOC_Min;
int TOC_Sec;
double sa0;
double sa1;
double sa2;
int sPRN_GPS;//GPS卫星PRN double IODE; double AODE;
int sPRN_BDS;//GPS卫星PRN double Crs;
int TOC_Y;//年 double deltan;
int TOC_M;//月 double M0;
int TOC_D;//日
int TOC_H;//时
int TOC_Min;//分
int TOC_Sec;//秒
double sa0;//卫星钟差
double sa1;//卫星钟偏
double sa2;//卫星钟漂
double IODE;//数据、星历发布时间(数据期龄) double Cuc;
double Crs;//轨道半径的正弦调和改正项的振幅(单位:m) double e;
double deltan;//卫星平均运动速率与计算值之差(rad/s) double Cus;
double M0;//参考时间的平近点角(rad) double sqrtA;
double Cuc;//维度幅角的余弦调和改正项的振幅(rad) double TOE;
double e;//轨道偏心率 double Cic;
double Cus;//轨道幅角的正弦调和改正项的振幅(rad) double OMEGA;
double sqrtA;//长半轴平方根 double Cis;
double TOE;//星历的参考时刻(GPS周内秒) double i0;
double Cic;//轨道倾角的余弦调和改正项的振幅(rad) double Crc;
double OMEGA;//参考时刻的升交点赤经 double omega;
double Cis;//维度倾角的正弦调和改正项的振幅(rad) double deltaomega;
double i0;//参考时间的轨道倾角(rad) double IDOT;
double Crc;//轨道平径的余弦调和改正项的振幅(m) double L2code; int Datasource;
double omega;//近地点角距 double GPSweek; double BDTweek; double GALweek;
double deltaomega;//升交点赤经变化率(rad) double L2Pflag;
double IDOT;//近地点角距(rad/s) double sACC;
double L2code;//L2上的码 double sHEA;
double GPSweek;//GPS周,于TOE一同表示 double TGD; double TGD1; double BGDa;
double L2Pflag;//L2,p码数据标记 double IODC; double TGD2; double BGDb;
double sACC;//卫星精度 double TTN;
double sHEA;//卫星健康状态 double fit; double AODC;
double TGD;//sec double spare1;
double IODC;//钟的数据龄期 double spare2;
double TTN;//电文发送时间
double fit;//拟合区间
double spare1;//空
double spare2;//空
}nav_body, *pnav_body; }nav_body, *pnav_body;
//观测值头文件结构体 //header data of file of obs
typedef struct obs_head typedef struct obs_head
{ {
double ver;//RINEX文件版本号 double ver;
char type[30];//文件类型 char type[30];
double apX;//测站近似位置XYZ(WGS84) double apX;
double apY; double apY;
double apZ; double apZ;
double ANTH;//天线高 double ANTH;
double ANTdeltaE;//天线中心对于测站标志在东方向上的偏移量 double ANTdeltaE;
double ANTdeltaN;//天线中心对于测站标志在北方向上的偏移量 double ANTdeltaN;
int obstypenum_gps;//GPS观测值类型数量 int obstypenum_gps;
int obstypenum_bds; int obstypenum_bds;
int obscode_gps[36];//rinex3.04GPS观测值类型列表 int obstypenum_gal;
int obscode_bds[36]; int obscode_gps[26];
double interval;//观测值的历元间隔 int obscode_bds[26];
int f_y;//第一个观测记录的时刻 int obscode_gal[26];
double interval;
int f_y;
int f_m; int f_m;
int f_d; int f_d;
int f_h; int f_h;
@@ -240,35 +267,35 @@ typedef struct obs_head
int l_h; int l_h;
int l_min; int l_min;
double l_sec; double l_sec;
char tsys[5];//时间系统 char tsys[5];//time system
}obs_head,*pobs_head; }obs_head,*pobs_head;
//epoch data of file of obs
//观测值历元数据结构体
typedef struct obs_epoch typedef struct obs_epoch
{ {
//观测历元时刻
int y; int y;
int m; int m;
int d; int d;
int h; int h;
int min; int min;
double sec; double sec;//epoch time
int p_flag;//历元标志 int p_flag;//epoch flag
int sat_num;//当前历元所观测到的卫星数量 int sat_num;//the total number of obsable sat
int gps_num;//当前历元所观测到的GPS卫星数量 int gps_num;//the total gps sat
int bds_num;//当前历元所观测到的BDS卫星数量 int bds_num;//the total bds sat
int sPRN[84];//当前历元所能观测到的卫星的PRN列表 int gal_num;//the total galileo sat
int sPRN_GPS[25]; int sPRN[84];//total sprn of obs sat
int sPRN_BDS[36]; int sPRN_GPS[30];
int sPRN_BDS[60];
int sPRN_GAL[30];
}obs_epoch,*pobs_epoch; }obs_epoch,*pobs_epoch;
//body data of file of obs
//观测值数据结构体
typedef struct obs_body typedef struct obs_body
{ {
double obs_gps[100][24];//GPS观测值 double obs_gps[30][26];//GPS obs data
double obs_bds[100][24];//BDS观测值 double obs_bds[60][26];//BDS obs data
double obs_gal[30][26];//GALILEO obs data
}obs_body,*pobs_body; }obs_body,*pobs_body;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
+6 -7
View File
@@ -12,14 +12,13 @@ typedef struct
double A; double A;
double H; double H;
}rahcal; }rahcal;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 计算站心坐标系下的卫星高度方位角 /// @brief satellite azimuth angle calculation
/// @param rahcal 自定义结构体变量用于传参 /// @param rahcal parameter transfer structure
/// @param E 站心坐标东 /// @param E east
/// @param N 站心坐标北 /// @param N north
/// @param U 站心坐标天 /// @param U up
/// @return 返回自定义结构体变量包含R, A, H成员 /// @return return structure contain R, A, H members
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
rahcal RAHCAL(rahcal rahcal, rahcal RAHCAL(rahcal rahcal,
double E, double N, double U) double E, double N, double U)
+282 -232
View File
@@ -5,192 +5,191 @@
#include"public.h" #include"public.h"
#include"type2code.h" #include"type2code.h"
/* ------------------------ 将字符串转换为浮点数,i起始位置,n输入多少个字符 ----------------------- */
static double strtonum(const char* buff, int i, int n) static double strtonum(const char* buff, int i, int n)
{ {
double value = 0.0; double value = 0.0;
char str[256] = { 0 }; char str[256] = { 0 };
char* p = str; char* p = str;
/************************************ /* ---------------------------------- */
* 当出现以下三种情况报错,返回0.0 /// Function will return 0.0 as error code when three occasion are below:
* 1.起始位置<0 /// 1.Begining position < 0
* 2.读取字符串个数<i /// 2.The number of Byte of read < i
* 3.str里面存放的字节数<n /// 3.The Byte size of string < n
*************************************/ /* ---------------------------------- */
if (i < 0 || (int)strlen(buff) < i || (int)sizeof(str) - 1 < n) if (i < 0 || (int)strlen(buff) < i || (int)sizeof(str) - 1 < n)
{ {
return 0.0; return 0.0;
} }
for (buff += i; *buff && --n >= 0; buff++) for (buff += i; *buff && --n >= 0; buff++)
{ {
//三目操作符:D和d为文件中科学计数法部分,将其转换成二进制能读懂的e
*p++ = ((*buff == 'D' || *buff == 'd') ? 'e' : *buff); *p++ = ((*buff == 'D' || *buff == 'd') ? 'e' : *buff);
} }
*p = '\0'; *p = '\0';
//三目操作符,将str中存放的数以格式化读取到value中。
return sscanf(str, "%lf", &value) == 1 ? value : 0.0; return sscanf(str, "%lf", &value) == 1 ? value : 0.0;
} }
/* -------------------------- Read the file of obs -------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* 读取O文件 /// @brief get the total number of epoch of obs
/// @param fp_obs the file pointer of obs
/// @return epoch number
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------- 获取O文件历元数 -------------------------------- */
extern int get_epochnum(FILE* fp_obs) extern int get_epochnum(FILE* fp_obs)
{ {
int n = 0;//记录历元数 int n = 0;
int satnum = 0;//记录每个历元的卫星数 int satnum = 0;
char flag;//存放标志符号'>' char flag;
char buff[MAXRINEX];//存放读取的字符串 char buff[MAXRINEX];
while (fgets(buff, MAXRINEX, fp_obs)) while (fgets(buff, MAXRINEX, fp_obs))
{ { satnum = (int)strtonum(buff, 33, 2);
satnum = (int)strtonum(buff, 33, 2);
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
if (flag == '>') if (flag == '>')
{ { n++;}
n++;
}
} }
return n; return n;
} }
/* ------------------- Read the header data of file of obs ------------------ */
/* -------------------------------- 读取O文件数据头 -------------------------------- */
extern void read_o_h(FILE* fp_obs, pobs_head obs_h) extern void read_o_h(FILE* fp_obs, pobs_head obs_h)
{ {
obs_h->f_y = obs_h->f_m = obs_h->f_d = obs_h->f_h = obs_h->f_min = obs_h->f_sec = 0;
obs_h->l_y = obs_h->l_m = obs_h->l_d = obs_h->l_h = obs_h->l_min = obs_h->l_sec = 0;
obs_h->interval = 30;
memset(obs_h->obscode_gps, 0, sizeof(obs_h->obscode_gps));
memset(obs_h->obscode_bds, 0, sizeof(obs_h->obscode_bds));
char buff[MAXRINEX] = { 0 }; char buff[MAXRINEX] = { 0 };
char flag = { 0 }; char flag = { 0 };
char* lable = buff + 60; char* lable = buff + 60;
int i = 0; int i = 0;
int j = 0; int j = 0;
obs_h->interval = 30;
obs_h->f_y = obs_h->f_m = obs_h->f_d = obs_h->f_h = obs_h->f_min = obs_h->f_sec = 0;
obs_h->l_y = obs_h->l_m = obs_h->l_d = obs_h->l_h = obs_h->l_min = obs_h->l_sec = 0;
memset(obs_h->obscode_gps, 0, sizeof(obs_h->obscode_gps));
memset(obs_h->obscode_bds, 0, sizeof(obs_h->obscode_bds));
memset(obs_h->obscode_gal, 0, sizeof(obs_h->obscode_gal));
while (fgets(buff, MAXRINEX, fp_obs)) while (fgets(buff, MAXRINEX, fp_obs))
{ { if (strstr(lable, "RINEX VERSION / TYPE"))
if (strstr(lable, "RINEX VERSION / TYPE")) { obs_h->ver = strtonum(buff, 0, 9);
{
obs_h->ver = strtonum(buff, 0, 9);
strncpy(obs_h->type, buff + 20, 30); strncpy(obs_h->type, buff + 20, 30);
continue; continue;}
}
else if (strstr(lable, "APPROX POSITION XYZ")) else if (strstr(lable, "APPROX POSITION XYZ"))
{ { obs_h->apX = strtonum(buff, 0, 14);
obs_h->apX = strtonum(buff, 0, 14);
obs_h->apY = strtonum(buff, 0 + 14, 14); obs_h->apY = strtonum(buff, 0 + 14, 14);
obs_h->apZ = strtonum(buff, 0 + 14 + 14, 14); obs_h->apZ = strtonum(buff, 0 + 14 + 14, 14);
continue; continue;}
}
else if (strstr(lable, "ANTENNA: DELTA H/E/N")) else if (strstr(lable, "ANTENNA: DELTA H/E/N"))
{ { obs_h->ANTH = strtonum(buff, 0, 14);
obs_h->ANTH = strtonum(buff, 0, 14);
obs_h->ANTdeltaE = strtonum(buff, 14, 14); obs_h->ANTdeltaE = strtonum(buff, 14, 14);
obs_h->ANTdeltaN = strtonum(buff, 14 + 14, 14); obs_h->ANTdeltaN = strtonum(buff, 14 + 14, 14);
continue; continue;}
}
else if (strstr(lable, "SYS / # / OBS TYPES")) else if (strstr(lable, "SYS / # / OBS TYPES"))
{ { char flag = {0};
char flag = {0};
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
if (flag == 'G') if (flag == 'G')
{ { obs_h->obstypenum_gps = (int)strtonum(buff, 4, 2);
obs_h->obstypenum_gps = (int)strtonum(buff, 4, 2);
if (obs_h->obstypenum_gps <= 13) if (obs_h->obstypenum_gps <= 13)
{ { for (i = 0; i < obs_h->obstypenum_gps; i++)
for (i = 0; i < obs_h->obstypenum_gps; i++) { obs_h->obscode_gps[i + 1] = Type2Code(i, buff);}}
{
obs_h->obscode_gps[i + 1] = Type2Code(i, buff);
}
}
else if (obs_h->obstypenum_gps > 13) else if (obs_h->obstypenum_gps > 13)
{ { for (i = 0; i < 13; i++)
for (i = 0; i < 13; i++) { obs_h->obscode_gps[i] = Type2Code(i, buff);}
{
obs_h->obscode_gps[i] = Type2Code(i, buff);
}
fgets(buff, MAXRINEX, fp_obs); fgets(buff, MAXRINEX, fp_obs);
for (i = 0; i < obs_h->obstypenum_gps - 13; i++) for (i = 0; i < obs_h->obstypenum_gps - 13; i++)
{ { obs_h->obscode_gps[i + 13] = Type2Code(i, buff);}}
obs_h->obscode_gps[i + 13] = Type2Code(i, buff);
} continue;}
}
continue; else if (flag == 'C')
} { obs_h->obstypenum_bds = (int)strtonum(buff, 4, 2);
if (flag == 'C')
{
obs_h->obstypenum_bds = (int)strtonum(buff, 4, 2);
if (obs_h->obstypenum_bds <= 13) if (obs_h->obstypenum_bds <= 13)
{ { for (i = 0; i < obs_h->obstypenum_bds; i++)
for (i = 0; i < obs_h->obstypenum_bds; i++) { obs_h->obscode_bds[i] = Type2Code(i, buff);}}
{
obs_h->obscode_bds[i] = Type2Code(i, buff);
}
}
else if (obs_h->obstypenum_bds > 13) else if (obs_h->obstypenum_bds > 13)
{ { for (i = 0; i < 13; i++)
for (i = 0; i < 13; i++) { obs_h->obscode_bds[i] = Type2Code(i, buff);}
{
obs_h->obscode_bds[i] = Type2Code(i, buff);
}
fgets(buff, MAXRINEX, fp_obs); fgets(buff, MAXRINEX, fp_obs);
for (i = 0; i < obs_h->obstypenum_bds - 13; i++) for (i = 0; i < obs_h->obstypenum_bds - 13; i++)
{ { obs_h->obscode_bds[i + 13] = Type2Code(i, buff);}}
obs_h->obscode_bds[i + 13] = Type2Code(i, buff); continue;}
}
} else if (flag == 'E')
continue; { obs_h->obstypenum_gal = (int)strtonum(buff, 4, 2);
}
} if (obs_h->obstypenum_gal <= 13)
{ for (i = 0; i < obs_h->obstypenum_gal; i++)
{obs_h->obscode_gal[i] = Type2Code(i, buff);}}
else if (obs_h->obstypenum_gal > 13)
{ for (i = 0; i < 13; i++)
{obs_h->obscode_gal[i] = Type2Code(i, buff);}
fgets(buff, MAXRINEX, fp_obs);
for (i = 0; i < obs_h->obstypenum_gal - 13; i++)
{obs_h->obscode_gal[i + 13] = Type2Code(i, buff);}}
continue;}
continue;}
else if (strstr(lable, "INTERVAL")) else if (strstr(lable, "INTERVAL"))
{ { obs_h->interval = strtonum(buff, 0, 10);
obs_h->interval = strtonum(buff, 0, 10); continue;}
continue;
}
else if (strstr(lable, "TIME OF FIRST OBS")) else if (strstr(lable, "TIME OF FIRST OBS"))
{ { obs_h->f_y = (int)strtonum(buff, 2, 4);
obs_h->f_y = (int)strtonum(buff, 2, 4);
obs_h->f_m = (int)strtonum(buff, 2 + 6, 4); obs_h->f_m = (int)strtonum(buff, 2 + 6, 4);
obs_h->f_d = (int)strtonum(buff, 2 + 6 + 6, 4); obs_h->f_d = (int)strtonum(buff, 2 + 6 + 6, 4);
obs_h->f_h = (int)strtonum(buff, 2 + 6 + 6 + 6, 4); obs_h->f_h = (int)strtonum(buff, 2 + 6 + 6 + 6, 4);
obs_h->f_min = (int)strtonum(buff, 2 + 6 + 6 + 6 + 6, 4); obs_h->f_min = (int)strtonum(buff, 2 + 6 + 6 + 6 + 6, 4);
obs_h->f_sec = strtonum(buff, 2 + 6 + 6 + 6 + 6 + 6, 9); obs_h->f_sec = strtonum(buff, 2 + 6 + 6 + 6 + 6 + 6, 9);
strncpy(obs_h->tsys, buff + 6 + 6 + 6 + 6 + 6 + 18, 3); strncpy(obs_h->tsys, buff + 6 + 6 + 6 + 6 + 6 + 18, 3);
continue; continue;}
}
else if (strstr(lable, "TIME OF LAST OBS")) else if (strstr(lable, "TIME OF LAST OBS"))
{ { obs_h->l_y = (int)strtonum(buff, 2, 4);
obs_h->l_y = (int)strtonum(buff, 2, 4);
obs_h->l_m = (int)strtonum(buff, 2 + 6, 4); obs_h->l_m = (int)strtonum(buff, 2 + 6, 4);
obs_h->l_d = (int)strtonum(buff, 2 + 6 + 6, 4); obs_h->l_d = (int)strtonum(buff, 2 + 6 + 6, 4);
obs_h->l_h = (int)strtonum(buff, 2 + 6 + 6 + 6, 4); obs_h->l_h = (int)strtonum(buff, 2 + 6 + 6 + 6, 4);
obs_h->l_min = (int)strtonum(buff, 2 + 6 + 6 + 6 + 6, 4); obs_h->l_min = (int)strtonum(buff, 2 + 6 + 6 + 6 + 6, 4);
obs_h->l_sec = strtonum(buff, 2 + 6 + 6 + 6 + 6 + 6, 9); obs_h->l_sec = strtonum(buff, 2 + 6 + 6 + 6 + 6 + 6, 9);
continue; continue;}
}
else if (strstr(lable, "END OF HEADER")) else if (strstr(lable, "END OF HEADER"))
break; { break;}
} }
} }
/* -------------------- Read the body data of file of obs ------------------- */
/* -------------------------------- 读取O文件数据块 -------------------------------- */ extern void read_o_b(FILE* fp_obs, pobs_epoch obs_e, pobs_body obs_b, pobs_head obs_h)
extern void read_o_b(FILE* fp_obs, pobs_epoch obs_e, pobs_body obs_b, int type_gps, int type_bds)
{ {
int n = 0;//历元数 int n = 0;
char buff[MAXRINEX] = { 0 }; char buff[MAXRINEX] = { 0 };
char flag = { 0 };//判断符号 char flag = { 0 };
while (fgets(buff, MAXRINEX, fp_obs)) while (fgets(buff, MAXRINEX, fp_obs))
{ {
int i = 0;//第i颗卫星 int i = 0;
int j_g = 0;//第j颗GPS卫星 int j_g = 0;
int k_g = 0;//第j颗GPS卫星的第k个观测值 int k_g = 0;
int j_c = 0;//第j颗BDS卫星 int j_c = 0;
int k_c = 0;//第j颗BDS卫星的第k个观测值 int k_c = 0;
int j_ga = 0;
int k_ga = 0;
obs_e[n].gps_num = 0; obs_e[n].gps_num = 0;
obs_e[n].bds_num = 0; obs_e[n].bds_num = 0;
obs_e[n].gal_num = 0;
//按照格式将历元参考时间依次存入
//除秒以外,均转换成整型
obs_e[n].y = (int)strtonum(buff, 2, 4); obs_e[n].y = (int)strtonum(buff, 2, 4);
obs_e[n].m = (int)strtonum(buff, 7, 2); obs_e[n].m = (int)strtonum(buff, 7, 2);
obs_e[n].d = (int)strtonum(buff, 10, 2); obs_e[n].d = (int)strtonum(buff, 10, 2);
@@ -198,99 +197,93 @@ extern void read_o_b(FILE* fp_obs, pobs_epoch obs_e, pobs_body obs_b, int type_g
obs_e[n].min = (int)strtonum(buff, 16, 2); obs_e[n].min = (int)strtonum(buff, 16, 2);
obs_e[n].sec = strtonum(buff, 19, 10); obs_e[n].sec = strtonum(buff, 19, 10);
obs_e[n].p_flag = (int)strtonum(buff, 31, 1); obs_e[n].p_flag = (int)strtonum(buff, 31, 1);
//输入卫星数
obs_e[n].sat_num = strtonum(buff, 33, 3); obs_e[n].sat_num = strtonum(buff, 33, 3);
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
memset(obs_e[n].sPRN, 0, sizeof(obs_e[n].sPRN)); memset(obs_e[n].sPRN, 0, sizeof(obs_e[n].sPRN));
memset(obs_e[n].sPRN_GPS, 0, sizeof(obs_e[n].sPRN_GPS)); memset(obs_e[n].sPRN_GPS, 0, sizeof(obs_e[n].sPRN_GPS));
memset(obs_e[n].sPRN_BDS, 0, sizeof(obs_e[n].sPRN_BDS)); memset(obs_e[n].sPRN_BDS, 0, sizeof(obs_e[n].sPRN_BDS));
memset(obs_e[n].sPRN_GAL, 0, sizeof(obs_e[n].sPRN_GAL));
memset(obs_b[n].obs_gps, 0, sizeof(obs_b[n].obs_gps)); memset(obs_b[n].obs_gps, 0, sizeof(obs_b[n].obs_gps));
memset(obs_b[n].obs_bds, 0, sizeof(obs_b[n].obs_bds)); memset(obs_b[n].obs_bds, 0, sizeof(obs_b[n].obs_bds));
memset(obs_b[n].obs_gal, 0, sizeof(obs_b[n].obs_gal));
for (i = 0; i < obs_e[n].sat_num; i++) for (i = 0; i < obs_e[n].sat_num; i++)
{ {
//判断是否为GPS卫星 if (flag == 'G')
if (flag == 'G')//获取flag标识,判断GPS卫星为真,读取该卫星PRN号 { obs_e[n].sPRN[i] = strtonum(buff, 1, 2);
{ obs_e[n].sPRN_GPS[j_g] = obs_e[n].sPRN[i];
obs_e[n].sPRN[i] = strtonum(buff, 1, 2);//将卫星编号存储到第n个历元中,第i个PRN位置
obs_e[n].sPRN_GPS[j_g] = obs_e[n].sPRN[i];//将GPS卫星编号与总观测卫星号关联 for (k_g = 0; k_g < obs_h->obstypenum_gps; k_g++)
for (k_g = 0; k_g < type_gps; k_g++) { obs_b[n].obs_gps[j_g][k_g] = strtonum(buff, 3 + 16 * k_g, 14);}
{
obs_b[n].obs_gps[j_g][k_g] = strtonum(buff, 3 + 16 * k_g, 14);
}
obs_e[n].gps_num++; j_g++; obs_e[n].gps_num++; j_g++;
fgets(buff, MAXRINEX, fp_obs); fgets(buff, MAXRINEX, fp_obs);
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);}
}
else if (flag == 'C')
{ obs_e[n].sPRN[i] = strtonum(buff, 1, 2);
obs_e[n].sPRN_BDS[j_c] = obs_e[n].sPRN[i];
for (k_c = 0; k_c < obs_h->obstypenum_bds; k_c++)
{ obs_b[n].obs_bds[j_c][k_c] = strtonum(buff, 3 + 16 * k_c, 14);}
else if (flag != 'G')//获取flag标识,判断GPS卫星为否
{
//判断是否为BDS卫星
if (flag == 'C')//获取flag标识,判断BDS卫星为真,读取该卫星PRN号
{
obs_e[n].sPRN[i] = strtonum(buff, 1, 2);//将卫星编号存储到第n个历元中,第i个PRN位置
obs_e[n].sPRN_BDS[j_c] = obs_e[n].sPRN[i];//将BDS卫星编号与总观测卫星号关联
for (k_c = 0; k_c < type_bds; k_c++)
{
obs_b[n].obs_bds[j_c][k_c] = strtonum(buff, 3 + 16 * k_c, 14);
}
obs_e[n].bds_num++; j_c++; obs_e[n].bds_num++; j_c++;
fgets(buff, MAXRINEX, fp_obs); fgets(buff, MAXRINEX, fp_obs);
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
} }
else if (flag != 'C')//获取flag标识,判断BDS卫星为真,读取该卫星PRN号 else if (flag == 'E')
{ obs_e[n].sPRN[i] = strtonum(buff, 1, 2);
obs_e[n].sPRN_GAL[j_ga] = obs_e[n].sPRN[i];
for (k_ga = 0; k_ga < obs_h->obstypenum_gal; k_ga++)
{ obs_b[n].obs_gal[j_ga][k_ga] = strtonum(buff, 3 + 16 * k_ga, 14);}
obs_e[n].gal_num++; j_ga++;
fgets(buff, MAXRINEX, fp_obs);
strncpy(&flag, buff + 0, 1);
}
else if (flag != 'G'&& flag != 'C'&& flag != 'E')
{ {
fgets(buff, MAXRINEX, fp_obs); fgets(buff, MAXRINEX, fp_obs);
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
} }
} }
}
n++; n++;
} }
} }
/* -------------------------- Read the file of nav -------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* 读取N文件 /// @brief get the total number of satellite boardcast data of nav file
/// @param fp_nav the file pointer of nav file
/// @return total number of satellite boardcast data
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int getsatnum(FILE* fp_nav)
/* ---------------------- 获取文件数据块行数,从END OF HEADER后开始起算 --------------------- */
int getsatnum(FILE* fp_nav)
{ {
int satnum = 0; int satnum = 0;
int flag = 0; int flag = 0;
char buff[MAXRINEX];//用来存放读取到的字符串 char buff[MAXRINEX];
char satvar; char satvar;
char* lable = buff + 60; char* lable = buff + 60;
//fgets函数,读取一行,当读取结束后返回NULL指针,格式如下:
//wchar_t * fgets ( wchar_t * str, int num, FILE * stream );
while (fgets(buff, MAXRINEX, fp_nav)) while (fgets(buff, MAXRINEX, fp_nav))
{ { if (strstr(lable, "END OF HEADER"))
if (strstr(lable, "END OF HEADER")) { flag = 1;}
{
flag = 1;
}
if (flag == 1) if (flag == 1)
{ { while (fgets(buff, MAXRINEX, fp_nav))
while (fgets(buff, MAXRINEX, fp_nav)) { strncpy(&satvar, buff + 0, 1);
{
strncpy(&satvar, buff + 0, 1);
if (satvar == 'G' || satvar == 'E' || satvar == 'R' || satvar == 'S' || satvar == 'C' || satvar == 'I' || satvar == 'J') if (satvar == 'G' || satvar == 'E' || satvar == 'R' || satvar == 'S' || satvar == 'C' || satvar == 'I' || satvar == 'J')
{ { satnum++;}
satnum++;
}
else else
{ { continue;}}}}
continue;
}
}
}
}
return satnum; return satnum;
} }
/* ------------------- Read the header data of file of nav ------------------ */
/* -------------------------------- 读取N文件数据头 -------------------------------- */
void read_n_h(FILE* fp_nav, pnav_head nav_h) void read_n_h(FILE* fp_nav, pnav_head nav_h)
{ {
char buff[MAXRINEX] = { 0 }; char buff[MAXRINEX] = { 0 };
@@ -300,88 +293,79 @@ void read_n_h(FILE* fp_nav, pnav_head nav_h)
while (fgets(buff, MAXRINEX, fp_nav)) while (fgets(buff, MAXRINEX, fp_nav))
{ {
if (strstr(lable, "RINEX VERSION / TYPE")) if (strstr(lable, "RINEX VERSION / TYPE"))
{ { nav_h->ver = strtonum(buff, 0, 9);
nav_h->ver = strtonum(buff, 0, 9);
strncpy((nav_h->type), buff + 20, 15); strncpy((nav_h->type), buff + 20, 15);
continue; continue;}
}
else if (strstr(lable, "GPSA")) else if (strstr(lable, "GPSA"))
{ { nav_h->ION_GPSA[0] = strtonum(buff, 6, 12);
nav_h->ION_GPSA[0] = strtonum(buff, 6, 12);
nav_h->ION_GPSA[1] = strtonum(buff, 6 + 12, 12); nav_h->ION_GPSA[1] = strtonum(buff, 6 + 12, 12);
nav_h->ION_GPSA[2] = strtonum(buff, 6 + 12 + 12, 12); nav_h->ION_GPSA[2] = strtonum(buff, 6 + 12 + 12, 12);
nav_h->ION_GPSA[3] = strtonum(buff, 6 + 12 + 12 + 12, 12); nav_h->ION_GPSA[3] = strtonum(buff, 6 + 12 + 12 + 12, 12);
continue; continue;}
}
else if (strstr(lable, "GPSB")) else if (strstr(lable, "GPSB"))
{ { nav_h->ION_GPSB[0] = strtonum(buff, 6, 12);
nav_h->ION_GPSB[0] = strtonum(buff, 6, 12);
nav_h->ION_GPSB[1] = strtonum(buff, 6 + 12, 12); nav_h->ION_GPSB[1] = strtonum(buff, 6 + 12, 12);
nav_h->ION_GPSB[2] = strtonum(buff, 6 + 12 + 12, 12); nav_h->ION_GPSB[2] = strtonum(buff, 6 + 12 + 12, 12);
nav_h->ION_GPSB[3] = strtonum(buff, 6 + 12 + 12 + 12, 12); nav_h->ION_GPSB[3] = strtonum(buff, 6 + 12 + 12 + 12, 12);
continue; continue;}
}
else if (strstr(lable, "BDSA")) else if (strstr(lable, "BDSA"))
{ { nav_h->ION_BDSA[0] = strtonum(buff, 6, 12);
nav_h->ION_BDSA[0] = strtonum(buff, 6, 12);
nav_h->ION_BDSA[1] = strtonum(buff, 6 + 12, 12); nav_h->ION_BDSA[1] = strtonum(buff, 6 + 12, 12);
nav_h->ION_BDSA[2] = strtonum(buff, 6 + 12 + 12, 12); nav_h->ION_BDSA[2] = strtonum(buff, 6 + 12 + 12, 12);
nav_h->ION_BDSA[3] = strtonum(buff, 6 + 12 + 12 + 12, 12); nav_h->ION_BDSA[3] = strtonum(buff, 6 + 12 + 12 + 12, 12);
continue; continue;}
}
else if (strstr(lable, "BDSB")) else if (strstr(lable, "BDSB"))
{ { nav_h->ION_BDSB[0] = strtonum(buff, 6, 12);
nav_h->ION_BDSB[0] = strtonum(buff, 6, 12);
nav_h->ION_BDSB[1] = strtonum(buff, 6 + 12, 12); nav_h->ION_BDSB[1] = strtonum(buff, 6 + 12, 12);
nav_h->ION_BDSB[2] = strtonum(buff, 6 + 12 + 12, 12); nav_h->ION_BDSB[2] = strtonum(buff, 6 + 12 + 12, 12);
nav_h->ION_BDSB[3] = strtonum(buff, 6 + 12 + 12 + 12, 12); nav_h->ION_BDSB[3] = strtonum(buff, 6 + 12 + 12 + 12, 12);
continue; continue;}
}
else if (strstr(lable, "BDUT")) else if (strstr(lable, "BDUT"))
{ { nav_h->BDUT[0] = strtonum(buff, 5, 17);
nav_h->BDUT[0] = strtonum(buff, 5, 17);
nav_h->BDUT[1] = strtonum(buff, 5 + 17, 16); nav_h->BDUT[1] = strtonum(buff, 5 + 17, 16);
nav_h->BDUT[2] = strtonum(buff, 5 + 17 + 16, 7); nav_h->BDUT[2] = strtonum(buff, 5 + 17 + 16, 7);
nav_h->BDUT[3] = strtonum(buff, 5 + 17 + 16 + 7, 5); nav_h->BDUT[3] = strtonum(buff, 5 + 17 + 16 + 7, 5);
continue; continue;}
}
else if (strstr(lable, "GPUT")) else if (strstr(lable, "GPUT"))
{ { nav_h->GPUT[0] = strtonum(buff, 5, 17);
nav_h->GPUT[0] = strtonum(buff, 5, 17);
nav_h->GPUT[1] = strtonum(buff, 5 + 17, 16); nav_h->GPUT[1] = strtonum(buff, 5 + 17, 16);
nav_h->GPUT[2] = strtonum(buff, 5 + 17 + 16, 7); nav_h->GPUT[2] = strtonum(buff, 5 + 17 + 16, 7);
nav_h->GPUT[3] = strtonum(buff, 5 + 17 + 16 + 7, 5); nav_h->GPUT[3] = strtonum(buff, 5 + 17 + 16 + 7, 5);
continue; continue;}
}
else if (strstr(lable, "LEAP SECONDS")) else if (strstr(lable, "LEAP SECONDS"))
{ { nav_h->leap = (int)strtonum(buff, 4, 2);}
nav_h->leap = (int)strtonum(buff, 4, 2);
} else if (strstr(lable, "END OF HEADER"))
else if (strstr(lable, "END OF HEADER"))//头文件读取结束
break; break;
} }
} }
/* -------------------- Read the body data of file of nav ------------------- */
/* -------------------------------- 读取N文件数据块 -------------------------------- */
void read_n_b(FILE* fp_nav, pnav_body nav_b) void read_n_b(FILE* fp_nav, pnav_body nav_b)
{ {
int i_g = 0;//第i_g个卫星数据 int i_g = 0;
char buff[MAXRINEX] = { 0 }; char buff[MAXRINEX] = { 0 };
char flag = { 0 };//判断符号 char flag = { 0 };
while (fgets(buff, MAXRINEX, fp_nav)) while (fgets(buff, MAXRINEX, fp_nav))
{ {
int j_g = 0;//数据块的第j_g行数据 int j_g = 0;
int j_c = 0;//数据块的第j_c行数据 int j_c = 0;
int j_ga = 0;
int j_gl = 0;
strncpy(&flag, buff + 0, 1); strncpy(&flag, buff + 0, 1);
if(flag == 'G') if(flag == 'G')
{ { for (j_g = 0; j_g < 8; j_g++)
for (j_g = 0; j_g < 8; j_g++)//读取总计第i_g颗 GPS卫星广播星历("总共包含8行数据") 数据块的第j_g行数据 { switch (j_g)
{
switch (j_g)
{ {
case 0: case 0:
nav_b[i_g].sPRN_BDS = 0; nav_b[i_g].sPRN_BDS = -1;
nav_b[i_g].sPRN_GAL = -1;
nav_b[i_g].sPRN_GPS = (int)strtonum(buff, 1, 2); nav_b[i_g].sPRN_GPS = (int)strtonum(buff, 1, 2);
nav_b[i_g].TOC_Y = (int)strtonum(buff, 4, 4); nav_b[i_g].TOC_Y = (int)strtonum(buff, 4, 4);
nav_b[i_g].TOC_M = (int)strtonum(buff, 9, 2); nav_b[i_g].TOC_M = (int)strtonum(buff, 9, 2);
@@ -439,22 +423,20 @@ void read_n_b(FILE* fp_nav, pnav_body nav_b)
case 7: case 7:
nav_b[i_g].TTN = strtonum(buff, 4, 19); nav_b[i_g].TTN = strtonum(buff, 4, 19);
nav_b[i_g].fit = strtonum(buff, 4 + 19, 19); nav_b[i_g].fit = strtonum(buff, 4 + 19, 19);
nav_b[i_g].spare1 = strtonum(buff, 4 + 19 + 19, 19); //nav_b[i_g].spare1 = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].spare2 = strtonum(buff, 4 + 19 + 19 + 19, 19); //nav_b[i_g].spare2 = strtonum(buff, 4 + 19 + 19 + 19, 19);
break; break;
} }}
}
i_g++; i_g++;
continue; continue;}
}
else if(flag == 'C') if(flag == 'C')
{ { for (j_c = 0; j_c < 8; j_c++)
for (j_c = 0; j_c < 8; j_c++)//读取总计第i_g颗 BDS卫星广播星历("总共包含8行数据") 数据块的第j_c行数据 { switch (j_c)
{
switch (j_c)
{ {
case 0: case 0:
nav_b[i_g].sPRN_GPS = 0; nav_b[i_g].sPRN_GPS = -1;
nav_b[i_g].sPRN_GAL = -1;
nav_b[i_g].sPRN_BDS = (int)strtonum(buff, 1, 2); nav_b[i_g].sPRN_BDS = (int)strtonum(buff, 1, 2);
nav_b[i_g].TOC_Y = (int)strtonum(buff, 4, 4); nav_b[i_g].TOC_Y = (int)strtonum(buff, 4, 4);
nav_b[i_g].TOC_M = (int)strtonum(buff, 9, 2); nav_b[i_g].TOC_M = (int)strtonum(buff, 9, 2);
@@ -467,6 +449,77 @@ void read_n_b(FILE* fp_nav, pnav_body nav_b)
nav_b[i_g].sa2 = strtonum(buff, 23 + 19 + 19, 19); nav_b[i_g].sa2 = strtonum(buff, 23 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav); fgets(buff, MAXRINEX, fp_nav);
break; break;
case 1:
nav_b[i_g].AODE = strtonum(buff, 4, 19);
nav_b[i_g].Crs = strtonum(buff, 4 + 19, 19);
nav_b[i_g].deltan = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].M0 = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 2:
nav_b[i_g].Cuc = strtonum(buff, 4, 19);
nav_b[i_g].e = strtonum(buff, 4 + 19, 19);
nav_b[i_g].Cus = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].sqrtA = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 3:
nav_b[i_g].TOE = strtonum(buff, 4, 19);
nav_b[i_g].Cic = strtonum(buff, 4 + 19, 19);
nav_b[i_g].OMEGA = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].Cis = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 4:
nav_b[i_g].i0 = strtonum(buff, 4, 19);
nav_b[i_g].Crc = strtonum(buff, 4 + 19, 19);
nav_b[i_g].omega = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].deltaomega = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 5:
nav_b[i_g].IDOT = strtonum(buff, 4, 19);
//nav_b[i_g].L2code = strtonum(buff, 4 + 19, 19);
nav_b[i_g].BDTweek = strtonum(buff, 4 + 19 + 19, 19);
//nav_b[i_g].L2Pflag = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 6:
nav_b[i_g].sACC = strtonum(buff, 4, 19);
nav_b[i_g].sHEA = strtonum(buff, 4 + 19, 19);
nav_b[i_g].TGD1 = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].TGD2 = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 7:
//nav_b[i_g].TTN = strtonum(buff, 4, 19);
nav_b[i_g].AODC = strtonum(buff, 4 + 19, 19);
//nav_b[i_g].spare1 = strtonum(buff, 4 + 19 + 19, 19);
//nav_b[i_g].spare2 = strtonum(buff, 4 + 19 + 19 + 19, 19);
break;
}}
i_g++;
continue;}
if (flag == 'E')
{ for (j_ga = 0; j_ga < 8; j_ga++)
{ switch (j_ga)
{
case 0:
nav_b[i_g].sPRN_BDS = -1;
nav_b[i_g].sPRN_GPS = -1;
nav_b[i_g].sPRN_GAL = (int)strtonum(buff, 1, 2);
nav_b[i_g].TOC_Y = (int)strtonum(buff, 4, 4);
nav_b[i_g].TOC_M = (int)strtonum(buff, 9, 2);
nav_b[i_g].TOC_D = (int)strtonum(buff, 12, 2);
nav_b[i_g].TOC_H = (int)strtonum(buff, 15, 2);
nav_b[i_g].TOC_Min = (int)strtonum(buff, 18, 2);
nav_b[i_g].TOC_Sec = strtonum(buff, 21, 2);
nav_b[i_g].sa0 = strtonum(buff, 23, 19);
nav_b[i_g].sa1 = strtonum(buff, 23 + 19, 19);
nav_b[i_g].sa2 = strtonum(buff, 23 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav);
break;
case 1: case 1:
nav_b[i_g].IODE = strtonum(buff, 4, 19); nav_b[i_g].IODE = strtonum(buff, 4, 19);
nav_b[i_g].Crs = strtonum(buff, 4 + 19, 19); nav_b[i_g].Crs = strtonum(buff, 4 + 19, 19);
@@ -497,31 +550,28 @@ void read_n_b(FILE* fp_nav, pnav_body nav_b)
break; break;
case 5: case 5:
nav_b[i_g].IDOT = strtonum(buff, 4, 19); nav_b[i_g].IDOT = strtonum(buff, 4, 19);
nav_b[i_g].L2code = strtonum(buff, 4 + 19, 19); //nav_b[i_g].L2code = strtonum(buff, 4 + 19, 19);
nav_b[i_g].GPSweek = strtonum(buff, 4 + 19 + 19, 19); nav_b[i_g].GALweek = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].L2Pflag = strtonum(buff, 4 + 19 + 19 + 19, 19); //nav_b[i_g].L2Pflag = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav); fgets(buff, MAXRINEX, fp_nav);
break; break;
case 6: case 6:
nav_b[i_g].sACC = strtonum(buff, 4, 19); nav_b[i_g].sACC = strtonum(buff, 4, 19);
nav_b[i_g].sHEA = strtonum(buff, 4 + 19, 19); nav_b[i_g].sHEA = strtonum(buff, 4 + 19, 19);
nav_b[i_g].TGD = strtonum(buff, 4 + 19 + 19, 19); nav_b[i_g].BGDa = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].IODC = strtonum(buff, 4 + 19 + 19 + 19, 19); nav_b[i_g].BGDb = strtonum(buff, 4 + 19 + 19 + 19, 19);
fgets(buff, MAXRINEX, fp_nav); fgets(buff, MAXRINEX, fp_nav);
break; break;
case 7: case 7:
nav_b[i_g].TTN = strtonum(buff, 4, 19); //nav_b[i_g].TTN = strtonum(buff, 4, 19);
nav_b[i_g].fit = strtonum(buff, 4 + 19, 19); //nav_b[i_g].fit = strtonum(buff, 4 + 19, 19);
nav_b[i_g].spare1 = strtonum(buff, 4 + 19 + 19, 19); //nav_b[i_g].spare1 = strtonum(buff, 4 + 19 + 19, 19);
nav_b[i_g].spare2 = strtonum(buff, 4 + 19 + 19 + 19, 19); //nav_b[i_g].spare2 = strtonum(buff, 4 + 19 + 19 + 19, 19);
break; break;
} }}
}
i_g++; i_g++;
continue; continue;}
}
} }
} }
/* -------------------------------------------------------------------------- */ /* ------------------------------ END OF READ_H ----------------------------- */
#endif #endif
+40 -22
View File
@@ -4,37 +4,55 @@
#include<math.h> #include<math.h>
#include"public.h" #include"public.h"
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 寻找与观测历元最近的卫星广播历元 /// @brief find the nearest obs epoch with boardcast
/// @param SecofWeek 计算得到的观测历元的周内秒 /// @param SecofWeek second of week of obs epoch time
/// @param sPRN 需要匹配的该历元卫星号 /// @param sPRN the satellite PRN which need to match
/// @param nav_b 导航文件数据块结构体,与卫星号匹配 /// @param nav_b nav data file structure
/// @param satnum 广播星历卫星数量 /// @param satnum total number of boardcast satellite
/// @param syscode 卫星系统代码,详情见PPUBLIC.H /// @param syscode GNSS code, more on PPUBLIC.H
/// @return 返回最佳历元的绝对历元序号 /// @return Return the absolute epoch number of the best epoch
/// When there is no matching satellite number, the function returns -1
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
extern int select_epoch(double SecofWeek, int sPRN, pnav_body nav_b, int satnum, int syscode) extern int select_epoch(double SecofWeek, int sPRN, pnav_body nav_b, int satnum, int syscode)
{ {
int best_epoch = 0; int best_epoch = -1;
double min = 10000;//初始化最小值 double min = 10000;//Initialize the minimum value
double Min; double Min;
if (syscode == GPS) if (syscode == GPS)//Be judged as GPS
{ { for (int i = 0; i < satnum; i++)
for (int i = 0; i < satnum; i++) { if (sPRN == nav_b[i].sPRN_GPS)
{ { Min = fabs(SecofWeek - nav_b[i].TOE);
if (sPRN == nav_b[i].sPRN_GPS)
{
Min = fabs(SecofWeek - nav_b[i].TOE);
if (Min <= min) if (Min <= min)
{ {
best_epoch = i; best_epoch = i;
min = Min; min = Min;
} }}}
} return best_epoch;}
}
} if (syscode == BDS)//Be judged as BeiDou
{ for (int i = 0; i < satnum; i++)
{ if (sPRN == nav_b[i].sPRN_BDS)
{ Min = fabs(SecofWeek - nav_b[i].TOE);
if (Min <= min)
{
best_epoch = i;
min = Min;
}}}
return best_epoch;}
if (syscode == GAL)//Be judged as Galileo
{for (int i = 0; i < satnum; i++)
{ if (sPRN == nav_b[i].sPRN_GAL)
{ Min = fabs(SecofWeek - nav_b[i].TOE);
if (Min <= min)
{
best_epoch = i;
min = Min;
}}}
return best_epoch;}
return best_epoch; return best_epoch;
} }
/* --------------------------- END OF SELECT_EPO_H -------------------------- */
#endif #endif
+77 -28
View File
@@ -5,12 +5,11 @@
#include<stdio.h> #include<stdio.h>
#include"public.h" #include"public.h"
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将观测值类型转换为PUBLIC.H中定义的数字代码 /// @brief converts the observation type to the numeric code defined in PUBLIC.H
/// @param i 读取循环中传入的循环次数 /// @param i reads the number of incoming loops in the loop
/// @param buff 传入的观测值类型 /// @param buff type of incoming observation
/// @return 返回观测值代码 /// @return Returns the obs code
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int Type2Code(int i, char buff[1000]) int Type2Code(int i, char buff[1000])
{ {
@@ -18,41 +17,91 @@ int Type2Code(int i, char buff[1000])
char code_contrast[4]; char code_contrast[4];
char code_original[4]; char code_original[4];
for(int j = 0; j < 19; j++) const char L1codeindex[] = "C1CC1SC1LC1XC1PC1WC1YC1MC1AC1BC1Z";//obs type of different frequency
{ const char L2codeindex[] = "C2CC2SC2LC2XC2PC2WC2YC2MC2IC2QC2X";
memset(code_contrast,0,sizeof(code_contrast)); const char L5codeindex[] = "C5IC5QC5X";
const char L6codeindex[] = "C6AC6BC6CC6XC6Z";
const char L7codeindex[] = "C7IC7QC7XC7DC7PC7Z";
const char L8codeindex[] = "C8JC8QC8X";
for(int j = 0; j < (strlen(L1codeindex)/3); j++)
{ memset(code_contrast,0,sizeof(code_contrast));
memset(code_original,0,sizeof(code_original)); memset(code_original,0,sizeof(code_original));
const char codeindex[]="C1CC1SC1LC1XC1PC1WC1YC1M" strncpy(code_contrast, L1codeindex + 0 + j * 3 , 3);
"C2CC2SC2LC2XC2PC2WC2YC2M"
"C5IC5QC5X";
strncpy(code_contrast, codeindex + 0 + j * 3 , 3);
strncpy(code_original, buff + 7 + 4 * i , 3); strncpy(code_original, buff + 7 + 4 * i , 3);
if(strcmp(code_contrast,code_original) == 0) if(strcmp(code_contrast,code_original) == 0)
{ { code_return = j + 100;
code_return = j + 1; return code_return;
break; break;}}
}
} for (int j = 0; j < (strlen(L2codeindex) / 3); j++)
{ memset(code_contrast, 0, sizeof(code_contrast));
memset(code_original, 0, sizeof(code_original));
strncpy(code_contrast, L2codeindex + 0 + j * 3, 3);
strncpy(code_original, buff + 7 + 4 * i, 3);
if (strcmp(code_contrast, code_original) == 0)
{ code_return = j + 200;
return code_return;
break;}}
for (int j = 0; j < (strlen(L5codeindex) / 3); j++)
{ memset(code_contrast, 0, sizeof(code_contrast));
memset(code_original, 0, sizeof(code_original));
strncpy(code_contrast, L5codeindex + 0 + j * 3, 3);
strncpy(code_original, buff + 7 + 4 * i, 3);
if (strcmp(code_contrast, code_original) == 0)
{ code_return = j + 500;
return code_return;
break;}}
for (int j = 0; j < (strlen(L6codeindex) / 3); j++)
{ memset(code_contrast, 0, sizeof(code_contrast));
memset(code_original, 0, sizeof(code_original));
strncpy(code_contrast, L6codeindex + 0 + j * 3, 3);
strncpy(code_original, buff + 7 + 4 * i, 3);
if (strcmp(code_contrast, code_original) == 0)
{ code_return = j + 600;
return code_return;
break;}}
for (int j = 0; j < (strlen(L7codeindex) / 3); j++)
{ memset(code_contrast, 0, sizeof(code_contrast));
memset(code_original, 0, sizeof(code_original));
strncpy(code_contrast, L7codeindex + 0 + j * 3, 3);
strncpy(code_original, buff + 7 + 4 * i, 3);
if (strcmp(code_contrast, code_original) == 0)
{ code_return = j + 700;
return code_return;
break;}}
for (int j = 0; j < (strlen(L8codeindex) / 3); j++)
{ memset(code_contrast, 0, sizeof(code_contrast));
memset(code_original, 0, sizeof(code_original));
strncpy(code_contrast, L8codeindex + 0 + j * 3, 3);
strncpy(code_original, buff + 7 + 4 * i, 3);
if (strcmp(code_contrast, code_original) == 0)
{ code_return = j + 800;
return code_return;
break;}}
return code_return; return code_return;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将读取的观测值类型匹配类型代码存储数组 /// @brief the type of the obs value read matches the type code stored in an array
/// @param typecode 希望匹配的观测值 /// @param typecode obs type that you want to match
/// @param typenum 观测值类型总数量 /// @param typenum the total number of obs types
/// @param typearr 类型代码存储数组 /// @param typearr type codes store arrays
/// @return 返回对应的观测值类型代码的数组位置 /// @return returns the array position of the corresponding obs type code
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int Code2Type(int typecode, int typenum, int typearr[36]) int Code2Type(int typecode, int typenum, int typearr[36])
{ {
int pos; int pos;
for (pos = 0; pos < typenum; pos++) for (pos = 0; pos < typenum; pos++)
{ { if (typearr[pos] == typecode)
if (typearr[pos] == typecode) { break;
{ return pos;}}
break;
}
}
return pos; return pos;
} }
+9 -12
View File
@@ -12,16 +12,15 @@ typedef struct
double L; double L;
double H; double H;
}xyz2blh; }xyz2blh;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/// @brief 将ECEF地心地固坐标转换为经纬高坐标 /// @brief Convert ECEF geostationary coordinates to BLH coordinates
/// @param xyz2blh 自定义结构体类型,用来传参 /// @param xyz2blh parameter transfer structure
/// @param X ECEF的X坐标 /// @param X X coordinates of ECEF
/// @param Y ECEF的Y坐标 /// @param Y Y coordinates of ECEF
/// @param Z ECEF的Z坐标 /// @param Z Z coordinates of ECEF
/// @param a 椭球的长半轴 /// @param a major semiaxis of WGS-84 ellipsoid
/// @param e2 椭球的第一偏心率平方 /// @param e2 the square of the first eccentricity of WGS-84 ellipsoid
/// @return 返回自定义结构体类型包含B,L,H成员 /// @return return type of structure contain B, L, H members
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
xyz2blh XYZ2BLH(xyz2blh xyz2blh, xyz2blh XYZ2BLH(xyz2blh xyz2blh,
double X, double Y, double Z) double X, double Y, double Z)
@@ -30,15 +29,13 @@ xyz2blh XYZ2BLH(xyz2blh xyz2blh,
double B = 0.0, N = 0.0, H = 0.0, R0, R1, deltaH, deltaB; double B = 0.0, N = 0.0, H = 0.0, R0, R1, deltaH, deltaB;
R0 = sqrt(pow(X, 2) + pow(Y, 2)); R0 = sqrt(pow(X, 2) + pow(Y, 2));
R1 = sqrt(pow(X, 2) + pow(Y, 2) + pow(Z, 2)); R1 = sqrt(pow(X, 2) + pow(Y, 2) + pow(Z, 2));
//经度直接求解
xyz2blh.L = atan2(Y, X); xyz2blh.L = atan2(Y, X);
//迭代求大地维度和大地高
N = a; N = a;
H = R1 - a; H = R1 - a;
B = atan2(Z * (N + H), R0 * (N * (1 - e2) + H)); B = atan2(Z * (N + H), R0 * (N * (1 - e2) + H));
do do
{ {
deltaH = N;//判断收敛所用 deltaH = N;
deltaB = B; deltaB = B;
N = a / sqrt(1 - e2 * pow(sin(B), 2)); N = a / sqrt(1 - e2 * pow(sin(B), 2));
H = R0 / cos(B) - N; H = R0 / cos(B) - N;
+765 -290
View File
File diff suppressed because it is too large. Load diff