f3cfd0826d22ab503b6c2699f2c9778e34a052ad
[snark14.git] / src / snark / getiters.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/getiters.c $
5  $LastChangedRevision: 86 $
6  $Date: 2014-07-02 16:45:09 -0400 (Wed, 02 Jul 2014) $
7  $Author: olangthaler $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  */
12
13 #include <string.h>
14 #include <strings.h>
15 #include <malloc.h>
16 #include <stdio.h>
17 #include "experimenter.h"
18 #include "errorc.h"
19 #include "getiters.h"
20
21 /* ------------------------- getiters.c -------------------------------
22
23  This function reads the iteration numbers from the file containing the comparisons to be made.
24
25  INPUTS:
26  anafl - file pointer to the file containing the comparisons to be made
27
28  OUTPUTS:
29  itr1 - array of length numiters containing the iteration numbers for the first algorithm.
30  itr2 - array of length numiters containing the iteration numbers for the first algorithm.
31  numiters - number of iterations to be compared.
32  string - line of text after the set of iteration numbers just read; this line will be COMPARE, MODE, or END commands.
33  */
34
35 void getiters(FILE* anafl, int** itr1, int** itr2, int* numiters, char* string)
36 {
37         int count = 0, iter1, iter2;
38         char line[MAXLINESIZE];
39
40         /* allocate memory for first set of iteration numbers */
41
42         *itr1 = (int *) malloc(sizeof(int));
43         *itr2 = (int *) malloc(sizeof(int));
44         if ((*itr1 == NULL) || (*itr2 == NULL))
45         {
46                 errorc("in analyze.c: memory allocation failed in ", "getiters");
47         }
48
49         /* at this point the file pointer anafl is at the first set of iteration
50          numbers since the previous line read in by the calling program was a COMPARE
51          line */
52
53         while (1)
54         {
55                 fgets(line, sizeof(line), anafl);
56                 while (isSkip(line))     //jump over comment lines and blank lines
57                 {
58                         fgets(line, sizeof(line), anafl);
59                 }
60                 if (sscanf(line, "%d %d", &iter1, &iter2) == 2)
61                 {
62                         if (iter1 == 0) (*itr1)[count] = 0; //??? whatever the last iteration is;
63                         if (iter2 == 0) (*itr2)[count] = 0; //??? whatever the last iteration is;
64
65                         (*itr1)[count] = iter1; /* store iteration numbers */
66                         (*itr2)[count] = iter2;
67                         count++; /* number of iteration lines read in */
68                         *itr1 = (int *) realloc(*itr1, (count + 1) * sizeof(int));
69                         *itr2 = (int *) realloc(*itr2, (count + 1) * sizeof(int));
70                         if ((*itr1 == NULL) || (*itr2 == NULL))
71                         {
72                                 errorc("in analyze.c: memory reallocation failed in ","getiters");
73                         }
74                 }
75                 else
76                 {
77                         break; /* break out of loop when iteration numbers done */
78                 }
79         }
80         *numiters = count;
81         // skip FLAG line
82         if (strncasecmp(line, "flag", 4) == 0)
83         {
84                 fgets(line, sizeof(line), anafl);
85         }
86         strcpy(string, line);
87         /* line and string now contain the string of text after
88          the set of iteration numbers and the FLAG command just read in.
89          This string will be COMPARE, MODE or END.
90          If not then terminate program */
91         if ((strncasecmp(string, "mode", 4) != 0) && (strncasecmp(string, "comp", 4) != 0) && (strncasecmp(string, "end", 3) != 0))
92         {
93                 errorc("In getiters: error in comparison file at line ", string);
94         }
95 }