2 ***********************************************************
3 $SNARK_Header: S N A R K 1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4 $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/get_phantom.c $
5 $LastChangedRevision: 80 $
6 $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
8 ***********************************************************
12 /*--------------------------------------------------------------------------
14 Written by Jingsheng Zheng... November 1992
15 Modified by Jolyon Browne... June 1993
16 ----------------------------------------------------------------------------*/
21 #include "experimenter.h"
23 #include "get_phantom.h"
25 /*--------------------------------------------------------------------------
26 This function reads the ensemble data file and returns a list of
27 the phantom filenames.
30 ensflname - name of ensemble data file.
33 name - string array of length szens containing the list of phantom filenames.
34 szens - number of phantom filenames in the ensemble data file.
35 ----------------------------------------------------------------------------*/
37 void read_ensemble(char* ensflname, char name[][MAXLINESIZE], int* szens)
40 char data[MAXLINESIZE];
43 if ((ensfl = fopen(ensflname, "r")) == NULL)
45 errorc("error in opening file", ensflname);
48 while (fgets(data, sizeof(data), ensfl) != NULL)
50 /* make sure 'i' is not over ensemble size limit */
51 if (i >= MAXENSEMSIZE)
54 sprintf(limitmsg, "(MAXENSEMSIZE = %d)", MAXENSEMSIZE);
55 errorc("Exceeded maximum number of basic phantoms. ", limitmsg);
57 if (!isSkip(data)) //ignore comment lines and blank lines
58 strcpy(name[i++], data);
65 /* -----------------------------------------------------------------
68 iexp - experiment number.
70 expflg - controls the phantom-file set used in each experiment as
71 follows: if expflg=0 the same set of phantom files is available
72 for use in both experiments. If expflg=1 the phantom files used
73 in the first experiment are excluded in the second experiment.
74 nphan - two-element array: nphan[i-1]= number of phantom files used for
76 size_ens - number of phantom filenames in name_lst.
77 name_lst - string array of length szens_ens containing the list of phantom
79 current_lst - string array of length phan[0] containing the list of
80 phantom filenames to be used for experiment 1.
84 size_ens - number of phantom filenames in name_lst.
85 name_lst - string array of length szens_ens containing the list of phantom
87 current_lst - string array of length phan[0] containing the list of
88 phantom filenames to be used for experiment 1.
89 phan_flname - the phantom filename randomly chosen.
90 --------------------------------------------------------------------- */
92 void get_phantom(int iexp, int irun, int expflg, int* nphan, int* size_ens, char name_lst[][MAXLINESIZE], char current_lst[][MAXLINESIZE], char* phan_flname)
94 int i, j, szens = *size_ens;
96 if (expflg == 1 && iexp == 0 && irun == 0)
98 for (j = 0; j < nphan[iexp]; j++)
101 i = (int) (szens * drand48()); /* (a) */
102 strcpy(current_lst[j], name_lst[i]); /* (b) */
103 strcpy(name_lst[i], name_lst[szens - 1]); /* (c) */
107 i = (int) (nphan[iexp] * drand48()); /* randomly select a phantom */
108 strcpy(phan_flname, current_lst[i]); /* filename from current_lst */
109 phan_flname[strlen(phan_flname) - 1] = '\0';
111 else if (expflg == 1 && iexp == 0 && irun > 0)
114 i = (int) (nphan[iexp] * drand48());
115 strcpy(phan_flname, current_lst[i]);
116 phan_flname[strlen(phan_flname) - 1] = '\0';
121 i = (int) (szens * drand48());
122 strcpy(phan_flname, name_lst[i]);
123 phan_flname[strlen(phan_flname) - 1] = '\0';
125 *size_ens = szens; /* number of phantom filenames in name_lst */