26 # pragma warning (disable: 4127 4701)
29 #include "RhumbSolve.usage"
43 (longfirst ? lonstr : latstr) +
" " + (longfirst ? latstr : lonstr);
51 int main(
int argc,
char* argv[]) {
54 bool linecalc =
false, inverse =
false, dms =
false, exact =
true,
61 std::string istring, ifile, ofile, cdelim;
62 char lsep =
';', dmssep = char(0);
64 for (
int m = 1; m < argc; ++m) {
65 std::string arg(argv[m]);
69 }
else if (arg ==
"-l") {
72 if (m + 3 >= argc)
return usage(1,
true);
75 lat1, lon1, longfirst);
78 catch (
const std::exception& e) {
79 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
83 }
else if (arg ==
"-e") {
84 if (m + 2 >= argc)
return usage(1,
true);
86 a = Utility::num<real>(std::string(argv[m + 1]));
87 f = Utility::fract<real>(std::string(argv[m + 2]));
89 catch (
const std::exception& e) {
90 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
95 else if (arg ==
"-d") {
98 }
else if (arg ==
"-:") {
101 }
else if (arg ==
"-w")
103 else if (arg ==
"-p") {
104 if (++m == argc)
return usage(1,
true);
106 prec = Utility::num<int>(std::string(argv[m]));
108 catch (
const std::exception&) {
109 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
112 }
else if (arg ==
"-s")
114 else if (arg ==
"--input-string") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--input-file") {
118 if (++m == argc)
return usage(1,
true);
120 }
else if (arg ==
"--output-file") {
121 if (++m == argc)
return usage(1,
true);
123 }
else if (arg ==
"--line-separator") {
124 if (++m == argc)
return usage(1,
true);
125 if (std::string(argv[m]).size() != 1) {
126 std::cerr <<
"Line separator must be a single character\n";
130 }
else if (arg ==
"--comment-delimiter") {
131 if (++m == argc)
return usage(1,
true);
133 }
else if (arg ==
"--version") {
134 std::cout << argv[0] <<
": GeographicLib version "
135 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
138 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
141 if (!ifile.empty() && !istring.empty()) {
142 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
145 if (ifile ==
"-") ifile.clear();
146 std::ifstream infile;
147 std::istringstream instring;
148 if (!ifile.empty()) {
149 infile.open(ifile.c_str());
150 if (!infile.is_open()) {
151 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
154 }
else if (!istring.empty()) {
155 std::string::size_type m = 0;
157 m = istring.find(lsep, m);
158 if (m == std::string::npos)
162 instring.str(istring);
164 std::istream* input = !ifile.empty() ? &infile :
165 (!istring.empty() ? &instring : &std::cin);
167 std::ofstream outfile;
168 if (ofile ==
"-") ofile.clear();
169 if (!ofile.empty()) {
170 outfile.open(ofile.c_str());
171 if (!outfile.is_open()) {
172 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
176 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
178 const Rhumb rh(a, f, exact);
184 std::string s, eol, slat1, slon1, slat2, slon2, sazi, ss12, strc;
185 std::istringstream str;
187 while (std::getline(*input, s)) {
190 if (!cdelim.empty()) {
191 std::string::size_type m = s.find(cdelim);
192 if (m != std::string::npos) {
193 eol =
" " + s.substr(m) +
"\n";
197 str.clear(); str.str(s);
203 rhl.Position(s12, lat2, lon2, S12);
204 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
205 <<
" " <<
Utility::str(S12, std::max(prec-7, 0)) << eol;
206 }
else if (inverse) {
207 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
213 rh.
Inverse(lat1, lon1, lat2, lon2, s12, azi12, S12);
218 if (!(str >> slat1 >> slon1 >> sazi >> s12))
224 rh.
Direct(lat1, lon1, azi12, s12, lat2, lon2, S12);
225 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
226 <<
" " <<
Utility::str(S12, std::max(prec-7, 0)) << eol;
229 catch (
const std::exception& e) {
231 *output <<
"ERROR: " << e.what() <<
"\n";
237 catch (
const std::exception& e) {
238 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
242 std::cerr <<
"Caught unknown exception\n";
void Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12, real &S12) const
int main(int argc, char *argv[])
GeographicLib::Math::real real
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
Namespace for GeographicLib.
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)
Exception handling for GeographicLib.
std::string AzimuthString(real azi, int prec, bool dms, char dmssep)
Solve of the direct and inverse rhumb problems.
Find a sequence of points on a single rhumb line.
void Direct(real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2, real &S12) const
Header for GeographicLib::DMS class.