Initial snark14m import
[snark14.git] / src / snark / read_eval_recon3.c
1 /*
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_recon3.c $
5  $LastChangedRevision: 92 $
6  $Date: 2014-07-02 17:46:48 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  */
12
13 #include <string.h>
14 #include <strings.h>
15
16 #include "experimenter.h"
17 #include "errorc.h"
18 #include "read_eval_recon3.h"
19
20 /* ----------------------------- read_eval_recon1.c ----------------------
21
22  This function reads from the eval file the variance for
23  all the structures in a reconstruction.
24
25  INPUTS:
26  iter - iteration number
27  keywrd - keyword which defines the algorithm whose reconstruction is
28  to be read in.
29  numstr - number of structures in reconstruction.
30
31  OUTPUT:
32  recon - array of length numstr containing the variance for each
33  structure in the reconstruction.
34  */
35
36 void read_eval_recon3(int iter, char* keywrd, int numstr, double* recon)
37 {
38         int reg, area, i;
39         double average, dist, rel_err, variance;
40         char string[MAXLINESIZE], iter_text[MAXLINESIZE], test[MAXLINESIZE];
41         FILE *evalfile;
42
43         /* convert iteration number to a string */
44         sprintf(iter_text, "%d", iter);
45
46         if ((evalfile = fopen("eval", "r")) == NULL)
47         {
48                 errorc("in read_eval_recon1.c: error in opening file ", "eval");
49         }
50
51         while (1)
52         {
53                 /* Read eval file until a line which contains the string
54                  'execution name' is reached. If this line contains the
55                  keyword break out of the while loop. If end of file is
56                  reached then keyword was not found so terminate program.  */
57
58                 fgets(string, sizeof(string), evalfile);
59                 if (strstr(string, "execution name") != NULL)
60                 {
61                         sscanf(string, "%*s%*s %s", test);
62                         if (strncasecmp(test, keywrd, 4) == 0)
63                         {
64                                 break;
65                         }
66                 }
67                 if (feof(evalfile))
68                 {
69                         sprintf(string, "Error in read_eval_recon1.c: keyword %s not found in file", keywrd);
70                         errorc(string, " eval");
71                 }
72         }
73
74         while (1)
75         {
76                 /* Continue reading eval file until a line which contains
77                  the string 'Metrics for algorithm' is reached. If this
78                  line contains the string 'iteration' and the required
79                  iteration number break out of the while loop. If end
80                  of file is reached then the appropriate string was
81                  not found so print error message and exit */
82
83                 fgets(string, sizeof(string), evalfile);
84                 if ((strstr(string, "metrics for algorithm") != NULL)
85                                 && // changed "m" in "metrics for algorithm" to lowercase. Lajos, Dec 16, 2004
86                                 (strstr(string, iter_text) != NULL)
87                                 && (strstr(string, "iteration") != NULL))
88                 {
89                         break;
90                 }
91
92                 if (feof(evalfile))
93                 {
94                         sprintf(string, "Error in read_eval_recon1.c: %s ---> iteration %d not found in", keywrd, iter);
95                         errorc(string, " eval");
96                 }
97         }
98
99         while (1)
100         {
101                 /* Continue reading eval file until a line of numbers is
102                  reached then break out of while loop. Terminate program
103                  if end of file is reached */
104
105                 fgets(string, sizeof(string), evalfile);
106                 if (sscanf(string, "%d %d %lf %lf %lf %lf", &reg, &area, &average, &dist, &rel_err, &variance) == 6)
107                 {
108                         break;
109                 }
110         }
111
112         if (feof(evalfile))
113         {
114                 errorc("Error in read_eval_recon1.c: end of file reached in file ", "eval");
115         }
116
117         /* this is the variance of the first structure
118          in the reconstruction */
119         recon[0] = variance;
120
121         /* now read in the abnormality index for the remaining
122          structures */
123
124         for (i = 1; i < numstr; i++)
125         {
126                 fgets(string, sizeof(string), evalfile);
127                 sscanf(string, "%d %d %lf %lf %lf %lf", &reg, &area, &average, &dist, &rel_err, &variance);
128                 recon[i] = variance;
129         }
130
131         fclose(evalfile); /* close eval file */
132 }