35 # pragma warning (disable: 4127 4701)
38 #include "GeodSolve.usage"
58 bool full,
bool arcmode,
int prec,
bool dms) {
75 int main(
int argc,
char* argv[]) {
79 bool linecalc =
false, inverse =
false, arcmode =
false,
80 dms =
false, full =
false, exact =
false;
84 real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12;
87 std::string istring, ifile, ofile, cdelim;
88 char lsep =
';', dmssep = char(0);
90 for (
int m = 1; m < argc; ++m) {
91 std::string arg(argv[m]);
95 }
else if (arg ==
"-a")
97 else if (arg ==
"-l") {
100 if (m + 3 >= argc)
return usage(1,
true);
106 catch (
const std::exception& e) {
107 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
111 }
else if (arg ==
"-e") {
112 if (m + 2 >= argc)
return usage(1,
true);
114 a = Utility::num<real>(std::string(argv[m + 1]));
115 f = Utility::fract<real>(std::string(argv[m + 2]));
117 catch (
const std::exception& e) {
118 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
123 else if (arg ==
"-d") {
126 }
else if (arg ==
"-:") {
129 }
else if (arg ==
"-b")
131 else if (arg ==
"-f")
133 else if (arg ==
"-p") {
134 if (++m == argc)
return usage(1,
true);
136 prec = Utility::num<int>(std::string(argv[m]));
138 catch (
const std::exception&) {
139 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
142 }
else if (arg ==
"-E")
144 else if (arg ==
"--input-string") {
145 if (++m == argc)
return usage(1,
true);
147 }
else if (arg ==
"--input-file") {
148 if (++m == argc)
return usage(1,
true);
150 }
else if (arg ==
"--output-file") {
151 if (++m == argc)
return usage(1,
true);
153 }
else if (arg ==
"--line-separator") {
154 if (++m == argc)
return usage(1,
true);
155 if (std::string(argv[m]).size() != 1) {
156 std::cerr <<
"Line separator must be a single character\n";
160 }
else if (arg ==
"--comment-delimiter") {
161 if (++m == argc)
return usage(1,
true);
163 }
else if (arg ==
"--version") {
165 << argv[0] <<
": GeographicLib version "
166 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
169 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
172 if (!ifile.empty() && !istring.empty()) {
173 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
176 if (ifile ==
"-") ifile.clear();
177 std::ifstream infile;
178 std::istringstream instring;
179 if (!ifile.empty()) {
180 infile.open(ifile.c_str());
181 if (!infile.is_open()) {
182 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
185 }
else if (!istring.empty()) {
186 std::string::size_type m = 0;
188 m = istring.find(lsep, m);
189 if (m == std::string::npos)
193 instring.str(istring);
195 std::istream* input = !ifile.empty() ? &infile :
196 (!istring.empty() ? &instring : &std::cin);
198 std::ofstream outfile;
199 if (ofile ==
"-") ofile.clear();
200 if (!ofile.empty()) {
201 outfile.open(ofile.c_str());
202 if (!outfile.is_open()) {
203 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
207 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
215 le = geode.
Line(lat1, lon1, azi1);
217 l = geod.
Line(lat1, lon1, azi1);
225 while (std::getline(*input, s)) {
227 std::string eol(
"\n");
228 if (!cdelim.empty()) {
229 std::string::size_type m = s.find(cdelim);
230 if (m != std::string::npos) {
231 eol =
" " + s.substr(m) +
"\n";
235 std::istringstream str(s);
237 std::string slat1, slon1, slat2, slon2;
238 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
246 geode.
Inverse(lat1, lon1, lat2, lon2, s12, azi1, azi2,
247 m12, M12, M21, S12) :
248 geod.
Inverse(lat1, lon1, lat2, lon2, s12, azi1, azi2,
251 *output <<
LatLonString(lat1, lon1, prec, dms, dmssep) <<
" ";
254 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" ";
255 *output <<
AzimuthString(azi2 + azi2sense, prec, dms, dmssep) <<
" "
274 le.
ArcPosition(s12, lat2, lon2, azi2, a12, m12, M12, M21, S12) :
275 l.
ArcPosition(s12, lat2, lon2, azi2, a12, m12, M12, M21, S12);
278 le.
Position(s12, lat2, lon2, azi2, m12, M12, M21, S12) :
279 l.
Position(s12, lat2, lon2, azi2, m12, M12, M21, S12);
281 std::string slat1, slon1, sazi1, ss12;
282 if (!(str >> slat1 >> slon1 >> sazi1 >> ss12))
292 geode.
ArcDirect(lat1, lon1, azi1, s12, lat2, lon2, azi2, a12,
293 m12, M12, M21, S12) :
294 geod.
ArcDirect(lat1, lon1, azi1, s12, lat2, lon2, azi2, a12,
298 geode.
Direct(lat1, lon1, azi1, s12, lat2, lon2, azi2,
299 m12, M12, M21, S12) :
300 geod.
Direct(lat1, lon1, azi1, s12, lat2, lon2, azi2,
306 *output <<
LatLonString(lat1, lon1, 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";
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 Position(real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
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
Math::real Position(real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
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)
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.
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep)
static int set_digits(int ndigits=0)
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[])
void ArcPosition(real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
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)
void ArcPosition(real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Header for GeographicLib::DMS class.