33 # pragma warning (disable: 4127 4701)
36 #include "ConicProj.usage"
38 int main(
int argc,
char* argv[]) {
40 using namespace GeographicLib;
43 bool lcc =
false, albers =
false, reverse =
false;
44 real lat1 = 0, lat2 = 0, lon0 = 0, k1 = 1;
49 std::string istring, ifile, ofile, cdelim;
52 for (
int m = 1; m < argc; ++m) {
53 std::string arg(argv[m]);
56 else if (arg ==
"-c" || arg ==
"-a") {
59 if (m + 2 >= argc)
return usage(1,
true);
61 for (
int i = 0; i < 2; ++i) {
63 (i ? lat2 : lat1) =
DMS::Decode(std::string(argv[++m]), ind);
68 catch (
const std::exception& e) {
69 std::cerr <<
"Error decoding arguments of " << arg <<
": "
73 }
else if (arg ==
"-l") {
74 if (++m == argc)
return usage(1,
true);
80 if (!(lon0 >= -540 && lon0 < 540))
84 catch (
const std::exception& e) {
85 std::cerr <<
"Error decoding argument of " << arg <<
": "
89 }
else if (arg ==
"-k") {
90 if (++m == argc)
return usage(1,
true);
92 k1 = Utility::num<real>(std::string(argv[m]));
94 catch (
const std::exception& e) {
95 std::cerr <<
"Error decoding argument of " << arg <<
": "
99 }
else if (arg ==
"-e") {
100 if (m + 2 >= argc)
return usage(1,
true);
102 a = Utility::num<real>(std::string(argv[m + 1]));
103 f = Utility::fract<real>(std::string(argv[m + 2]));
105 catch (
const std::exception& e) {
106 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
110 }
else if (arg ==
"-p") {
111 if (++m == argc)
return usage(1,
true);
113 prec = Utility::num<int>(std::string(argv[m]));
115 catch (
const std::exception&) {
116 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
119 }
else if (arg ==
"--input-string") {
120 if (++m == argc)
return usage(1,
true);
122 }
else if (arg ==
"--input-file") {
123 if (++m == argc)
return usage(1,
true);
125 }
else if (arg ==
"--output-file") {
126 if (++m == argc)
return usage(1,
true);
128 }
else if (arg ==
"--line-separator") {
129 if (++m == argc)
return usage(1,
true);
130 if (std::string(argv[m]).size() != 1) {
131 std::cerr <<
"Line separator must be a single character\n";
135 }
else if (arg ==
"--comment-delimiter") {
136 if (++m == argc)
return usage(1,
true);
138 }
else if (arg ==
"--version") {
140 << argv[0] <<
": GeographicLib version "
141 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
144 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
147 if (!ifile.empty() && !istring.empty()) {
148 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
151 if (ifile ==
"-") ifile.clear();
152 std::ifstream infile;
153 std::istringstream instring;
154 if (!ifile.empty()) {
155 infile.open(ifile.c_str());
156 if (!infile.is_open()) {
157 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
160 }
else if (!istring.empty()) {
161 std::string::size_type m = 0;
163 m = istring.find(lsep, m);
164 if (m == std::string::npos)
168 instring.str(istring);
170 std::istream* input = !ifile.empty() ? &infile :
171 (!istring.empty() ? &instring : &std::cin);
173 std::ofstream outfile;
174 if (ofile ==
"-") ofile.clear();
175 if (!ofile.empty()) {
176 outfile.open(ofile.c_str());
177 if (!outfile.is_open()) {
178 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
182 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
184 if (!(lcc || albers)) {
185 std::cerr <<
"Must specify \"-c lat1 lat2\" or "
186 <<
"\"-a lat1 lat2\"\n";
192 : LambertConformalConic(1, 0, 0, 0, 1);
195 : AlbersEqualArea(1, 0, 0, 0, 1);
202 std::cout << std::fixed;
203 while (std::getline(*input, s)) {
205 std::string eol(
"\n");
206 if (!cdelim.empty()) {
207 std::string::size_type m = s.find(cdelim);
208 if (m != std::string::npos) {
209 eol =
" " + s.substr(m) +
"\n";
213 std::istringstream str(s);
214 real lat, lon, x, y, gamma, k;
215 std::string stra, strb;
216 if (!(str >> stra >> strb))
219 x = Utility::num<real>(stra);
220 y = Utility::num<real>(strb);
228 lproj.Reverse(lon0, x, y, lat, lon, gamma, k);
230 aproj.Reverse(lon0, x, y, lat, lon, gamma, k);
237 lproj.Forward(lon0, lat, lon, x, y, gamma, k);
239 aproj.Forward(lon0, lat, lon, x, y, gamma, k);
246 catch (
const std::exception& e) {
247 *output <<
"ERROR: " << e.what() <<
"\n";
253 catch (
const std::exception& e) {
254 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
258 std::cerr <<
"Caught unknown exception\n";