27 # pragma warning (disable: 4127 4701)
30 #include "GeodSolve.usage"
35 using namespace GeographicLib;
44 using namespace GeographicLib;
50 bool full,
bool arcmode,
int prec,
bool dms) {
51 using namespace GeographicLib;
63 using namespace GeographicLib;
67 int main(
int argc,
char* argv[]) {
69 using namespace GeographicLib;
71 bool linecalc =
false, inverse =
false, arcmode =
false,
72 dms =
false, full =
false, exact =
false, unroll =
false;
76 real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12;
79 std::string istring, ifile, ofile, cdelim;
80 char lsep =
';', dmssep = char(0);
82 for (
int m = 1; m < argc; ++m) {
83 std::string arg(argv[m]);
87 }
else if (arg ==
"-a")
89 else if (arg ==
"-l") {
92 if (m + 3 >= argc)
return usage(1,
true);
98 catch (
const std::exception& e) {
99 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
103 }
else if (arg ==
"-e") {
104 if (m + 2 >= argc)
return usage(1,
true);
106 a = Utility::num<real>(std::string(argv[m + 1]));
107 f = Utility::fract<real>(std::string(argv[m + 2]));
109 catch (
const std::exception& e) {
110 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
114 }
else if (arg ==
"-u")
116 else if (arg ==
"-d") {
119 }
else if (arg ==
"-:") {
122 }
else if (arg ==
"-b")
124 else if (arg ==
"-f")
126 else if (arg ==
"-p") {
127 if (++m == argc)
return usage(1,
true);
129 prec = Utility::num<int>(std::string(argv[m]));
131 catch (
const std::exception&) {
132 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
135 }
else if (arg ==
"-E")
137 else if (arg ==
"--input-string") {
138 if (++m == argc)
return usage(1,
true);
140 }
else if (arg ==
"--input-file") {
141 if (++m == argc)
return usage(1,
true);
143 }
else if (arg ==
"--output-file") {
144 if (++m == argc)
return usage(1,
true);
146 }
else if (arg ==
"--line-separator") {
147 if (++m == argc)
return usage(1,
true);
148 if (std::string(argv[m]).size() != 1) {
149 std::cerr <<
"Line separator must be a single character\n";
153 }
else if (arg ==
"--comment-delimiter") {
154 if (++m == argc)
return usage(1,
true);
156 }
else if (arg ==
"--version") {
157 std::cout << argv[0] <<
": GeographicLib version "
158 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
161 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
164 if (!ifile.empty() && !istring.empty()) {
165 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
168 if (ifile ==
"-") ifile.clear();
169 std::ifstream infile;
170 std::istringstream instring;
171 if (!ifile.empty()) {
172 infile.open(ifile.c_str());
173 if (!infile.is_open()) {
174 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
177 }
else if (!istring.empty()) {
178 std::string::size_type m = 0;
180 m = istring.find(lsep, m);
181 if (m == std::string::npos)
185 instring.str(istring);
187 std::istream* input = !ifile.empty() ? &infile :
188 (!istring.empty() ? &instring : &std::cin);
190 std::ofstream outfile;
191 if (ofile ==
"-") ofile.clear();
192 if (!ofile.empty()) {
193 outfile.open(ofile.c_str());
194 if (!outfile.is_open()) {
195 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
199 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
219 le = geode.
Line(lat1, lon1, azi1, outmask);
221 ls = geods.Line(lat1, lon1, azi1, outmask);
229 while (std::getline(*input, s)) {
231 std::string eol(
"\n");
232 if (!cdelim.empty()) {
233 std::string::size_type m = s.find(cdelim);
234 if (m != std::string::npos) {
235 eol =
" " + s.substr(m) +
"\n";
239 std::istringstream str(s);
241 std::string slat1, slon1, slat2, slon2;
242 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
250 geode.
GenInverse(lat1, lon1, lat2, lon2, outmask,
251 s12, azi1, azi2, m12, M12, M21, S12) :
252 geods.GenInverse(lat1, lon1, lat2, lon2, outmask,
253 s12, azi1, azi2, m12, M12, M21, S12);
260 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep) <<
" ";
264 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" ";
265 *output <<
AzimuthString(azi2 + azi2sense, prec, dms, dmssep) <<
" "
283 le.GenPosition(arcmode, s12, outmask,
284 lat2, lon2, azi2, s12, m12, M12, M21, S12) :
285 ls.GenPosition(arcmode, s12, outmask,
286 lat2, lon2, azi2, s12, m12, M12, M21, S12);
288 std::string slat1, slon1, sazi1, ss12;
289 if (!(str >> slat1 >> slon1 >> sazi1 >> ss12))
298 geode.
GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
299 lat2, lon2, azi2, s12, m12, M12, M21, S12) :
300 geods.GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
301 lat2, lon2, azi2, s12, m12, M12, M21, S12);
306 prec, dms, dmssep) <<
" "
308 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" "
320 catch (
const std::exception& e) {
322 *output <<
"ERROR: " << e.what() <<
"\n";
328 catch (
const std::exception& e) {
329 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
333 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)
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)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
GeodesicLineExact Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
Header for GeographicLib::GeodesicLineExact class.
static std::string str(T x, int p=-1)
static T AngDiff(T x, T y)
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep)
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)
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.