36 # pragma warning (disable: 4127 4701)
39 #include "GeoidEval.usage"
41 int main(
int argc,
char* argv[]) {
43 using namespace GeographicLib;
45 bool cacheall =
false, cachearea =
false, verbose =
false,
46 cubic =
true, gradp =
false;
47 real caches, cachew, cachen, cachee;
51 std::string istring, ifile, ofile, cdelim;
56 for (
int m = 1; m < argc; ++m) {
57 std::string arg(argv[m]);
62 else if (arg ==
"-c") {
63 if (m + 4 >= argc)
return usage(1,
true);
72 catch (
const std::exception& e) {
73 std::cerr <<
"Error decoding argument of -c: " << e.what() <<
"\n";
77 }
else if (arg ==
"--msltohae")
79 else if (arg ==
"--haetomsl")
81 else if (arg ==
"-z") {
82 if (++m == argc)
return usage(1,
true);
83 std::string zone = argv[m];
87 catch (
const std::exception& e) {
88 std::cerr <<
"Error decoding zone: " << e.what() <<
"\n";
92 std::cerr <<
"Illegal zone " << zone <<
"\n";
95 }
else if (arg ==
"-n") {
96 if (++m == argc)
return usage(1,
true);
98 }
else if (arg ==
"-d") {
99 if (++m == argc)
return usage(1,
true);
101 }
else if (arg ==
"-l")
103 else if (arg ==
"-g")
105 else if (arg ==
"-v")
107 else if (arg ==
"--input-string") {
108 if (++m == argc)
return usage(1,
true);
110 }
else if (arg ==
"--input-file") {
111 if (++m == argc)
return usage(1,
true);
113 }
else if (arg ==
"--output-file") {
114 if (++m == argc)
return usage(1,
true);
116 }
else if (arg ==
"--line-separator") {
117 if (++m == argc)
return usage(1,
true);
118 if (std::string(argv[m]).size() != 1) {
119 std::cerr <<
"Line separator must be a single character\n";
123 }
else if (arg ==
"--comment-delimiter") {
124 if (++m == argc)
return usage(1,
true);
126 }
else if (arg ==
"--version") {
128 << argv[0] <<
": GeographicLib version "
129 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
132 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
141 if (!ifile.empty() && !istring.empty()) {
142 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
145 if (ifile ==
"-") ifile.clear();
146 std::ifstream infile;
147 std::istringstream instring;
148 if (!ifile.empty()) {
149 infile.open(ifile.c_str());
150 if (!infile.is_open()) {
151 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
154 }
else if (!istring.empty()) {
155 std::string::size_type m = 0;
157 m = istring.find(lsep, m);
158 if (m == std::string::npos)
162 instring.str(istring);
164 std::istream* input = !ifile.empty() ? &infile :
165 (!istring.empty() ? &instring : &std::cin);
167 std::ofstream outfile;
168 if (ofile ==
"-") ofile.clear();
169 if (!ofile.empty()) {
170 outfile.open(ofile.c_str());
171 if (!outfile.is_open()) {
172 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
176 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
180 const Geoid g(geoid, dir, cubic);
185 g.
CacheArea(caches, cachew, cachen, cachee);
187 catch (
const std::exception& e) {
188 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
191 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n"
194 <<
"Date & Time: " << g.
DateTime() <<
"\n"
195 <<
"Offset (m): " << g.
Offset() <<
"\n"
196 <<
"Scale (m): " << g.
Scale() <<
"\n"
197 <<
"Max error (m): " << g.
MaxError() <<
"\n"
198 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
200 std::cerr<<
"Caching:"
208 const char* spaces =
" \t\n\v\f\r,";
209 while (std::getline(*input, s)) {
211 std::string eol(
"\n");
212 if (!cdelim.empty()) {
213 std::string::size_type m = s.find(cdelim);
214 if (m != std::string::npos) {
215 eol =
" " + s.substr(m) +
"\n";
216 std::string::size_type m1 =
217 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
218 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
225 std::string::size_type pa = 0, pb = 0;
226 real easting = 0, northing = 0;
227 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
228 if (pb == std::string::npos)
231 pa = s.find_first_not_of(spaces, pb);
232 if (pa == std::string::npos)
235 pb = s.find_first_of(spaces, pa);
236 (i == 2 ? height : (i == 0 ? easting : northing)) =
237 Utility::num<real>(s.substr(pa, (pb == std::string::npos ?
240 p.
Reset(zonenum, northp, easting, northing);
242 suff = pb == std::string::npos ?
"" : s.substr(pb);
251 std::string::size_type pb = s.find_last_not_of(spaces);
252 std::string::size_type pa = s.find_last_of(spaces, pb);
253 if (pa == std::string::npos || pb == std::string::npos)
255 height = Utility::num<real>(s.substr(pa + 1, pb - pa));
256 s = s.substr(0, pa + 1);
263 << Utility::str<real>(height +
real(heightmult) * h, 4)
269 *output << Utility::str<real>(h, 4) <<
" "
270 << Utility::str<real>(gradn * 1e6, 2)
272 << Utility::str<real>(grade * 1e6, 2)
277 *output << Utility::str<real>(h, 4) << eol;
281 catch (
const std::exception& e) {
282 *output <<
"ERROR: " << e.what() <<
"\n";
287 catch (
const std::exception& e) {
288 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
293 catch (
const std::exception& e) {
294 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
298 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)
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.