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, longfirst =
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);
74 catch (
const std::exception& e) {
75 std::cerr <<
"Error decoding argument of " << arg <<
": "
79 }
else if (arg ==
"-k") {
80 if (++m == argc)
return usage(1,
true);
82 k1 = Utility::num<real>(std::string(argv[m]));
84 catch (
const std::exception& e) {
85 std::cerr <<
"Error decoding argument of " << arg <<
": "
89 }
else if (arg ==
"-e") {
90 if (m + 2 >= argc)
return usage(1,
true);
92 a = Utility::num<real>(std::string(argv[m + 1]));
93 f = Utility::fract<real>(std::string(argv[m + 2]));
95 catch (
const std::exception& e) {
96 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
100 }
else if (arg ==
"-w")
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") {
131 std::cout << argv[0] <<
": GeographicLib version "
132 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
135 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
138 if (!ifile.empty() && !istring.empty()) {
139 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
142 if (ifile ==
"-") ifile.clear();
143 std::ifstream infile;
144 std::istringstream instring;
145 if (!ifile.empty()) {
146 infile.open(ifile.c_str());
147 if (!infile.is_open()) {
148 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
151 }
else if (!istring.empty()) {
152 std::string::size_type m = 0;
154 m = istring.find(lsep, m);
155 if (m == std::string::npos)
159 instring.str(istring);
161 std::istream* input = !ifile.empty() ? &infile :
162 (!istring.empty() ? &instring : &std::cin);
164 std::ofstream outfile;
165 if (ofile ==
"-") ofile.clear();
166 if (!ofile.empty()) {
167 outfile.open(ofile.c_str());
168 if (!outfile.is_open()) {
169 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
173 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
175 if (!(lcc || albers)) {
176 std::cerr <<
"Must specify \"-c lat1 lat2\" or "
177 <<
"\"-a lat1 lat2\"\n";
183 : LambertConformalConic(1, 0, 0, 0, 1);
186 : AlbersEqualArea(1, 0, 0, 0, 1);
191 std::string s, eol, stra, strb, strc;
192 std::istringstream str;
194 while (std::getline(*input, s)) {
197 if (!cdelim.empty()) {
198 std::string::size_type m = s.find(cdelim);
199 if (m != std::string::npos) {
200 eol =
" " + s.substr(m) +
"\n";
204 str.clear(); str.str(s);
205 real lat, lon, x, y, gamma, k;
206 if (!(str >> stra >> strb))
209 x = Utility::num<real>(stra);
210 y = Utility::num<real>(strb);
217 lproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
219 aproj.
Reverse(lon0, x, y, lat, lon, gamma, k);
220 *output <<
Utility::str(longfirst ? lon : lat, prec + 5) <<
" "
226 lproj.
Forward(lon0, lat, lon, x, y, gamma, k);
228 aproj.
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";
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.