00001 #pragma ident "$Id: ObsEphReaderFramework.cpp 3140 2012-06-18 15:03:02Z susancummins $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00029 #include "ObsEphReaderFramework.hpp"
00030 #include <MSCData.hpp>
00031 #include <MSCStream.hpp>
00032 #include <GPSEphemerisStore.hpp>
00033
00034 using namespace std;
00035
00036 namespace gpstk
00037 {
00038 using namespace StringUtils;
00039
00040 template<class T> ostream& operator<<(ostream& ostr, const vector<T>& x)
00041 {
00042 using namespace std;
00043 for (typename vector<T>::const_iterator i = x.begin(); i!=x.end(); i++)
00044 ostr << *i << " ";
00045 return ostr;
00046 }
00047
00048 bool ObsEphReaderFramework::initialize(int argc, char *argv[]) throw()
00049 {
00050 CommandOptionNoArg debugOption('d', "debug", "Increase debug level");
00051 CommandOptionNoArg verboseOption('v', "verbose", "Increase verbosity");
00052 CommandOptionNoArg helpOption('h', "help", "Print help usage");
00053
00054 CommandOptionWithAnyArg obsFileOption(
00055 'o', "obs","Where to get the observation data. "
00056 "Supported formats are " +
00057 ObsReader::formatsUnderstood() + ".", true);
00058
00059 CommandOptionWithAnyArg ephFileOption(
00060 'e', "eph", "Where to get the Ephemeris data. Supported formats are " +
00061 EphReader::formatsUnderstood() + ".", true);
00062
00063 CommandOptionWithAnyArg outputFileOption(
00064 '\0', "output", "A file to write the output to. The default is stdout.");
00065 outputFileOption.setMaxCount(1);
00066
00067 CommandOptionWithAnyArg rxPosOption(
00068 'p', "position", "Receiver antenna position in ECEF "
00069 "(x,y,z) coordinates. Format as a string: \"X Y Z\". "
00070 "Defaluts to estimating the position from the obs data "
00071 "unless a position can be read from the input.");
00072 rxPosOption.setMaxCount(1);
00073
00074 CommandOptionWithAnyArg mscFileOption(
00075 'c', "msc", "Station coordinate file.");
00076 mscFileOption.setMaxCount(1);
00077
00078 CommandOptionWithAnyArg msidOption(
00079 'm', "msid", "Station to process data for. Used to select "
00080 "a station position from the msc file.");
00081 msidOption.setMaxCount(1);
00082
00083 CommandOptionNoArg searchNearOption('\0', "search-near", "Specify search near option when determining SV position with a broadcast ephemers. Usefull when ephemers data starts soon *after* the start of the observation data.");
00084
00085 CommandOptionParser cop(appDesc);
00086
00087 cop.parseOptions(argc, argv);
00088
00089 if (helpOption.getCount())
00090 {
00091 cop.displayUsage(cout);
00092 exit(0);
00093 }
00094
00095 if (cop.hasErrors())
00096 {
00097 cop.dumpErrors(cout);
00098 cop.displayUsage(cout);
00099 exit(0);
00100 }
00101
00102 debugLevel = debugOption.getCount();
00103 verboseLevel = verboseOption.getCount();
00104
00105 if (outputFileOption.getCount())
00106 outputFn = outputFileOption.getValue()[0];
00107
00108 if (outputFn=="-" || outputFn=="")
00109 {
00110 output.copyfmt(cout);
00111 output.clear(cout.rdstate());
00112 output.ios::rdbuf(cout.rdbuf());
00113 outputFn = "<stdout>";
00114 }
00115 else
00116 output.open(outputFn.c_str(), ios::out);
00117
00118 if (!output)
00119 {
00120 cout << "Could not open: " << outputFn << ". Terminating." << endl;
00121 exit(0);
00122 }
00123
00124 obsFiles = obsFileOption.getValue();
00125 ephFiles = ephFileOption.getValue();
00126
00127 if (verboseLevel)
00128 output << "Reading Observation data from: " << obsFiles << endl
00129 << "Reading Ephemeris data from: " << ephFiles << endl
00130 << "Writing output to " << outputFn << endl;
00131
00132
00133
00134 ephReader.verboseLevel = verboseLevel;
00135 FFIdentifier::debugLevel = debugLevel;
00136 for (int i=0; i<ephFiles.size(); i++)
00137 ephReader.read(ephFiles[i]);
00138 gpstk::XvtStore<SatID>& eph = *ephReader.eph;
00139
00140 bool searchNear = searchNearOption.getCount() > 0;
00141 if (searchNear && typeid(eph) == typeid(GPSEphemerisStore))
00142 {
00143 GPSEphemerisStore& bce = dynamic_cast<GPSEphemerisStore&>(eph);
00144 bce.SearchNear();
00145 if (verboseLevel)
00146 output << "Using SearchNear() for ephemers" << endl;
00147 }
00148
00149 if (msidOption.getCount())
00150 {
00151 msid = msidOption.getValue()[0];
00152 if (verboseLevel)
00153 output << "Monitor station ID:" << msid << endl;
00154 }
00155
00156
00157
00158
00159
00160
00161 string rxPosSource;
00162 if (rxPosOption.getCount())
00163 {
00164 string aps = rxPosOption.getValue()[0];
00165 change(aps, ",", " ");
00166 if (numWords(aps) != 3)
00167 {
00168 output << "Please specify three coordinates in the antenna postion." << endl;
00169 return false;
00170 }
00171 else
00172 {
00173 rxPos = Position(asDouble(word(aps, 0)),
00174 asDouble(word(aps, 1)),
00175 asDouble(word(aps, 2)));
00176 rxPosSource = "command line";
00177 }
00178 }
00179 else if (msidOption.getCount() && mscFileOption.getCount())
00180 {
00181 string mscfn = mscFileOption.getValue()[0];
00182 MSCStream msc(mscfn.c_str(), ios::in);
00183 MSCData mscd;
00184 unsigned id = StringUtils::asUnsigned(msid);
00185 while (msc >> mscd && mscd.station != id)
00186 ;
00187 if (mscd.station == id)
00188 {
00189 rxPos = mscd.coordinates;
00190 rxPosSource = "msc file";
00191 }
00192 }
00193 else
00194 {
00195 string fn = (obsFileOption.getValue())[0];
00196 ObsReader obsReader(fn, debugLevel);
00197 if (obsReader.inputType == FFIdentifier::tRinexObs)
00198 {
00199 rxPos = obsReader.roh.antennaPosition;
00200 rxPosSource = "rinex obs header";
00201 }
00202 else
00203 {
00204 rxPosSource = "esitmated from obs and ephemers data";
00205 output << "code me " << endl;
00206 exit(0);
00207 }
00208 }
00209
00210 if (verboseLevel)
00211 output << "Receier position : " << rxPos
00212 << " (from " << rxPosSource << ")" << endl;
00213
00214 if (rxPos.radius() < 1)
00215 output << "Warning! The antenna appears to be within one meter of the" << endl
00216 << "center of the geoid. If this location is correct, the " << endl
00217 << "antenna is probably no longer functional." << endl;
00218
00219 return true;
00220 }
00221
00222 }