24 # pragma warning (disable: 4127 4701)
27 #include "Gravity.usage"
29 int main(
int argc,
const char*
const argv[]) {
34 bool verbose =
false, longfirst =
false;
37 std::string istring, ifile, ofile, cdelim;
49 for (
int m = 1;
m < argc; ++
m) {
50 std::string
arg(argv[
m]);
52 if (++
m == argc)
return usage(1,
true);
54 }
else if (
arg ==
"-d") {
55 if (++
m == argc)
return usage(1,
true);
57 }
else if (
arg ==
"-G")
65 else if (
arg ==
"-c") {
66 if (
m + 2 >= argc)
return usage(1,
true);
75 h = Utility::val<real>(std::string(argv[++
m]));
78 catch (
const std::exception&
e) {
79 std::cerr <<
"Error decoding argument of " <<
arg <<
": "
83 }
else if (
arg ==
"-w")
84 longfirst = !longfirst;
85 else if (
arg ==
"-p") {
86 if (++
m == argc)
return usage(1,
true);
88 prec = Utility::val<int>(std::string(argv[
m]));
90 catch (
const std::exception&) {
91 std::cerr <<
"Precision " << argv[
m] <<
" is not a number\n";
94 }
else if (
arg ==
"-v")
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") {
116 std::cout << argv[0] <<
": GeographicLib version "
120 int retval = usage(!(
arg ==
"-h" ||
arg ==
"--help"),
arg !=
"--help");
122 std::cout<<
"\nDefault gravity path = \""
124 <<
"\"\nDefault gravity name = \""
131 if (!ifile.empty() && !istring.empty()) {
132 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
135 if (ifile ==
"-") ifile.clear();
136 std::ifstream infile;
137 std::istringstream instring;
138 if (!ifile.empty()) {
139 infile.open(ifile.c_str());
140 if (!infile.is_open()) {
141 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
144 }
else if (!istring.empty()) {
145 std::string::size_type
m = 0;
147 m = istring.find(lsep,
m);
148 if (
m == std::string::npos)
152 instring.str(istring);
154 std::istream* input = !ifile.empty() ? &infile :
155 (!istring.empty() ? &instring : &std::cin);
157 std::ofstream outfile;
158 if (ofile ==
"-") ofile.clear();
159 if (!ofile.empty()) {
160 outfile.open(ofile.c_str());
161 if (!outfile.is_open()) {
162 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
166 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
187 else if (
mode == UNDULATION &&
h != 0)
188 throw GeographicErr(
"Height should be zero for geoid undulations");
191 std::cerr <<
"Gravity file: " <<
g.GravityFile() <<
"\n"
192 <<
"Name: " <<
g.GravityModelName() <<
"\n"
193 <<
"Description: " <<
g.Description() <<
"\n"
194 <<
"Date & Time: " <<
g.DateTime() <<
"\n";
201 std::string
s, eol, stra, strb;
202 std::istringstream
str;
203 while (std::getline(*input,
s)) {
206 if (!cdelim.empty()) {
207 std::string::size_type
m =
s.find(cdelim);
208 if (
m != std::string::npos) {
209 eol =
" " +
s.substr(
m) +
"\n";
223 if (!(
str >> stra >> strb))
229 if (
mode == UNDULATION &&
h != 0)
230 throw GeographicErr(
"Height must be zero for geoid heights");
239 c.Gravity(
lon, gx, gy, gz);
250 real deltax, deltay, deltaz;
252 c.Disturbance(
lon, deltax, deltay, deltaz);
254 g.Disturbance(
lat,
lon,
h, deltax, deltay, deltaz);
267 c.SphericalAnomaly(
lon, Dg01,
xi, eta);
269 g.SphericalAnomaly(
lat,
lon,
h, Dg01,
xi, eta);
287 catch (
const std::exception&
e) {
288 *output <<
"ERROR: " <<
e.what() <<
"\n";
293 catch (
const std::exception&
e) {
294 std::cerr <<
"Error reading " <<
model <<
": " <<
e.what() <<
"\n";
299 catch (
const std::exception&
e) {
300 std::cerr <<
"Caught exception: " <<
e.what() <<
"\n";
304 std::cerr <<
"Caught unknown exception\n";