40int main(
int argc,
const char*
const argv[]) {
47 bool reverse =
false, dms =
false,
48 longfirst =
false, altell =
false;
53 e2 = -1, k2 = 0, kp2 = 0,
54 ax = -1, bx = 0, cx = 0, e2x = -1, k2x = 0, kp2x = 0;
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]);
63 else if (arg ==
"-t") {
64 if (m + 3 >= argc)
return usage(1,
true);
70 catch (
const std::exception& e) {
71 std::cerr <<
"Error decoding arguments of -t: " << e.what() <<
"\n";
76 }
else if (arg ==
"-e") {
79 if (m + 4 >= argc)
return usage(1,
true);
86 catch (
const std::exception& e) {
87 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
92 }
else if (arg ==
"-tx") {
93 if (m + 3 >= argc)
return usage(1,
true);
99 catch (
const std::exception& e) {
100 std::cerr <<
"Error decoding arguments of -t: " << e.what() <<
"\n";
105 }
else if (arg ==
"-ex") {
108 if (m + 4 >= argc)
return usage(1,
true);
115 catch (
const std::exception& e) {
116 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
121 }
else if (arg ==
"-d") {
124 }
else if (arg ==
"-:") {
127 }
else if (arg ==
"-w")
128 longfirst = !longfirst;
129 else if (arg ==
"-p") {
130 if (++m == argc)
return usage(1,
true);
134 catch (
const std::exception&) {
135 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
138 }
else if (arg ==
"--input-string") {
139 if (++m == argc)
return usage(1,
true);
141 }
else if (arg ==
"--input-file") {
142 if (++m == argc)
return usage(1,
true);
144 }
else if (arg ==
"--output-file") {
145 if (++m == argc)
return usage(1,
true);
147 }
else if (arg ==
"--line-separator") {
148 if (++m == argc)
return usage(1,
true);
149 if (std::string(argv[m]).size() != 1) {
150 std::cerr <<
"Line separator must be a single character\n";
154 }
else if (arg ==
"--comment-delimiter") {
155 if (++m == argc)
return usage(1,
true);
157 }
else if (arg ==
"--version") {
158 std::cout << argv[0] <<
": GeographicLib version "
159 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
162 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
165 Conformal3 tc(e2 >= 0 ? Ellipsoid3(b, e2, k2, kp2) : Ellipsoid3(a, b, c));
166 altell = e2x >= 0 || ax > 0;
167 Conformal3 tcx(e2x >= 0 ? Ellipsoid3(bx, e2x, k2x, kp2x) :
168 ax > 0 ? Ellipsoid3(ax, bx, cx) : Ellipsoid3());
170 if (!ifile.empty() && !istring.empty()) {
171 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
174 if (ifile ==
"-") ifile.clear();
175 std::ifstream infile;
176 std::istringstream instring;
177 if (!ifile.empty()) {
178 infile.open(ifile.c_str());
179 if (!infile.is_open()) {
180 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
183 }
else if (!istring.empty()) {
184 std::string::size_type m = 0;
186 m = istring.find(lsep, m);
187 if (m == std::string::npos)
191 instring.str(istring);
193 std::istream* input = !ifile.empty() ? &infile :
194 (!istring.empty() ? &instring : &std::cin);
196 std::ofstream outfile;
197 if (ofile ==
"-") ofile.clear();
198 if (!ofile.empty()) {
199 outfile.open(ofile.c_str());
200 if (!outfile.is_open()) {
201 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
205 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
210 using std::round, std::log10, std::ceil, std::signbit;
211 int disprec = std::max(0, prec +
int(round(log10(6400000/b)))),
212 angprec = prec + 5, scalprec = prec + 7;
214 scalprec += int(round(log10(b/bx)));
215 scalprec = std::max(0, scalprec);
217 std::string s, eol, stra, strb, strc;
218 std::istringstream str;
220 while (std::getline(*input, s)) {
223 if (!cdelim.empty()) {
224 std::string::size_type m = s.find(cdelim);
225 if (m != std::string::npos) {
226 eol =
" " + s.substr(m) +
"\n";
231 str.clear(); str.str(s);
232 if (!(str >> stra >> strb))
242 tc.ReverseOther(tcx, betx, omgx, bet, omg, gam, k);
245 tc.Reverse(x, y, bet, omg, k);
248 angprec, dms, dmssep, longfirst);
254 tc.ForwardOther(tcx, bet, omg, betx, omgx, gam, k);
256 angprec, dms, dmssep, longfirst);
259 tc.Forward(bet, omg, x, y, k);
268 catch (
const std::exception& e) {
270 *output <<
"ERROR: " << e.what() <<
"\n";
276 catch (
const std::exception& e) {
277 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
281 std::cerr <<
"Caught unknown exception\n";