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;
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") {
117 << argv[0] <<
": GeographicLib version "
118 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
121 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
130 if (!ifile.empty() && !istring.empty()) {
131 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
134 if (ifile ==
"-") ifile.clear();
135 std::ifstream infile;
136 std::istringstream instring;
137 if (!ifile.empty()) {
138 infile.open(ifile.c_str());
139 if (!infile.is_open()) {
140 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
143 }
else if (!istring.empty()) {
144 std::string::size_type m = 0;
146 m = istring.find(lsep, m);
147 if (m == std::string::npos)
151 instring.str(istring);
153 std::istream* input = !ifile.empty() ? &infile :
154 (!istring.empty() ? &instring : &std::cin);
156 std::ofstream outfile;
157 if (ofile ==
"-") ofile.clear();
158 if (!ofile.empty()) {
159 outfile.open(ofile.c_str());
160 if (!outfile.is_open()) {
161 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
165 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
169 const Geoid g(geoid, dir, cubic);
174 g.
CacheArea(caches, cachew, cachen, cachee);
176 catch (
const std::exception& e) {
177 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
180 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n"
183 <<
"Date & Time: " << g.
DateTime() <<
"\n"
184 <<
"Offset (m): " << g.
Offset() <<
"\n"
185 <<
"Scale (m): " << g.
Scale() <<
"\n"
186 <<
"Max error (m): " << g.
MaxError() <<
"\n"
187 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
189 std::cerr<<
"Caching:"
197 const char* spaces =
" \t\n\v\f\r,";
198 while (std::getline(*input, s)) {
200 std::string eol(
"\n");
201 if (!cdelim.empty()) {
202 std::string::size_type m = s.find(cdelim);
203 if (m != std::string::npos) {
204 eol =
" " + s.substr(m) +
"\n";
205 std::string::size_type m1 =
206 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
207 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
214 std::string::size_type pa = 0, pb = 0;
215 real easting = 0, northing = 0;
216 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
217 if (pb == std::string::npos)
220 pa = s.find_first_not_of(spaces, pb);
221 if (pa == std::string::npos)
224 pb = s.find_first_of(spaces, pa);
225 (i == 2 ? height : (i == 0 ? easting : northing)) =
226 Utility::num<real>(s.substr(pa, (pb == std::string::npos ?
229 p.
Reset(zonenum, northp, easting, northing);
231 suff = pb == std::string::npos ?
"" : s.substr(pb);
240 std::string::size_type pb = s.find_last_not_of(spaces);
241 std::string::size_type pa = s.find_last_of(spaces, pb);
242 if (pa == std::string::npos || pb == std::string::npos)
244 height = Utility::num<real>(s.substr(pa + 1, pb - pa));
245 s = s.substr(0, pa + 1);
270 catch (
const std::exception& e) {
271 *output <<
"ERROR: " << e.what() <<
"\n";
276 catch (
const std::exception& e) {
277 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
282 catch (
const std::exception& e) {
283 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
287 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
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 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.
int main(int argc, char *argv[])
Math::real Longitude() const
Looking up the height of the geoid.
Header for GeographicLib::DMS class.