X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fphm2rs.c;h=b92c9141de8fa9e5fe72aad21d37484667a26e70;hb=c95a927599e20c3d7762073450e3126d9694107d;hp=3c4217d1c3e4551e66ad45d5e04152690182c0a0;hpb=cda35cc393bfef9a53de1a5c611e09992fb77022;p=ctsim.git diff --git a/src/phm2rs.c b/src/phm2rs.c index 3c4217d..b92c914 100644 --- a/src/phm2rs.c +++ b/src/phm2rs.c @@ -2,8 +2,24 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2rs.c,v 1.7 2000/05/03 08:49:50 kevin Exp $ +** PURPOSE +** Generate raysum projections from phantom object +** +** HISTORY +** 1984 -- Final DOS version +** 1999 -- First UNIX version +** +** $Id: phm2rs.c,v 1.11 2000/05/16 04:33:59 kevin Exp $ ** $Log: phm2rs.c,v $ +** Revision 1.11 2000/05/16 04:33:59 kevin +** Improved option processing +** +** 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 +** ** Revision 1.7 2000/05/03 08:49:50 kevin ** Code cleanup ** @@ -41,28 +57,14 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/* FILE - * phm2rs.c Generate raysum projections from phantom object - * - * HISTORY - * 1984 -- Final DOS version - * 1999 -- First UNIX version - */ + #include "ct.h" -#define O_PHANTOM 1 -#define O_DESC 2 -#define O_NRAY 3 -#define O_ROTANGLE 4 -#define O_TRACE 5 -#define O_VERBOSE 6 -#define O_HELP 7 -#define O_PHMFILE 8 -#define O_DEBUG 10 -#define O_VERSION 11 - -static struct option my_options[] = +enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE, + O_TRACE, O_VERBOSE, O_HELP, O_DEBUG, O_VERSION }; + +static struct option phm2rs_options[] = { {"phantom", 1, 0, O_PHANTOM}, {"phmfile", 1, 0, O_PHMFILE}, @@ -77,8 +79,9 @@ static struct option my_options[] = {0, 0, 0, 0} }; + void -usage (const char *program) +phm2rs_usage (const char *program) { #ifdef MPI_CT if (mpi_ct.my_rank == 0) @@ -115,14 +118,14 @@ if (mpi_ct.my_rank == 0) } MPI_Abort(mpi_ct.comm, 1); #endif - exit(1); } - +#ifdef MPI_CT void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug); +#endif int -main (const int argc, char *const argv[]) +phm2rs_main (const int argc, char *const argv[]) { DETECTOR *det; PHANTOM *phm = NULL; @@ -137,7 +140,10 @@ main (const int argc, char *const argv[]) int opt_debug = 0; double opt_rotangle = 1; double time_start = 0, time_end = 0; -#ifdef MPI_CT + +#ifndef MPI_CT + time_start = td_current_sec(); +#else RAYSUM *rs_local; int mpi_argc = argc; char **mpi_argv = (char **) argv; @@ -149,13 +155,10 @@ main (const int argc, char *const argv[]) MPI_Comm_rank(mpi_ct.comm, &mpi_ct.my_rank); 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); + sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", mpi_ct.nproc, MPI_MAX_PROCESS); exit(1); } time_start = MPI_Wtime(); -#else - time_start = td_current_sec(); #endif #ifdef MPI_CT @@ -164,7 +167,7 @@ main (const int argc, char *const argv[]) strcpy(opt_desc, ""); strcpy(opt_phmfilename, ""); while (1) { - int c = getopt_long(argc, argv, "", my_options, NULL); + int c = getopt_long(argc, argv, "", phm2rs_options, NULL); char *endptr = NULL; char *endstr; @@ -173,14 +176,17 @@ 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) { + phm2rs_usage(argv[0]); + return (1); + } phm = phm_create (opt_phmnum); break; case O_PHMFILE: #ifdef MPI_CT if (mpi_ct.my_rank == 0) fprintf(stderr, "Can not read phantom from file in MPI mode\n"); - exit(1); + return (1); #endif strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); phm = phm_create_from_file(opt_phmfilename); @@ -193,7 +199,10 @@ main (const int argc, char *const argv[]) break; break; case O_TRACE: - opt_trace = opt_set_trace(optarg, argv[0]); + if ((opt_trace = opt_set_trace(optarg)) < 0) { + phm2rs_usage(argv[0]); + return (1); + } break; case O_DESC: strncpy(opt_desc, optarg, sizeof(opt_desc)); @@ -203,8 +212,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --rotangle to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } break; case O_NRAY: @@ -212,8 +221,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --nray to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } break; case O_VERSION: @@ -225,37 +234,38 @@ main (const int argc, char *const argv[]) exit(0); case O_HELP: case '?': - usage(argv[0]); - exit(0); + phm2rs_usage(argv[0]); + return (0); default: - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } } if (phm == NULL) { fprintf(stderr, "No phantom defined\n"); - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } if (optind + 3 != argc) { - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } + opt_outfile = argv[optind]; opt_ndet = strtol(argv[optind+1], &endptr, 10); endstr = argv[optind+1] + strlen(argv[optind+1]); if (endptr != endstr) { fprintf(stderr,"Error setting --ndet to %s\n", argv[optind+1]); - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } opt_nview = strtol(argv[optind+2], &endptr, 10); endstr = argv[optind+2] + strlen(argv[optind+2]); if (endptr != endstr) { fprintf(stderr,"Error setting --nview to %s\n", argv[optind+2]); - usage(argv[0]); - exit(1); + phm2rs_usage(argv[0]); + return (1); } snprintf(str, sizeof(str), @@ -288,12 +298,12 @@ main (const int argc, char *const argv[]) MPI_Bcast(&opt_debug, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_trace, 1, MPI_INT, 0, mpi_ct.comm); - if (mpi_ct.my_rank > 0 && opt_phmnum > 0) + if (mpi_ct.my_rank > 0 && opt_phmnum >= 0) phm = phm_create (opt_phmnum); #endif opt_rotangle *= PI; - det = detect_create (phm, opt_ndet, opt_nview, opt_nray, opt_rotangle); + det = detector_create (phm, DETECTOR_PARALLEL, opt_ndet, opt_nview, opt_nray, opt_rotangle); #ifdef MPI_CT mpi_ct_calc_work_units(opt_nview); @@ -333,48 +343,43 @@ main (const int argc, char *const argv[]) raysum_collect (rs_global, det, phm, 0, opt_trace, FALSE); #endif -#ifdef MPI_CT - time_end = MPI_Wtime(); - if (mpi_ct.my_rank == 0) { - rs_global->calctime = time_end - time_start; - strncpy (rs_global->remark, opt_desc, sizeof(rs_global->remark)); - if (opt_verbose) { - fprintf(stdout, "Remark: %s\n", rs_global->remark); - fprintf(stdout, "Time active = %.2f secs\n", rs_global->calctime); - } - } -#else +#ifndef MPI_CT time_end = td_current_sec(); - rs_global->calctime = time_end - time_start; - strncpy (rs_global->remark, opt_desc, sizeof(rs_global->remark)); - if (opt_verbose) { - fprintf(stdout, "Remark: %s\n", rs_global->remark); - fprintf(stdout, "Time active = %.2f secs\n", rs_global->calctime); - } +#else + time_end = MPI_Wtime(); + if (mpi_ct.my_rank == 0) #endif + { + rs_global->calctime = time_end - time_start; + strncpy (rs_global->remark, opt_desc, sizeof(rs_global->remark)); + if (opt_verbose) { + fprintf(stdout, "Remark: %s\n", rs_global->remark); + fprintf(stdout, "Time active = %.2f secs\n", rs_global->calctime); + } + } #ifdef MPI_CT - if (mpi_ct.my_rank == 0) { - raysum_write (rs_global); - raysum_close (rs_global); - } -#else - raysum_write (rs_global); - raysum_close (rs_global); + if (mpi_ct.my_rank == 0) #endif - - detect_free (det); - - if (opt_trace >= TRACE_PHM) { - crt_set_cpos (1, 1); - printf("Finished\n"); + raysum_write (rs_global); + raysum_close (rs_global); } + phm_free (phm); + detector_free (det); + return (0); } +/* FUNCTION + * mpi_gather_rs + * + * SYNOPSIS + * Gather's raysums from all processes in rs_local in rs_global in process 0 + */ + #ifdef MPI_CT void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug) { @@ -410,3 +415,13 @@ void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug) } #endif + + +#ifndef NO_MAIN +int +main (const int argc, char *const argv[]) +{ + return (phm2rs_main(argc, argv)); +} +#endif +