25 # pragma warning (disable: 4127 4701)
28 #include "ConicProj.usage"
30 int main(
int argc,
char* argv[]) {
35 bool lcc =
false, albers =
false, reverse =
false;
36 real lat1 = 0, lat2 = 0, lon0 = 0, k1 = 1;
41 std::string istring, ifile, ofile, cdelim;
44 for (
int m = 1; m < argc; ++m) {
45 std::string arg(argv[m]);
48 else if (arg ==
"-c" || arg ==
"-a") {
51 if (m + 2 >= argc)
return usage(1,
true);
53 for (
int i = 0; i < 2; ++i) {
55 (i ? lat2 : lat1) =
DMS::Decode(std::string(argv[++m]), ind);
60 catch (
const std::exception& e) {
61 std::cerr <<
"Error decoding arguments of " << arg <<
": "
65 }
else if (arg ==
"-l") {
66 if (++m == argc)
return usage(1,
true);
72 if (!(lon0 >= -540 && lon0 < 540))
76 catch (
const std::exception& e) {
77 std::cerr <<
"Error decoding argument of " << arg <<
": "
81 }
else if (arg ==
"-k") {
82 if (++m == argc)
return usage(1,
true);
84 k1 = Utility::num<real>(std::string(argv[m]));
86 catch (
const std::exception& e) {
87 std::cerr <<
"Error decoding argument of " << arg <<
": "
91 }
else if (arg ==
"-e") {
92 if (m + 2 >= argc)
return usage(1,
true);
94 a = Utility::num<real>(std::string(argv[m + 1]));
95 f = Utility::fract<real>(std::string(argv[m + 2]));
97 catch (
const std::exception& e) {
98 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
102 }
else if (arg ==
"-p") {
103 if (++m == argc)
return usage(1,
true);
105 prec = Utility::num<int>(std::string(argv[m]));
107 catch (
const std::exception&) {
108 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
111 }
else if (arg ==
"--input-string") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--input-file") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--output-file") {
118 if (++m == argc)
return usage(1,
true);
120 }
else if (arg ==
"--line-separator") {
121 if (++m == argc)
return usage(1,
true);
122 if (std::string(argv[m]).size() != 1) {
123 std::cerr <<
"Line separator must be a single character\n";
127 }
else if (arg ==
"--comment-delimiter") {
128 if (++m == argc)
return usage(1,
true);
130 }
else if (arg ==
"--version") {
132 << 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 if (!(lcc || albers)) {
177 std::cerr <<
"Must specify \"-c lat1 lat2\" or "
178 <<
"\"-a lat1 lat2\"\n";
184 : LambertConformalConic(1, 0, 0, 0, 1);
187 : AlbersEqualArea(1, 0, 0, 0, 1);
194 std::cout << std::fixed;
195 while (std::getline(*input, s)) {
197 std::string eol(
"\n");
198 if (!cdelim.empty()) {
199 std::string::size_type m = s.find(cdelim);
200 if (m != std::string::npos) {
201 eol =
" " + s.substr(m) +
"\n";
205 std::istringstream str(s);
206 real lat, lon, x, y, gamma, k;
207 std::string stra, strb;
208 if (!(str >> stra >> strb))
211 x = Utility::num<real>(stra);
212 y = Utility::num<real>(strb);
220 lproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
222 aproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
229 lproj.
Forward(lon0, lat, lon, x, y, gamma, k);
231 aproj.
Forward(lon0, lat, lon, x, y, gamma, k);
238 catch (
const std::exception& e) {
239 *output <<
"ERROR: " << e.what() <<
"\n";
245 catch (
const std::exception& e) {
246 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
250 std::cerr <<
"Caught unknown exception\n";
static T AngNormalize(T x)
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
static int extra_digits()
Header for GeographicLib::AlbersEqualArea class.
Albers equal area conic projection.
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
static Math::real Decode(const std::string &dms, flag &ind)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
int main(int argc, char *argv[])
static int set_digits(int ndigits=0)
Exception handling for GeographicLib.
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Header for GeographicLib::DMS class.