34 # pragma warning (disable: 4127)
37 #include "GeoConvert.usage"
39 int main(
int argc,
char* argv[]) {
45 int outputmode = GEOGRAPHIC;
48 bool centerp =
true, swaplatlong =
false;
49 std::string istring, ifile, ofile, cdelim;
50 char lsep =
';', dmssep = char(0);
51 bool sethemisphere =
false, northp =
false, abbrev =
true;
53 for (
int m = 1; m < argc; ++m) {
54 std::string arg(argv[m]);
56 outputmode = GEOGRAPHIC;
57 else if (arg ==
"-d") {
60 }
else if (arg ==
"-:") {
63 }
else if (arg ==
"-u")
68 outputmode = CONVERGENCE;
77 else if (arg ==
"-p") {
78 if (++m == argc)
return usage(1,
true);
80 prec = Utility::num<int>(std::string(argv[m]));
82 catch (
const std::exception&) {
83 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
86 }
else if (arg ==
"-z") {
87 if (++m == argc)
return usage(1,
true);
88 std::string zonestr(argv[m]);
93 catch (
const std::exception&) {
94 std::istringstream str(zonestr);
96 if (!(str >> zone) || (str >> c)) {
97 std::cerr <<
"Zone " << zonestr
98 <<
" is not a number or zone+hemisphere\n";
102 std::cerr <<
"Zone " << zone <<
" not in [0, 60]\n";
105 sethemisphere =
false;
107 }
else if (arg ==
"-s") {
109 sethemisphere =
false;
110 }
else if (arg ==
"-t") {
112 sethemisphere =
false;
113 }
else if (arg ==
"--input-string") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--input-file") {
117 if (++m == argc)
return usage(1,
true);
119 }
else if (arg ==
"--output-file") {
120 if (++m == argc)
return usage(1,
true);
122 }
else if (arg ==
"--line-separator") {
123 if (++m == argc)
return usage(1,
true);
124 if (std::string(argv[m]).size() != 1) {
125 std::cerr <<
"Line separator must be a single character\n";
129 }
else if (arg ==
"--comment-delimiter") {
130 if (++m == argc)
return usage(1,
true);
132 }
else if (arg ==
"--version") {
134 << argv[0] <<
": GeographicLib version "
135 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
138 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
141 if (!ifile.empty() && !istring.empty()) {
142 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
145 if (ifile ==
"-") ifile.clear();
146 std::ifstream infile;
147 std::istringstream instring;
148 if (!ifile.empty()) {
149 infile.open(ifile.c_str());
150 if (!infile.is_open()) {
151 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
154 }
else if (!istring.empty()) {
155 std::string::size_type m = 0;
157 m = istring.find(lsep, m);
158 if (m == std::string::npos)
162 instring.str(istring);
164 std::istream* input = !ifile.empty() ? &infile :
165 (!istring.empty() ? &instring : &std::cin);
167 std::ofstream outfile;
168 if (ofile ==
"-") ofile.clear();
169 if (!ofile.empty()) {
170 outfile.open(ofile.c_str());
171 if (!outfile.is_open()) {
172 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
176 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
183 while (std::getline(*input, s)) {
184 std::string eol(
"\n");
186 if (!cdelim.empty()) {
187 std::string::size_type m = s.find(cdelim);
188 if (m != std::string::npos) {
189 eol =
" " + s.substr(m) +
"\n";
193 p.
Reset(s, centerp, swaplatlong);
195 switch (outputmode) {
221 catch (
const std::exception& e) {
223 os = std::string(
"ERROR: ") + e.what();
226 *output << os << eol;
230 catch (
const std::exception& e) {
231 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
235 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.