26 #  pragma warning (disable: 4127 4701) 
   29 #include "GeodSolve.usage" 
   42     (longfirst ? lonstr : latstr) + 
" " + (longfirst ? latstr : lonstr);
 
   52                             bool full, 
bool arcmode, 
int prec, 
bool dms) {
 
   69 int main(
int argc, 
const char* 
const argv[]) {
 
   72     enum { NONE = 0, LINE, DIRECT, INVERSE };
 
   74     bool inverse = 
false, arcmode = 
false,
 
   75       dms = 
false, full = 
false, exact = 
false, unroll = 
false,
 
   76       longfirst = 
false, azi2back = 
false, fraction = 
false,
 
   81     real lat1, lon1, azi1, lat2, lon2, azi2, s12, m12, a12, M12, M21, S12,
 
   83     int linecalc = NONE, prec = 3;
 
   84     std::string istring, ifile, ofile, cdelim;
 
   85     char lsep = 
';', dmssep = char(0);
 
   87     for (
int m = 1; 
m < argc; ++
m) {
 
   88       std::string 
arg(argv[
m]);
 
   92       } 
else if (
arg == 
"-a")
 
   96       else if (
arg == 
"-L" || 
arg == 
"-l") { 
 
   99         if (
m + 3 >= argc) 
return usage(1, 
true);
 
  102                             lat1, lon1, longfirst);
 
  105         catch (
const std::exception& 
e) {
 
  106           std::cerr << 
"Error decoding arguments of -L: " << 
e.what() << 
"\n";
 
  110       } 
else if (
arg == 
"-D") {
 
  113         if (
m + 4 >= argc) 
return usage(1, 
true);
 
  116                             lat1, lon1, longfirst);
 
  119           arcmodeline = arcmode;
 
  121         catch (
const std::exception& 
e) {
 
  122           std::cerr << 
"Error decoding arguments of -D: " << 
e.what() << 
"\n";
 
  126       } 
else if (
arg == 
"-I") {
 
  129         if (
m + 4 >= argc) 
return usage(1, 
true);
 
  132                             lat1, lon1, longfirst);
 
  134                             lat2, lon2, longfirst);
 
  136         catch (
const std::exception& 
e) {
 
  137           std::cerr << 
"Error decoding arguments of -I: " << 
e.what() << 
"\n";
 
  141       } 
else if (
arg == 
"-e") {
 
  142         if (
m + 2 >= argc) 
return usage(1, 
true);
 
  144           a = Utility::val<real>(std::string(argv[
m + 1]));
 
  145           f = Utility::fract<real>(std::string(argv[
m + 2]));
 
  147         catch (
const std::exception& 
e) {
 
  148           std::cerr << 
"Error decoding arguments of -e: " << 
e.what() << 
"\n";
 
  152       } 
else if (
arg == 
"-u")
 
  154       else if (
arg == 
"-d") {
 
  157       } 
else if (
arg == 
"-:") {
 
  160       } 
else if (
arg == 
"-w")
 
  161         longfirst = !longfirst;
 
  162       else if (
arg == 
"-b")
 
  164       else if (
arg == 
"-f")
 
  166       else if (
arg == 
"-p") {
 
  167         if (++
m == argc) 
return usage(1, 
true);
 
  169           prec = Utility::val<int>(std::string(argv[
m]));
 
  171         catch (
const std::exception&) {
 
  172           std::cerr << 
"Precision " << argv[
m] << 
" is not a number\n";
 
  175       } 
else if (
arg == 
"-E")
 
  177       else if (
arg == 
"--input-string") {
 
  178         if (++
m == argc) 
return usage(1, 
true);
 
  180       } 
else if (
arg == 
"--input-file") {
 
  181         if (++
m == argc) 
return usage(1, 
true);
 
  183       } 
else if (
arg == 
"--output-file") {
 
  184         if (++
m == argc) 
return usage(1, 
true);
 
  186       } 
else if (
arg == 
"--line-separator") {
 
  187         if (++
m == argc) 
return usage(1, 
true);
 
  188         if (std::string(argv[
m]).
size() != 1) {
 
  189           std::cerr << 
"Line separator must be a single character\n";
 
  193       } 
else if (
arg == 
"--comment-delimiter") {
 
  194         if (++
m == argc) 
return usage(1, 
true);
 
  196       } 
else if (
arg == 
"--version") {
 
  197         std::cout << argv[0] << 
": GeographicLib version " 
  201         return usage(!(
arg == 
"-h" || 
arg == 
"--help"), 
arg != 
"--help");
 
  204     if (!ifile.empty() && !istring.empty()) {
 
  205       std::cerr << 
"Cannot specify --input-string and --input-file together\n";
 
  208     if (ifile == 
"-") ifile.clear();
 
  209     std::ifstream infile;
 
  210     std::istringstream instring;
 
  211     if (!ifile.empty()) {
 
  212       infile.open(ifile.c_str());
 
  213       if (!infile.is_open()) {
 
  214         std::cerr << 
"Cannot open " << ifile << 
" for reading\n";
 
  217     } 
else if (!istring.empty()) {
 
  218       std::string::size_type 
m = 0;
 
  220         m = istring.find(lsep, 
m);
 
  221         if (
m == std::string::npos)
 
  225       instring.str(istring);
 
  227     std::istream* input = !ifile.empty() ? &infile :
 
  228       (!istring.empty() ? &instring : &std::cin);
 
  230     std::ofstream outfile;
 
  231     if (ofile == 
"-") ofile.clear();
 
  232     if (!ofile.empty()) {
 
  233       outfile.open(ofile.c_str());
 
  234       if (!outfile.is_open()) {
 
  235         std::cerr << 
"Cannot open " << ofile << 
" for writing\n";
 
  239     std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
 
  258       if (linecalc == LINE) fraction = 
false;
 
  260         le = linecalc == DIRECT ?
 
  261           geode.
GenDirectLine(lat1, lon1, azi1, arcmodeline, s12, outmask) :
 
  262           linecalc == INVERSE ?
 
  263           geode.
InverseLine(lat1, lon1, lat2, lon2, outmask) :
 
  265           geode.
Line(lat1, lon1, azi1, outmask);
 
  267         if (linecalc == INVERSE) azi1 = le.
Azimuth();
 
  269         ls = linecalc == DIRECT ?
 
  270           geods.GenDirectLine(lat1, lon1, azi1, arcmodeline, s12, outmask) :
 
  271           linecalc == INVERSE ?
 
  272           geods.InverseLine(lat1, lon1, lat2, lon2, outmask) :
 
  274           geods.Line(lat1, lon1, azi1, outmask);
 
  276         if (linecalc == INVERSE) azi1 = ls.
Azimuth();
 
  283     std::string 
s, eol, slat1, slon1, slat2, slon2, sazi1, ss12, strc;
 
  284     std::istringstream 
str;
 
  286     while (std::getline(*input, 
s)) {
 
  289         if (!cdelim.empty()) {
 
  290           std::string::size_type 
m = 
s.find(cdelim);
 
  291           if (
m != std::string::npos) {
 
  292             eol = 
" " + 
s.substr(
m) + 
"\n";
 
  298           if (!(
str >> slat1 >> slon1 >> slat2 >> slon2))
 
  305             geode.
GenInverse(lat1, lon1, lat2, lon2, outmask,
 
  306                              s12, azi1, azi2, m12, M12, M21, S12) :
 
  307             geods.GenInverse(lat1, lon1, lat2, lon2, outmask,
 
  308                              s12, azi1, azi2, m12, M12, M21, S12);
 
  318             *output << 
LatLonString(lat1, lon1, prec, dms, dmssep, longfirst)
 
  323             *output << 
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
 
  326             azi2 += azi2 >= 0 ? -180 : 180;
 
  345                              lat2, lon2, azi2, s12, m12, M12, M21, S12) :
 
  347                              lat2, lon2, azi2, s12, m12, M12, M21, S12);
 
  349             if (!(
str >> slat1 >> slon1 >> sazi1 >> ss12))
 
  357               geode.
GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
 
  358                               lat2, lon2, azi2, s12, m12, M12, M21, S12) :
 
  359               geods.GenDirect(lat1, lon1, azi1, arcmode, s12, outmask,
 
  360                               lat2, lon2, azi2, s12, m12, M12, M21, S12);
 
  365                               prec, dms, dmssep, longfirst)
 
  368             azi2 += azi2 >= 0 ? -180 : 180;
 
  369           *output << 
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
 
  381       catch (
const std::exception& 
e) {
 
  383         *output << 
"ERROR: " << 
e.what() << 
"\n";
 
  389   catch (
const std::exception& 
e) {
 
  390     std::cerr << 
"Caught exception: " << 
e.what() << 
"\n";
 
  394     std::cerr << 
"Caught unknown exception\n";