23 # pragma warning (disable: 4127)
26 #include "GeoConvert.usage"
28 int main(
int argc,
char* argv[]) {
34 int outputmode = GEOGRAPHIC;
37 bool centerp =
true, swaplatlong =
false;
38 std::string istring, ifile, ofile, cdelim;
39 char lsep =
';', dmssep = char(0);
40 bool sethemisphere =
false, northp =
false, abbrev =
true;
42 for (
int m = 1; m < argc; ++m) {
43 std::string arg(argv[m]);
45 outputmode = GEOGRAPHIC;
46 else if (arg ==
"-d") {
49 }
else if (arg ==
"-:") {
52 }
else if (arg ==
"-u")
57 outputmode = CONVERGENCE;
66 else if (arg ==
"-p") {
67 if (++m == argc)
return usage(1,
true);
69 prec = Utility::num<int>(std::string(argv[m]));
71 catch (
const std::exception&) {
72 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
75 }
else if (arg ==
"-z") {
76 if (++m == argc)
return usage(1,
true);
77 std::string zonestr(argv[m]);
82 catch (
const std::exception&) {
83 std::istringstream str(zonestr);
85 if (!(str >> zone) || (str >> c)) {
86 std::cerr <<
"Zone " << zonestr
87 <<
" is not a number or zone+hemisphere\n";
91 std::cerr <<
"Zone " << zone <<
" not in [0, 60]\n";
94 sethemisphere =
false;
96 }
else if (arg ==
"-s") {
98 sethemisphere =
false;
99 }
else if (arg ==
"-t") {
101 sethemisphere =
false;
102 }
else if (arg ==
"--input-string") {
103 if (++m == argc)
return usage(1,
true);
105 }
else if (arg ==
"--input-file") {
106 if (++m == argc)
return usage(1,
true);
108 }
else if (arg ==
"--output-file") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--line-separator") {
112 if (++m == argc)
return usage(1,
true);
113 if (std::string(argv[m]).size() != 1) {
114 std::cerr <<
"Line separator must be a single character\n";
118 }
else if (arg ==
"--comment-delimiter") {
119 if (++m == argc)
return usage(1,
true);
121 }
else if (arg ==
"--version") {
123 << argv[0] <<
": GeographicLib version "
124 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
127 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
130 if (!ifile.empty() && !istring.empty()) {
131 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
134 if (ifile ==
"-") ifile.clear();
135 std::ifstream infile;
136 std::istringstream instring;
137 if (!ifile.empty()) {
138 infile.open(ifile.c_str());
139 if (!infile.is_open()) {
140 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
143 }
else if (!istring.empty()) {
144 std::string::size_type m = 0;
146 m = istring.find(lsep, m);
147 if (m == std::string::npos)
151 instring.str(istring);
153 std::istream* input = !ifile.empty() ? &infile :
154 (!istring.empty() ? &instring : &std::cin);
156 std::ofstream outfile;
157 if (ofile ==
"-") ofile.clear();
158 if (!ofile.empty()) {
159 outfile.open(ofile.c_str());
160 if (!outfile.is_open()) {
161 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
165 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
172 while (std::getline(*input, s)) {
173 std::string eol(
"\n");
175 if (!cdelim.empty()) {
176 std::string::size_type m = s.find(cdelim);
177 if (m != std::string::npos) {
178 eol =
" " + s.substr(m) +
"\n";
182 p.
Reset(s, centerp, swaplatlong);
184 switch (outputmode) {
210 catch (
const std::exception& e) {
212 os = std::string(
"ERROR: ") + e.what();
215 *output << os << eol;
219 catch (
const std::exception& e) {
220 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
224 std::cerr <<
"Caught unknown exception\n";
std::string GeoRepresentation(int prec=0, bool swaplatlong=false) const
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Conversion between geographic coordinates.
std::string AltUTMUPSRepresentation(int prec=0, bool abbrev=true) const
std::string DMSRepresentation(int prec=0, bool swaplatlong=false, char dmssep=char(0)) const
Header for GeographicLib::GeoCoords class.
static int extra_digits()
void Reset(const std::string &s, bool centerp=true, bool swaplatlong=false)
Convert between geographic coordinates and UTM/UPS.
Convert between degrees and the DMS representation.
std::string AltMGRSRepresentation(int prec=0) const
Namespace for GeographicLib.
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
static int set_digits(int ndigits=0)
Math::real AltConvergence() const
int main(int argc, char *argv[])
Math::real AltScale() const
void SetAltZone(int zone=UTMUPS::STANDARD) const
Convert between UTM/UPS and MGRS.
Header for GeographicLib::DMS class.