r117: *** empty log message ***
[ctsim.git] / src / if-1.cpp
index b28ac181baad166d2cbf481ff4cc072d59694fa5..07359a0323c88e21e6c1f7dfa0ba1b9daf84134a 100644 (file)
@@ -1,34 +1,15 @@
 /*****************************************************************************
-**  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
-**
-**  $Id: if-1.cpp,v 1.2 2000/06/07 03:50:27 kevin Exp $
-**  $Log: if-1.cpp,v $
-**  Revision 1.2  2000/06/07 03:50:27  kevin
-**  *** empty log message ***
-**
-**  Revision 1.1  2000/06/07 02:29:05  kevin
-**  Initial C++ versions
-**
-**  Revision 1.6  2000/05/24 22:50:04  kevin
-**  Added support for new SGP library
-**
-**  Revision 1.5  2000/05/16 04:33:59  kevin
-**  Improved option processing
-**
-**  Revision 1.4  2000/05/09 14:52:27  kevin
-**  added sqr and sqrt functions
-**
-**  Revision 1.3  2000/05/08 20:02:32  kevin
-**  ANSI C changes
+** FILE IDENTIFICATION
 **
-**  Revision 1.2  2000/05/03 08:49:50  kevin
-**  Code cleanup
-**
-**  Revision 1.1.1.1  2000/04/28 13:02:44  kevin
-**  Initial CVS import for first public release
+**   Name:          if-1.cpp
+**   Purpose:       Manipulate a single image file
+**   Programmer:    Kevin Rosenberg
+**   Date Started:  Aug 1984
 **
+**  This is part of the CTSim program
+**  Copyright (C) 1983-2000 Kevin Rosenberg
 **
+**  $Id: if-1.cpp,v 1.8 2000/06/19 17:58:13 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
@@ -68,17 +49,17 @@ static struct option my_options[] =
 void 
 if1_usage (const char *program)
 {
-  fprintf(stdout, "if1_usage: %s infile outfile [OPTIONS]\n", kbasename(program));
-  fprintf(stdout, "Generate a IF file from a IF file\n");
-  fprintf(stdout, "\n");
-  fprintf(stdout, "     --invert   Invert image\n");
-  fprintf(stdout, "     --log      Natural logrithm of image\n");
-  fprintf(stdout, "     --exp      Natural exponential of image\n");
-  fprintf(stdout, "     --sqr      Square of image\n");
-  fprintf(stdout, "     --sqrt     Square root of image\n");
-  fprintf(stdout, "     --verbose  Verbose modem\n");
-  fprintf(stdout, "     --version  Print version\n");
-  fprintf(stdout, "     --help     Print this help message\n");
+  cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << endl;
+  cout << "Generate a IF file from a IF file" << endl;
+  cout << endl;
+  cout << "     --invert   Invert image" << endl;
+  cout << "     --log      Natural logrithm of image" << endl;
+  cout << "     --exp      Natural exponential of image" << endl;
+  cout << "     --sqr      Square of image" << endl;
+  cout << "     --sqrt     Square root of image" << endl;
+  cout << "     --verbose  Verbose modem" << endl;
+  cout << "     --version  Print version" << endl;
+  cout << "     --help     Print this help message" << endl;
 }
 
 int 
@@ -124,11 +105,11 @@ if1_main (int argc, char *const argv[])
          break;
         case O_VERSION:
 #ifdef VERSION
-         fprintf(stdout, "Version %s\n", VERSION);
+         cout << "Version " <<  VERSION << endl;
 #else
-         fprintf(stderr, "Unknown version number");
+          cout << "Unknown version number" << endl;
 #endif
-         exit(0);
+         return (0);
        case O_HELP:
        case '?':
          if1_usage(argv[0]);
@@ -155,14 +136,14 @@ if1_main (int argc, char *const argv[])
     int ix, iy;
 
     im_in = new ImageFile (in_file);
-    im_in->adf.fileRead ();
-    int nx = im_in->adf.nx();
-    int ny = im_in->adf.ny();
+    im_in->fileRead ();
+    int nx = im_in->nx();
+    int ny = im_in->ny();
     im_out = new ImageFile (out_file, nx, ny);
-    im_out->adf.fileCreate ();
+    im_out->fileCreate ();
 
-    ImageFileArray vIn = im_in->adf.getArray();
-    ImageFileArray vOut = im_out->adf.getArray();
+    ImageFileArray vIn = im_in->getArray();
+    ImageFileArray vOut = im_out->getArray();
 
     if (opt_invert) {
       for (ix = 0; ix < nx; ix++)
@@ -195,14 +176,10 @@ if1_main (int argc, char *const argv[])
       histString = "Sqrt transformation";
     }
 
-    im_out->adf.arrayDataWrite ();
-    for (int i = 0; i < im_in->adf.getNumLabels(); i++) {
-      Array2dFileLabel l;
-      im_in->adf.labelRead (l, i);
-      im_out->adf.labelAdd (l);
-    }
-    im_out->adf.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
-    im_out->adf.fileClose ();
+    im_out->arrayDataWrite ();
+    im_out->labelsCopy (*im_in);
+    im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
+    im_out->fileClose ();
   }
 
   return (0);
@@ -212,7 +189,17 @@ if1_main (int argc, char *const argv[])
 int 
 main (int argc, char *const argv[])
 {
-  return (if1_main(argc, argv));
+  int retval = 1;
+
+  try {
+    retval = if1_main(argc, argv);
+  } catch (exception e) {
+    cerr << "Exception: " << e.what() << endl;
+  } catch (...) {
+    cerr << "Unknown exception" << endl;
+  }
+
+  return (retval);
 }
 #endif