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 " 119 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";
196 std::string
s, eol, suff;
197 const char* spaces =
" \t\n\v\f\r,";
198 while (std::getline(*input, s)) {
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::val<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::val<real>(s.substr(pa + 1, pb - pa));
245 s = s.substr(0, pa + 1);
247 p.
Reset(s,
true, longfirst);
259 catch (
const std::exception& e) {
260 *output <<
"ERROR: " << e.what() <<
"\n";
265 catch (
const std::exception&
e) {
266 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
271 catch (
const std::exception&
e) {
272 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
276 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.
static std::string DefaultGeoidPath()
void g(const string &key, int i)
Math::real CacheNorth() const
Math::real MaxError() const
Header for GeographicLib::GeoCoords class.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
#define GEOGRAPHICLIB_VERSION_STRING
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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.