#include "sp3.hh" #include #include #include #include #include using namespace std; SP3Reader::SP3Reader(std::string_view fname) { d_fp = fopen(&fname[0], "r"); if(!d_fp) throw runtime_error("Unable to open "+(string)fname+": "+strerror(errno)); } SP3Reader::~SP3Reader() { if(d_fp) fclose(d_fp); } bool SP3Reader::get(SP3Entry& entry) { char line[80]; struct tm tm; while(fgets(line, sizeof(line), d_fp)) { if(line[0]=='*') { //0 1 2 3 4 5 6 //* 2019 9 17 1 0 0.00000000 std::stringstream ss(line); std::string token; int num = 0; memset(&tm, 0, sizeof(tm)); while (std::getline(ss, token, ' ')) { if(token.empty()) continue; int val = atoi(token.c_str()); if(num == 1) tm.tm_year = val - 1900; else if(num==2) tm.tm_mon = val - 1; else if(num == 3) tm.tm_mday = val; else if(num == 4) tm.tm_hour = val; else if(num == 5) tm.tm_min = val; else if(num==6) tm.tm_sec = val; num++; // cout<<"Token: "<