00001 #pragma ident "$Id: EOPDataStore.cpp 2953 2011-10-28 17:00:32Z yanweignss $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "EOPDataStore.hpp"
00032 #include "MiscMath.hpp"
00033 #include <fstream>
00034
00035 namespace gpstk
00036 {
00037 using namespace std;
00038
00039
00040 void EOPDataStore::addEOPData(const DayTime& utc,
00041 const EOPDataStore::EOPData& d)
00042 throw()
00043 {
00044 std::vector<double> data(5,0.0);
00045
00046 data[0] = d.xp;
00047 data[1] = d.yp;
00048 data[2] = d.UT1mUTC;
00049
00050 data[3] = d.dPsi;
00051 data[4] = d.dEps;
00052
00053 addData(utc, data);
00054
00055 }
00056
00057
00058 EOPDataStore::EOPData EOPDataStore::getEOPData(const DayTime& utc) const
00059 throw(InvalidRequest)
00060 {
00061 std::vector<double> data = getData(utc);
00062
00063 return EOPData(data[0],data[1],data[2],data[3],data[4]);
00064
00065 }
00066
00067
00068
00069 void EOPDataStore::loadIERSFile(std::string iersFile)
00070 throw(FileMissingException)
00071 {
00072 ifstream inpf(iersFile.c_str());
00073 if(!inpf)
00074 {
00075 FileMissingException fme("Could not open IERS file " + iersFile);
00076 GPSTK_THROW(fme);
00077 }
00078
00079 clear();
00080
00081 bool ok (true);
00082 while(!inpf.eof() && inpf.good())
00083 {
00084 string line;
00085 getline(inpf,line);
00086 StringUtils::stripTrailing(line,'\r');
00087 if(inpf.eof()) break;
00088
00089
00090 if(inpf.bad() || line.size() < 70) { ok = false; break; }
00091
00092 double mjd = StringUtils::asDouble(line.substr(7,8));
00093 double xp = StringUtils::asDouble(line.substr(18,9));
00094 double yp = StringUtils::asDouble(line.substr(37,9));
00095 double UT1mUTC = StringUtils::asDouble(line.substr(58,10));
00096
00097 double dPsi(0.0);
00098 double dEps(0.0);
00099 if(line.size()>=185)
00100 {
00101 dPsi = StringUtils::asDouble(line.substr(165,10))/1000.0;
00102 dEps = StringUtils::asDouble(line.substr(175,10))/1000.0;
00103 }
00104
00105 addEOPData(DayTime(mjd), EOPData(xp,yp,UT1mUTC,dPsi,dEps));
00106 };
00107 inpf.close();
00108
00109 if(!ok)
00110 {
00111 FileMissingException fme("IERS File " + iersFile
00112 + " is corrupted or wrong format");
00113 GPSTK_THROW(fme);
00114 }
00115 }
00116
00117 void EOPDataStore::loadIGSFile(std::string igsFile)
00118 throw(FileMissingException)
00119 {
00120 ifstream inpf(igsFile.c_str());
00121 if(!inpf)
00122 {
00123 FileMissingException fme("Could not open IERS file " + igsFile);
00124 GPSTK_THROW(fme);
00125 }
00126
00127 clear();
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 string temp;
00138 getline(inpf,temp);
00139 getline(inpf,temp);
00140 getline(inpf,temp);
00141 getline(inpf,temp);
00142
00143 bool ok (true);
00144 while(!inpf.eof() && inpf.good())
00145 {
00146 string line;
00147 getline(inpf,line);
00148 StringUtils::stripTrailing(line,'\r');
00149 if(inpf.eof()) break;
00150
00151
00152 if(inpf.bad() || line.size() < 120) { ok = false; break; }
00153
00154 istringstream istrm(line);
00155
00156 double mjd(0.0),xp(0.0),yp(0.0),UT1mUTC(0.0),dPsi(0.0),dEps(0.0);
00157
00158 istrm >> mjd >> xp >> yp >> UT1mUTC;
00159
00160 double tmp;
00161 for(int i=0;i<12;i++) istrm >> temp;
00162
00163 istrm >> dPsi >> dEps;
00164
00165 xp *= 1e-6;
00166 yp *= 1e-6;
00167 UT1mUTC *= 1e-7;
00168
00169 dPsi *= 1e-6;
00170 dEps *= 1e-6;
00171
00172 addEOPData(DayTime(mjd), EOPData(xp,yp,UT1mUTC,dPsi,dEps));
00173 };
00174 inpf.close();
00175
00176 if(!ok)
00177 {
00178 FileMissingException fme("IERS File " + igsFile
00179 + " is corrupted or wrong format");
00180 GPSTK_THROW(fme);
00181 }
00182 }
00183
00190 void EOPDataStore::loadSTKFile(std::string stkFile)
00191 throw(FileMissingException)
00192 {
00193 std::ifstream fstk(stkFile.c_str());
00194
00195 int numData = 0;
00196 bool bData = false;
00197
00198 std::string buf;
00199 while(getline(fstk,buf))
00200 {
00201 if(buf.substr(0,19) == "NUM_OBSERVED_POINTS")
00202 {
00203 numData = StringUtils::asInt(buf.substr(20));
00204 continue;
00205 }
00206 else if(buf.substr(0,14) == "BEGIN OBSERVED")
00207 {
00208 bData = true;
00209 continue;
00210 }
00211 else if(buf.substr(0,13) == "END PREDICTED")
00212 {
00213 bData = false;
00214 break;
00215 }
00216 if(!StringUtils::isDigitString(buf.substr(0,4)))
00217 {
00218
00219 continue;
00220 }
00221
00222 if(bData)
00223 {
00224
00225
00226
00227
00228 double mjd = StringUtils::asInt(buf.substr(10,6));
00229
00230 double xp = StringUtils::asDouble(buf.substr(16,10));
00231 double yp = StringUtils::asDouble(buf.substr(26,10));
00232 double UT1mUTC = StringUtils::asDouble(buf.substr(36,11));
00233 double dPsi = 0.0;
00234 double dEps = 0.0;
00235
00236 addEOPData(DayTime(mjd), EOPData(xp,yp,UT1mUTC,dPsi,dEps));
00237 }
00238
00239 }
00240
00241 fstk.close();
00242 }
00243
00244 ostream& operator<<(std::ostream& os, const EOPDataStore::EOPData& d)
00245 {
00246 os << " " << setw(18) << setprecision(8) << d.xp
00247 << " " << setw(18) << setprecision(8) << d.yp
00248 << " " << setw(18) << setprecision(8) << d.UT1mUTC
00249 << " " << setw(18) << setprecision(8) << d.dPsi
00250 << " " << setw(18) << setprecision(8) << d.dEps;
00251
00252
00253 return os;
00254 }
00255
00256 }
00257
00258
00259
00260
00261
00262