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);
73 if (!(
abs(lat) <= 90))
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" 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";
213 str.clear(); str.str(s);
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);
267 c.SphericalAnomaly(lon, Dg01, xi, eta);
281 real
N = circle ?
c.GeoidHeight(lon) : g.
GeoidHeight(lat, lon);
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";
const std::string & GravityModelName() const
const std::string & Description() const
noiseModel::Diagonal::shared_ptr model
Header for GeographicLib::Utility class.
static bool isfinite(T x)
Header for GeographicLib::GravityModel class.
const std::string & DateTime() const
void g(const string &key, int i)
static int extra_digits()
int main(int argc, const char *const argv[])
Math::real Gravity(real lat, real lon, real h, real &gx, real &gy, real &gz) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
#define GEOGRAPHICLIB_VERSION_STRING
static Math::real Decode(const std::string &dms, flag &ind)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static std::string str(T x, int p=-1)
Math::real Disturbance(real lat, real lon, real h, real &deltax, real &deltay, real &deltaz) const
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)
Model of the earth's gravity field.
static std::string DefaultGravityName()
GravityCircle Circle(real lat, real h, unsigned caps=ALL) const
Exception handling for GeographicLib.
static std::string DefaultGravityPath()
const std::string & GravityFile() const
static const DiscreteKey mode(modeKey, 2)
Header for GeographicLib::GravityCircle class.
void SphericalAnomaly(real lat, real lon, real h, real &Dg01, real &xi, real &eta) const
Gravity on a circle of latitude.
Math::real GeoidHeight(real lat, real lon) const
Header for GeographicLib::DMS class.