23 # pragma warning (disable: 4127) 26 #include "GeoConvert.usage" 28 int main(
int argc,
const char*
const argv[]) {
34 int outputmode = GEOGRAPHIC;
37 bool centerp =
true, longfirst =
false;
38 std::string istring, ifile, ofile, cdelim;
39 char lsep =
';', dmssep = char(0);
40 bool sethemisphere =
false, northp =
false, abbrev =
true, latch =
false;
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;
60 else if (arg ==
"-z") {
61 if (++m == argc)
return usage(1,
true);
62 std::string zonestr(argv[m]);
67 catch (
const std::exception&) {
68 std::istringstream
str(zonestr);
70 if (!(str >> zone) || (str >> c)) {
71 std::cerr <<
"Zone " << zonestr
72 <<
" is not a number or zone+hemisphere\n";
76 std::cerr <<
"Zone " << zone <<
" not in [0, 60]\n";
79 sethemisphere =
false;
82 }
else if (arg ==
"-s") {
84 sethemisphere =
false;
86 }
else if (arg ==
"-S") {
88 sethemisphere =
false;
90 }
else if (arg ==
"-t") {
92 sethemisphere =
false;
94 }
else if (arg ==
"-T") {
96 sethemisphere =
false;
98 }
else if (arg ==
"-w")
99 longfirst = !longfirst;
100 else if (arg ==
"-p") {
101 if (++m == argc)
return usage(1,
true);
103 prec = Utility::val<int>(std::string(argv[m]));
105 catch (
const std::exception&) {
106 std::cerr <<
"Precision " << argv[
m] <<
" is not a number\n";
109 }
else if (arg ==
"-l")
111 else if (arg ==
"-a")
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") {
133 std::cout << argv[0] <<
": GeographicLib version " 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)) {
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, longfirst);
195 switch (outputmode) {
224 sethemisphere =
true;
228 catch (
const std::exception&
e) {
230 os = std::string(
"ERROR: ") + e.what();
233 *output << os << eol;
237 catch (
const std::exception&
e) {
238 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
242 std::cerr <<
"Caught unknown exception\n";
Header for GeographicLib::Utility class.
Math::real AltScale() const
Conversion between geographic coordinates.
Header for GeographicLib::GeoCoords class.
Header for GeographicLib::MGRS class.
static int extra_digits()
Convert between geographic coordinates and UTM/UPS.
Convert between degrees and the DMS representation.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
#define GEOGRAPHICLIB_VERSION_STRING
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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)
std::string GeoRepresentation(int prec=0, bool longfirst=false) const
ofstream os("timeSchurFactors.csv")
std::string DMSRepresentation(int prec=0, bool longfirst=false, char dmssep=char(0)) const
int main(int argc, const char *const argv[])
void SetAltZone(int zone=UTMUPS::STANDARD) const
Math::real AltConvergence() const
void Reset(const std::string &s, bool centerp=true, bool longfirst=false)
Convert between UTM/UPS and MGRS.
Header for GeographicLib::DMS class.