r279: msvc compatibility changes
[ctsim.git] / tools / if-2.cpp
index 525330ea568fcf0813da766d724ba2ad412a21b4..b2afcb268d3f9254c389f85f06794fe08b4900b2 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: if-2.cpp,v 1.1 2000/07/13 07:01:35 kevin Exp $
+**  $Id: if-2.cpp,v 1.7 2000/12/17 23:30:48 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -45,24 +45,26 @@ static struct option my_options[] =
   {0, 0, 0, 0}
 };
 
+static const char* g_szIdStr = "$Id: if-2.cpp,v 1.7 2000/12/17 23:30:48 kevin Exp $";
+
 void 
 if2_usage (const char *program)
 {
-  cout << "usage: " << fileBasename(program) << " infile1 infile2 outfile [OPTIONS]" << endl;
-  cout << "Perform functions on two input image files" << endl;
-  cout << endl;
-  cout << "     infile1            Name of first input IF file" << endl;
-  cout << "     infile2            Name of second input IF file" << endl;
-  cout << "     outfile            Name of output IF file" << endl;
-  cout << "     --add              Add images" << endl;
-  cout << "     --sub              Subtract image 2 from image 1" << endl;
-  cout << "     --mul              Multiply images" << endl;
-  cout << "     --comp             Compare images" << endl;
-  cout << "     --column-plot n    Plot column\n";
-  cout << "     --row-plot n       Plot row\n";
-  cout << "     --verbose          Verbose modem" << endl;
-  cout << "     --version          Print version" << endl;
-  cout << "     --help             Print this help message" << endl;
+  std::cout << "usage: " << fileBasename(program) << " infile1 infile2 outfile [OPTIONS]\n";
+  std::cout << "Perform functions on two input image files\n";
+  std::cout << std::endl;
+  std::cout << "     infile1            Name of first input IF file\n";
+  std::cout << "     infile2            Name of second input IF file\n";
+  std::cout << "     outfile            Name of output IF file\n";
+  std::cout << "     --add              Add images\n";
+  std::cout << "     --sub              Subtract image 2 from image 1\n";
+  std::cout << "     --mul              Multiply images\n";
+  std::cout << "     --comp             Compare images\n";
+  std::cout << "     --column-plot n    Plot column\n";
+  std::cout << "     --row-plot n       Plot row\n";
+  std::cout << "     --verbose          Verbose modem\n";
+  std::cout << "     --version          Print version\n";
+  std::cout << "     --help             Print this help message\n";
 }
 
 int 
@@ -71,15 +73,15 @@ if2_main (int argc, char *const argv[])
   ImageFile* pim_in1;
   ImageFile* pim_in2;
   ImageFile* pim_out = NULL;
-  string in_file1;
-  string in_file2;
-  string out_file;
+  std::string in_file1;
+  std::string in_file2;
+  std::string out_file;
   int opt_verbose = 0;
   int opt_add = 0;
   int opt_sub = 0;
   int opt_mul = 0;
   int opt_comp = 0;
-  int opt_outputFile = 0;
+  bool opt_outputFile = false;
   int opt_rowPlot = -1;
   int opt_columnPlot = -1;
   Timer timerProgram;
@@ -94,26 +96,28 @@ if2_main (int argc, char *const argv[])
     switch (c) {
     case O_ADD:
       opt_add = 1;
-      opt_outputFile = 1;
+      opt_outputFile = true;
       break;
     case O_SUB :
       opt_sub = 1;
-      opt_outputFile = 1;
+      opt_outputFile = true;
       break;
     case O_MUL:
       opt_mul = 1;
-      opt_outputFile = 1;
+      opt_outputFile = true;
       break;
     case O_ROW_PLOT:
       opt_rowPlot = strtol(optarg, &endptr, 10);
       if (endptr != optarg + strlen(optarg)) {
        if2_usage(argv[0]);
       }
+      break;
     case O_COLUMN_PLOT:
       opt_columnPlot = strtol(optarg, &endptr, 10);
       if (endptr != optarg + strlen(optarg)) {
        if2_usage(argv[0]);
       }
+      break;
     case O_COMP:
       opt_comp = 1;
       break;
@@ -122,9 +126,9 @@ if2_main (int argc, char *const argv[])
       break;
     case O_VERSION:
 #ifdef VERSION
-      cout << "Version " << VERSION << endl;
+      std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
 #else
-      cout << "Unknown version number" << endl;
+      std::cout << "Unknown version number\n";
 #endif
       return (0);
     case O_HELP:
@@ -180,7 +184,7 @@ if2_main (int argc, char *const argv[])
     vout = pim_out->getArray();
   }
 
-  string strOperation;
+  std::string strOperation;
   int nx = im_in1.nx();
   int ny = im_in1.ny();
   int nx2 = im_in2.nx();
@@ -217,7 +221,7 @@ if2_main (int argc, char *const argv[])
   if (opt_comp) {
     double d, r, e;
     im_in1.comparativeStatistics (im_in2, d, r, e);
-    cout << "d=" << d << ", r=" << r << ", e=" << e << endl;
+    std::cout << "d=" << d << ", r=" << r << ", e=" << e << std::endl;
   }
   if (opt_columnPlot > 0) {
     if (opt_columnPlot >= nx || opt_columnPlot >= nx2) {
@@ -228,22 +232,21 @@ if2_main (int argc, char *const argv[])
     for (int i = 0; i < nx; i++)
       plot_xaxis[i] = i;
 #if HAVE_SGP
-#if 0
-#else
-    ezset  ("clear.");
-    ezset  ("xticks major 5.");
-    ezset  ("xlabel Column");
-    ezset  ("ylabel Pixel");
-    ezset ("curves 2");
-    ezset  ("box.");
-    ezset  ("grid.");
-    ezplot (v1[opt_columnPlot], plot_xaxis, im_in1.ny());
-    ezplot (v2[opt_columnPlot], plot_xaxis, im_in2.ny());
-#endif
-    char str[256];
-    cout << "Press enter to continue" << flush;
-    fgets(str, sizeof(str), stdin);
-    sgp2_close (sgp2_get_active_win());
+    SGPDriver driver ("Column Plot");
+    SGP sgp (driver);
+    EZPlot ezplot (sgp);
+    ezplot.ezset ("clear.");
+    ezplot.ezset ("xticks major 5.");
+    ezplot.ezset ("xlabel Column");
+    ezplot.ezset ("title Column Plot");
+    ezplot.ezset ("ylabel Pixel");
+    ezplot.ezset ("box.");
+    ezplot.ezset ("grid.");
+    ezplot.addCurve (plot_xaxis, v1[opt_columnPlot], im_in1.ny());
+    ezplot.addCurve (plot_xaxis, v2[opt_columnPlot], im_in2.ny());
+    ezplot.plot();
+    std::cout << "Press enter to continue" << flush;
+    cio_kb_getc();
 #endif
   }
 
@@ -258,27 +261,26 @@ if2_main (int argc, char *const argv[])
     for (int i = 0; i < ny; i++)
       plot_xaxis[i] = i;
     for (int i = 0; i < nx; i++)
-      v1Row[i] = v1[opt_rowPlot][i];
+      v1Row[i] = v1[i][opt_rowPlot];
     for (int i = 0; i < nx2; i++)
-      v2Row[i] = v2[opt_rowPlot][i];
+      v2Row[i] = v2[i][opt_rowPlot];
 
 #if HAVE_SGP
-#if 0
-#else
-    ezset  ("clear.");
-    ezset  ("xticks major 5.");
-    ezset  ("xlabel Column");
-    ezset  ("ylabel Pixel");
-    ezset ("curves 2");
-    ezset  ("box.");
-    ezset  ("grid.");
-    ezplot (v1Row, plot_xaxis, im_in1.nx());
-    ezplot (v2Row, plot_xaxis, im_in2.nx());
-#endif
-    char str[256];
-    cout << "Press enter to continue" << flush;
-    fgets(str, sizeof(str), stdin);
-    sgp2_close (sgp2_get_active_win());
+    SGPDriver driver ("Row Plot");
+    SGP sgp (driver);
+    EZPlot ezplot (sgp);
+    ezplot.ezset ("clear.");
+    ezplot.ezset ("xticks major 5.");
+    ezplot.ezset ("title Row Plot");
+    ezplot.ezset ("xlabel Row");
+    ezplot.ezset ("ylabel Pixel");
+    ezplot.ezset ("box.");
+    ezplot.ezset ("grid.");
+    ezplot.addCurve (plot_xaxis, v1Row, im_in1.nx());
+    ezplot.addCurve (plot_xaxis, v2Row, im_in2.nx());
+    ezplot.plot();
+    std::cout << "Press enter to continue" << flush;
+    cio_kb_getc();
 #endif
   }
 
@@ -301,9 +303,9 @@ main (int argc, char *const argv[])
   try {
     retval = if2_main(argc, argv);
   } catch (exception e) {
-    cerr << "Exception: " << e.what() << endl;
+    std::cerr << "Exception: " << e.what() << std::endl;
   } catch (...) {
-    cerr << "Unknown exception" << endl;
+    std::cerr << "Unknown exception\n";
   }
 
   return (retval);