23 #include "Geod3Solve.usage" 29 using std::isnan, std::signbit;
41 bet = bet.
modang(1 / (1 - f));
45 using std::isnan, std::signbit;
50 if (signbit(f)) alp.
reflect(
false,
false,
true);
53 int main(
int argc,
const char*
const argv[]) {
56 using namespace Triaxial;
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);
83 a = Utility::val<real>(std::string(argv[m + 1]));
84 b = Utility::val<real>(std::string(argv[m + 2]));
85 c = Utility::val<real>(std::string(argv[m + 3]));
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);
98 b = Utility::val<real>(std::string(argv[m + 1]));
99 e2 = Utility::fract<real>(std::string(argv[m + 2]));
100 k2 = Utility::fract<real>(std::string(argv[m + 3]));
101 kp2 = Utility::fract<real>(std::string(argv[m + 4]));
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);
112 b = Utility::val<real>(std::string(argv[m + 1]));
113 f = Utility::fract<real>(std::string(argv[m + 2]));
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);
158 prec = Utility::val<int>(std::string(argv[m]));
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))
299 s12 = Utility::val<real>(ss12);
301 lp->Position(s12, bet2, omg2, alp2);
306 t.Direct(bet1, omg1, alp1, s12, bet2, omg2, alp2);
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";
static void DecodeLatLon(const std::string &stra, const std::string &strb, AngleT &lat, AngleT &lon, bool longfirst=false)
Header for GeographicLib::Utility class.
AngleT & reflect(bool flips, bool flipc=false, bool swapp=false)
AngleT< Math::real > Angle
static T Triaxial_Earth_a()
static AngleT cardinal(Math::real q)
static int extra_digits()
int usage(int retval, bool)
Header for GeographicLib::Triaxial::Geodesic3 class.
Header for GeographicLib::Math class.
static AngleT DecodeAzimuth(const std::string &azistr)
static bool AngNorm(Angle &bet, Angle &omg, Angle &alp, bool alt=false)
Namespace for GeographicLib.
static std::string AzimuthString(AngleT azi, int prec, bool dms=false, char dmssep='\0')
static std::string str(T x, int p=-1)
void BiaxialCoords(bool fwd, real f, ang &bet, ang &omg)
GeographicLib::Math::real real
static int set_digits(int ndigits=0)
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
Exception handling for GeographicLib.
static T Triaxial_Earth_c()
static std::string LatLonString(AngleT lat, AngleT lon, int prec, bool dms=false, char dmssep='\0', bool longfirst=false)
Header for the GeographicLib::AngleT class.
static T Triaxial_Earth_b()
int main(int argc, const char *const argv[])
Header for GeographicLib::DMS class.