23 # pragma warning (disable: 4701) 26 #include "GeoidEval.usage" 28 int main(
int argc,
const char*
const argv[]) {
33 bool cacheall =
false, cachearea =
false, verbose =
false, cubic =
true;
34 real caches, cachew, cachen, cachee;
38 std::string istring, ifile, ofile, cdelim;
40 bool northp =
false, longfirst =
false;
43 for (
int m = 1; m < argc; ++m) {
44 std::string arg(argv[m]);
49 else if (arg ==
"-c") {
50 if (m + 4 >= argc)
return usage(1,
true);
55 caches, cachew, longfirst);
57 cachen, cachee, longfirst);
59 catch (
const std::exception& e) {
60 std::cerr <<
"Error decoding argument of -c: " << e.what() <<
"\n";
64 }
else if (arg ==
"--msltohae")
66 else if (arg ==
"--haetomsl")
69 longfirst = !longfirst;
70 else if (arg ==
"-z") {
71 if (++m == argc)
return usage(1,
true);
72 std::string zone = argv[m];
76 catch (
const std::exception& e) {
77 std::cerr <<
"Error decoding zone: " << e.what() <<
"\n";
81 std::cerr <<
"Illegal zone " << zone <<
"\n";
84 }
else if (arg ==
"-n") {
85 if (++m == argc)
return usage(1,
true);
87 }
else if (arg ==
"-d") {
88 if (++m == argc)
return usage(1,
true);
90 }
else if (arg ==
"-l")
94 else if (arg ==
"--input-string") {
95 if (++m == argc)
return usage(1,
true);
97 }
else if (arg ==
"--input-file") {
98 if (++m == argc)
return usage(1,
true);
100 }
else if (arg ==
"--output-file") {
101 if (++m == argc)
return usage(1,
true);
103 }
else if (arg ==
"--line-separator") {
104 if (++m == argc)
return usage(1,
true);
105 if (std::string(argv[m]).size() != 1) {
106 std::cerr <<
"Line separator must be a single character\n";
110 }
else if (arg ==
"--comment-delimiter") {
111 if (++m == argc)
return usage(1,
true);
113 }
else if (arg ==
"--version") {
114 std::cout << argv[0] <<
": GeographicLib version " 115 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
118 int retval =
usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
128 if (!ifile.empty() && !istring.empty()) {
129 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
132 if (ifile ==
"-") ifile.clear();
133 std::ifstream infile;
134 std::istringstream instring;
135 if (!ifile.empty()) {
136 infile.open(ifile.c_str());
137 if (!infile.is_open()) {
138 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
141 }
else if (!istring.empty()) {
142 std::string::size_type m = 0;
144 m = istring.find(lsep, m);
145 if (m == std::string::npos)
149 instring.str(istring);
151 std::istream* input = !ifile.empty() ? &infile :
152 (!istring.empty() ? &instring : &std::cin);
154 std::ofstream outfile;
155 if (ofile ==
"-") ofile.clear();
156 if (!ofile.empty()) {
157 outfile.open(ofile.c_str());
158 if (!outfile.is_open()) {
159 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
163 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
167 const Geoid g(geoid, dir, cubic);
172 g.
CacheArea(caches, cachew, cachen, cachee);
174 catch (
const std::exception& e) {
175 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
178 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n" 181 <<
"Date & Time: " << g.
DateTime() <<
"\n" 182 <<
"Offset (m): " << g.
Offset() <<
"\n" 183 <<
"Scale (m): " << g.
Scale() <<
"\n" 184 <<
"Max error (m): " << g.
MaxError() <<
"\n" 185 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
195 std::string s, eol, suff;
196 const char* spaces =
" \t\n\v\f\r,";
197 while (std::getline(*input, s)) {
200 if (!cdelim.empty()) {
201 std::string::size_type m = s.find(cdelim);
202 if (m != std::string::npos) {
203 eol =
" " + s.substr(m) +
"\n";
204 std::string::size_type m1 =
205 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
206 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
213 std::string::size_type pa = 0, pb = 0;
214 real easting = 0, northing = 0;
215 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
216 if (pb == std::string::npos)
219 pa = s.find_first_not_of(spaces, pb);
220 if (pa == std::string::npos)
223 pb = s.find_first_of(spaces, pa);
224 (i == 2 ? height : (i == 0 ? easting : northing)) =
225 Utility::val<real>(s.substr(pa, (pb == std::string::npos ?
228 p.
Reset(zonenum, northp, easting, northing);
230 suff = pb == std::string::npos ?
"" : s.substr(pb);
239 std::string::size_type pb = s.find_last_not_of(spaces);
240 std::string::size_type pa = s.find_last_of(spaces, pb);
241 if (pa == std::string::npos || pb == std::string::npos)
243 height = Utility::val<real>(s.substr(pa + 1, pb - pa));
244 s = s.substr(0, pa + 1);
246 p.
Reset(s,
true, longfirst);
258 catch (
const std::exception& e) {
259 *output <<
"ERROR: " << e.what() <<
"\n";
264 catch (
const std::exception& e) {
265 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
270 catch (
const std::exception& e) {
271 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
275 std::cerr <<
"Caught unknown exception\n";
const std::string & GeoidFile() const
Math::real RMSError() const
const std::string Interpolation() const
Math::real Offset() const
Header for GeographicLib::Utility class.
void CacheArea(real south, real west, real north, real east) const
Conversion between geographic coordinates.
Math::real CacheNorth() const
Math::real MaxError() const
Header for GeographicLib::GeoCoords class.
int usage(int retval, bool)
Namespace for GeographicLib.
static std::string DefaultGeoidPath()
const std::string & Description() const
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
Math::real Longitude() const
int main(int argc, const char *const argv[])
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
GeographicLib::Math::real real
static int set_digits(int ndigits=0)
static std::string DefaultGeoidName()
Exception handling for GeographicLib.
Math::real CacheSouth() const
Math::real CacheWest() const
Math::real Latitude() const
Header for GeographicLib::Geoid class.
const std::string & DateTime() const
void Reset(const std::string &s, bool centerp=true, bool longfirst=false)
Math::real CacheEast() const
Looking up the height of the geoid above the ellipsoid.
Header for GeographicLib::DMS class.