26 # pragma warning (disable: 4127 4701) 29 #include "RhumbSolve.usage" 47 int main(
int argc,
char* argv[]) {
50 bool linecalc =
false, inverse =
false, dms =
false, exact =
true;
56 std::string istring, ifile, ofile, cdelim;
57 char lsep =
';', dmssep = char(0);
59 for (
int m = 1; m < argc; ++m) {
60 std::string arg(argv[m]);
64 }
else if (arg ==
"-l") {
67 if (m + 3 >= argc)
return usage(1,
true);
73 catch (
const std::exception& e) {
74 std::cerr <<
"Error decoding arguments of -l: " << e.what() <<
"\n";
78 }
else if (arg ==
"-e") {
79 if (m + 2 >= argc)
return usage(1,
true);
81 a = Utility::num<real>(std::string(argv[m + 1]));
82 f = Utility::fract<real>(std::string(argv[m + 2]));
84 catch (
const std::exception& e) {
85 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
90 else if (arg ==
"-d") {
93 }
else if (arg ==
"-:") {
96 }
else if (arg ==
"-p") {
97 if (++m == argc)
return usage(1,
true);
99 prec = Utility::num<int>(std::string(argv[m]));
101 catch (
const std::exception&) {
102 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
105 }
else if (arg ==
"-s")
107 else if (arg ==
"--input-string") {
108 if (++m == argc)
return usage(1,
true);
110 }
else if (arg ==
"--input-file") {
111 if (++m == argc)
return usage(1,
true);
113 }
else if (arg ==
"--output-file") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--line-separator") {
117 if (++m == argc)
return usage(1,
true);
118 if (std::string(argv[m]).size() != 1) {
119 std::cerr <<
"Line separator must be a single character\n";
123 }
else if (arg ==
"--comment-delimiter") {
124 if (++m == argc)
return usage(1,
true);
126 }
else if (arg ==
"--version") {
127 std::cout << argv[0] <<
": GeographicLib version " 128 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
131 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
134 if (!ifile.empty() && !istring.empty()) {
135 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
138 if (ifile ==
"-") ifile.clear();
139 std::ifstream infile;
140 std::istringstream instring;
141 if (!ifile.empty()) {
142 infile.open(ifile.c_str());
143 if (!infile.is_open()) {
144 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
147 }
else if (!istring.empty()) {
148 std::string::size_type m = 0;
150 m = istring.find(lsep, m);
151 if (m == std::string::npos)
155 instring.str(istring);
157 std::istream* input = !ifile.empty() ? &infile :
158 (!istring.empty() ? &instring : &std::cin);
160 std::ofstream outfile;
161 if (ofile ==
"-") ofile.clear();
162 if (!ofile.empty()) {
163 outfile.open(ofile.c_str());
164 if (!outfile.is_open()) {
165 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
169 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
171 const Rhumb rh(a, f, exact);
179 while (std::getline(*input, s)) {
181 std::string eol(
"\n");
182 if (!cdelim.empty()) {
183 std::string::size_type m = s.find(cdelim);
184 if (m != std::string::npos) {
185 eol =
" " + s.substr(m) +
"\n";
189 std::istringstream str(s);
196 rhl.Position(s12, lat2, lon2, S12);
197 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" " 199 }
else if (inverse) {
200 std::string slat1, slon1, slat2, slon2;
201 if (!(str >> slat1 >> slon1 >> slat2 >> slon2))
208 rh.
Inverse(lat1, lon1, lat2, lon2, s12, azi12, S12);
213 std::string slat1, slon1, sazi;
214 if (!(str >> slat1 >> slon1 >> sazi >> s12))
221 rh.
Direct(lat1, lon1, azi12, s12, lat2, lon2, S12);
222 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep) <<
" " 226 catch (
const std::exception& e) {
228 *output <<
"ERROR: " << e.what() <<
"\n";
234 catch (
const std::exception& e) {
235 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
239 std::cerr <<
"Caught unknown exception\n";
RhumbLine Line(real lat1, real lon1, real azi12) const
int main(int argc, char *argv[])
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
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)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
std::string LatLonString(real lat, real lon, int prec, bool dms, char dmssep)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static int set_digits(int ndigits=0)
void Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12, real &S12) const
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.