00001 #pragma ident "$Id: EarthOceanTide.cpp 2457 2010-08-18 14:20:12Z coandrei $"
00002
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00045 const double EarthOceanTide::G = 6.67259e-11;
00046 const double EarthOceanTide::GE = 9.780327;
00047
00048
00049
00050
00051
00052 void EarthOceanTide::loadTideFile(std::string fileName,int NMAX,double XMIN)
00053 {
00054 if(isLoaded) return;
00055
00056
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
00065 std::string buf;
00066
00067
00068 getline(fin,buf);
00069
00070
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
00078 getline(fin,buf);
00079
00080
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
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
00100 for(int i=0;i<NWAV;i++) getline(fin,buf);
00101
00102
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
00139
00140
00141
00142
00143
00144
00145 }
00146
00147
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
00161
00162
00163
00164
00165
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
00176
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
00191
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 }
00231
00232
00233 void EarthOceanTide::test()
00234 {
00235 std::cout<<"test Earth Ocean Tide"<<std::endl;
00236
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 }