#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<io.h>
#include"UTC2GPST.h"
using namespace std;
void getJustCurrentFile(string path, vector<string> & files);
int main()
{
string filepath = "C:\\Users\\think\\Desktop\\PPP";
vector<string>files;
getJustCurrentFile(filepath, files);
//char str[40];
int size = files.size();
for (int i = 0; i < size; i++)
{
//cout <<files[i].c_str() << endl;
string file = files[i].c_str();
//cout << file << endl;
//string a = file.substr(40, 7);
//cout << a<< endl;
string name = filepath + "\\" + file.substr(0,4) + file.substr(12,7)+".txt";
string path = filepath + "\\" + file;
cout << name << endl;
ifstream in_file(path);
//ofstream datafile("C:\\Users\\think\\Desktop\\PPP1\\b.txt");
ofstream datafile(name);
string filename;
string line;
string ch = "CLK";
int year, month, day, hour, minute, second, data, second_of_week;
if (in_file)
{
while (getline(in_file, line))
if (line.find(ch) != string::npos)
{
string year1, month1, day1, hour1, minute1, second1, data1;
//char data2[10];
char *end;
year1 = line.substr(0, 4);
month1 = line.substr(5, 2);
day1 = line.substr(8, 2);
hour1 = line.substr(11, 2);
minute1 = line.substr(14, 2);
second1 = line.substr(17, 2);
data1 = line.substr(34, 9);
// << line.substr(0, 4) + " " + line.substr(5, 2) + " " + line.substr(8, 2) + " " + line.substr(11, 2) + " "
// + line.substr(14, 2) + " " + line.substr(17, 2) + " " + line.substr(34, 9) << " " << endl;
//datafile << line.substr(0, 4) << " " << line.substr(5, 2) << " " << line.substr(8, 2) << " " << line.substr(11, 2) << " "
//<< line.substr(11, 2) << " " << line.substr(14, 2) << " " << line.substr(17, 2) << " " << line.substr(34, 9)<<endl;
// string2int
year = static_cast<int>(strtol(year1.c_str(), &end, 10));
month = static_cast<int>(strtol(month1.c_str(), &end, 10));
day = static_cast<int>(strtol(day1.c_str(), &end, 10));
hour = static_cast<int>(strtol(hour1.c_str(), &end, 10));
minute = static_cast<int>(strtol(minute1.c_str(), &end, 10));
second = static_cast<int>(strtol(second1.c_str(), &end, 10));
data = static_cast<int>(strtol(data1.c_str(), &end, 10));
second_of_week = utc2gpst(year, month, day, hour, minute, second);
//int2string
stringstream ss, ss1;
ss << second_of_week;
string gpst = ss.str();
datafile << gpst << " " << data1 << endl;
}
}
else
{
cout << "no such file" << endl;
exit(1);
}
in_file.close();
datafile.close();
}
system("pause");
return 0;
}
void getJustCurrentFile(string path, vector<string>& files)
{
long hFile = 0;
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
;
}
else
{
files.push_back(fileinfo.name);
//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
下面自己写的函数调用,目的用与计算周和周内秒其实可以放到一个.cpp中的,简单点。
// UTC2GPST.h
#include<iostream>
#ifndef UTC2GPST_H_
#define UTC2GPST_H_
int utc2gpst(int year2,int month2,int day2,int hour2,int minute2,int second2);
#endif
//UTC2GPST.cpp
#include<iostream>
#include<cmath>
int utc2gpst(int year2, int month2, int day2, int hour2, int minute2, int second2)
{
int dayofyear = 0;
int dayofmonth = 0;
//从1980年到当前年的上一年经过的天数
for (int i = 1980; i < year2; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
dayofyear += 366;
else
dayofyear += 365;
}
//从一月到当前月的上一月经历的天数
for (int i = 1; i < month2; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
dayofmonth += 31;
else if (i == 4 || i == 6 || i == 9 || i == 11)
dayofmonth += 30;
else
{
if ((year2 % 4 == 0 && year2 % 100 != 0) || year2 % 400 == 0)
dayofmonth += 29;
else
dayofmonth += 28;
}
}
int Day;
Day = dayofmonth + day2 + dayofyear - 6;
int week_of_year = Day / 7;
int doy1=Day * 86400 + hour2 * 3600 + minute2 * 60 + second2;
return doy1 ;
}
读取BNC软件结果文件中clk:输出周和周内秒,以及接收机钟差。windows版本的上传,linux版本也有,后续写入。
最新推荐文章于 2023-08-09 14:19:49 发布