📄 rinsum.cpp
字号:
return 1;} // end main()//------------------------------------------------------------------------------------int GetCommandLine(int argc, char **argv) throw(Exception){try { bool help=false; int j; // required options // optional CommandOption dashi(CommandOption::hasArgument, CommandOption::stdType, 'i',"input"," [-i|--input] <file> Input RINEX observation file name(s)"); //dashi.setMaxCount(1); // optional options // this only so it will show up in help page... CommandOption dashf(CommandOption::hasArgument, CommandOption::stdType, 'f',""," [-f|--file] <file> file containing more options"); CommandOption dasho(CommandOption::hasArgument, CommandOption::stdType, 'o',"output"," [-o|--output] <file> Output the summary to a file named <file>"); dasho.setMaxCount(1); CommandOption dashp(CommandOption::hasArgument, CommandOption::stdType, 'p',"path"," [-p|--path] <path> Find the input file(s) in this directory"); dashp.setMaxCount(1); CommandOptionNoArg dashr('R', "Replace", " [-R|--Replace] Replace input file header with a full one, in place."); dashr.setMaxCount(1); CommandOptionNoArg dashs('s', "sort", " [-s|--sort] Sort the SAT/Obs table on begin time."); CommandOptionNoArg dashg('g', "gps", " [-g|--gps] Print times in the SAT/Obs table as GPS times."); // time // times - don't use CommandOptionWithTimeArg CommandOption dashbt(CommandOption::hasArgument, CommandOption::stdType, 0,"start", " --start <time> Start time: <time> is 'GPSweek,sow' OR " "'YYYY,MM,DD,HH,Min,Sec'"); dashbt.setMaxCount(1); CommandOption dashet(CommandOption::hasArgument, CommandOption::stdType, 0,"stop", " --stop <time> Stop time: <time> is 'GPSweek,sow' OR " "'YYYY,MM,DD,HH,Min,Sec'"); dashet.setMaxCount(1); CommandOptionNoArg dashb('b', "brief", " [-b|--brief] produce a brief (6-line) summary."); // help and debug CommandOptionNoArg dashh('h', "help", " [-h|--help] print this help page and quit."); CommandOptionNoArg dashd('d', "debug", " [-d|--debug] print debugging info."); // ... other options CommandOptionRest Rest("<filename(s)>"); CommandOptionParser Par( "Prgm RINSUM reads a Rinex file and summarizes it content.\n" " It can optionally fill the header of the input file.\n" " [either <filenames> or --input required; put <filenames> after options].\n" ); // allow user to put all options in a file // could also scan for debug here vector<string> Args; for(j=1; j<argc; j++) PreProcessArgs(argv[j],Args); if(Args.size()==0) Args.push_back(string("-h")); argc = Args.size()+1; char **CArgs; CArgs = new char * [argc]; if(!CArgs) { cerr << "Failed to allocate CArgs\n"; return -1; } CArgs[0] = argv[0]; for(j=1; j<argc; j++) { CArgs[j] = new char[Args[j-1].size()+1]; if(!CArgs[j]) { cerr << "Failed to allocate CArgs[j]\n"; return -1; } strcpy(CArgs[j],Args[j-1].c_str()); } Par.parseOptions(argc, CArgs); delete[] CArgs; // get help option first if(dashh.getCount() > 0) { Par.displayUsage(cout,false); help = true; //return 1; } if (Par.hasErrors()) { cerr << "\nErrors found in command line input:\n"; Par.dumpErrors(cerr); cerr << "...end of Errors\n\n"; Par.displayUsage(cout,false); help = true; // return -1; } // get values found on command line string msg; vector<string> values,field; // f never appears because we intercept it above //if(dashf.getCount()) { cout << "Option f "; dashf.dumpValue(cout); } if(dashi.getCount()) { InputFiles = dashi.getValue(); if(help) { cout << "Input: input files (--input) are:\n"; for(int i=0; i<InputFiles.size(); i++) cout << " " << InputFiles[i] << endl; } } if(dasho.getCount()) { values = dasho.getValue(); OutputFile = values[0]; if(help) cout << "Input: output file is " << OutputFile << endl; } if(dashp.getCount()) { values = dashp.getValue(); InputDirectory = values[0]; if(help) cout << "Input: set path to " << InputDirectory << endl; } if(dashr.getCount()) { ReplaceHeader=true; if(help) cout << "Input: replace header in output" << endl; } if(dashs.getCount()) { TimeSortTable=true; if(help) cout << "Input: sort the SAT/Obs table" << endl; } if(dashg.getCount()) { GPSTimeOutput=true; if(help) cout << "Input: output in GPS time" << endl; } // times // TD put try {} around setToString and catch invalid formats... if(dashbt.getCount()) { values = dashbt.getValue(); msg = values[0]; field.clear(); while(msg.size() > 0) field.push_back(stripFirstWord(msg,',')); if(field.size() == 2) BegTime.setToString(field[0]+","+field[1], "%F,%g"); else if(field.size() == 6) BegTime.setToString(field[0]+","+field[1]+","+field[2]+","+field[3]+"," +field[4]+","+field[5], "%Y,%m,%d,%H,%M,%S"); else { cerr << "Error: invalid --start input: " << values[0] << endl; } if(help) cout << " Input: begin time " << values[0] << " = " << BegTime.printf("%Y/%02m/%02d %2H:%02M:%06.3f = %F/%10.3g") << endl; } if(dashet.getCount()) { values = dashet.getValue(); msg = values[0]; field.clear(); while(msg.size() > 0) field.push_back(stripFirstWord(msg,',')); if(field.size() == 2) EndTime.setToString(field[0]+","+field[1], "%F,%g"); else if(field.size() == 6) EndTime.setToString(field[0]+","+field[1]+","+field[2]+","+field[3]+"," +field[4]+","+field[5], "%Y,%m,%d,%H,%M,%S"); else { cerr << "Error: invalid --stop input: " << values[0] << endl; } if(help) cout << " Input: end time " << values[0] << " = " << EndTime.printf("%Y/%02m/%02d %2H:%02M:%06.3f = %F/%10.3g") << endl; } if(dashb.getCount()) { brief = true; if(help) cout << "Input: found the brief flag" << endl; } if(dashd.getCount()) { debug = true; if(help) cout << "Input: found the debug flag" << endl; } if(Rest.getCount()) { values = Rest.getValue(); if(help) cout << "Input: input files are:\n"; for (int i=0; i<values.size(); i++) { if(help) cout << " " << values[i] << endl; InputFiles.push_back(values[i]); } } if(debug && help) { cout << "\nTokens on command line (" << Args.size() << ") are:" << endl; for(j=0; j<Args.size(); j++) cout << Args[j] << endl; } if(help) return 1; return 0;}catch(Exception& e) { GPSTK_RETHROW(e); }catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } return -1;}//------------------------------------------------------------------------------------// Pull out -f<f> and --file <f> and deprecated optionsvoid PreProcessArgs(const char *arg, vector<string>& Args) throw(Exception){try { static bool found_cfg_file=false; if(found_cfg_file || (arg[0]=='-' && arg[1]=='f')) { string filename(arg); if(!found_cfg_file) filename.erase(0,2); else found_cfg_file = false; ifstream infile(filename.c_str()); if(!infile) { cout << "Error: could not open options file " << filename << endl; return; } bool again_cfg_file=false; char c; string buffer,word; while(1) { getline(infile,buffer); stripTrailing(buffer,'\r'); // process the buffer before checking eof or bad b/c there can be // a line at EOF that has no CRLF... while(!buffer.empty()) { word = firstWord(buffer); if(again_cfg_file) { word = "-f" + word; again_cfg_file = false; PreProcessArgs(word.c_str(),Args); } else if(word[0] == '#') { // skip to end of line buffer = ""; } else if(word == "--file" || word == "-f") again_cfg_file = true; else if(word[0] == '"') { word = stripFirstWord(buffer,'"'); buffer = "dummy " + buffer; // to be stripped later PreProcessArgs(word.c_str(),Args); } else PreProcessArgs(word.c_str(),Args); word = stripFirstWord(buffer); // now remove it from buffer } if(infile.eof() || !infile.good()) break; } } else if(string(arg) == "--file" || string(arg) == "-f") found_cfg_file = true; // old versions of args -- deprecated else if(string(arg)==string("--EpochBeg")) { Args.push_back("--start"); } else if(string(arg)==string("--GPSBeg")) { Args.push_back("--start"); } else if(string(arg)==string("--EpochEnd")) { Args.push_back("--stop"); } else if(string(arg)==string("--GPSEnd")) { Args.push_back("--stop"); } // regular arg else Args.push_back(arg);}catch(Exception& e) { GPSTK_RETHROW(e); }catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }}//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -