23 # pragma warning (disable: 4701) 26 #include "GeodSolve.usage" 39 (longfirst ? lonstr : latstr) +
" " + (longfirst ? latstr : lonstr);
49 bool full,
bool arcmode,
int prec,
bool dms) {
63 return fraction ? Utility::fract<real>(s) :
67 int main(
int argc,
const char*
const argv[]) {
70 enum { NONE = 0, LINE, DIRECT, INVERSE };
72 bool inverse =
false, arcmode =
false,
73 dms =
false, full =
false, exact =
false, unroll =
false,
74 longfirst =
false, azi2back =
false, fraction =
false,
79 real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12,
81 int linecalc = NONE, prec = 3;
82 std::string istring, ifile, ofile, cdelim;
83 char lsep =
';', dmssep = char(0);
85 for (
int m = 1; m < argc; ++m) {
86 std::string arg(argv[m]);
90 }
else if (arg ==
"-a")
94 else if (arg ==
"-L") {
97 if (m + 3 >= argc)
return usage(1,
true);
100 lat1, lon1, longfirst);
103 catch (
const std::exception& e) {
104 std::cerr <<
"Error decoding arguments of -L: " << e.what() <<
"\n";
108 }
else if (arg ==
"-D") {
111 if (m + 4 >= argc)
return usage(1,
true);
114 lat1, lon1, longfirst);
117 arcmodeline = arcmode;
119 catch (
const std::exception& e) {
120 std::cerr <<
"Error decoding arguments of -D: " << e.what() <<
"\n";
124 }
else if (arg ==
"-I") {
127 if (m + 4 >= argc)
return usage(1,
true);
130 lat1, lon1, longfirst);
132 lat2, lon2, longfirst);
134 catch (
const std::exception& e) {
135 std::cerr <<
"Error decoding arguments of -I: " << e.what() <<
"\n";
139 }
else if (arg ==
"-e") {
140 if (m + 2 >= argc)
return usage(1,
true);
142 a = Utility::val<real>(std::string(argv[m + 1]));
143 f = Utility::fract<real>(std::string(argv[m + 2]));
145 catch (
const std::exception& e) {
146 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
150 }
else if (arg ==
"-u")
152 else if (arg ==
"-d") {
155 }
else if (arg ==
"-:") {
158 }
else if (arg ==
"-w")
159 longfirst = !longfirst;
160 else if (arg ==
"-b")
162 else if (arg ==
"-f")
164 else if (arg ==
"-p") {
165 if (++m == argc)
return usage(1,
true);
167 prec = Utility::val<int>(std::string(argv[m]));
169 catch (
const std::exception&) {
170 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
173 }
else if (arg ==
"-E")
175 else if (arg ==
"--input-string") {
176 if (++m == argc)
return usage(1,
true);
178 }
else if (arg ==
"--input-file") {
179 if (++m == argc)
return usage(1,
true);
181 }
else if (arg ==
"--output-file") {
182 if (++m == argc)
return usage(1,
true);
184 }
else if (arg ==
"--line-separator") {
185 if (++m == argc)
return usage(1,
true);
186 if (std::string(argv[m]).size() != 1) {
187 std::cerr <<
"Line separator must be a single character\n";
191 }
else if (arg ==
"--comment-delimiter") {
192 if (++m == argc)
return usage(1,
true);
194 }
else if (arg ==
"--version") {
195 std::cout << argv[0] <<
": GeographicLib version " 196 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
199 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
202 if (!ifile.empty() && !istring.empty()) {
203 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
206 if (ifile ==
"-") ifile.clear();
207 std::ifstream infile;
208 std::istringstream instring;
209 if (!ifile.empty()) {
210 infile.open(ifile.c_str());
211 if (!infile.is_open()) {
212 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
215 }
else if (!istring.empty()) {
216 std::string::size_type m = 0;
218 m = istring.find(lsep, m);
219 if (m == std::string::npos)
223 instring.str(istring);
225 std::istream* input = !ifile.empty() ? &infile :
226 (!istring.empty() ? &instring : &std::cin);
228 std::ofstream outfile;
229 if (ofile ==
"-") ofile.clear();
230 if (!ofile.empty()) {
231 outfile.open(ofile.c_str());
232 if (!outfile.is_open()) {
233 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
237 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
253 if (linecalc == LINE) fraction =
false;
254 ls = linecalc == DIRECT ?
255 geods.GenDirectLine(lat1, lon1, azi1, arcmodeline, s12, outmask) :
256 linecalc == INVERSE ?
257 geods.InverseLine(lat1, lon1, lat2, lon2, outmask) :
259 geods.Line(lat1, lon1, azi1, outmask);
261 if (linecalc == INVERSE) azi1 = ls.
Azimuth();
267 std::string s, eol, slat1, slon1, slat2, slon2, sazi1, ss12, strc;
268 std::istringstream str;
270 while (std::getline(*input, s)) {
273 if (!cdelim.empty()) {
274 std::string::size_type m = s.find(cdelim);
275 if (m != std::string::npos) {
276 eol =
" " + s.substr(m) +
"\n";
280 str.clear(); str.str(s);
282 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
288 a12 = geods.GenInverse(lat1, lon1, lat2, lon2, outmask,
289 s12, azi1, azi2, m12, M12, M21, S12);
299 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep, longfirst)
304 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
310 azi2 = copysign(azi2 + copysign(
real(
Math::hd), -azi2), -azi2);
327 s12 =
ReadDistance(ss12, !fraction && arcmode, fraction) * mult;
329 lat2, lon2, azi2, s12, m12, M12, M21, S12);
331 if (!(str >> slat1 >> slon1 >> sazi1 >> ss12))
338 a12 = geods.GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
339 lat2, lon2, azi2, s12, m12, M12, M21, S12);
344 prec, dms, dmssep, longfirst)
350 azi2 = copysign(azi2 + copysign(
real(
Math::hd), -azi2), -azi2);
352 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
364 catch (
const std::exception& e) {
366 *output <<
"ERROR: " << e.what() <<
"\n";
372 catch (
const std::exception& e) {
373 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
377 std::cerr <<
"Caught unknown exception\n";
Header for GeographicLib::GeodesicLine class.
static Math::real DecodeAngle(const std::string &angstr)
int main(int argc, const char *const argv[])
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Math::real GenDistance(bool arcmode) const
static constexpr int hd
degrees per half turn
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep, bool longfirst)
Math::real Azimuth() const
static int extra_digits()
int usage(int retval, bool)
Header for GeographicLib::Geodesic class.
static std::string Encode(real angle, component trailing, unsigned prec, flag ind=NONE, char dmssep=char(0))
static T AngNormalize(T x)
static Math::real DecodeAzimuth(const std::string &azistr)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static T AngDiff(T x, T y, T &e)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
GeographicLib::Math::real real
static int set_digits(int ndigits=0)
Exception handling for GeographicLib.
std::string AzimuthString(real azi, int prec, bool dms, char dmssep)
real ReadDistance(const std::string &s, bool arcmode, bool fraction=false)
std::string DistanceStrings(real s12, real a12, bool full, bool arcmode, int prec, bool dms)
Math::real GenPosition(bool arcmode, real s12_a12, unsigned outmask, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Header for GeographicLib::DMS class.