48int main(
int argc,
const char*
const argv[]) {
51 bool linecalc =
false, inverse =
false, dms =
false, exact =
false,
52 unroll =
false, longfirst =
false;
58 std::string istring, ifile, ofile, cdelim;
59 char lsep =
';', dmssep = char(0);
61 for (
int m = 1; m < argc; ++m) {
62 std::string arg(argv[m]);
66 }
else if (arg ==
"-L") {
69 if (m + 3 >= argc)
return usage(1,
true);
72 lat1, lon1, longfirst);
75 catch (
const std::exception& e) {
76 std::cerr <<
"Error decoding arguments of -L: " << e.what() <<
"\n";
80 }
else if (arg ==
"-e") {
81 if (m + 2 >= argc)
return usage(1,
true);
83 a = Utility::val<real>(std::string(argv[m + 1]));
84 f = Utility::fract<real>(std::string(argv[m + 2]));
86 catch (
const std::exception& e) {
87 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
91 }
else if (arg ==
"-u")
93 else if (arg ==
"-d") {
96 }
else if (arg ==
"-:") {
99 }
else if (arg ==
"-w")
100 longfirst = !longfirst;
101 else if (arg ==
"-p") {
102 if (++m == argc)
return usage(1,
true);
104 prec = Utility::val<int>(std::string(argv[m]));
106 catch (
const std::exception&) {
107 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
110 }
else if (arg ==
"-E")
112 else if (arg ==
"--input-string") {
113 if (++m == argc)
return usage(1,
true);
115 }
else if (arg ==
"--input-file") {
116 if (++m == argc)
return usage(1,
true);
118 }
else if (arg ==
"--output-file") {
119 if (++m == argc)
return usage(1,
true);
121 }
else if (arg ==
"--line-separator") {
122 if (++m == argc)
return usage(1,
true);
123 if (std::string(argv[m]).size() != 1) {
124 std::cerr <<
"Line separator must be a single character\n";
128 }
else if (arg ==
"--comment-delimiter") {
129 if (++m == argc)
return usage(1,
true);
131 }
else if (arg ==
"--version") {
132 std::cout << argv[0] <<
": GeographicLib version "
133 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
136 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
139 if (!ifile.empty() && !istring.empty()) {
140 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
143 if (ifile ==
"-") ifile.clear();
144 std::ifstream infile;
145 std::istringstream instring;
146 if (!ifile.empty()) {
147 infile.open(ifile.c_str());
148 if (!infile.is_open()) {
149 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
152 }
else if (!istring.empty()) {
153 std::string::size_type m = 0;
155 m = istring.find(lsep, m);
156 if (m == std::string::npos)
160 instring.str(istring);
162 std::istream* input = !ifile.empty() ? &infile :
163 (!istring.empty() ? &instring : &std::cin);
165 std::ofstream outfile;
166 if (ofile ==
"-") ofile.clear();
167 if (!ofile.empty()) {
168 outfile.open(ofile.c_str());
169 if (!outfile.is_open()) {
170 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
174 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
176 const Rhumb rh(a, f, exact);
182 std::string s, eol, slat1, slon1, slat2, slon2, sazi, ss12, strc;
183 std::istringstream str;
185 while (std::getline(*input, s)) {
188 if (!cdelim.empty()) {
189 std::string::size_type m = s.find(cdelim);
190 if (m != std::string::npos) {
191 eol =
" " + s.substr(m) +
"\n";
195 str.clear(); str.str(s);
201 s12 = Utility::val<real>(ss12);
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 >> ss12))
224 s12 = Utility::val<real>(ss12);
225 rh.GenDirect(lat1, lon1, azi12, s12,
228 *output <<
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
229 <<
" " <<
Utility::str(S12, std::max(prec-7, 0)) << eol;
232 catch (
const std::exception& e) {
234 *output <<
"ERROR: " << e.what() <<
"\n";
240 catch (
const std::exception& e) {
241 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
245 std::cerr <<
"Caught unknown exception\n";