25 # pragma warning (disable: 4127 4701) 28 #include "TransverseMercatorProj.usage" 30 int main(
int argc,
const char*
const argv[]) {
35 bool exact =
true, extended =
false, series =
false,
reverse =
false,
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 ==
"-t") {
54 }
else if (arg ==
"-s") {
58 }
else if (arg ==
"-l") {
59 if (++m >= argc)
return usage(1,
true);
67 catch (
const std::exception&
e) {
68 std::cerr <<
"Error decoding argument of " << arg <<
": " 72 }
else if (arg ==
"-k") {
73 if (++m >= argc)
return usage(1,
true);
75 k0 = Utility::val<real>(std::string(argv[m]));
77 catch (
const std::exception&
e) {
78 std::cerr <<
"Error decoding argument of " << arg <<
": " 82 }
else if (arg ==
"-e") {
83 if (m + 2 >= argc)
return usage(1,
true);
85 a = Utility::val<real>(std::string(argv[m + 1]));
86 f = Utility::fract<real>(std::string(argv[m + 2]));
88 catch (
const std::exception&
e) {
89 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
93 }
else if (arg ==
"-w")
94 longfirst = !longfirst;
95 else if (arg ==
"-p") {
96 if (++m == argc)
return usage(1,
true);
98 prec = Utility::val<int>(std::string(argv[m]));
100 catch (
const std::exception&) {
101 std::cerr <<
"Precision " << argv[
m] <<
" is not a number\n";
104 }
else if (arg ==
"--input-string") {
105 if (++m == argc)
return usage(1,
true);
107 }
else if (arg ==
"--input-file") {
108 if (++m == argc)
return usage(1,
true);
110 }
else if (arg ==
"--output-file") {
111 if (++m == argc)
return usage(1,
true);
113 }
else if (arg ==
"--line-separator") {
114 if (++m == argc)
return usage(1,
true);
115 if (std::string(argv[m]).
size() != 1) {
116 std::cerr <<
"Line separator must be a single character\n";
120 }
else if (arg ==
"--comment-delimiter") {
121 if (++m == argc)
return usage(1,
true);
123 }
else if (arg ==
"--version") {
124 std::cout << argv[0] <<
": GeographicLib version " 128 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
131 if (!ifile.empty() && !istring.empty()) {
132 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
135 if (ifile ==
"-") ifile.clear();
136 std::ifstream infile;
137 std::istringstream instring;
138 if (!ifile.empty()) {
139 infile.open(ifile.c_str());
140 if (!infile.is_open()) {
141 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
144 }
else if (!istring.empty()) {
145 std::string::size_type
m = 0;
147 m = istring.find(lsep, m);
148 if (m == std::string::npos)
152 instring.str(istring);
154 std::istream* input = !ifile.empty() ? &infile :
155 (!istring.empty() ? &instring : &std::cin);
157 std::ofstream outfile;
158 if (ofile ==
"-") ofile.clear();
159 if (!ofile.empty()) {
160 outfile.open(ofile.c_str());
161 if (!outfile.is_open()) {
162 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
166 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
173 : TransverseMercatorExact(1,
real(0.1), 1,
false);
178 std::string
s, eol, stra, strb, strc;
179 std::istringstream
str;
181 std::cout << std::fixed;
182 while (std::getline(*input, s)) {
185 if (!cdelim.empty()) {
186 std::string::size_type
m = s.find(cdelim);
187 if (m != std::string::npos) {
188 eol =
" " + s.substr(m) +
"\n";
192 str.clear(); str.str(s);
194 if (!(str >> stra >> strb))
197 x = Utility::val<real>(stra);
198 y = Utility::val<real>(strb);
209 *output <<
Utility::str(longfirst ? lon : lat, prec + 5) <<
" " 224 catch (
const std::exception&
e) {
225 *output <<
"ERROR: " << e.what() <<
"\n";
231 catch (
const std::exception&
e) {
232 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
236 std::cerr <<
"Caught unknown exception\n";
static T AngNormalize(T x)
An exact implementation of the transverse Mercator projection.
Header for GeographicLib::Utility class.
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Header for GeographicLib::TransverseMercatorExact class.
Transverse Mercator projection.
Header for GeographicLib::TransverseMercator class.
static int extra_digits()
const mpreal gamma(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
#define GEOGRAPHICLIB_VERSION_STRING
static Math::real Decode(const std::string &dms, flag &ind)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
static std::string str(T x, int p=-1)
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
static int set_digits(int ndigits=0)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Exception handling for GeographicLib.
void reverse(const MatrixType &m)
int main(int argc, const char *const argv[])
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Header for GeographicLib::DMS class.