24 # pragma warning (disable: 4127 4701)
27 #include "GeoidEval.usage"
29 int main(
int argc,
char* argv[]) {
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;
42 bool northp =
false, longfirst =
false;
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);
57 caches, cachew, longfirst);
59 cachen, cachee, longfirst);
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")
72 else if (arg ==
"-z") {
73 if (++m == argc)
return usage(1,
true);
74 std::string zone = argv[m];
78 catch (
const std::exception& e) {
79 std::cerr <<
"Error decoding zone: " << e.what() <<
"\n";
83 std::cerr <<
"Illegal zone " << zone <<
"\n";
86 }
else if (arg ==
"-n") {
87 if (++m == argc)
return usage(1,
true);
89 }
else if (arg ==
"-d") {
90 if (++m == argc)
return usage(1,
true);
92 }
else if (arg ==
"-l")
98 else if (arg ==
"--input-string") {
99 if (++m == argc)
return usage(1,
true);
101 }
else if (arg ==
"--input-file") {
102 if (++m == argc)
return usage(1,
true);
104 }
else if (arg ==
"--output-file") {
105 if (++m == argc)
return usage(1,
true);
107 }
else if (arg ==
"--line-separator") {
108 if (++m == argc)
return usage(1,
true);
109 if (std::string(argv[m]).size() != 1) {
110 std::cerr <<
"Line separator must be a single character\n";
114 }
else if (arg ==
"--comment-delimiter") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--version") {
118 std::cout << argv[0] <<
": GeographicLib version "
119 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
122 int retval = 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;
170 const Geoid g(geoid, dir, cubic);
175 g.
CacheArea(caches, cachew, cachen, cachee);
177 catch (
const std::exception& e) {
178 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
181 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n"
184 <<
"Date & Time: " << g.
DateTime() <<
"\n"
185 <<
"Offset (m): " << g.
Offset() <<
"\n"
186 <<
"Scale (m): " << g.
Scale() <<
"\n"
187 <<
"Max error (m): " << g.
MaxError() <<
"\n"
188 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
190 std::cerr<<
"Caching:"
197 std::string s, eol, suff;
198 const char* spaces =
" \t\n\v\f\r,";
199 while (std::getline(*input, s)) {
202 if (!cdelim.empty()) {
203 std::string::size_type m = s.find(cdelim);
204 if (m != std::string::npos) {
205 eol =
" " + s.substr(m) +
"\n";
206 std::string::size_type m1 =
207 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
208 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
215 std::string::size_type pa = 0, pb = 0;
216 real easting = 0, northing = 0;
217 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
218 if (pb == std::string::npos)
221 pa = s.find_first_not_of(spaces, pb);
222 if (pa == std::string::npos)
225 pb = s.find_first_of(spaces, pa);
226 (i == 2 ? height : (i == 0 ? easting : northing)) =
227 Utility::num<real>(s.substr(pa, (pb == std::string::npos ?
230 p.
Reset(zonenum, northp, easting, northing);
232 suff = pb == std::string::npos ?
"" : s.substr(pb);
241 std::string::size_type pb = s.find_last_not_of(spaces);
242 std::string::size_type pa = s.find_last_of(spaces, pb);
243 if (pa == std::string::npos || pb == std::string::npos)
245 height = Utility::num<real>(s.substr(pa + 1, pb - pa));
246 s = s.substr(0, pa + 1);
248 p.
Reset(s,
true, longfirst);
271 catch (
const std::exception& e) {
272 *output <<
"ERROR: " << e.what() <<
"\n";
277 catch (
const std::exception& e) {
278 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
283 catch (
const std::exception& e) {
284 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
288 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 CacheArea(real south, real west, real north, real east) const
const std::string Interpolation() const
Math::real Offset() const
Namespace for GeographicLib.
Math::real RMSError() const
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
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.
void Reset(const std::string &s, bool centerp=true, bool longfirst=false)
int main(int argc, char *argv[])
Math::real Longitude() const
Looking up the height of the geoid above the ellipsoid.
Header for GeographicLib::DMS class.