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_recon2.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_recon2.h"
20 /* ----------------------------- read_eval_recon2.c ----------------------
22 This function reads from the eval file the normalized root mean
23 square distance between a reconstruction and the phantom
26 mode - number of MODEs read in so far by analyze.c.
27 iteration - iteration number
28 keywrd - keyword which defines the algorithm whose reconstruction is
33 recon - double precision variable which stores the normalized root mean
34 square distance between the (clipped) reconstruction and the
38 void read_eval_recon2(int mode, int iteration, char* keywrd, double* recon)
40 int area, global = 0, iter;
41 double average, distance;
42 char string[MAXLINESIZE], test[MAXLINESIZE];
45 if ((evalfile = fopen("eval", "r")) == NULL)
46 errorc("in read_eval_recon2.c: error in opening file ", "eval");
48 /* read eval until the (mode+1)th occurrence of 'global' is reached. */
49 while (global != (mode + 1))
52 fgets(string, sizeof(string), evalfile);
53 if (strstr(string, "global") != NULL)
59 errorc( "Error in read_eval_recon2.c: number of MODEs in comparison file exceeds number of globals in file", " eval");
65 /* Read eval file until a line which contains the string
66 'execution name' is reached. If this line contains the
67 keyword, break out of the while loop. If end of file is
68 reached then keyword was not found so terminate program. */
70 fgets(string, sizeof(string), evalfile);
72 if (strstr(string, "execution name") != NULL)
75 sscanf(string, "%*s%*s %s", test);
76 if (strncasecmp(test, keywrd, 4) == 0)
85 "Error in read_eval_recon2.c: keyword %s not found in file",
87 errorc(string, " eval");
93 /* Continue reading eval file until a line of numbers is
94 reached then break out of while loop. If end of file
95 is encountered then terminate program. */
97 fgets(string, sizeof(string), evalfile);
98 if (sscanf(string, "%d %d %lf %lf", &iter, &area, &average, &distance) == 4)
104 errorc("Error in read_eval_recon2.c: end of file reached in file ", "eval");
108 /* If necessary search the remaining lines of numbers until
109 the appropriate iteration number is found. Then save the
110 distance and break out of while loop. If approriate
111 iteration number is not found then terminate program. */
116 /* if this first line of numbers has correct iteration
117 number save the distance and return*/
119 if (iter == iteration)
129 fgets(string, sizeof(string), evalfile);
130 sscanf(string, "%d %d %lf %lf", &iter, &area, &average, &distance);
131 if (iter == iteration)
138 sprintf(string, "Error in read_eval_recon2.c: %s --> iteration %d not found in file", keywrd, iteration);
139 errorc(string, " eval");
144 // special case iteration == 0
145 // the last iteration should be processed instead of a literal interpretation of 0
146 // olangthaler, 03/14/14
149 char prev[MAXLINESIZE];
153 strcpy(prev, string);
154 fgets(string, sizeof(string), evalfile);
155 if (strlen(string) < 3)
161 sprintf(string, "Error in read_eval_recon2.c: %s --> iteration %d not found in file", keywrd, iteration);
162 errorc(string, " eval");
166 sscanf(prev, "%d %d %lf %lf", &iter, &area, &average, &distance);
170 fclose(evalfile); /* close eval file */