Go to the documentation of this file.
   24 #  pragma warning (disable: 4127 4701) 
   27 #include "CartConvert.usage" 
   29 int main(
int argc, 
const char* 
const argv[]) {
 
   34     bool localcartesian = 
false, 
reverse = 
false, longfirst = 
false;
 
   40     std::string istring, ifile, ofile, cdelim;
 
   43     for (
int m = 1; 
m < argc; ++
m) {
 
   44       std::string 
arg(argv[
m]);
 
   47       else if (
arg == 
"-l") {
 
   48         localcartesian = 
true;
 
   49         if (
m + 3 >= argc) 
return usage(1, 
true);
 
   53           h0 = Utility::val<real>(std::string(argv[
m + 3]));
 
   55         catch (
const std::exception& 
e) {
 
   56           std::cerr << 
"Error decoding arguments of -l: " << 
e.what() << 
"\n";
 
   60       } 
else if (
arg == 
"-e") {
 
   61         if (
m + 2 >= argc) 
return usage(1, 
true);
 
   63           a = Utility::val<real>(std::string(argv[
m + 1]));
 
   64           f = Utility::fract<real>(std::string(argv[
m + 2]));
 
   66         catch (
const std::exception& 
e) {
 
   67           std::cerr << 
"Error decoding arguments of -e: " << 
e.what() << 
"\n";
 
   71       } 
else if (
arg == 
"-w")
 
   72         longfirst = !longfirst;
 
   73       else if (
arg == 
"-p") {
 
   74         if (++
m == argc) 
return usage(1, 
true);
 
   76           prec = Utility::val<int>(std::string(argv[
m]));
 
   78         catch (
const std::exception&) {
 
   79           std::cerr << 
"Precision " << argv[
m] << 
" is not a number\n";
 
   82       }  
else if (
arg == 
"--input-string") {
 
   83         if (++
m == argc) 
return usage(1, 
true);
 
   85       } 
else if (
arg == 
"--input-file") {
 
   86         if (++
m == argc) 
return usage(1, 
true);
 
   88       } 
else if (
arg == 
"--output-file") {
 
   89         if (++
m == argc) 
return usage(1, 
true);
 
   91       } 
else if (
arg == 
"--line-separator") {
 
   92         if (++
m == argc) 
return usage(1, 
true);
 
   93         if (std::string(argv[
m]).
size() != 1) {
 
   94           std::cerr << 
"Line separator must be a single character\n";
 
   98       } 
else if (
arg == 
"--comment-delimiter") {
 
   99         if (++
m == argc) 
return usage(1, 
true);
 
  101      } 
else if (
arg == 
"--version") {
 
  102         std::cout << argv[0] << 
": GeographicLib version " 
  106         return usage(!(
arg == 
"-h" || 
arg == 
"--help"), 
arg != 
"--help");
 
  109     if (!ifile.empty() && !istring.empty()) {
 
  110       std::cerr << 
"Cannot specify --input-string and --input-file together\n";
 
  113     if (ifile == 
"-") ifile.clear();
 
  114     std::ifstream infile;
 
  115     std::istringstream instring;
 
  116     if (!ifile.empty()) {
 
  117       infile.open(ifile.c_str());
 
  118       if (!infile.is_open()) {
 
  119         std::cerr << 
"Cannot open " << ifile << 
" for reading\n";
 
  122     } 
else if (!istring.empty()) {
 
  123       std::string::size_type 
m = 0;
 
  125         m = istring.find(lsep, 
m);
 
  126         if (
m == std::string::npos)
 
  130       instring.str(istring);
 
  132     std::istream* input = !ifile.empty() ? &infile :
 
  133       (!istring.empty() ? &instring : &std::cin);
 
  135     std::ofstream outfile;
 
  136     if (ofile == 
"-") ofile.clear();
 
  137     if (!ofile.empty()) {
 
  138       outfile.open(ofile.c_str());
 
  139       if (!outfile.is_open()) {
 
  140         std::cerr << 
"Cannot open " << ofile << 
" for writing\n";
 
  144     std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
 
  152     std::string 
s, eol, stra, strb, strc, strd;
 
  153     std::istringstream 
str;
 
  155     while (std::getline(*input, 
s)) {
 
  158         if (!cdelim.empty()) {
 
  159           std::string::size_type 
m = 
s.find(cdelim);
 
  160           if (
m != std::string::npos) {
 
  161             eol = 
" " + 
s.substr(
m) + 
"\n";
 
  168         if (!(
str >> stra >> strb >> strc))
 
  171           x = Utility::val<real>(stra);
 
  172           y = Utility::val<real>(strb);
 
  173           z = Utility::val<real>(strc);
 
  176           h = Utility::val<real>(strc);
 
  198       catch (
const std::exception& 
e) {
 
  199         *output << 
"ERROR: " << 
e.what() << 
"\n";
 
  205   catch (
const std::exception& 
e) {
 
  206     std::cerr << 
"Caught exception: " << 
e.what() << 
"\n";
 
  210     std::cerr << 
"Caught unknown exception\n";
 
  
static int extra_digits()
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
void Forward(real lat, real lon, real h, real &x, real &y, real &z) const
void Reverse(real X, real Y, real Z, real &lat, real &lon, real &h) const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
static constexpr double lon0
Exception handling for GeographicLib.
void Forward(real lat, real lon, real h, real &X, real &Y, real &Z) const
Header for GeographicLib::Geocentric class.
static constexpr double lat0
int main(int argc, const char *const argv[])
void Reverse(real x, real y, real z, real &lat, real &lon, real &h) const
Header for GeographicLib::Utility class.
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE ArgReturnType arg() const
str(const char *c, const SzType &n)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Header for GeographicLib::LocalCartesian class.
Local cartesian coordinates.
#define GEOGRAPHICLIB_VERSION_STRING
void reverse(const MatrixType &m)
static constexpr double h0
static int set_digits(int ndigits=0)
Header for GeographicLib::DMS class.
gtsam
Author(s): 
autogenerated on Wed May 28 2025 03:00:58