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
+1830 -947

No files matched your search

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