24 # pragma warning (disable: 4127) 27 #include "GeoConvert.usage" 29 int main(
int argc,
char* argv[]) {
35 int outputmode = GEOGRAPHIC;
38 bool centerp =
true, swaplatlong =
false;
39 std::string istring, ifile, ofile, cdelim;
40 char lsep =
';', dmssep = char(0);
41 bool sethemisphere =
false, northp =
false, abbrev =
true;
43 for (
int m = 1; m < argc; ++m) {
44 std::string arg(argv[m]);
46 outputmode = GEOGRAPHIC;
47 else if (arg ==
"-d") {
50 }
else if (arg ==
"-:") {
53 }
else if (arg ==
"-u")
58 outputmode = CONVERGENCE;
67 else if (arg ==
"-p") {
68 if (++m == argc)
return usage(1,
true);
70 prec = Utility::num<int>(std::string(argv[m]));
72 catch (
const std::exception&) {
73 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
76 }
else if (arg ==
"-z") {
77 if (++m == argc)
return usage(1,
true);
78 std::string zonestr(argv[m]);
83 catch (
const std::exception&) {
84 std::istringstream str(zonestr);
86 if (!(str >> zone) || (str >> c)) {
87 std::cerr <<
"Zone " << zonestr
88 <<
" is not a number or zone+hemisphere\n";
92 std::cerr <<
"Zone " << zone <<
" not in [0, 60]\n";
95 sethemisphere =
false;
97 }
else if (arg ==
"-s") {
99 sethemisphere =
false;
100 }
else if (arg ==
"-t") {
102 sethemisphere =
false;
103 }
else if (arg ==
"--input-string") {
104 if (++m == argc)
return usage(1,
true);
106 }
else if (arg ==
"--input-file") {
107 if (++m == argc)
return usage(1,
true);
109 }
else if (arg ==
"--output-file") {
110 if (++m == argc)
return usage(1,
true);
112 }
else if (arg ==
"--line-separator") {
113 if (++m == argc)
return usage(1,
true);
114 if (std::string(argv[m]).size() != 1) {
115 std::cerr <<
"Line separator must be a single character\n";
119 }
else if (arg ==
"--comment-delimiter") {
120 if (++m == argc)
return usage(1,
true);
122 }
else if (arg ==
"--version") {
123 std::cout << argv[0] <<
": GeographicLib version " 124 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
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 while (std::getline(*input, s)) {
174 std::string eol(
"\n");
176 if (!cdelim.empty()) {
177 std::string::size_type m = s.find(cdelim);
178 if (m != std::string::npos) {
179 eol =
" " + s.substr(m) +
"\n";
183 p.
Reset(s, centerp, swaplatlong);
185 switch (outputmode) {
211 catch (
const std::exception& e) {
213 os = std::string(
"ERROR: ") + e.what();
216 *output << os << eol;
220 catch (
const std::exception& e) {
221 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
225 std::cerr <<
"Caught unknown exception\n";
std::string DMSRepresentation(int prec=0, bool swaplatlong=false, char dmssep=char(0)) const
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Math::real AltScale() const
Conversion between geographic coordinates.
std::string GeoRepresentation(int prec=0, bool swaplatlong=false) const
Header for GeographicLib::GeoCoords class.
Header for GeographicLib::MGRS 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.
Namespace for GeographicLib.
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
std::string AltMGRSRepresentation(int prec=0) const
std::string AltUTMUPSRepresentation(int prec=0, bool abbrev=true) const
static int set_digits(int ndigits=0)
int main(int argc, char *argv[])
void SetAltZone(int zone=UTMUPS::STANDARD) const
Math::real AltConvergence() const
Convert between UTM/UPS and MGRS.
Header for GeographicLib::DMS class.