2 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
6 * A PICTURE RECONSTRUCTION PROGRAM *
8 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10 supersnk.c,v 1.16 2011/02/21 00:45:48 jklukowska Exp
12 Previously part of SuperSNARK*/
14 //#define SS_DEBUG //bug 269, Joanna Klukowska, converted to a variable below
21 #include "experimenter.h"
23 #include "get_phantom.h"
24 #include "create_phantom.h"
25 #include "projection.h"
31 #include "get_iter_flag.h"
32 //#include "get_seed.h"
33 #include "check_if_iroi.h"
36 /* --------------------------- supersnk.c -------------------------------
38 * This function is the driver program to SNARK. It controls phantom
39 * selection and feeds SNARK the necessary commands to generate the phantoms
40 * plus their projection data, to implement the desired reconstruciton
41 * algorithms on these data, and to evaluate the reconstructed images.
42 * This function also calls the necessary routines to compute the
43 * desired figures of merit and their statistical significance.
46 * nexp - number of experiments.
47 * expflg - controls the phantom-file set used in each experiment as
48 * follows: if expflg=0 the same set of phantom files is available
49 * for use in both experiments. If expflg=1 the phantom files used
50 * in the first experiment are excluded in the second experiment.
51 * navel, nelem,pixsz - modifiers described by Set 4 of the SNARK CREATE
52 * input sequence (see the SNARK manual for details).
53 * nphan - two-element array: nphan[i-1]= number of phantom files used for
54 * experiment i (i=1,2).
55 * nrun - two-element array: nrun[i-1]= number of runs for experiment i
57 * ensflname - name of ensemble data file.
58 * projflname - name of file containing information about the projection
60 * recflname - name of file containing information about the reconstruction
61 * algorithms to be implemented.
62 * anaflname - name of file containing information about the algorithms
67 * -------------------------------------------------------------------- */
85 //int nexp,expflg,nelem,navel,*nphan,*nrun;
87 //char *ensflname,*projflname,*recflname,*anaflname;
91 //changed pairsarray[MAXNSTR] to *pairsarray
92 //changed structure[MAXNSTR][MAXLINESIZE] to **structure
93 //to allow unlimited number of structures
94 //the file will need to be scanned firest to
95 //allocate the array of right size
98 int i, j, run, szens, nstr, npairs, tot_PAIRS;
99 int iroi_used; //set to 0 or 1 by check_if_iroi
100 //it is used by create_phantom() to verify that density of one out
101 //of each paired structures is zero
102 char namelst[MAXENSEMSIZE][MAXLINESIZE],
103 phanflname[MAXLINESIZE],
104 currentlst[MAXENSEMSIZE][MAXLINESIZE], fomflname[MAXLINESIZE],
105 iter_flag[51], ifname[64], ofname[64], recfilname[64], enums[8], rnums[8], command[256],pipcommand[256];
111 mode = getenv("SNARK_EXP");
112 if (mode != NULL && strcasecmp(mode, "DEBUG") == 0)
115 printf("Running in DEBUG mode: extra files will be saved.\n");
118 /* get list of phantom filenames and iteration flag for EVALUATE command */
119 read_ensemble(ensflname, namelst, &szens);
120 strncpy(iter_flag, "10000000000000000000000000000000000000000000000000\0",51);
121 getiterflag(anaflname, iter_flag);
123 strcat(pipcommand,"tee snark_e.in | (");
124 strcat(pipcommand,progName);
125 strcat(pipcommand," > snark_e.out)");
126 for (i = 0; i < nexp; i++) {
127 fprintf(stdout, "experiment %d\n", i + 1); // bug 187 - progress indicator - swr - 11/11/05
128 /* sprintf(fomflname,"%s.%d",fomflname,i+1); */ /* bug: concats. exp.# onto prev. name ('fomfil.1.2.3....') */
129 sprintf(fomflname, "fomfil.%d", i + 1); /* fix: concats. exp.# onto 'fomfil' only (JD 8/8/05) */
130 tot_PAIRS = 0; /* number of phantoms with PAIRed structures */
132 for (run = 0; run < nrun[i]; run++) {
133 fprintf(stdout, "run %d\n", run + 1); // bug 187 - progress indicator - swr - 11/11/05
134 /* beginning of inner for loop */
138 //fprintf(stdout, "------------------------------");
141 sprintf(enums, "%02d", i);
144 sprintf(rnums, "%02d", run);
147 //strcat(ifname, "snark_e");
148 //strcat(ifname, ".in");
149 sprintf(ifname, "snark_e%d.in", run);
152 //strcat(ofname, "snark_e");
153 //strcat(ofname, ".out");
154 sprintf(ofname, "snark_e%d.out", run);
156 recfilname[0] = '\0';
157 sprintf(recfilname, "recfil%d", run);
159 if ((pstream = fopen(ifname, "w")) == NULL) {
160 errorc("Could not open", ifname);
163 // bug 170 - swr - 10/01/05
164 if (system("test -x ./bin/snark14UserDefined") || // file exists and executable
165 system("test -s ./bin/snark14UserDefined") || // exists and has non-zero size
166 system("test -f ./bin/snark14UserDefined")) { // exists and is regular (not a directory
167 // bug 298 - Ze Ye 08/13/15
168 if ((pstream = popen("tee snark_e.in | (./bin/snark14 > snark_e.out)", "w")) == NULL) {
169 errorc("Could not run", "snark");
173 if ((pstream = popen("tee snark_e.in | (./bin/snark14UserDefined> snark_e.out )", "w")) == NULL) {
174 errorc("Could not run", "snark");
180 get_phantom(i, run, expflg, nphan, &szens, namelst, currentlst,
183 check_if_iroi(anaflname, &iroi_used);
185 create_phantom(phanflname, seed, navel, nelem, pixsz, &structure,
186 &nstr, &npairs, &pairsarray, iroi_used);
188 projection(projflname, seed);
190 recon(recflname, i + 1, run + 1);
192 evaluate(anaflname, &structure, nstr, iter_flag);
194 fprintf(pstream, "END \n");
200 //strcat(command, "snark14 ");
201 strcat(command, progName);
202 strcat(command, " ");
203 strcat(command, ifname);
204 strcat(command, " > ");
205 strcat(command, ofname);
207 if (system(command) != 0) {
208 fprintf(stdout, "\nERROR running: %s\n", command);
212 rename ("recfil", recfilname);
219 /* keep count of the number of phantoms */
221 tot_PAIRS += 1; /* with PAIRed structures */
225 if ((fomfl = fopen(fomflname, "w")) == NULL) {
226 errorc("in supersnk.c: error opening file ", fomflname);
229 if ((fomfl = fopen(fomflname, "a")) == NULL) {
230 errorc("in supersnk.c: error opening file ", fomflname);
235 analyze(i + 1, run + 1, npairs, pairsarray, anaflname, fomfl);
238 /* remove snark.out after every run except the very last run */
242 if (run != nrun[0] - 1) {
243 if (remove("snark_e.out") != 0) {
244 errorc("in supersnk: error deleting file ", "snark.out");
248 if ((i == 0) || ((i == 1) && (run != nrun[1] - 1))) {
249 if (remove("snark_e.out") != 0) {
250 errorc("in supersnk: error deleting file ", "snark_e.out");
256 } /* end of inner for loop */
258 //jk 01/01/08 free memory
260 for (j = nstr - 1; j >= 0; j--) {
261 free((void*) (structure[j]));
264 analyze2(i + 1, nrun[i], tot_PAIRS, anaflname);
266 } /* end of outer for loop */