24 # pragma warning (disable: 4127 4701) 27 #include "GeoidEval.usage" 29 int main(
int argc,
const char*
const argv[]) {
34 bool cacheall =
false, cachearea =
false, verbose =
false, cubic =
true;
35 real caches, cachew, cachen, cachee;
39 std::string istring, ifile, ofile, cdelim;
41 bool northp =
false, longfirst =
false;
44 for (
int m = 1; m < argc; ++m) {
45 std::string arg(argv[m]);
50 else if (arg ==
"-c") {
51 if (m + 4 >= argc)
return usage(1,
true);
56 caches, cachew, longfirst);
58 cachen, cachee, longfirst);
60 catch (
const std::exception& e) {
61 std::cerr <<
"Error decoding argument of -c: " << e.what() <<
"\n";
65 }
else if (arg ==
"--msltohae")
67 else if (arg ==
"--haetomsl")
70 longfirst = !longfirst;
71 else if (arg ==
"-z") {
72 if (++m == argc)
return usage(1,
true);
73 std::string zone = argv[m];
77 catch (
const std::exception& e) {
78 std::cerr <<
"Error decoding zone: " << e.what() <<
"\n";
82 std::cerr <<
"Illegal zone " << zone <<
"\n";
85 }
else if (arg ==
"-n") {
86 if (++m == argc)
return usage(1,
true);
88 }
else if (arg ==
"-d") {
89 if (++m == argc)
return usage(1,
true);
91 }
else if (arg ==
"-l")
95 else if (arg ==
"--input-string") {
96 if (++m == argc)
return usage(1,
true);
98 }
else if (arg ==
"--input-file") {
99 if (++m == argc)
return usage(1,
true);
101 }
else if (arg ==
"--output-file") {
102 if (++m == argc)
return usage(1,
true);
104 }
else if (arg ==
"--line-separator") {
105 if (++m == argc)
return usage(1,
true);
106 if (std::string(argv[m]).size() != 1) {
107 std::cerr <<
"Line separator must be a single character\n";
111 }
else if (arg ==
"--comment-delimiter") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--version") {
115 std::cout << argv[0] <<
": GeographicLib version " 116 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
119 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";
187 std::cerr<<
"Caching:" 194 std::string s, eol, suff;
195 const char* spaces =
" \t\n\v\f\r,";
196 while (std::getline(*input, s)) {
199 if (!cdelim.empty()) {
200 std::string::size_type m = s.find(cdelim);
201 if (m != std::string::npos) {
202 eol =
" " + s.substr(m) +
"\n";
203 std::string::size_type m1 =
204 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
205 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
212 std::string::size_type pa = 0, pb = 0;
213 real easting = 0, northing = 0;
214 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
215 if (pb == std::string::npos)
218 pa = s.find_first_not_of(spaces, pb);
219 if (pa == std::string::npos)
222 pb = s.find_first_of(spaces, pa);
223 (i == 2 ? height : (i == 0 ? easting : northing)) =
224 Utility::val<real>(s.substr(pa, (pb == std::string::npos ?
227 p.
Reset(zonenum, northp, easting, northing);
229 suff = pb == std::string::npos ?
"" : s.substr(pb);
238 std::string::size_type pb = s.find_last_not_of(spaces);
239 std::string::size_type pa = s.find_last_of(spaces, pb);
240 if (pa == std::string::npos || pb == std::string::npos)
242 height = Utility::val<real>(s.substr(pa + 1, pb - pa));
243 s = s.substr(0, pa + 1);
245 p.
Reset(s,
true, longfirst);
257 catch (
const std::exception& e) {
258 *output <<
"ERROR: " << e.what() <<
"\n";
263 catch (
const std::exception& e) {
264 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
269 catch (
const std::exception& e) {
270 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
274 std::cerr <<
"Caught unknown exception\n";
const std::string & GeoidFile() const
Math::real RMSError() const
GeographicLib::Math::real real
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.
static std::string DefaultGeoidPath()
Math::real CacheNorth() const
Math::real MaxError() const
Header for GeographicLib::GeoCoords class.
Namespace for GeographicLib.
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)
static int set_digits(int ndigits=0)
Exception handling for GeographicLib.
Math::real CacheSouth() const
Math::real CacheWest() const
static std::string DefaultGeoidName()
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.