53int main(
int argc,
const char*
const argv[]) {
57 using std::signbit, std::isnan, std::fabs;
60 dms =
false, full =
false, unroll =
false,
68 e2 = -1, f =
Math::NaN(), k2 = 0, kp2 = 0;
69 ang bet1, omg1, alp1, bet2, omg2, alp2;
72 std::string istring, ifile, ofile, cdelim;
73 char lsep =
';', dmssep = char(0);
75 for (
int m = 1; m < argc; ++m) {
76 std::string arg(argv[m]);
80 }
else if (arg ==
"-t") {
81 if (m + 3 >= argc)
return usage(1,
true);
87 catch (
const std::exception& e) {
88 std::cerr <<
"Error decoding arguments of -t: " << e.what() <<
"\n";
93 }
else if (arg ==
"-e") {
96 if (m + 4 >= argc)
return usage(1,
true);
103 catch (
const std::exception& e) {
104 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
109 }
else if (arg ==
"-e2") {
110 if (m + 2 >= argc)
return usage(1,
true);
123 catch (
const std::exception& e) {
124 std::cerr <<
"Error decoding arguments of -e2: " << e.what() <<
"\n";
129 }
else if (arg ==
"-L") {
132 if (m + 3 >= argc)
return usage(1,
true);
135 bet1, omg1, longfirst);
138 catch (
const std::exception& e) {
139 std::cerr <<
"Error decoding arguments of -L: " << e.what() <<
"\n";
143 }
else if (arg ==
"-u")
145 else if (arg ==
"-d") {
148 }
else if (arg ==
"-:") {
151 }
else if (arg ==
"-w")
152 longfirst = !longfirst;
153 else if (arg ==
"-f")
155 else if (arg ==
"-p") {
156 if (++m == argc)
return usage(1,
true);
160 catch (
const std::exception&) {
161 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
164 }
else if (arg ==
"--input-string") {
165 if (++m == argc)
return usage(1,
true);
167 }
else if (arg ==
"--input-file") {
168 if (++m == argc)
return usage(1,
true);
170 }
else if (arg ==
"--output-file") {
171 if (++m == argc)
return usage(1,
true);
173 }
else if (arg ==
"--line-separator") {
174 if (++m == argc)
return usage(1,
true);
175 if (std::string(argv[m]).size() != 1) {
176 std::cerr <<
"Line separator must be a single character\n";
180 }
else if (arg ==
"--comment-delimiter") {
181 if (++m == argc)
return usage(1,
true);
183 }
else if (arg ==
"--version") {
184 std::cout << argv[0] <<
": GeographicLib version "
185 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
188 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
191 Geodesic3 t = e2 >= 0 ? Geodesic3(b, e2, k2, kp2) :
192 !isnan(f) ? Geodesic3(b, fabs(f) * (2 - f),
193 signbit(f) ? 0 : 1, signbit(f) ? 1 : 0) :
196 if (!ifile.empty() && !istring.empty()) {
197 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
200 if (ifile ==
"-") ifile.clear();
201 std::ifstream infile;
202 std::istringstream instring;
203 if (!ifile.empty()) {
204 infile.open(ifile.c_str());
205 if (!infile.is_open()) {
206 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
209 }
else if (!istring.empty()) {
210 std::string::size_type m = 0;
212 m = istring.find(lsep, m);
213 if (m == std::string::npos)
217 instring.str(istring);
219 std::istream* input = !ifile.empty() ? &infile :
220 (!istring.empty() ? &instring : &std::cin);
222 std::ofstream outfile;
223 if (ofile ==
"-") ofile.clear();
224 if (!ofile.empty()) {
225 outfile.open(ofile.c_str());
226 if (!outfile.is_open()) {
227 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
231 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
236 std::unique_ptr<GeodesicLine3> lp = linecalc ?
237 std::make_unique<GeodesicLine3>(t, bet1, omg1, alp1) :
nullptr;
241 using std::round, std::log10, std::ceil;
242 int disprec = std::max(0, prec +
int(round(log10(6400000/b)))),
244 std::string s, eol, sbet1, somg1, salp1, sbet2, somg2, salp2, ss12, strc;
245 std::istringstream str;
247 while (std::getline(*input, s)) {
250 if (!cdelim.empty()) {
251 std::string::size_type m = s.find(cdelim);
252 if (m != std::string::npos) {
253 eol =
" " + s.substr(m) +
"\n";
257 str.clear(); str.str(s);
260 if (!(str >> sbet1 >> somg1 >> sbet2 >> somg2))
268 GeodesicLine3 l = t.Inverse(bet1, omg1, bet2, omg2,
270 if (unroll && full) {
271 l.Position(s12, bet2, omg2, alp2);
277 angprec, dms, dmssep, longfirst)
281 angprec, dms, dmssep, longfirst)
294 if (!(str >> sbet1 >> somg1 >> salp1 >> ss12))
301 lp->Position(s12, bet2, omg2, alp2);
306 t.Direct(bet1, omg1, alp1, s12, bet2, omg2, alp2);
309 Ellipsoid3::AngNorm(bet2, omg2, alp2, !isnan(f) && signbit(f));
318 angprec, dms, dmssep, longfirst)
322 angprec, dms, dmssep, longfirst)
328 angprec, dms, dmssep, longfirst)
333 catch (
const std::exception& e) {
335 *output <<
"ERROR: " << e.what() <<
"\n";
341 catch (
const std::exception& e) {
342 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
346 std::cerr <<
"Caught unknown exception\n";