27 # pragma warning (disable: 4127 4701) 30 #include "GeodesicProj.usage" 32 int main(
int argc,
char* argv[]) {
37 bool azimuthal =
false, cassini =
false, gnomonic =
false, reverse =
false;
38 real lat0 = 0, lon0 = 0;
43 std::string istring, ifile, ofile, cdelim;
46 for (
int m = 1; m < argc; ++m) {
47 std::string arg(argv[m]);
50 else if (arg ==
"-c" || arg ==
"-z" || arg ==
"-g") {
51 cassini = arg ==
"-c";
52 azimuthal = arg ==
"-z";
53 gnomonic = arg ==
"-g";
54 if (m + 2 >= argc)
return usage(1,
true);
59 catch (
const std::exception& e) {
60 std::cerr <<
"Error decoding arguments of " << arg <<
": " 65 }
else if (arg ==
"-e") {
66 if (m + 2 >= argc)
return usage(1,
true);
68 a = Utility::num<real>(std::string(argv[m + 1]));
69 f = Utility::fract<real>(std::string(argv[m + 2]));
71 catch (
const std::exception& e) {
72 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
76 }
else if (arg ==
"-p") {
77 if (++m == argc)
return usage(1,
true);
79 prec = Utility::num<int>(std::string(argv[m]));
81 catch (
const std::exception&) {
82 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
85 }
else if (arg ==
"--input-string") {
86 if (++m == argc)
return usage(1,
true);
88 }
else if (arg ==
"--input-file") {
89 if (++m == argc)
return usage(1,
true);
91 }
else if (arg ==
"--output-file") {
92 if (++m == argc)
return usage(1,
true);
94 }
else if (arg ==
"--line-separator") {
95 if (++m == argc)
return usage(1,
true);
96 if (std::string(argv[m]).size() != 1) {
97 std::cerr <<
"Line separator must be a single character\n";
101 }
else if (arg ==
"--comment-delimiter") {
102 if (++m == argc)
return usage(1,
true);
104 }
else if (arg ==
"--version") {
105 std::cout << argv[0] <<
": GeographicLib version " 106 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
109 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
112 if (!ifile.empty() && !istring.empty()) {
113 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
116 if (ifile ==
"-") ifile.clear();
117 std::ifstream infile;
118 std::istringstream instring;
119 if (!ifile.empty()) {
120 infile.open(ifile.c_str());
121 if (!infile.is_open()) {
122 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
125 }
else if (!istring.empty()) {
126 std::string::size_type m = 0;
128 m = istring.find(lsep, m);
129 if (m == std::string::npos)
133 instring.str(istring);
135 std::istream* input = !ifile.empty() ? &infile :
136 (!istring.empty() ? &instring : &std::cin);
138 std::ofstream outfile;
139 if (ofile ==
"-") ofile.clear();
140 if (!ofile.empty()) {
141 outfile.open(ofile.c_str());
142 if (!outfile.is_open()) {
143 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
147 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
149 if (!(azimuthal || cassini || gnomonic)) {
150 std::cerr <<
"Must specify \"-z lat0 lon0\" or " 151 <<
"\"-c lat0 lon0\" or \"-g lat0 lon0\"\n";
166 std::cout << std::fixed;
167 while (std::getline(*input, s)) {
169 std::string eol(
"\n");
170 if (!cdelim.empty()) {
171 std::string::size_type m = s.find(cdelim);
172 if (m != std::string::npos) {
173 eol =
" " + s.substr(m) +
"\n";
177 std::istringstream str(s);
178 real lat, lon, x, y, azi, rk;
179 std::string stra, strb;
180 if (!(str >> stra >> strb))
183 x = Utility::num<real>(stra);
184 y = Utility::num<real>(strb);
192 cs.
Reverse(x, y, lat, lon, azi, rk);
194 az.
Reverse(lat0, lon0, x, y, lat, lon, azi, rk);
196 gn.
Reverse(lat0, lon0, x, y, lat, lon, azi, rk);
203 cs.
Forward(lat, lon, x, y, azi, rk);
205 az.
Forward(lat0, lon0, lat, lon, x, y, azi, rk);
207 gn.
Forward(lat0, lon0, lat, lon, x, y, azi, rk);
214 catch (
const std::exception& e) {
215 *output <<
"ERROR: " << e.what() <<
"\n";
221 catch (
const std::exception& e) {
222 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
226 std::cerr <<
"Caught unknown exception\n";
Header for GeographicLib::CassiniSoldner class.
GeographicLib::Math::real real
void Reverse(real lat0, real lon0, real x, real y, real &lat, real &lon, real &azi, real &rk) const
int main(int argc, char *argv[])
Header for GeographicLib::Utility class.
void Forward(real lat, real lon, real &x, real &y, real &azi, real &rk) const
Cassini-Soldner projection.
void Reverse(real lat0, real lon0, real x, real y, real &lat, real &lon, real &azi, real &rk) const
Header for GeographicLib::Gnomonic class.
void Reverse(real x, real y, real &lat, real &lon, real &azi, real &rk) const
static int extra_digits()
Header for GeographicLib::Geodesic class.
Azimuthal equidistant projection.
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static int set_digits(int ndigits=0)
void Forward(real lat0, real lon0, real lat, real lon, real &x, real &y, real &azi, real &rk) const
void Forward(real lat0, real lon0, real lat, real lon, real &x, real &y, real &azi, real &rk) const
Exception handling for GeographicLib.
Header for GeographicLib::AzimuthalEquidistant class.
Header for GeographicLib::DMS class.