24 # pragma warning (disable: 4127 4701)
27 #include "ConicProj.usage"
29 int main(
int argc,
char* argv[]) {
34 bool lcc =
false, albers =
false, reverse =
false, longfirst =
false;
35 real lat1 = 0, lat2 = 0, lon0 = 0, k1 = 1;
40 std::string istring, ifile, ofile, cdelim;
43 for (
int m = 1; m < argc; ++m) {
44 std::string arg(argv[m]);
47 else if (arg ==
"-c" || arg ==
"-a") {
50 if (m + 2 >= argc)
return usage(1,
true);
52 for (
int i = 0; i < 2; ++i) {
54 (i ? lat2 : lat1) =
DMS::Decode(std::string(argv[++m]), ind);
59 catch (
const std::exception& e) {
60 std::cerr <<
"Error decoding arguments of " << arg <<
": "
64 }
else if (arg ==
"-l") {
65 if (++m == argc)
return usage(1,
true);
73 catch (
const std::exception& e) {
74 std::cerr <<
"Error decoding argument of " << arg <<
": "
78 }
else if (arg ==
"-k") {
79 if (++m == argc)
return usage(1,
true);
81 k1 = Utility::num<real>(std::string(argv[m]));
83 catch (
const std::exception& e) {
84 std::cerr <<
"Error decoding argument of " << arg <<
": "
88 }
else if (arg ==
"-e") {
89 if (m + 2 >= argc)
return usage(1,
true);
91 a = Utility::num<real>(std::string(argv[m + 1]));
92 f = Utility::fract<real>(std::string(argv[m + 2]));
94 catch (
const std::exception& e) {
95 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
99 }
else if (arg ==
"-w")
100 longfirst = !longfirst;
101 else if (arg ==
"-p") {
102 if (++m == argc)
return usage(1,
true);
104 prec = Utility::num<int>(std::string(argv[m]));
106 catch (
const std::exception&) {
107 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
110 }
else if (arg ==
"--input-string") {
111 if (++m == argc)
return usage(1,
true);
113 }
else if (arg ==
"--input-file") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--output-file") {
117 if (++m == argc)
return usage(1,
true);
119 }
else if (arg ==
"--line-separator") {
120 if (++m == argc)
return usage(1,
true);
121 if (std::string(argv[m]).size() != 1) {
122 std::cerr <<
"Line separator must be a single character\n";
126 }
else if (arg ==
"--comment-delimiter") {
127 if (++m == argc)
return usage(1,
true);
129 }
else if (arg ==
"--version") {
130 std::cout << argv[0] <<
": GeographicLib version "
131 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
134 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
137 if (!ifile.empty() && !istring.empty()) {
138 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
141 if (ifile ==
"-") ifile.clear();
142 std::ifstream infile;
143 std::istringstream instring;
144 if (!ifile.empty()) {
145 infile.open(ifile.c_str());
146 if (!infile.is_open()) {
147 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
150 }
else if (!istring.empty()) {
151 std::string::size_type m = 0;
153 m = istring.find(lsep, m);
154 if (m == std::string::npos)
158 instring.str(istring);
160 std::istream* input = !ifile.empty() ? &infile :
161 (!istring.empty() ? &instring : &std::cin);
163 std::ofstream outfile;
164 if (ofile ==
"-") ofile.clear();
165 if (!ofile.empty()) {
166 outfile.open(ofile.c_str());
167 if (!outfile.is_open()) {
168 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
172 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
174 if (!(lcc || albers)) {
175 std::cerr <<
"Must specify \"-c lat1 lat2\" or "
176 <<
"\"-a lat1 lat2\"\n";
182 : LambertConformalConic(1, 0, 0, 0, 1);
185 : AlbersEqualArea(1, 0, 0, 0, 1);
190 std::string s, eol, stra, strb, strc;
191 std::istringstream str;
193 while (std::getline(*input, s)) {
196 if (!cdelim.empty()) {
197 std::string::size_type m = s.find(cdelim);
198 if (m != std::string::npos) {
199 eol =
" " + s.substr(m) +
"\n";
203 str.clear(); str.str(s);
204 real lat, lon, x, y, gamma, k;
205 if (!(str >> stra >> strb))
208 x = Utility::num<real>(stra);
209 y = Utility::num<real>(strb);
216 lproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
218 aproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
219 *output <<
Utility::str(longfirst ? lon : lat, prec + 5) <<
" "
225 lproj.
Forward(lon0, lat, lon, x, y, gamma, k);
227 aproj.
Forward(lon0, lat, lon, x, y, gamma, k);
234 catch (
const std::exception& e) {
235 *output <<
"ERROR: " << e.what() <<
"\n";
241 catch (
const std::exception& e) {
242 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
246 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 Math::real Decode(const std::string &dms, flag &ind)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
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.