36 # pragma warning (disable: 4127 4701)
39 #include "GeoidEval.usage"
41 int main(
int argc,
char* argv[]) {
43 using namespace GeographicLib;
46 bool cacheall =
false, cachearea =
false, verbose =
false,
47 cubic =
true, gradp =
false;
48 real caches, cachew, cachen, cachee;
52 std::string istring, ifile, ofile, cdelim;
57 for (
int m = 1; m < argc; ++m) {
58 std::string arg(argv[m]);
63 else if (arg ==
"-c") {
64 if (m + 4 >= argc)
return usage(1,
true);
73 catch (
const std::exception& e) {
74 std::cerr <<
"Error decoding argument of -c: " << e.what() <<
"\n";
78 }
else if (arg ==
"--msltohae")
80 else if (arg ==
"--haetomsl")
82 else if (arg ==
"-z") {
83 if (++m == argc)
return usage(1,
true);
84 std::string zone = argv[m];
88 catch (
const std::exception& e) {
89 std::cerr <<
"Error decoding zone: " << e.what() <<
"\n";
93 std::cerr <<
"Illegal zone " << zone <<
"\n";
96 }
else if (arg ==
"-n") {
97 if (++m == argc)
return usage(1,
true);
99 }
else if (arg ==
"-d") {
100 if (++m == argc)
return usage(1,
true);
102 }
else if (arg ==
"-l")
104 else if (arg ==
"-g")
106 else if (arg ==
"-v")
108 else if (arg ==
"--input-string") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--input-file") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--output-file") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--line-separator") {
118 if (++m == argc)
return usage(1,
true);
119 if (std::string(argv[m]).size() != 1) {
120 std::cerr <<
"Line separator must be a single character\n";
124 }
else if (arg ==
"--comment-delimiter") {
125 if (++m == argc)
return usage(1,
true);
127 }
else if (arg ==
"--version") {
129 << argv[0] <<
": GeographicLib version "
130 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
133 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
142 if (!ifile.empty() && !istring.empty()) {
143 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
146 if (ifile ==
"-") ifile.clear();
147 std::ifstream infile;
148 std::istringstream instring;
149 if (!ifile.empty()) {
150 infile.open(ifile.c_str());
151 if (!infile.is_open()) {
152 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
155 }
else if (!istring.empty()) {
156 std::string::size_type m = 0;
158 m = istring.find(lsep, m);
159 if (m == std::string::npos)
163 instring.str(istring);
165 std::istream* input = !ifile.empty() ? &infile :
166 (!istring.empty() ? &instring : &std::cin);
168 std::ofstream outfile;
169 if (ofile ==
"-") ofile.clear();
170 if (!ofile.empty()) {
171 outfile.open(ofile.c_str());
172 if (!outfile.is_open()) {
173 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
177 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
181 const Geoid g(geoid, dir, cubic);
186 g.
CacheArea(caches, cachew, cachen, cachee);
188 catch (
const std::exception& e) {
189 std::cerr <<
"ERROR: " << e.what() <<
"\nProceeding without a cache\n";
192 std::cerr <<
"Geoid file: " << g.
GeoidFile() <<
"\n"
195 <<
"Date & Time: " << g.
DateTime() <<
"\n"
196 <<
"Offset (m): " << g.
Offset() <<
"\n"
197 <<
"Scale (m): " << g.
Scale() <<
"\n"
198 <<
"Max error (m): " << g.
MaxError() <<
"\n"
199 <<
"RMS error (m): " << g.
RMSError() <<
"\n";
201 std::cerr<<
"Caching:"
209 const char* spaces =
" \t\n\v\f\r,";
210 while (std::getline(*input, s)) {
212 std::string eol(
"\n");
213 if (!cdelim.empty()) {
214 std::string::size_type m = s.find(cdelim);
215 if (m != std::string::npos) {
216 eol =
" " + s.substr(m) +
"\n";
217 std::string::size_type m1 =
218 m > 0 ? s.find_last_not_of(spaces, m - 1) : std::string::npos;
219 s = s.substr(0, m1 != std::string::npos ? m1 + 1 : m);
226 std::string::size_type pa = 0, pb = 0;
227 real easting = 0, northing = 0;
228 for (
int i = 0; i < (heightmult ? 3 : 2); ++i) {
229 if (pb == std::string::npos)
232 pa = s.find_first_not_of(spaces, pb);
233 if (pa == std::string::npos)
236 pb = s.find_first_of(spaces, pa);
237 (i == 2 ? height : (i == 0 ? easting : northing)) =
238 Utility::num<real>(s.substr(pa, (pb == std::string::npos ?
241 p.
Reset(zonenum, northp, easting, northing);
243 suff = pb == std::string::npos ?
"" : s.substr(pb);
252 std::string::size_type pb = s.find_last_not_of(spaces);
253 std::string::size_type pa = s.find_last_of(spaces, pb);
254 if (pa == std::string::npos || pb == std::string::npos)
256 height = Utility::num<real>(s.substr(pa + 1, pb - pa));
257 s = s.substr(0, pa + 1);
282 catch (
const std::exception& e) {
283 *output <<
"ERROR: " << e.what() <<
"\n";
288 catch (
const std::exception& e) {
289 std::cerr <<
"Error reading " << geoid <<
": " << e.what() <<
"\n";
294 catch (
const std::exception& e) {
295 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
299 std::cerr <<
"Caught unknown exception\n";