25 #  pragma warning (disable: 4127 4701) 
   28 #include "RhumbSolve.usage" 
   42     (longfirst ? lonstr : latstr) + 
" " + (longfirst ? latstr : lonstr);
 
   50 int main(
int argc, 
const char* 
const argv[]) {
 
   53     bool linecalc = 
false, 
inverse = 
false, dms = 
false, exact = 
true,
 
   60     std::string istring, ifile, ofile, cdelim;
 
   61     char lsep = 
';', dmssep = char(0);
 
   63     for (
int m = 1; 
m < argc; ++
m) {
 
   64       std::string 
arg(argv[
m]);
 
   68       } 
else if (
arg == 
"-L" || 
arg == 
"-l") { 
 
   71         if (
m + 3 >= argc) 
return usage(1, 
true);
 
   74                             lat1, lon1, longfirst);
 
   77         catch (
const std::exception& 
e) {
 
   78           std::cerr << 
"Error decoding arguments of -L: " << 
e.what() << 
"\n";
 
   82       } 
else if (
arg == 
"-e") {
 
   83         if (
m + 2 >= argc) 
return usage(1, 
true);
 
   85           a = Utility::val<real>(std::string(argv[
m + 1]));
 
   86           f = Utility::fract<real>(std::string(argv[
m + 2]));
 
   88         catch (
const std::exception& 
e) {
 
   89           std::cerr << 
"Error decoding arguments of -e: " << 
e.what() << 
"\n";
 
   94       else if (
arg == 
"-d") {
 
   97       } 
else if (
arg == 
"-:") {
 
  100       } 
else if (
arg == 
"-w")
 
  101         longfirst = !longfirst;
 
  102       else if (
arg == 
"-p") {
 
  103         if (++
m == argc) 
return usage(1, 
true);
 
  105           prec = Utility::val<int>(std::string(argv[
m]));
 
  107         catch (
const std::exception&) {
 
  108           std::cerr << 
"Precision " << argv[
m] << 
" is not a number\n";
 
  111       } 
else if (
arg == 
"-s")
 
  113       else if (
arg == 
"--input-string") {
 
  114         if (++
m == argc) 
return usage(1, 
true);
 
  116       } 
else if (
arg == 
"--input-file") {
 
  117         if (++
m == argc) 
return usage(1, 
true);
 
  119       } 
else if (
arg == 
"--output-file") {
 
  120         if (++
m == argc) 
return usage(1, 
true);
 
  122       } 
else if (
arg == 
"--line-separator") {
 
  123         if (++
m == argc) 
return usage(1, 
true);
 
  124         if (std::string(argv[
m]).
size() != 1) {
 
  125           std::cerr << 
"Line separator must be a single character\n";
 
  129       } 
else if (
arg == 
"--comment-delimiter") {
 
  130         if (++
m == argc) 
return usage(1, 
true);
 
  132       } 
else if (
arg == 
"--version") {
 
  133         std::cout << argv[0] << 
": GeographicLib version " 
  137         return usage(!(
arg == 
"-h" || 
arg == 
"--help"), 
arg != 
"--help");
 
  140     if (!ifile.empty() && !istring.empty()) {
 
  141       std::cerr << 
"Cannot specify --input-string and --input-file together\n";
 
  144     if (ifile == 
"-") ifile.clear();
 
  145     std::ifstream infile;
 
  146     std::istringstream instring;
 
  147     if (!ifile.empty()) {
 
  148       infile.open(ifile.c_str());
 
  149       if (!infile.is_open()) {
 
  150         std::cerr << 
"Cannot open " << ifile << 
" for reading\n";
 
  153     } 
else if (!istring.empty()) {
 
  154       std::string::size_type 
m = 0;
 
  156         m = istring.find(lsep, 
m);
 
  157         if (
m == std::string::npos)
 
  161       instring.str(istring);
 
  163     std::istream* input = !ifile.empty() ? &infile :
 
  164       (!istring.empty() ? &instring : &std::cin);
 
  166     std::ofstream outfile;
 
  167     if (ofile == 
"-") ofile.clear();
 
  168     if (!ofile.empty()) {
 
  169       outfile.open(ofile.c_str());
 
  170       if (!outfile.is_open()) {
 
  171         std::cerr << 
"Cannot open " << ofile << 
" for writing\n";
 
  175     std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
 
  183     std::string 
s, eol, slat1, slon1, slat2, slon2, sazi, ss12, strc;
 
  184     std::istringstream 
str;
 
  186     while (std::getline(*input, 
s)) {
 
  189         if (!cdelim.empty()) {
 
  190           std::string::size_type 
m = 
s.find(cdelim);
 
  191           if (
m != std::string::npos) {
 
  192             eol = 
" " + 
s.substr(
m) + 
"\n";
 
  203           *output << 
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
 
  206           if (!(
str >> slat1 >> slon1 >> slat2 >> slon2))
 
  212           rh.
Inverse(lat1, lon1, lat2, lon2, s12, azi12, S12);
 
  217           if (!(
str >> slat1 >> slon1 >> sazi >> s12))
 
  223           rh.
Direct(lat1, lon1, azi12, s12, lat2, lon2, S12);
 
  224           *output << 
LatLonString(lat2, lon2, prec, dms, dmssep, longfirst)
 
  228       catch (
const std::exception& 
e) {
 
  230         *output << 
"ERROR: " << 
e.what() << 
"\n";
 
  236   catch (
const std::exception& 
e) {
 
  237     std::cerr << 
"Caught exception: " << 
e.what() << 
"\n";
 
  241     std::cerr << 
"Caught unknown exception\n";