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/read_eval_recon1.c $
5 $LastChangedRevision: 92 $
6 $Date: 2014-07-02 17:46:48 -0400 (Wed, 02 Jul 2014) $
8 ***********************************************************
10 Previously part of SuperSNARK
16 #include "experimenter.h"
18 #include "read_eval_recon1.h"
20 /* ----------------------------- read_eval_recon1.c ----------------------
22 This function reads from the eval file the abnormality index for
23 all the structures in a reconstruction. The abnormality index for a
24 structure is defined to be the average pixel value for those pixels
25 whose centers are within that structure.
28 iter - iteration number
29 keywrd - keyword which defines the algorithm whose reconstruction is
31 numstr - number of structures in reconstruction.
34 recon - array of length numstr containing the abnormality index for each
35 structure in the reconstruction.
38 void read_eval_recon1(int* iter, char* keywrd, int numstr, double* recon)
40 int reg, area, i, tmp_iter;
42 char string[MAXLINESIZE], iter_text[MAXLINESIZE], test[MAXLINESIZE];
48 /* this means we want the LAST iteration of the given algorithm;
49 * first we need to figure out the number of this iteration though;
51 * 1) scan the eval file until the like containing the keywrd for the
53 * 2) keep scanning until the last iteration is found
56 if ((evalfile = fopen("eval", "r")) == NULL)
58 errorc("in read_eval_recon1.c: error in opening file ", "eval");
63 /* Read eval file until a line which contains the string
64 'execution name' is reached. If this line contains the
65 keyword break out of the while loop. If end of file is
66 reached then keyword was not found so terminate program. */
68 fgets(string, sizeof(string), evalfile);
69 if (strstr(string, "execution name") != NULL)
71 sscanf(string, "%*s%*s %s", test);
72 if (strncasecmp(test, keywrd, 4) == 0)
79 sprintf(string, "Error in read_eval_recon1.c: keyword %s not "
80 "found in file", keywrd);
81 errorc(string, " eval");
87 /* Continue reading eval file until a line which contains
88 the string 'Metrics for algorithm' is reached. If this
89 line contains the string 'iteration' and the required
90 iteration number break out of the while loop. If end
91 of file is reached then the appropriate string was
92 not found so print error message and exit */
94 fgets(string, sizeof(string), evalfile);
95 if ((strstr(string, "metrics for algorithm") != NULL) && // changed "m" in "metrics for algorithm" to lowercase. Lajos, Dec 16, 2004
96 ((tmp_iter_ptr = strstr(string, "iteration")) != NULL))
98 //grab the iteration number from this line
99 tmp_iter_ptr = tmp_iter_ptr + 9;
100 if (0 == sscanf(tmp_iter_ptr, "%d", &tmp_iter))
102 "Error in read_eval_recon1.c: iteration number missing");
105 if ((strstr(string, "execution name") != NULL) || (strstr(string, "execution name") != NULL))
107 //we got to the next algorithm section, so better save the
108 //number of last iteration and break
114 fclose(evalfile); /* close eval file */
117 /* convert iteration number to a string */
119 sprintf(iter_text, "%d", *iter);
121 if ((evalfile = fopen("eval", "r")) == NULL)
123 errorc("in read_eval_recon1.c: error in opening file ", "eval");
128 /* Read eval file until a line which contains the string
129 'execution name' is reached. If this line contains the
130 keyword break out of the while loop. If end of file is
131 reached then keyword was not found so terminate program. */
133 fgets(string, sizeof(string), evalfile);
134 if (strstr(string, "execution name") != NULL)
136 sscanf(string, "%*s%*s %s", test);
137 if (strncasecmp(test, keywrd, 4) == 0)
144 sprintf(string, "Error in read_eval_recon1.c: keyword %s not found in file", keywrd);
145 errorc(string, " eval");
151 /* Continue reading eval file until a line which contains
152 the string 'Metrics for algorithm' is reached. If this
153 line contains the string 'iteration' and the required
154 iteration number break out of the while loop. If end
155 of file is reached then the appropriate string was
156 not found so print error message and exit */
158 fgets(string, sizeof(string), evalfile);
159 if ((strstr(string, "metrics for algorithm") != NULL)
160 && // changed "m" in "metrics for algorithm" to lowercase. Lajos, Dec 16, 2004
161 (strstr(string, iter_text) != NULL)
162 && (strstr(string, "iteration") != NULL))
169 sprintf(string, "Error in read_eval_recon1.c: %s ---> iteration %d not found in", keywrd, *iter);
170 errorc(string, " eval");
176 /* Continue reading eval file until a line of numbers is
177 reached then break out of while loop. Terminate program
178 if end of file is reached */
180 fgets(string, sizeof(string), evalfile);
181 if (sscanf(string, "%d %d %lf", ®, &area, &average) == 3)
189 errorc("Error in read_eval_recon1.c: end of file reached in file ",
192 /* this is the abnormality index of the first structure
193 in the reconstruction */
197 /* now read in the abnormality index for the remaining
200 for (i = 1; i < numstr; i++)
202 fgets(string, sizeof(string), evalfile);
203 sscanf(string, "%d %d %lf", ®, &area, &average);
207 fclose(evalfile); /* close eval file */