EarthOceanTide.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: EarthOceanTide.cpp 2457 2010-08-18 14:20:12Z coandrei $"
00002 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 //
00027 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010
00028 //
00029 //============================================================================
00030 
00031 #include "EarthOceanTide.hpp"
00032 #include <fstream>
00033 #include <math.h>
00034 #include <string>
00035 #include "UTCTime.hpp"
00036 #include "ASConstant.hpp"
00037 #include "ReferenceFrames.hpp"
00038 
00039 
00040 namespace gpstk
00041 {
00042    using namespace gpstk::StringUtils;
00043 
00044    // constants
00045    const double EarthOceanTide::G  = 6.67259e-11; // m^3/kg/s/s
00046    const double EarthOceanTide::GE = 9.780327;    // m/s/s 
00047 
00048       /*
00049       * load ocean data file see bern "OT_CSRC.TID"
00050       * reference bernese5 OTIDES.f
00051       */
00052    void EarthOceanTide::loadTideFile(std::string fileName,int NMAX,double XMIN)
00053    {
00054       if(isLoaded) return;
00055 
00056       // open the file
00057       std::ifstream fin(fileName.c_str());
00058       if(!fin.good())
00059       {
00060          Exception e("Can not Open the CSR Ocean Tide File:"+fileName);
00061          GPSTK_THROW(e);
00062       }
00063 
00064       // read the file
00065       std::string buf;
00066 
00067       // line 1 ,skip it
00068       getline(fin,buf);   
00069 
00070       // line 2
00071       getline(fin,buf);
00072       NWAV = asInt(buf.substr(0,4));
00073       NTOT = asInt(buf.substr(4,4));
00074       NMX = asInt(buf.substr(8,4));
00075       MMX = asInt(buf.substr(12,4));
00076 
00077       // line 3 ,skip it
00078       getline(fin,buf);
00079 
00080       // line 4
00081       getline(fin,buf);
00082       RRE = asDouble(buf.substr(0,21));
00083       RHOW = asDouble(buf.substr(21,21));
00084       XME = asDouble(buf.substr(42,21));
00085       PFCN = asDouble(buf.substr(63,21));
00086       XXX = asDouble(buf.substr(84,21));
00087 
00088       // line 5 ~ 8
00089       for(int i=0;i<4;i++)
00090       {
00091          getline(fin,buf);
00092          for(int j=0;j<6;j++   )      
00093          {
00094             if((i*6+j) > 19) break;
00095             tideData.KNMP[i*6+j] = asDouble(buf.substr(j*21,21));   
00096          }
00097       }
00098 
00099       //IGNORE  THE NWAV LINE
00100       for(int i=0;i<NWAV;i++) getline(fin,buf);
00101 
00102       // CEXTRACT REQUIRED INFORMATION FROM NEXT NTOT LINES
00103       int id = 0;
00104       for(int i=0;i<NTOT;i++)
00105       {
00106          getline(fin,buf);
00107 
00108          tideData.NDOD[id][0] = asInt(buf.substr(13,1)); 
00109          tideData.NDOD[id][1] = asInt(buf.substr(14,1)); 
00110          tideData.NDOD[id][2] = asInt(buf.substr(15,1)); 
00111 
00112          tideData.NDOD[id][3] = asInt(buf.substr(17,1)); 
00113          tideData.NDOD[id][4] = asInt(buf.substr(18,1)); 
00114          tideData.NDOD[id][5] = asInt(buf.substr(19,1));          
00115 
00116          tideData.NM[id][0] = asInt(buf.substr(24,2)); 
00117          tideData.NM[id][1] = asInt(buf.substr(26,2));       
00118 
00119          tideData.CSPM[id][0] = asDouble(buf.substr(30,22)); 
00120          tideData.CSPM[id][1] = asDouble(buf.substr(52,22));
00121          tideData.CSPM[id][2] = asDouble(buf.substr(74,22));
00122          tideData.CSPM[id][3] = asDouble(buf.substr(96,22));
00123 
00124 
00125          if((tideData.NM[id][0]<=NMAX) &&
00126             (
00127             (fabs(tideData.CSPM[id][0])>XMIN) ||
00128             (fabs(tideData.CSPM[id][1])>XMIN) ||
00129             (fabs(tideData.CSPM[id][2])>XMIN) ||
00130             (fabs(tideData.CSPM[id][3])>XMIN))
00131             )
00132          {
00133             for(int j=1;j<6;j++) tideData.NDOD[id][j]-=5;
00134 
00135             id ++;
00136             tideData.NTACT = id;
00137          }
00138          // check
00139          /*
00140          if(m_csr_otide.NTACT>=MAXTRM)
00141          {
00142          cerr << "ERROR: SR OTIDES: NOT ALL TERMS AVAILABLE IN FILE" << endl;
00143          exit(1);
00144          }*/
00145       }   
00146 
00147       // close the file
00148       fin.close();
00149 
00150       isLoaded = true;
00151 
00152       FAC[0] = 1.0;
00153       for(int i=1;i<=30;i++)
00154       {
00155          FAC[i]=FAC[i-1]*i;
00156       }
00157 
00158    }
00159 
00160       /* Ocean pole tide to normalized earth potential coefficients
00161        *
00162        * @param mjdUtc UTC in MJD
00163        * @param dC     Correction to normalized coefficients dC
00164        * @param dS     Correction to normalized coefficients dS
00165        *    C20 C21 C22 C30 C31 C32 C33 C40 C41 C42 C43 C44
00166        */
00167    void EarthOceanTide::getOceanTide(double mjdUtc, double dC[], double dS[] )
00168    {
00169       try
00170       {
00171          loadTideFile(fileName,maxN,minX);
00172       }
00173       catch (...)
00174       {
00175          // faild to get the ocean tide model
00176          // return zeros
00177          const int n = (maxN-1)*(maxN+4)/2; 
00178          for(int i=0;i<n;i++)
00179          {
00180             dC[i] = 0.0;
00181             dS[i] = 0.0;
00182          }
00183 
00184          return;
00185       }
00186       
00187       UTCTime utc;
00188       utc.setMJD(mjdUtc);
00189 
00190       //   CC PURPOSE    :  COMPUTE DOODSON'S FUNDAMENTAL ARGUMENTS (BETA)
00191       //  CC               AND FUNDAMENTAL ARGUMENTS FOR NUTATION (FNUT)
00192       double BETA[6]={0.0};
00193       double FNUT[5] ={0.0};
00194       ReferenceFrames::doodsonArguments(utc.asUT1(), utc.asTT(), BETA,FNUT);
00195 
00196       for(int i=0;i<tideData.NTACT;i++)
00197       {
00198          int N= tideData.NM[i][0];
00199          int M= tideData.NM[i][1];
00200 
00201          if(tideData.NM[i][0]>maxN) continue;
00202 
00203          double delta = M ? 0 : 1;
00204 
00205          double FNM = 4.0*ASConstant::PI*G*RHOW/GE* std::sqrt(FAC[N+M]/FAC[N-M]/(2.0*N+1.0)/(2.0-delta))
00206             *(1.0+tideData.KNMP[N-1])/(2.0*N+1)/100.0;
00207 
00208          double ARG =0;
00209          for(int j=0;j<6;j++)
00210          {
00211             ARG +=tideData.NDOD[i][j]*BETA[j];
00212          }
00213 
00214          double CARG = std::cos(ARG);
00215          double SARG = std::sin(ARG);
00216 
00217          int index=N*(N+1)/2-3+M;
00218 
00219          dC[index]=dC[index]
00220          +FNM*(
00221             (tideData.CSPM[i][0]+tideData.CSPM[i][2])*CARG
00222             +(tideData.CSPM[i][1]+tideData.CSPM[i][3])*SARG);
00223 
00224          dS[index]=dS[index]
00225          +FNM*(
00226             (tideData.CSPM[i][1]-tideData.CSPM[i][3])*CARG
00227             -(tideData.CSPM[i][0]-tideData.CSPM[i][2])*SARG);
00228       }
00229       
00230    }    // End of method 'EarthOceanTide::getOceanTide()'
00231    
00232 
00233    void EarthOceanTide::test()
00234    {
00235       std::cout<<"test Earth Ocean Tide"<<std::endl;
00236       // debuging
00237       double mjdUtc = 2454531 + 0.49983796296296296 - 2400000.5;
00238       double dc[12]={0.0},ds[12]={0.0};
00239       getOceanTide(mjdUtc,dc,ds);
00240 
00241       int a = 0;
00242 
00243    }
00244 
00245 }  // End of namespace 'gpstk'

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