35 # pragma warning (disable: 4127 4701)
38 #include "GeodSolve.usage"
43 using namespace GeographicLib;
52 using namespace GeographicLib;
58 bool full,
bool arcmode,
int prec,
bool dms) {
59 using namespace GeographicLib;
62 s += Utility::str<real>(s12, prec);
71 using namespace GeographicLib;
75 int main(
int argc,
char* argv[]) {
77 using namespace GeographicLib;
78 bool linecalc =
false, inverse =
false, arcmode =
false,
79 dms =
false, full =
false, exact =
false;
81 a = Constants::WGS84_a<real>(),
82 f = Constants::WGS84_f<real>();
83 real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12;
86 std::string istring, ifile, ofile, cdelim;
87 char lsep =
';', dmssep = char(0);
89 for (
int m = 1; m < argc; ++m) {
90 std::string arg(argv[m]);
94 }
else if (arg ==
"-a")
96 else if (arg ==
"-l") {
99 if (m + 3 >= argc)
return usage(1,
true);
105 catch (
const std::exception& e) {
106 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
110 }
else if (arg ==
"-e") {
111 if (m + 2 >= argc)
return usage(1,
true);
113 a = Utility::num<real>(std::string(argv[m + 1]));
114 f = Utility::fract<real>(std::string(argv[m + 2]));
116 catch (
const std::exception& e) {
117 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
122 else if (arg ==
"-d") {
125 }
else if (arg ==
"-:") {
128 }
else if (arg ==
"-b")
130 else if (arg ==
"-f")
132 else if (arg ==
"-p") {
133 if (++m == argc)
return usage(1,
true);
135 prec = Utility::num<int>(std::string(argv[m]));
137 catch (
const std::exception&) {
138 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
141 }
else if (arg ==
"-E")
143 else if (arg ==
"--input-string") {
144 if (++m == argc)
return usage(1,
true);
146 }
else if (arg ==
"--input-file") {
147 if (++m == argc)
return usage(1,
true);
149 }
else if (arg ==
"--output-file") {
150 if (++m == argc)
return usage(1,
true);
152 }
else if (arg ==
"--line-separator") {
153 if (++m == argc)
return usage(1,
true);
154 if (std::string(argv[m]).size() != 1) {
155 std::cerr <<
"Line separator must be a single character\n";
159 }
else if (arg ==
"--comment-delimiter") {
160 if (++m == argc)
return usage(1,
true);
162 }
else if (arg ==
"--version") {
164 << argv[0] <<
": GeographicLib version "
165 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
168 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
171 if (!ifile.empty() && !istring.empty()) {
172 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
175 if (ifile ==
"-") ifile.clear();
176 std::ifstream infile;
177 std::istringstream instring;
178 if (!ifile.empty()) {
179 infile.open(ifile.c_str());
180 if (!infile.is_open()) {
181 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
184 }
else if (!istring.empty()) {
185 std::string::size_type m = 0;
187 m = istring.find(lsep, m);
188 if (m == std::string::npos)
192 instring.str(istring);
194 std::istream* input = !ifile.empty() ? &infile :
195 (!istring.empty() ? &instring : &std::cin);
197 std::ofstream outfile;
198 if (ofile ==
"-") ofile.clear();
199 if (!ofile.empty()) {
200 outfile.open(ofile.c_str());
201 if (!outfile.is_open()) {
202 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
206 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
214 le = geode.
Line(lat1, lon1, azi1);
216 l = geod.
Line(lat1, lon1, azi1);
224 while (std::getline(*input, s)) {
226 std::string eol(
"\n");
227 if (!cdelim.empty()) {
228 std::string::size_type m = s.find(cdelim);
229 if (m != std::string::npos) {
230 eol =
" " + s.substr(m) +
"\n";
234 std::istringstream str(s);
236 std::string slat1, slon1, slat2, slon2;
237 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
245 geode.
Inverse(lat1, lon1, lat2, lon2, s12, azi1, azi2,
246 m12, M12, M21, S12) :
247 geod.
Inverse(lat1, lon1, lat2, lon2, s12, azi1, azi2,
250 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep) <<
" ";
253 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" ";
254 *output <<
AzimuthString(azi2 + azi2sense, prec, dms, dmssep) <<
" "
257 *output <<
" " << Utility::str<real>(m12, prec)
258 <<
" " << Utility::str<real>(M12, prec+7)
259 <<
" " << Utility::str<real>(M21, prec+7)
260 <<
" " << Utility::str<real>(S12, std::max(prec-7, 0));
273 le.ArcPosition(s12, lat2, lon2, azi2, a12, m12, M12, M21, S12) :
274 l.ArcPosition(s12, lat2, lon2, azi2, a12, m12, M12, M21, S12);
277 le.Position(s12, lat2, lon2, azi2, m12, M12, M21, S12) :
278 l.Position(s12, lat2, lon2, azi2, m12, M12, M21, S12);
280 std::string slat1, slon1, sazi1, ss12;
281 if (!(str >> slat1 >> slon1 >> sazi1 >> ss12))
291 geode.
ArcDirect(lat1, lon1, azi1, s12, lat2, lon2, azi2, a12,
292 m12, M12, M21, S12) :
293 geod.
ArcDirect(lat1, lon1, azi1, s12, lat2, lon2, azi2, a12,
297 geode.
Direct(lat1, lon1, azi1, s12, lat2, lon2, azi2,
298 m12, M12, M21, S12) :
299 geod.
Direct(lat1, lon1, azi1, s12, lat2, lon2, azi2,
305 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep) <<
" "
307 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" "
312 <<
" " << Utility::str<real>(m12, prec)
313 <<
" " << Utility::str<real>(M12, prec+7)
314 <<
" " << Utility::str<real>(M21, prec+7)
315 <<
" " << Utility::str<real>(S12, std::max(prec-7, 0));
319 catch (
const std::exception& e) {
321 *output <<
"ERROR: " << e.what() <<
"\n";
327 catch (
const std::exception& e) {
328 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
332 std::cerr <<
"Caught unknown exception\n";
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Header for GeographicLib::GeodesicLine class.
static Math::real DecodeAngle(const std::string &angstr)
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
static const int extradigits
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
real ReadDistance(const std::string &s, bool arcmode)
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.
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep)
Exact geodesic calculations.
Header for GeographicLib::GeodesicExact class.
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Exception handling for GeographicLib.
std::string AzimuthString(real azi, int prec, bool dms, char dmssep)
int main(int argc, char *argv[])
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
std::string DistanceStrings(real s12, real a12, bool full, bool arcmode, int prec, bool dms)
Header for GeographicLib::DMS class.