35 # pragma warning (disable: 4127 4701)
38 #include "TransverseMercatorProj.usage"
40 int main(
int argc,
char* argv[]) {
42 using namespace GeographicLib;
45 bool exact =
true, extended =
false, series =
false, reverse =
false;
52 std::string istring, ifile, ofile, cdelim;
55 for (
int m = 1; m < argc; ++m) {
56 std::string arg(argv[m]);
59 else if (arg ==
"-t") {
63 }
else if (arg ==
"-s") {
67 }
else if (arg ==
"-l") {
68 if (++m >= argc)
return usage(1,
true);
74 if (!(lon0 >= -540 && lon0 < 540))
78 catch (
const std::exception& e) {
79 std::cerr <<
"Error decoding argument of " << arg <<
": "
83 }
else if (arg ==
"-k") {
84 if (++m >= argc)
return usage(1,
true);
86 k0 = Utility::num<real>(std::string(argv[m]));
88 catch (
const std::exception& e) {
89 std::cerr <<
"Error decoding argument of " << arg <<
": "
93 }
else if (arg ==
"-e") {
94 if (m + 2 >= argc)
return usage(1,
true);
96 a = Utility::num<real>(std::string(argv[m + 1]));
97 f = Utility::fract<real>(std::string(argv[m + 2]));
99 catch (
const std::exception& e) {
100 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
104 }
else if (arg ==
"-p") {
105 if (++m == argc)
return usage(1,
true);
107 prec = Utility::num<int>(std::string(argv[m]));
109 catch (
const std::exception&) {
110 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
113 }
else if (arg ==
"--input-string") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--input-file") {
117 if (++m == argc)
return usage(1,
true);
119 }
else if (arg ==
"--output-file") {
120 if (++m == argc)
return usage(1,
true);
122 }
else if (arg ==
"--line-separator") {
123 if (++m == argc)
return usage(1,
true);
124 if (std::string(argv[m]).size() != 1) {
125 std::cerr <<
"Line separator must be a single character\n";
129 }
else if (arg ==
"--comment-delimiter") {
130 if (++m == argc)
return usage(1,
true);
132 }
else if (arg ==
"--version") {
134 << 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;
183 : TransverseMercatorExact(1,
real(0.1), 1,
false);
190 std::cout << std::fixed;
191 while (std::getline(*input, s)) {
193 std::string eol(
"\n");
194 if (!cdelim.empty()) {
195 std::string::size_type m = s.find(cdelim);
196 if (m != std::string::npos) {
197 eol =
" " + s.substr(m) +
"\n";
201 std::istringstream str(s);
203 std::string stra, strb;
204 if (!(str >> stra >> strb))
207 x = Utility::num<real>(stra);
208 y = Utility::num<real>(strb);
217 TMS.Reverse(lon0, x, y, lat, lon, gamma, k);
219 TME.Reverse(lon0, x, y, lat, lon, gamma, k);
226 TMS.Forward(lon0, lat, lon, x, y, gamma, k);
228 TME.Forward(lon0, lat, lon, x, y, gamma, k);
235 catch (
const std::exception& e) {
236 *output <<
"ERROR: " << e.what() <<
"\n";
242 catch (
const std::exception& e) {
243 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
247 std::cerr <<
"Caught unknown exception\n";