00001 #pragma ident "$Id: RinexUtilities.cpp 1953 2009-06-19 12:53:42Z btolman $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00044
00045
00046
00047
00048 #include "RinexObsStream.hpp"
00049 #include "RinexObsHeader.hpp"
00050 #include "RinexNavStream.hpp"
00051 #include "RinexNavHeader.hpp"
00052 #include "RinexNavData.hpp"
00053 #include "RinexUtilities.hpp"
00054
00055 namespace gpstk {
00056
00057 using namespace std;
00058 using namespace gpstk;
00059
00060
00061 int RegisterARLUTExtendedTypes(void)
00062 {
00063 try {
00064 unsigned int EPPS =
00065 RinexObsHeader::RinexObsType::EPdepend | RinexObsHeader::RinexObsType::PSdepend;
00066 unsigned int L1L2 =
00067 RinexObsHeader::RinexObsType::L1depend | RinexObsHeader::RinexObsType::L2depend;
00068 unsigned int P1P2 =
00069 RinexObsHeader::RinexObsType::P1depend | RinexObsHeader::RinexObsType::P2depend;
00070 unsigned int EPEP=RinexObsHeader::RinexObsType::EPdepend;
00071 unsigned int PELL=EPPS | L1L2;
00072 unsigned int PEPP=EPPS | P1P2;
00073 unsigned int PsLs=L1L2 | P1P2;
00074 unsigned int L1P1 =
00075 RinexObsHeader::RinexObsType::L1depend | RinexObsHeader::RinexObsType::P1depend;
00076 unsigned int L2P2 =
00077 RinexObsHeader::RinexObsType::L2depend | RinexObsHeader::RinexObsType::P2depend;
00078 int j;
00079 j = RegisterExtendedRinexObsType("ER","Ephemeris range", "meters", EPPS);
00080 if(j) return j;
00081 j = RegisterExtendedRinexObsType("RI","Iono Delay, Range", "meters", P1P2);
00082 if(j) return j;
00083 j = RegisterExtendedRinexObsType("PI","Iono Delay, Phase", "meters", L1L2);
00084 if(j) return j;
00085 j = RegisterExtendedRinexObsType("TR","Tropospheric Delay", "meters", EPPS);
00086 if(j) return j;
00087 j = RegisterExtendedRinexObsType("RL","Relativity Correct.", "meters", EPEP);
00088 if(j) return j;
00089 j = RegisterExtendedRinexObsType("SC","SV Clock Bias", "meters", EPEP);
00090 if(j) return j;
00091 j = RegisterExtendedRinexObsType("EL","Elevation Angle", "degrees",EPPS);
00092 if(j) return j;
00093 j = RegisterExtendedRinexObsType("AZ","Azimuth Angle", "degrees",EPPS);
00094 if(j) return j;
00095 j = RegisterExtendedRinexObsType("SR","Slant TEC (PR)", "TECU", P1P2);
00096 if(j) return j;
00097 j = RegisterExtendedRinexObsType("SP","Slant TEC (Ph)", "TECU", L1L2);
00098 if(j) return j;
00099 j = RegisterExtendedRinexObsType("VR","Vertical TEC (PR)", "TECU", PEPP);
00100 if(j) return j;
00101 j = RegisterExtendedRinexObsType("VP","Vertical TEC (Ph)", "TECU", PELL);
00102 if(j) return j;
00103 j = RegisterExtendedRinexObsType("LA","Lat Iono Intercept", "degrees",EPPS);
00104 if(j) return j;
00105 j = RegisterExtendedRinexObsType("LO","Lon Iono Intercept", "degrees",EPPS);
00106 if(j) return j;
00107 j = RegisterExtendedRinexObsType("P3","TFC(IF) Pseudorange", "meters", P1P2);
00108 if(j) return j;
00109 j = RegisterExtendedRinexObsType("L3","TFC(IF) Phase", "meters", L1L2);
00110 if(j) return j;
00111 j = RegisterExtendedRinexObsType("PF","GeoFree Pseudorange", "meters", P1P2);
00112 if(j) return j;
00113 j = RegisterExtendedRinexObsType("LF","GeoFree Phase", "meters", L1L2);
00114 if(j) return j;
00115 j = RegisterExtendedRinexObsType("PW","WideLane Pseudorange","meters", P1P2);
00116 if(j) return j;
00117 j = RegisterExtendedRinexObsType("LW","WideLane Phase", "meters", L1L2);
00118 if(j) return j;
00119 j = RegisterExtendedRinexObsType("MP","Multipath (=M3)", "meters", PsLs);
00120 if(j) return j;
00121 j = RegisterExtendedRinexObsType("R1","(P1 + L1)/2" ,"meters", L1P1);
00122 if(j) return j;
00123 j = RegisterExtendedRinexObsType("R2","(P2 + L2)/2" ,"meters", L2P2);
00124 if(j) return j;
00125 j = RegisterExtendedRinexObsType("M1","L1 Range minus Phase","meters", L1P1);
00126 if(j) return j;
00127 j = RegisterExtendedRinexObsType("M2","L2 Range minus Phase","meters", L2P2);
00128 if(j) return j;
00129 j = RegisterExtendedRinexObsType("M3","IF Range minus Phase","meters", PsLs);
00130 if(j) return j;
00131 j = RegisterExtendedRinexObsType("M4","GF Range minus Phase","meters", PsLs);
00132 if(j) return j;
00133 j = RegisterExtendedRinexObsType("M5","WL Range minus Phase","meters", PsLs);
00134 if(j) return j;
00135 j = RegisterExtendedRinexObsType("XR","Non-dispersive Range","meters", PsLs);
00136 if(j) return j;
00137 j = RegisterExtendedRinexObsType("XI","Ionospheric delay", "meters", PsLs);
00138 if(j) return j;
00139 j = RegisterExtendedRinexObsType("X1","Range Error L1", "meters", PsLs);
00140 if(j) return j;
00141 j = RegisterExtendedRinexObsType("X2","Range Error L2", "meters", PsLs);
00142 if(j) return j;
00143 j = RegisterExtendedRinexObsType("SX","Satellite ECEF-X", "meters", EPEP);
00144 if(j) return j;
00145 j = RegisterExtendedRinexObsType("SY","Satellite ECEF-Y", "meters", EPEP);
00146 if(j) return j;
00147 j = RegisterExtendedRinexObsType("SZ","Satellite ECEF-Z", "meters", EPEP);
00148 if(j) return j;
00149 return 0;
00150 }
00151 catch(Exception& e) { GPSTK_RETHROW(e); }
00152 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00153 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00154 }
00155
00156
00157 bool isSP3File(const string& file)
00158 {
00159 try {
00160 SP3Header header;
00161 SP3Stream strm(file.c_str());
00162 strm.exceptions(fstream::failbit);
00163 try { strm >> header; } catch(Exception& e) { return false; }
00164 strm.close();
00165 return true;
00166 }
00167 catch(Exception& e) { GPSTK_RETHROW(e); }
00168 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00169 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00170 }
00171
00172
00173 bool isRinexNavFile(const string& file)
00174 {
00175 try {
00176 RinexNavHeader header;
00177 RinexNavStream rnstream;
00178 try {
00179 rnstream.open(file.c_str(),ios::in);
00180 if(!rnstream) return false;
00181 rnstream.exceptions(fstream::failbit);
00182 }
00183 catch(Exception& e) { return false; }
00184 catch(exception& e) { return false; }
00185 try { rnstream >> header; }
00186 catch(Exception& e) { return false; }
00187 catch(exception& e) { return false; }
00188 rnstream.close();
00189 return true;
00190 }
00191 catch(Exception& e) { GPSTK_RETHROW(e); }
00192 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00193 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00194 }
00195
00196
00197 bool isRinexObsFile(const string& file)
00198 {
00199 try {
00200 RinexObsHeader header;
00201 RinexObsStream rostream;
00202 try {
00203 rostream.open(file.c_str(),ios::in);
00204 if(!rostream) return false;
00205 rostream.exceptions(fstream::failbit);
00206 }
00207 catch(Exception& e) { return false; }
00208 catch(exception& e) { return false; }
00209 try { rostream >> header; }
00210 catch(Exception& e) { return false; }
00211 catch(exception& e) { return false; }
00212 rostream.close();
00213 return true;
00214 }
00215 catch(Exception& e) { GPSTK_RETHROW(e); }
00216 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00217 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00218 }
00219
00220
00221 void sortRinexObsFiles(vector<string>& files)
00222 {
00223 try {
00224 if(files.size() <= 1) return;
00225
00226 multimap<DayTime,string> hash;
00227 for(int n=0; n<files.size(); n++) {
00228 try {
00229 RinexObsHeader header;
00230 RinexObsStream rostream(files[n].c_str());
00231 rostream.exceptions(fstream::failbit);
00232 rostream >> header;
00233 rostream.close();
00234 if(!header.isValid()) continue;
00235
00236 hash.insert(multimap<DayTime,string>::value_type(header.firstObs,files[n]));
00237 }
00238 catch(Exception& e) { continue; }
00239 }
00240
00241
00242 files.clear();
00243 multimap<DayTime,string>::const_iterator it = hash.begin();
00244 while(it != hash.end()) {
00245 files.push_back(it->second);
00246 it++;
00247 }
00248 }
00249 catch(Exception& e) { GPSTK_RETHROW(e); }
00250 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00251 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00252 }
00253
00254
00255 int FillEphemerisStore(const vector<string>& files, SP3EphemerisStore& PE,
00256 GPSEphemerisStore& BCE)
00257 {
00258 try {
00259 int nread=0;
00260 RinexNavHeader rnh;
00261 RinexNavData rne;
00262 for(int i=0; i<files.size(); i++) {
00263 if(files[i].empty()) throw Exception("File name is empty");
00264 RinexNavStream strm(files[i].c_str());
00265 if(!strm) throw Exception("Could not open file " + files[i]);
00266 strm.close();
00267 if(isRinexNavFile(files[i])) {
00268 RinexNavStream RNFileIn(files[i].c_str());
00269 RNFileIn.exceptions(fstream::failbit);
00270 try {
00271 RNFileIn >> rnh;
00272 while (RNFileIn >> rne)
00273 {
00274
00275 if(rne.health == 0)
00276 BCE.addEphemeris(rne);
00277 }
00278 nread++;
00279 }
00280 catch(Exception& e) {
00281
00282
00283
00284 GPSTK_RETHROW(e);
00285 }
00286 }
00287 else if(isSP3File(files[i])) {
00288 try {
00289 PE.loadFile(files[i]);
00290 }
00291 catch(Exception& e) {
00292
00293
00294
00295 GPSTK_RETHROW(e);
00296 }
00297 nread++;
00298 }
00299 else
00300 throw Exception("File " + files[i] + " is neither BCE nor PE file.");
00301 }
00302 return nread;
00303 }
00304 catch(Exception& e) { GPSTK_RETHROW(e); }
00305 catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
00306 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
00307 }
00308
00309 }
00310
00311
00312