24 # pragma warning (disable: 4127 4701)
27 #include "GeoidEval.usage"
29 int main(
int argc,
char* argv[]) {
31 using namespace GeographicLib;
34 bool cacheall =
false, cachearea =
false, verbose =
false,
35 cubic =
true, gradp =
false;
36 real caches, cachew, cachen, cachee;
40 std::string istring, ifile, ofile, cdelim;
45 for (
int m = 1; m < argc; ++m) {
46 std::string arg(argv[m]);
51 else if (arg ==
"-c") {
52 if (m + 4 >= argc)
return usage(1,
true);
61 catch (
const std::exception& e) {
62 std::cerr <<
"Error decoding argument of -c: " << e.what() <<
"\n";
66 }
else if (arg ==
"--msltohae")
68 else if (arg ==
"--haetomsl")
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")
96 else if (arg ==
"--input-string") {
97 if (++m == argc)
return usage(1,
true);
99 }
else if (arg ==
"--input-file") {
100 if (++m == argc)
return usage(1,
true);
102 }
else if (arg ==
"--output-file") {
103 if (++m == argc)
return usage(1,
true);
105 }
else if (arg ==
"--line-separator") {
106 if (++m == argc)
return usage(1,
true);
107 if (std::string(argv[m]).size() != 1) {
108 std::cerr <<
"Line separator must be a single character\n";
112 }
else if (arg ==
"--comment-delimiter") {
113 if (++m == argc)
return usage(1,
true);
115 }
else if (arg ==
"--version") {
116 std::cout << argv[0] <<
": GeographicLib version "
117 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
120 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
129 if (!ifile.empty() && !istring.empty()) {
130 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
133 if (ifile ==
"-") ifile.clear();
134 std::ifstream infile;
135 std::istringstream instring;
136 if (!ifile.empty()) {
137 infile.open(ifile.c_str());
138 if (!infile.is_open()) {
139 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
142 }
else if (!istring.empty()) {
143 std::string::size_type m = 0;
145 m = istring.find(lsep, m);
146 if (m == std::string::npos)
150 instring.str(istring);
152 std::istream* input = !ifile.empty() ? &infile :
153 (!istring.empty() ? &instring : &std::cin);
155 std::ofstream outfile;
156 if (ofile ==
"-") ofile.clear();
157 if (!ofile.empty()) {
158 outfile.open(ofile.c_str());
159 if (!outfile.is_open()) {
160 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
164 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
168 const Geoid g(geoid, dir, cubic);
173 g.
CacheArea(caches, cachew, cachen, cachee);
175 catch (
const std::exception& e) {
176 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
179 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n"
182 <<
"Date & Time: " << g.
DateTime() <<
"\n"
183 <<
"Offset (m): " << g.
Offset() <<
"\n"
184 <<
"Scale (m): " << g.
Scale() <<
"\n"
185 <<
"Max error (m): " << g.
MaxError() <<
"\n"
186 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
188 std::cerr<<
"Caching:"
196 const char* spaces =
" \t\n\v\f\r,";
197 while (std::getline(*input, s)) {
199 std::string eol(
"\n");
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::num<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::num<real>(s.substr(pa + 1, pb - pa));
244 s = s.substr(0, pa + 1);
269 catch (
const std::exception& e) {
270 *output <<
"ERROR: " << e.what() <<
"\n";
275 catch (
const std::exception& e) {
276 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
281 catch (
const std::exception& e) {
282 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
286 std::cerr <<
"Caught unknown exception\n";
Math::real Latitude() const
Math::real MaxError() const
GeographicLib::Math::real real
Math::real CacheWest() const
Header for GeographicLib::Utility class.
Math::real CacheNorth() const
Conversion between geographic coordinates.
const std::string & DateTime() const
static std::string DefaultGeoidPath()
const std::string & GeoidFile() const
Header for GeographicLib::GeoCoords class.
void Reset(const std::string &s, bool centerp=true, bool swaplatlong=false)
void CacheArea(real south, real west, real north, real east) const
const std::string Interpolation() const
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
Math::real Offset() const
Math::real RMSError() const
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
int main(int argc, char *argv[])
static int set_digits(int ndigits=0)
Exception handling for GeographicLib.
static std::string DefaultGeoidName()
Math::real CacheSouth() const
Math::real CacheEast() const
const std::string & Description() const
Header for GeographicLib::Geoid class.
Math::real Longitude() const
Looking up the height of the geoid above the ellipsoid.
Header for GeographicLib::DMS class.