23int main(
int argc,
const char*
const argv[]) {
27 Utility::set_digits();
29 int outputmode = GEOGRAPHIC;
31 int zone = UTMUPS::MATCH;
32 bool centerp =
true, longfirst =
false;
33 std::string istring, ifile, ofile, cdelim;
34 char lsep =
';', dmssep = char(0);
35 bool sethemisphere =
false, northp =
false, abbrev =
true, latch =
false;
37 for (
int m = 1; m < argc; ++m) {
38 std::string arg(argv[m]);
40 outputmode = GEOGRAPHIC;
41 else if (arg ==
"-d") {
44 }
else if (arg ==
"-:") {
47 }
else if (arg ==
"-u")
52 outputmode = CONVERGENCE;
55 else if (arg ==
"-z") {
56 if (++m == argc)
return usage(1,
true);
57 std::string zonestr(argv[m]);
59 UTMUPS::DecodeZone(zonestr, zone, northp);
62 catch (
const std::exception&) {
63 std::istringstream str(zonestr);
65 if (!(str >> zone) || (str >> c)) {
66 std::cerr <<
"Zone " << zonestr
67 <<
" is not a number or zone+hemisphere\n";
70 if (!(zone >= UTMUPS::MINZONE && zone <= UTMUPS::MAXZONE)) {
71 std::cerr <<
"Zone " << zone <<
" not in [0, 60]\n";
74 sethemisphere =
false;
77 }
else if (arg ==
"-s") {
78 zone = UTMUPS::STANDARD;
79 sethemisphere =
false;
81 }
else if (arg ==
"-S") {
82 zone = UTMUPS::STANDARD;
83 sethemisphere =
false;
85 }
else if (arg ==
"-t") {
87 sethemisphere =
false;
89 }
else if (arg ==
"-T") {
91 sethemisphere =
false;
93 }
else if (arg ==
"-w")
94 longfirst = !longfirst;
95 else if (arg ==
"-p") {
96 if (++m == argc)
return usage(1,
true);
98 prec = Utility::val<int>(std::string(argv[m]));
100 catch (
const std::exception&) {
101 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
104 }
else if (arg ==
"-l")
106 else if (arg ==
"-a")
108 else if (arg ==
"--input-string") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--input-file") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--output-file") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--line-separator") {
118 if (++m == argc)
return usage(1,
true);
119 if (std::string(argv[m]).size() != 1) {
120 std::cerr <<
"Line separator must be a single character\n";
124 }
else if (arg ==
"--comment-delimiter") {
125 if (++m == argc)
return usage(1,
true);
127 }
else if (arg ==
"--version") {
128 std::cout << argv[0] <<
": GeographicLib version "
129 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
133 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
136 if (!ifile.empty() && !istring.empty()) {
137 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
140 if (ifile ==
"-") ifile.clear();
141 std::ifstream infile;
142 std::istringstream instring;
143 if (!ifile.empty()) {
144 infile.open(ifile.c_str());
145 if (!infile.is_open()) {
146 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
149 }
else if (!istring.empty()) {
150 std::string::size_type m = 0;
152 m = istring.find(lsep, m);
153 if (m == std::string::npos)
157 instring.str(istring);
159 std::istream* input = !ifile.empty() ? &infile :
160 (!istring.empty() ? &instring : &std::cin);
162 std::ofstream outfile;
163 if (ofile ==
"-") ofile.clear();
164 if (!ofile.empty()) {
165 outfile.open(ofile.c_str());
166 if (!outfile.is_open()) {
167 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
171 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
178 while (std::getline(*input, s)) {
181 if (!cdelim.empty()) {
182 std::string::size_type m = s.find(cdelim);
183 if (m != std::string::npos) {
184 eol =
" " + s.substr(m) +
"\n";
188 p.
Reset(s, centerp, longfirst);
190 switch (outputmode) {
210 int prec1 = std::max(-5, std::min(Math::extra_digits() + 8, prec));
211 os = Utility::str(gamma, prec1 + 5) +
" "
212 + Utility::str(k, prec1 + 7);
216 zone < UTMUPS::MINZONE && p.
AltZone() >= UTMUPS::MINZONE) {
219 sethemisphere =
true;
223 catch (
const std::exception& e) {
225 os = std::string(
"ERROR: ") + e.what();
228 *output << os << eol;
232 catch (
const std::exception& e) {
233 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
237 std::cerr <<
"Caught unknown exception\n";