X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fphm2sdf.c;h=4f063896ebf776aac8134184fb0d54160b011d40;hb=c95a927599e20c3d7762073450e3126d9694107d;hp=ac3481cd18e478794ec46ec1ec9a4565684cc590;hpb=cda35cc393bfef9a53de1a5c611e09992fb77022;p=ctsim.git diff --git a/src/phm2sdf.c b/src/phm2sdf.c index ac3481c..4f06389 100644 --- a/src/phm2sdf.c +++ b/src/phm2sdf.c @@ -2,8 +2,17 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2sdf.c,v 1.6 2000/05/03 08:49:50 kevin Exp $ +** $Id: phm2sdf.c,v 1.9 2000/05/16 04:33:59 kevin Exp $ ** $Log: phm2sdf.c,v $ +** Revision 1.9 2000/05/16 04:33:59 kevin +** Improved option processing +** +** Revision 1.8 2000/05/11 01:06:30 kevin +** Changed sprintf to snprintf +** +** Revision 1.7 2000/05/08 20:02:32 kevin +** ANSI C changes +** ** Revision 1.6 2000/05/03 08:49:50 kevin ** Code cleanup ** @@ -38,6 +47,7 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ + /* FILE * phm2sdf.c Generate a SDF image from a phantom * @@ -48,19 +58,8 @@ #include "ct.h" -#define O_PHANTOM 1 -#define O_DESC 2 -#define O_NSAMPLE 3 -#define O_FILTER 4 -#define O_TRACE 5 -#define O_VERBOSE 6 -#define O_HELP 7 -#define O_PHMFILE 8 -#define O_FILTER_DOMAIN 9 -#define O_FILTER_BW 10 -#define O_FILTER_PARAM 11 -#define O_DEBUG 12 -#define O_VERSION 13 +enum { O_PHANTOM, O_DESC, O_NSAMPLE, O_FILTER, O_TRACE, O_VERBOSE, O_HELP, + O_PHMFILE, O_FILTER_DOMAIN, O_FILTER_BW, O_FILTER_PARAM, O_DEBUG, O_VERSION }; static struct option my_options[] = { @@ -81,9 +80,9 @@ static struct option my_options[] = }; void -usage (const char *program) +phm2sdf_usage (const char *program) { - fprintf(stdout,"usage: %s outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n",kbasename(program)); + fprintf(stdout,"phm2sdf_usage: %s outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n",kbasename(program)); fprintf(stdout,"Generate phantom image from a predefined --phantom or a --phmfile\n"); fprintf(stdout,"\n"); fprintf(stdout," outfile Name of output file for image\n"); @@ -124,7 +123,6 @@ usage (const char *program) fprintf(stdout," --verbose Verbose mode\n"); fprintf(stdout," --version Print version\n"); fprintf(stdout," --help Print this help message\n"); - exit(1); } #ifdef MPI_CT @@ -132,7 +130,7 @@ void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug); #endif int -main (const int argc, char *const argv[]) +phm2sdf_main (const int argc, char *const argv[]) { IMAGE *im_global = NULL; PHANTOM *phm = NULL; @@ -165,7 +163,6 @@ main (const int argc, char *const argv[]) if (mpi_ct.nproc > MPI_MAX_PROCESS) { sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", mpi_ct.nproc, MPI_MAX_PROCESS); - exit(1); } #endif @@ -191,7 +188,10 @@ main (const int argc, char *const argv[]) switch (c) { case O_PHANTOM: - opt_phmnum = opt_set_phantom(optarg, argv[0]); + if ((opt_phmnum = opt_set_phantom(optarg)) < 0) { + phm2sdf_usage(argv[0]); + return (1); + } break; case O_PHMFILE: strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); @@ -199,7 +199,7 @@ main (const int argc, char *const argv[]) #ifdef MPI_CT if (mpi_ct.my_rank == 0) fprintf(stderr, "Can't use phantom from file in MPI mode\n"); - exit(1); + return (1); #endif break; case O_VERBOSE: @@ -209,13 +209,22 @@ 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) { + phm2sdf_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) { + phm2sdf_usage (argv[0]); + return (1); + } break; case O_FILTER_DOMAIN: - opt_filter_domain = opt_set_filter_domain(optarg, argv[0]); + if ((opt_filter_domain = opt_set_filter_domain(optarg)) < 0) { + phm2sdf_usage (argv[0]); + return (1); + } break; case O_DESC: strncpy(opt_desc, optarg, sizeof(opt_desc)); @@ -225,8 +234,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --filter-bw to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_FILTER_PARAM: @@ -234,8 +243,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --filter-param to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_NSAMPLE: @@ -243,8 +252,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --nsample to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_VERSION: @@ -255,43 +264,43 @@ main (const int argc, char *const argv[]) #endif case O_HELP: case '?': - usage(argv[0]); - exit(0); + phm2sdf_usage(argv[0]); + return (0); default: - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } } if (phm == NULL && opt_phmnum == -1 && opt_filter == -1) { fprintf(stderr, "No phantom defined\n"); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } #if HAVE_INTERACTIVE_GRAPHICS if (opt_trace >= TRACE_PHM) - show_phm(phm); + phm_show(phm); #endif if (optind + 3 != argc) { - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } opt_outfile = argv[optind]; opt_nx = strtol(argv[optind+1], &endptr, 10); endstr = argv[optind+1] + strlen(argv[optind+1]); if (endptr != endstr) { fprintf(stderr,"Error setting nx to %s\n", argv[optind+1]); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } opt_ny = strtol(argv[optind+2], &endptr, 10); endstr = argv[optind+2] + strlen(argv[optind+2]); if (endptr != endstr) { fprintf(stderr,"Error setting ny to %s\n", argv[optind+2]); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } snprintf(str, sizeof(str), "nx=%d, ny=%d, nsample=%d, ", opt_nx, opt_ny, opt_nsample); @@ -352,9 +361,10 @@ main (const int argc, char *const argv[]) #else im_global = image_create (opt_outfile, opt_nx, opt_ny); #endif - - if (opt_phmnum > 0) - phm = phm_create (opt_phmnum); + + if (opt_phmnum >= 0) + phm = phm_create (opt_phmnum); + #ifdef MPI_CT else { if (mpi_ct.my_rank == 0) @@ -402,30 +412,20 @@ main (const int argc, char *const argv[]) #ifdef MPI_CT time_end = MPI_Wtime(); - if (mpi_ct.my_rank == 0) { +#else + time_end = td_current_sec(); +#endif + +#ifdef MPI_CT + if (mpi_ct.my_rank == 0) +#endif + { im_global->calctime = time_end - time_start; strncpy (im_global->remark, opt_desc, sizeof(im_global->remark)); - } - - if (mpi_ct.my_rank == 0) { image_save (im_global); if (opt_verbose) fprintf (stdout, "Time to compile image = %.2f sec\n\n", im_global->calctime); } -#else - time_end = td_current_sec(); - im_global->calctime = time_end - time_start; - strncpy (im_global->remark, opt_desc, sizeof(im_global->remark)); - image_save (im_global); - - if (opt_trace >= TRACE_PHM) - { - crt_set_cpos (1, 1); - } - - if (opt_verbose) - fprintf (stdout, "Time to compile image = %.2f sec\n\n", im_global->calctime); -#endif if (opt_trace >= TRACE_PHM) { @@ -437,12 +437,11 @@ main (const int argc, char *const argv[]) printf ("Enter minimum and maximum densities (min, max): "); scanf ("%lf %lf", &dmin, &dmax); // image_paint (CRTDEV, im_global, 0, 0, nx, ny, dmin, dmax, 0); - WAITKEY(); - crt_put_stra ("Finished", 8 + C_WHITE); - crt_set_cpos (1, 2); } + phm_free (phm); + return (0); } @@ -483,3 +482,11 @@ void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug) } #endif + +#ifndef NO_MAIN +int +main (const int argc, char *const argv[]) +{ + return (phm2sdf_main(argc, argv)); +} +#endif