Initial snark14m import
[snark14.git] / src / snark / read_fomfile.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_fomfile.c $
5  $LastChangedRevision: 94 $
6  $Date: 2014-07-02 18:53:30 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  */
12
13 #include <string.h>
14
15 #include "experimenter.h"
16 #include "errorc.h"
17 #include "read_fomfile.h"
18
19 /* ----------------------------- read_fomfile.c -------------------------
20
21  This function reads the fom values stored in fomfile.
22
23  INPUTS:
24  iexp - experiment number
25  irun - run number
26  compare - counter for the number of COMPAREs read in so far
27  niters - number of iterations to be compared
28  fom - character string denoting the figure of merit
29
30  OUTPUTS:
31  fom1 - array of length niters containing the fom for the first algorithm.
32  fom2 - array of length niters containing the fom for the second algorithm.
33
34  */
35
36 void read_fomfile(int iexp, int irun, int compare, int niters, char* fom, double* fom1, double* fom2)
37 {
38         int itr_a, itr_b, rexp, rrun, rcompare, i;
39         double fom_a, fom_b;
40         char string[MAXLINESIZE];
41         FILE *fomfile;
42
43         strcpy(string, "fomfil");
44         sprintf(string, "%s.%d", string, iexp);
45
46         if ((fomfile = fopen(string, "r")) == NULL)
47         {
48                 errorc("in read_fomfile.c: error in opening file ", string);
49         }
50
51         while (1)
52         {
53                 /* Read fomfil until a line which contains the strings
54                  'run','experiment', and 'compare' is reached. If this
55                  line contains the correct combination of iexp, irun
56                  and compare break out of while loop  */
57
58                 fgets(string, sizeof(string), fomfile);
59                 if (strstr(string, "experiment") != NULL)
60                 {
61                         sscanf(string, "%*s %d %*s %d %*s %d", &rexp, &rrun, &rcompare);
62                         if ((rexp == iexp) && (rrun == irun) && (rcompare == compare))
63                         {
64                                 break;
65                         }
66                 }
67         }
68         while (1)
69         {
70                 /* Continue reading fomfil until a line which contains
71                  either the string '*****' or the fom is reached
72                  then break out of while loop */
73
74                 fgets(string, sizeof(string), fomfile);
75                 if (strstr(string, fom) != NULL)
76                 {
77                         break;
78                 }
79
80                 if (strstr(string, "*****") != NULL)
81                 {
82                         /* the string '*****' means no paired structures */
83                         for (i = 0; i < niters; i++)
84                         {
85                                 fom1[i] = 0.0;
86                                 fom2[i] = 0.0;
87                         }
88                         fclose(fomfile);
89                         return;
90                 }
91         }
92
93         /* now read in the iteration numbers and the foms */
94
95         for (i = 0; i < niters; i++)
96         {
97                 fgets(string, sizeof(string), fomfile);
98                 sscanf(string, "%d %lf %d %lf", &itr_a, &fom_a, &itr_b, &fom_b);
99                 fom1[i] = fom_a;
100                 fom2[i] = fom_b;
101         }
102
103         fclose(fomfile);
104 }