23int main(
int argc,
const char*
const argv[]) {
28 bool verbose =
false, longfirst =
false;
31 std::string istring, ifile, ofile, cdelim;
35 int prec = -1, Nmax = -1, Mmax = -1;
42 unsigned mode = GRAVITY;
43 for (
int m = 1; m < argc; ++m) {
44 std::string arg(argv[m]);
46 if (++m == argc)
return usage(1,
true);
48 }
else if (arg ==
"-d") {
49 if (++m == argc)
return usage(1,
true);
51 }
else if (arg ==
"-N") {
52 if (++m == argc)
return usage(1,
true);
56 std::cerr <<
"Maximum degree " << argv[m] <<
" is negative\n";
60 catch (
const std::exception&) {
61 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
64 }
else if (arg ==
"-M") {
65 if (++m == argc)
return usage(1,
true);
69 std::cerr <<
"Maximum order " << argv[m] <<
" is negative\n";
73 catch (
const std::exception&) {
74 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
77 }
else if (arg ==
"-G")
85 else if (arg ==
"-c") {
86 if (m + 2 >= argc)
return usage(1,
true);
95 +
"d, " + std::to_string(
Math::qd) +
"d]");
99 catch (
const std::exception& e) {
100 std::cerr <<
"Error decoding argument of " << arg <<
": "
104 }
else if (arg ==
"-w")
105 longfirst = !longfirst;
106 else if (arg ==
"-p") {
107 if (++m == argc)
return usage(1,
true);
111 catch (
const std::exception&) {
112 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
115 }
else if (arg ==
"-v")
117 else if (arg ==
"--input-string") {
118 if (++m == argc)
return usage(1,
true);
120 }
else if (arg ==
"--input-file") {
121 if (++m == argc)
return usage(1,
true);
123 }
else if (arg ==
"--output-file") {
124 if (++m == argc)
return usage(1,
true);
126 }
else if (arg ==
"--line-separator") {
127 if (++m == argc)
return usage(1,
true);
128 if (std::string(argv[m]).size() != 1) {
129 std::cerr <<
"Line separator must be a single character\n";
133 }
else if (arg ==
"--comment-delimiter") {
134 if (++m == argc)
return usage(1,
true);
136 }
else if (arg ==
"--version") {
137 std::cout << argv[0] <<
": GeographicLib version "
138 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
141 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
143 std::cout<<
"\nDefault gravity path = \""
145 <<
"\"\nDefault gravity name = \""
152 if (!ifile.empty() && !istring.empty()) {
153 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
156 if (ifile ==
"-") ifile.clear();
157 std::ifstream infile;
158 std::istringstream instring;
159 if (!ifile.empty()) {
160 infile.open(ifile.c_str());
161 if (!infile.is_open()) {
162 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
165 }
else if (!istring.empty()) {
166 std::string::size_type m = 0;
168 m = istring.find(lsep, m);
169 if (m == std::string::npos)
173 instring.str(istring);
175 std::istream* input = !ifile.empty() ? &infile :
176 (!istring.empty() ? &instring : &std::cin);
178 std::ofstream outfile;
179 if (ofile ==
"-") ofile.clear();
180 if (!ofile.empty()) {
181 outfile.open(ofile.c_str());
182 if (!outfile.is_open()) {
183 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
187 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
209 else if (mode == UNDULATION && h != 0)
210 throw GeographicErr(
"Height should be zero for geoid undulations");
213 std::cerr <<
"Gravity file: " << g.
GravityFile() <<
"\n"
216 <<
"Date & Time: " << g.
DateTime() <<
"\n";
223 std::string s, eol, stra, strb;
224 std::istringstream str;
225 while (std::getline(*input, s)) {
228 if (!cdelim.empty()) {
229 std::string::size_type m = s.find(cdelim);
230 if (m != std::string::npos) {
231 eol =
" " + s.substr(m) +
"\n";
235 str.clear(); str.str(s);
245 if (!(str >> stra >> strb))
251 if (mode == UNDULATION && h != 0)
252 throw GeographicErr(
"Height must be zero for geoid heights");
263 g.
Gravity(lat, lon, h, gx, gy, gz);
272 real deltax, deltay, deltaz;
276 g.
Disturbance(lat, lon, h, deltax, deltay, deltaz);
309 catch (
const std::exception& e) {
310 *output <<
"ERROR: " << e.what() <<
"\n";
315 catch (
const std::exception& e) {
316 std::cerr <<
"Error reading " << model <<
": " << e.what() <<
"\n";
321 catch (
const std::exception& e) {
322 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
326 std::cerr <<
"Caught unknown exception\n";