Linux 环境下,C++语言,两组不同频率的数据 在相同时间(最近的时间)进行数据的比较
Linux下简单工程创建连接:
https://blog.csdn.net/hltt3838/article/details/105329079
#include <iostream>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>
#include <string>
#include <string.h>
using namespace std;
int ReadOneLine(FILE *fp, char buff[], int sz)
;
int ExtractSameEpochDataAddDiff_msckf()
;
int main()
{
cout<<"hello world!"<<endl;
cout<<"PVQ difference"<<endl;
ExtractSameEpochDataAddDiff_msckf()
;
return 0;
}
int ReadOneLine(FILE *fp, char buff[], int sz)
{
if (feof(fp)) return 0;
memset(buff, 0, sz);
fgets(buff, sz, fp);
return 1;
}
#define PVAR_FORMAT "%lf %lf %lf %lf\n"
#define PVAW_FORMAT "%9.3f %12.4f %12.4f %12.4f\n"
int ExtractSameEpochDataAddDiff_msckf()
{
char srcFileName1[256];
char srcFileName2[256];
char diffFileName[256];
double AngleOffset[3] = { 0, 0, 0 };
strcpy(srcFileName1, "/home/hltt3838/PVQ_diff/output/PVA_out.txt");
strcpy(srcFileName2, "/home/hltt3838/PVQ_diff/output/Real_data.txt");
strcpy(diffFileName, "/home/hltt3838/PVQ_diff/output/diff_200Hz.txt");
// ----------------------------------------------------------------------------------------
char buff1[2048] = { 0 };
char buff2[2048] = { 0 };
double t1,t2 = 0;
int rec = 1;
FILE *srcFp1, *srcFp2, *fp_diff;
srcFp1 = fopen(srcFileName1, "r");
srcFp2 = fopen(srcFileName2, "r");
fp_diff = fopen(diffFileName, "w");
if (NULL == srcFp1)
{
return 0;
cout<<"PVA_out error"<<endl;
}
if (NULL == srcFp2)
{
return 0;
cout<<"Real_data error"<<endl;
}
if (NULL == fp_diff)
{
return 0;
cout<<"diff_200Hz error"<<endl;
}
double timeGap = 0.006;//0.015;//100Hz
double BLH[3], BLH_ref[3];
double deltaXYZ[3] ;
int num[2];
while (rec == 1)
{
if (ReadOneLine(srcFp1, buff1, 2048) == 0)
{
fclose(srcFp1);
fclose(srcFp2);
fclose(fp_diff);
return 0;
}
num[0] = sscanf(buff1, "%lf", &t1);
if (num[0] < 1) break;
sscanf(buff1, PVAR_FORMAT, &t1, BLH, BLH + 1, BLH + 2);
while (true)
{
if (t2 >= t1)
{
break;
}
if (ReadOneLine(srcFp2, buff2, 2048) == 0)
{
fclose(srcFp1);
fclose(srcFp2);
fclose(fp_diff);
return 0;
}
//num[0] = sscanf(buff2, "%lf", &t2);
sscanf(buff2, PVAR_FORMAT, &t2, BLH_ref, BLH_ref + 1, BLH_ref + 2);
if (fabs(t1 - t2) > timeGap)
{
break;
}
// 进行线性内插
//slope = (t1 - t2_0) / (t2 - t2_0);
//for (int i = 0; i < 3; i++)
//{
// XYZ_m[i] = XYZ_ref0[i] + slope * (XYZ_ref[i] - XYZ_ref0[i]);
// //Vel_m[i] = Vel_ref0[i] + slope * (Vel_ref[i] - Vel_ref0[i]);
// //Att_m[i] = Att_ref0[i] + slope * (Att_ref[i] - Att_ref0[i]);
//}
cout<<"current time = "<< t2 <<endl;
for (int i = 0; i < 3; i++)
deltaXYZ[i] = BLH[i] - BLH_ref[i];
cout<<"deltaXYZ = "<<deltaXYZ[0]<<endl;
// if (fabs(t1) < 1.0) continue;
fprintf(fp_diff, PVAW_FORMAT, t1, deltaXYZ[0], deltaXYZ[1], deltaXYZ[2]);
}
}
printf("\n");
//fcloseall();
fclose(srcFp1);
fclose(srcFp2);
fclose(fp_diff);
return 0;
}
|