27 # pragma warning (disable: 4127 4701)
30 #include "GeodSolve.usage"
43 (longfirst ? lonstr : latstr) +
" " + (longfirst ? latstr : lonstr);
53 bool full,
bool arcmode,
int prec,
bool dms) {
70 int main(
int argc,
char* argv[]) {
74 bool linecalc =
false, inverse =
false, arcmode =
false,
75 dms =
false, full =
false, exact =
false, unroll =
false,
76 longfirst =
false, azi2back =
false;
80 real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12;
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")
92 else if (arg ==
"-l") {
95 if (m + 3 >= argc)
return usage(1,
true);
98 lat1, lon1, longfirst);
101 catch (
const std::exception& e) {
102 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
106 }
else if (arg ==
"-e") {
107 if (m + 2 >= argc)
return usage(1,
true);
109 a = Utility::num<real>(std::string(argv[m + 1]));
110 f = Utility::fract<real>(std::string(argv[m + 2]));
112 catch (
const std::exception& e) {
113 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
117 }
else if (arg ==
"-u")
119 else if (arg ==
"-d") {
122 }
else if (arg ==
"-:") {
125 }
else if (arg ==
"-w")
127 else if (arg ==
"-b")
129 else if (arg ==
"-f")
131 else if (arg ==
"-p") {
132 if (++m == argc)
return usage(1,
true);
134 prec = Utility::num<int>(std::string(argv[m]));
136 catch (
const std::exception&) {
137 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
140 }
else if (arg ==
"-E")
142 else if (arg ==
"--input-string") {
143 if (++m == argc)
return usage(1,
true);
145 }
else if (arg ==
"--input-file") {
146 if (++m == argc)
return usage(1,
true);
148 }
else if (arg ==
"--output-file") {
149 if (++m == argc)
return usage(1,
true);
151 }
else if (arg ==
"--line-separator") {
152 if (++m == argc)
return usage(1,
true);
153 if (std::string(argv[m]).size() != 1) {
154 std::cerr <<
"Line separator must be a single character\n";
158 }
else if (arg ==
"--comment-delimiter") {
159 if (++m == argc)
return usage(1,
true);
161 }
else if (arg ==
"--version") {
162 std::cout << argv[0] <<
": GeographicLib version "
163 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
166 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
169 if (!ifile.empty() && !istring.empty()) {
170 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
173 if (ifile ==
"-") ifile.clear();
174 std::ifstream infile;
175 std::istringstream instring;
176 if (!ifile.empty()) {
177 infile.open(ifile.c_str());
178 if (!infile.is_open()) {
179 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
182 }
else if (!istring.empty()) {
183 std::string::size_type m = 0;
185 m = istring.find(lsep, m);
186 if (m == std::string::npos)
190 instring.str(istring);
192 std::istream* input = !ifile.empty() ? &infile :
193 (!istring.empty() ? &instring : &std::cin);
195 std::ofstream outfile;
196 if (ofile ==
"-") ofile.clear();
197 if (!ofile.empty()) {
198 outfile.open(ofile.c_str());
199 if (!outfile.is_open()) {
200 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
204 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
224 le = geode.
Line(lat1, lon1, azi1, outmask);
226 ls = geods.Line(lat1, lon1, azi1, outmask);
232 std::string s, eol, slat1, slon1, slat2, slon2, sazi1, ss12, strc;
233 std::istringstream str;
235 while (std::getline(*input, s)) {
238 if (!cdelim.empty()) {
239 std::string::size_type m = s.find(cdelim);
240 if (m != std::string::npos) {
241 eol =
" " + s.substr(m) +
"\n";
245 str.clear(); str.str(s);
247 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
254 geode.
GenInverse(lat1, lon1, lat2, lon2, outmask,
255 s12, azi1, azi2, m12, M12, M21, S12) :
256 geods.GenInverse(lat1, lon1, lat2, lon2, outmask,
257 s12, azi1, azi2, m12, M12, M21, S12);
265 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep, longfirst)
270 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
273 azi2 += azi2 >= 0 ? -180 : 180;
291 lat2, lon2, azi2, s12, m12, M12, M21, S12) :
293 lat2, lon2, azi2, s12, m12, M12, M21, S12);
295 if (!(str >> slat1 >> slon1 >> sazi1 >> ss12))
303 geode.
GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
304 lat2, lon2, azi2, s12, m12, M12, M21, S12) :
305 geods.GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
306 lat2, lon2, azi2, s12, m12, M12, M21, S12);
311 prec, dms, dmssep, longfirst)
314 azi2 += azi2 >= 0 ? -180 : 180;
315 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
327 catch (
const std::exception& e) {
329 *output <<
"ERROR: " << e.what() <<
"\n";
335 catch (
const std::exception& e) {
336 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
340 std::cerr <<
"Caught unknown exception\n";
static T AngNormalize(T x)
Header for GeographicLib::GeodesicLine class.
static Math::real DecodeAngle(const std::string &angstr)
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
real ReadDistance(const std::string &s, bool arcmode)
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep, bool longfirst)
Math::real GenInverse(real lat1, real lon1, real lat2, real lon2, unsigned outmask, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
static int extra_digits()
Header for GeographicLib::Geodesic class.
static std::string Encode(real angle, component trailing, unsigned prec, flag ind=NONE, char dmssep=char(0))
static Math::real DecodeAzimuth(const std::string &azistr)
GeodesicLineExact Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
Header for GeographicLib::GeodesicLineExact class.
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
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static T AngDiff(T x, T y)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
static int set_digits(int ndigits=0)
Math::real GenDirect(real lat1, real lon1, real azi1, bool arcmode, real s12_a12, unsigned outmask, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Exact geodesic calculations.
Header for GeographicLib::GeodesicExact class.
Exception handling for GeographicLib.
std::string AzimuthString(real azi, int prec, bool dms, char dmssep)
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
int main(int argc, char *argv[])
std::string DistanceStrings(real s12, real a12, bool full, bool arcmode, int prec, bool dms)
Header for GeographicLib::DMS class.