📄 cut.cpp
字号:
#include<iostream>
#include"timeStruct.h"
#include<cmath>
#include<fstream>
#include<vector>
#include <string>
#include<iomanip>
using namespace std;
double GregToJD(time_calendar tc);//声明时间转换
int main()
{
char igr[20]="igr",sp3[5]=".SP3",*p1,*p2,*p3;
char str[6];
int n=14570,m,k;
k=n;
m=n+7;
ofstream outfile("igr1457.txt",ios::out|ios::app);
for(n=k;n<m;n++)
{
p1=igr;
sprintf(str,"%d",n);//数值转为字符
p2=str; p3=sp3;
for(;*p2!='\0';p1++,p2++)
{
*(p1+3)=*p2;
}
p1=igr;
for(;*p3!='\0';p1++,p3++)
{
*(p1+8)=*p3;
}
p1=igr;
cout<<"p1="<<p1<<endl;
//cout<<"Enter O file name:";
//scanf("%s",p);
ifstream infile(p1,ios::in);
if(! infile)
{
cerr<<"open error!"<<endl;
exit(1);//打开文件失败
}
/*
ifstream infile("1457解压SP3\igr14570.sp3",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}*/
string strs,str1;
//int pos,pos1;
vector<double> v;
vector<double> v1;
do
{
time_calendar tc1;
double tg1;
getline(infile,strs);//读一行
//str1=strs.substr(0,1);
//pos=str3.find("*",0);
if(strs.substr(0,1)=="*")
{
string str2=strs.substr(3,14);//提取4个字符--year
tc1.year=atoi(str2.c_str());//字符转数值
str2=strs.substr(8,2);//提取--month
tc1.month=atoi(str2.c_str());
str2=strs.substr(11,2);//提取--day
tc1.day=atoi(str2.c_str());
str2=strs.substr(14,2);//提取--hour
tc1.hour=atoi(str2.c_str());
str2=strs.substr(17,2);//提取--minute
tc1.minute=atoi(str2.c_str());
str2=strs.substr(20,9);//提取--second
tc1.second=atoi(str2.c_str());
tg1=GregToJD(tc1);//-2444244.5;//转换为jd时间
//cout<<floor((tg1-2444244.5)/7.0)<<endl;
v.push_back(tg1);
getline(infile,str1);
double x;
str2=str1.substr(4,14);//提取14个字
x=1000*atof(str2.c_str());//字符转数值
v1.push_back(x);
}
} while(strs.substr(0,3)!="EOF");
infile.close();
//ofstream outfile("igr14571.txt",ios::out|ios::app);
for(int i=0;i<v.size();i++)
{
outfile.precision(15);
outfile<<v[i]<<" "<<v1[i]<<endl;
}
}
outfile.close();
return 0;
}
double GregToJD(time_calendar tc)
{
double JD,h,yr,mth,WN,WN0;
if(tc.month>2) {yr=tc.year;mth=tc.month;}
else {yr=tc.year-1;mth=tc.month+12;}
//if(yr>10) yr+=1900;//如果1989年写为89,2005年写为05,恢复
//else yr+=2000;
h=tc.hour+tc.minute/60.0+tc.second/3600.0;
JD=floor(365.25*yr)+floor(30.6001*(mth+1))+tc.day+h/24.0+1720981.5;
//WN=floor((JD-2444244.5)/96.0);
WN0=(JD-2444244.5)*96;
WN=floor(WN0);
if((WN0-WN)>0.5)
WN++;
//TOW=(JD-2444244.5-7*WN)*86400.0;
//tg.num_week=WN;tg.num_sec=TOW;
return WN;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -