Initial snark14m import
[snark14.git] / src / snark / get_iter_flag.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/get_iter_flag.c $
5  $LastChangedRevision: 137 $
6  $Date: 2014-07-15 16:38:33 -0400 (Tue, 15 Jul 2014) $
7  $Author: bprommegger $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  */
12
13 #include <string.h>
14 #include "experimenter.h"
15 #include "errorc.h"
16 #include "get_iter_flag.h"
17
18 /* --------------------------- get_iter_flag.c ---------------------------
19
20  This function reads the list of iteration numbers stored in the
21  file containing the comparisons to be made and generates an iteration_flag_line
22  which is needed for the EVALUATE command.
23
24  INPUTS:
25  anaflname - name of file containing comparisons to be made.
26  iter_flag - string containing a 1 followed by 50 0's.
27
28  OUTPUTS:
29  iter_flag - iteration_flag_line needed for the EVALUATE command
30  ------------------------------------------------------------------     */
31
32 void getiterflag(char* anaflname, char* iter_flag)
33 {
34         int iter1, iter2, bit1, bit2, i;
35         char string[MAXLINESIZE];
36         char flag = '1';
37
38         FILE *anafl;
39
40         if ((anafl = fopen(anaflname, "r")) == NULL)
41         {
42                 errorc("in get_iter_flag.c: error in opening file", anaflname);
43         }
44
45         /* the iter_flag is the union of all the iteration numbers */
46
47         while (fgets(string, sizeof(string), anafl) != NULL)
48         {
49                 // upgrade flag to 3 if klds is specified
50                 if (!isSkip(string))
51                 {
52                         if (strcasestr(string, "klds")) flag='3';
53                         if (strcasestr(string, "wsqd")) flag='3';
54                 }
55
56                 if (sscanf(string, "%d %d", &iter1, &iter2) == 2)
57                 {
58                         /* if an iteration number is a multiple of 50
59                          set bit 50 */
60                         bit1 = iter1 % 50;
61                         bit2 = iter2 % 50;
62                         if (bit1 == 0 && iter1 != 0)
63                         {
64                                 iter_flag[50] = flag;
65                         }
66                         else
67                         {
68                                 iter_flag[bit1] = flag;
69                         }
70
71                         if (bit2 == 0 && iter2 != 0)
72                         {
73                                 iter_flag[50] = flag;
74                         }
75                         else
76                         {
77                                 iter_flag[bit2] = flag;
78                         }
79                 }
80         }
81
82         iter_flag[51] = '\0';
83         fclose(anafl);
84 }