EOPDataStore.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: EOPDataStore.cpp 2953 2011-10-28 17:00:32Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Wei Yan - Chinese Academy of Sciences . 2011
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       // Add to the store directly
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    }  // End of 'EOPDataStore::addEOPData()'
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    }  // End of method 'EOPDataStore::getEOPData()'
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          // line length is actually 185
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));      // arcseconds
00094          double yp = StringUtils::asDouble(line.substr(37,9));      // arcseconds
00095          double UT1mUTC = StringUtils::asDouble(line.substr(58,10));// arcseconds
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       // first we skip the header section
00130       // skip the header
00131 
00132       //version 2
00133       //EOP  SOLUTION
00134       //  MJD         X        Y     UT1-UTC    LOD   Xsig   Ysig   UTsig LODsig  Nr Nf Nt     Xrt    Yrt  Xrtsig Yrtsig   dpsi    deps
00135       //               10**-6"        .1us    .1us/d    10**-6"     .1us  .1us/d                10**-6"/d    10**-6"/d        10**-6
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          // line length is actually 185
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             // for observed data and predicted data
00219             continue;
00220          }
00221 
00222          if(bData)
00223          {
00224             // # FORMAT(I4,I3,I3,I6,2F10.6,2F11.7,4F10.6,I4)
00225             //int year = StringUtils::asInt(buf.substr(0,4));
00226             //int month = StringUtils::asInt(buf.substr(4,3));
00227             //int day = StringUtils::asInt(buf.substr(7,3));
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       }  // End of 'while'
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 }  // End of namespace 'gpstk'
00257 
00258 
00259 
00260 
00261 
00262 

Generated on Tue May 22 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1