r61: Added support for new SGP library
[ctsim.git] / src / ctrec.c
index fb23af9f456ea3a7fbf9270d790a2d180edd6985..01874dd82b8aecaa2c71896645102221af8b121b 100644 (file)
@@ -2,8 +2,20 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ctrec.c,v 1.8 2000/05/04 18:16:34 kevin Exp $
+**  $Id: ctrec.c,v 1.12 2000/05/24 22:50:04 kevin Exp $
 **  $Log: ctrec.c,v $
+**  Revision 1.12  2000/05/24 22:50:04  kevin
+**  Added support for new SGP library
+**
+**  Revision 1.11  2000/05/16 04:33:59  kevin
+**  Improved option processing
+**
+**  Revision 1.10  2000/05/11 01:06:30  kevin
+**  Changed sprintf to snprintf
+**
+**  Revision 1.9  2000/05/08 20:02:32  kevin
+**  ANSI C changes
+**
 **  Revision 1.8  2000/05/04 18:16:34  kevin
 **  renamed filter definitions
 **
 
 #include "ct.h"
 
-#define O_INTERP       1
-#define O_FILTER       2
-#define O_FILTER_PARAM 3
-#define O_BACKPROJ     4
-#define O_VERBOSE      5
-#define O_TRACE        6
-#define O_HELP         7
-#define O_DEBUG        8
-#define O_VERSION      9
+enum {O_INTERP, O_FILTER, O_FILTER_PARAM, O_BACKPROJ, O_VERBOSE, O_TRACE, O_HELP, O_DEBUG, O_VERSION};
 
 static struct option my_options[] =
 {
@@ -81,7 +85,7 @@ static struct option my_options[] =
 };
 
 void 
-usage (const char *program)
+ctrec_usage (const char *program)
 {
   fprintf(stdout,"usage: %s raysum-file image-file nx-image ny-image [OPTIONS]\n", kbasename(program));
   fprintf(stdout,"Image reconstruction from raysum projections\n");
@@ -114,7 +118,7 @@ usage (const char *program)
   fprintf(stdout,"    --filter-param Alpha level for Hamming filter\n");
   fprintf(stdout,"    --trace        Set tracing to level\n");
   fprintf(stdout,"         none      No tracing (default)\n");
-  fprintf(stdout,"         status    Status tracing\n");
+  fprintf(stdout,"         text      Text level tracing\n");
   fprintf(stdout,"         phm       Trace phantom\n");
   fprintf(stdout,"         rays      Trace allrays\n");
   fprintf(stdout,"         plot      Trace plotting\n");
@@ -123,17 +127,17 @@ usage (const char *program)
   fprintf(stdout,"    --debug        Turn on debug mode\n");
   fprintf(stdout,"    --version      Print version\n");
   fprintf(stdout,"    --help         Print this help message\n");
-  exit(1);  
 }
 
 
 #ifdef MPI_CT
 static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int debug);
 #endif
+
 static void print_raysum_info(const RAYSUM *rs);
 
 int 
-main (const int argc, char *const argv[])
+ctrec_main (const int argc, char *const argv[])
 {
   IMAGE *im_global = NULL;
   RAYSUM *rs_global = NULL;
@@ -150,7 +154,7 @@ main (const int argc, char *const argv[])
   int opt_filter = FILTER_ABS_BANDLIMIT;
   int opt_interp = I_LINEAR;
   int opt_interp_param = 1;
-  int opt_backproj = O_BPROJ_DIFF2;
+  BackprojType opt_backproj = O_BPROJ_DIFF2;
 #ifdef MPI_CT
   IMAGE *im_local;
   RAYSUM *rs_local;
@@ -192,19 +196,27 @@ main (const int argc, char *const argv[])
       switch (c)
        {
        case O_INTERP:
-         opt_interp = opt_set_interpolation(optarg, argv[0]);
+         if ((opt_interp = opt_set_interpolation(optarg)) < 0) {
+           ctrec_usage(argv[0]);
+           return (1);
+         }
          break;
        case O_FILTER:
-         opt_filter = opt_set_filter(optarg, argv[0]);
+         if ((opt_filter = opt_set_filter(optarg)) < 0) {
+           ctrec_usage(argv[0]);
+           return (1);
+         }
          break;
        case O_BACKPROJ:
-         opt_backproj = opt_set_backproj(optarg, argv[0]);
+         if ((opt_backproj = opt_set_backproj(optarg)) < 0) {
+             ctrec_usage(argv[0]);
+             return (1);
+         }
          break;
        case O_FILTER_PARAM:
          opt_filter_param = strtod(optarg, &endptr);
          if (endptr != optarg + strlen(optarg)) {
-           usage(argv[0]);
-           exit(1);
+           ctrec_usage(argv[0]);
          }
          break;
        case O_VERBOSE:
@@ -214,7 +226,10 @@ main (const int argc, char *const argv[])
          opt_debug = 1;
          break;
        case O_TRACE:
-         opt_trace = opt_set_trace(optarg, argv[0]);
+         if ((opt_trace = opt_set_trace(optarg)) < 0) {
+           ctrec_usage(argv[0]);
+           return (1);
+         }
          break;
         case O_VERSION:
 #ifdef VERSION
@@ -225,17 +240,17 @@ main (const int argc, char *const argv[])
          exit(0);
        case O_HELP:
        case '?':
-         usage(argv[0]);
-         exit(0);
+         ctrec_usage(argv[0]);
+         return (0);
        default:
-         usage(argv[0]);
-         exit(1);
+         ctrec_usage(argv[0]);
+         return (1);
        }
     }
   
     if (optind + 4 != argc) {
-      usage(argv[0]);
-      exit(1);
+      ctrec_usage(argv[0]);
+      return (1);
     }
 
     rs_name = argv[optind];
@@ -246,13 +261,12 @@ main (const int argc, char *const argv[])
     ny = strtol(argv[optind + 3], &endptr, 10);
   
     if (opt_filter == FILTER_G_HAMMING || opt_filter == FILTER_ABS_G_HAMMING)
-      sprintf (filt_name, "%s: alpha = %.2f",
+      snprintf (filt_name, sizeof(filt_name), "%s: alpha = %.2f",
               name_of_filter (opt_filter), opt_filter_param); 
     else
-      sprintf (filt_name, "%s", name_of_filter (opt_filter));
+      snprintf (filt_name, sizeof(filt_name), "%s", name_of_filter (opt_filter));
   
-    sprintf (remark,
-            "Reconstruct: %dx%d, %s, %s, %s",
+    snprintf (remark, sizeof(remark), "Reconstruct: %dx%d, %s, %s, %s",
             nx, ny, filt_name, name_of_interpolation (opt_interp), name_of_backproj(opt_backproj));
   
     if (opt_verbose)
@@ -353,10 +367,6 @@ main (const int argc, char *const argv[])
 #endif
 
 #ifdef MPI_CT
-  if (mpi_ct.my_rank == 0) {
-    raysum_close (rs_global);
-  }
-
   if (opt_verbose)
     mpi_t1 = MPI_Wtime();
 
@@ -375,24 +385,26 @@ main (const int argc, char *const argv[])
     if (mpi_ct.my_rank == 0)
       printf("Time to reduce image = %f secs, max time = %f\n", mpi_t, mpi_t_g);
   }
-  if (mpi_ct.my_rank == 0) {
-    strncpy (im_global->remark, remark, MAXREMARK);
-    time_end = MPI_Wtime();
-    im_global->calctime = time_end - time_start;
-    image_save (im_global);
-    if (opt_verbose)
-      fprintf (stdout, "Time active = %.2f\n", im_global->calctime);
-    }
-#else  
-  raysum_close (rs_global);
-  strncpy (im_global->remark, remark, MAXREMARK);
+
+  if (mpi_ct.my_rank == 0)
+      time_end = MPI_Wtime();
+#else
   time_end = td_current_sec();
-  im_global->calctime = time_end - time_start;
-  image_save (im_global);
-  if (opt_verbose)
-    fprintf (stdout, "Time active = %.2f secs\n", im_global->calctime);
 #endif
 
+
+#ifdef MPI_CT
+  if (mpi_ct.my_rank == 0)
+#endif
+    {
+      raysum_close (rs_global);
+      strncpy (im_global->remark, remark, sizeof(im_global->remark));
+      im_global->calctime = time_end - time_start;
+      image_save (im_global);
+      if (opt_verbose)
+         fprintf (stdout, "Time active = %.2f\n", im_global->calctime);
+    }
+
 #ifdef MPI_CT
        MPI_Finalize();
 #endif
@@ -451,3 +463,12 @@ static void print_raysum_info(const RAYSUM *rs)
   printf ("          rot_start: %f\n", rs->rot_start);
   printf ("            rot_inc: %f\n", rs->rot_inc);
 }
+
+#ifndef NO_MAIN
+int 
+main (const int argc, char *const argv[])
+{
+  return (ctrec_main(argc, argv));
+}
+#endif
+