25 # pragma warning (disable: 4127 4701) 28 #include "RhumbSolve.usage" 42 (longfirst ? lonstr : latstr) +
" " + (longfirst ? latstr : lonstr);
50 int main(
int argc,
const char*
const argv[]) {
53 bool linecalc =
false,
inverse =
false, dms =
false, exact =
true,
60 std::string istring, ifile, ofile, cdelim;
61 char lsep =
';', dmssep = char(0);
63 for (
int m = 1;
m < argc; ++
m) {
64 std::string
arg(argv[
m]);
68 }
else if (arg ==
"-L" || arg ==
"-l") {
71 if (m + 3 >= argc)
return usage(1,
true);
74 lat1, lon1, longfirst);
77 catch (
const std::exception&
e) {
78 std::cerr <<
"Error decoding arguments of -L: " << e.what() <<
"\n";
82 }
else if (arg ==
"-e") {
83 if (m + 2 >= argc)
return usage(1,
true);
85 a = Utility::val<real>(std::string(argv[m + 1]));
86 f = Utility::fract<real>(std::string(argv[m + 2]));
88 catch (
const std::exception&
e) {
89 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
94 else if (arg ==
"-d") {
97 }
else if (arg ==
"-:") {
100 }
else if (arg ==
"-w")
101 longfirst = !longfirst;
102 else if (arg ==
"-p") {
103 if (++m == argc)
return usage(1,
true);
105 prec = Utility::val<int>(std::string(argv[m]));
107 catch (
const std::exception&) {
108 std::cerr <<
"Precision " << argv[
m] <<
" is not a number\n";
111 }
else if (arg ==
"-s")
113 else if (arg ==
"--input-string") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--input-file") {
117 if (++m == argc)
return usage(1,
true);
119 }
else if (arg ==
"--output-file") {
120 if (++m == argc)
return usage(1,
true);
122 }
else if (arg ==
"--line-separator") {
123 if (++m == argc)
return usage(1,
true);
124 if (std::string(argv[m]).
size() != 1) {
125 std::cerr <<
"Line separator must be a single character\n";
129 }
else if (arg ==
"--comment-delimiter") {
130 if (++m == argc)
return usage(1,
true);
132 }
else if (arg ==
"--version") {
133 std::cout << argv[0] <<
": GeographicLib version " 137 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
140 if (!ifile.empty() && !istring.empty()) {
141 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
144 if (ifile ==
"-") ifile.clear();
145 std::ifstream infile;
146 std::istringstream instring;
147 if (!ifile.empty()) {
148 infile.open(ifile.c_str());
149 if (!infile.is_open()) {
150 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
153 }
else if (!istring.empty()) {
154 std::string::size_type
m = 0;
156 m = istring.find(lsep, m);
157 if (m == std::string::npos)
161 instring.str(istring);
163 std::istream* input = !ifile.empty() ? &infile :
164 (!istring.empty() ? &instring : &std::cin);
166 std::ofstream outfile;
167 if (ofile ==
"-") ofile.clear();
168 if (!ofile.empty()) {
169 outfile.open(ofile.c_str());
170 if (!outfile.is_open()) {
171 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
175 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
177 const Rhumb rh(a,
f, exact);
183 std::string
s, eol, slat1, slon1, slat2, slon2, sazi, ss12, strc;
184 std::istringstream
str;
186 while (std::getline(*input, s)) {
189 if (!cdelim.empty()) {
190 std::string::size_type
m = s.find(cdelim);
191 if (m != std::string::npos) {
192 eol =
" " + s.substr(m) +
"\n";
196 str.clear(); str.str(s);
202 rhl.Position(s12, lat2, lon2, S12);
203 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
206 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
212 rh.
Inverse(lat1, lon1, lat2, lon2, s12, azi12, S12);
217 if (!(str >> slat1 >> slon1 >> sazi >> s12))
223 rh.
Direct(lat1, lon1, azi12, s12, lat2, lon2, S12);
224 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
228 catch (
const std::exception&
e) {
230 *output <<
"ERROR: " << e.what() <<
"\n";
236 catch (
const std::exception&
e) {
237 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
241 std::cerr <<
"Caught unknown exception\n";
void Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12, real &S12) const
Header for GeographicLib::Utility class.
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep, bool longfirst)
Header for GeographicLib::Rhumb and GeographicLib::RhumbLine classes.
static int extra_digits()
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)
RhumbLine Line(real lat1, real lon1, real azi12) const
#define GEOGRAPHICLIB_VERSION_STRING
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static std::string str(T x, int p=-1)
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)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Exception handling for GeographicLib.
std::string AzimuthString(real azi, int prec, bool dms, char dmssep)
Solve of the direct and inverse rhumb problems.
int main(int argc, const char *const argv[])
Find a sequence of points on a single rhumb line.
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
void Direct(real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2, real &S12) const
Header for GeographicLib::DMS class.