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/experimenter.c $
5 $LastChangedRevision: 177 $
6 $Date: 2015-08-03 16:44:07 -0400 (Mon, 03 Aug 2015) $
8 ***********************************************************
10 Previously part of SuperSNARK
13 /* --------------------------- experimenter.c -----------------------------
15 This is the main program. It reads input directly from the keyboard
16 or from a redirected file.
18 --------------------------------------------------------------------------- */
20 #include <sys/types.h>
28 #include "experimenter.h"
36 int strncasecmp(char* str1, char* str2, int len)
38 return strncmp(_strupr(str1), _strupr(str2), len);
43 void errorchk1(int nexp, int expflg, int nphan1, int nrun1);
45 int experimenter(int argc, char* argv[])
47 char string[MAXLINESIZE], ensflname[MAXLINESIZE], projflname[MAXLINESIZE],
48 recflname[MAXLINESIZE], anaflname[MAXLINESIZE], tmp[MAXLINESIZE];
49 int nexp, expflg, nelem, navel, nphan[MAXEXP], nrun[MAXEXP];
54 strcpy(progName, argv[0]);
56 fprintf(stdout, "snark14Experimenter.s170426\n");
61 if (open(argv[2], O_RDONLY) < 0)
70 // optional SEED line and ENSEMBLE line
71 if (fgets(string, sizeof(string), stdin) == NULL)
73 fprintf(stdout, "input error: end of file reached\n");
76 while (isSkip(string)) // skip comment lines and blank lines
78 if (fgets(string, sizeof(string), stdin) == NULL)
80 fprintf(stdout, "input error: end of file reached\n");
84 if (strncasecmp(string, "see", 3) == 0)
86 if (1 == sscanf(string, "%*s%ld", &seed))
94 errorc("Error reading supersnark input file at ", string);
96 // now read the ens line
97 if (fgets(string, sizeof(string), stdin) == NULL)
99 fprintf(stdout, "input error: end of file reached\n");
102 while (isSkip(string)) // skip comment lines and blank lines
104 if (fgets(string, sizeof(string), stdin) == NULL)
106 fprintf(stdout, "input error: end of file reached\n");
110 if (strncasecmp(string, "ens", 3) == 0)
112 sscanf(string, "%*s%s", ensflname);
114 else if (strncasecmp(string, "end", 3) == 0)
120 errorc("Error reading supersnark input file at ", string);
125 else if (strncasecmp(string, "ens", 3) == 0)
127 sscanf(string, "%*s%s", ensflname);
128 // there is not seed line, so set seed to current time
132 else if (strncasecmp(string, "end", 3) == 0)
138 errorc("Error reading supersnark input file at ", string);
142 if (fgets(string, sizeof(string), stdin) == NULL)
144 fprintf(stdout, "input error: end of file reached\n");
147 while (isSkip(string)) // skip comment lines and blank lines
149 if (fgets(string, sizeof(string), stdin) == NULL)
151 fprintf(stdout, "input error: end of file reached\n");
155 if (strncasecmp(string, "exp", 3) == 0)
158 sscanf(string, "%*s %d %d %d %f %d %d %d", &nexp, &expflg, &nelem,
159 &pixsz, &navel, &nphan[0], &nrun[0]);
160 errorchk1(nexp, expflg, nphan[0], nrun[0]);
164 sscanf(string, "%*s%*d%*d%*d%*f%*d%*d%*d%d%d", &nphan[1],
166 if (nphan[1] <= 0 || nrun[1] <= 0)
168 errorc("Invalid number of phantoms and/or runs ",
175 errorc("Error reading supersnark input file at ", string);
179 if (fgets(string, sizeof(string), stdin) == NULL)
181 fprintf(stdout, "input error: end of file reached\n");
184 while (isSkip(string)) // skip comment lines and blank lines
186 if (fgets(string, sizeof(string), stdin) == NULL)
188 fprintf(stdout, "input error: end of file reached\n");
192 if (strncasecmp(string, "dat", 3) == 0)
194 sscanf(string, "%*s %s", projflname);
198 errorc("Error reading supersnark input file at ", string);
202 if (fgets(string, sizeof(string), stdin) == NULL)
204 fprintf(stdout, "input error: end of file reached\n");
207 while (isSkip(string)) // skip comment lines and blank lines
209 if (fgets(string, sizeof(string), stdin) == NULL)
211 fprintf(stdout, "input error: end of file reached\n");
215 if (strncasecmp(string, "rec", 3) == 0)
217 sscanf(string, "%*s %s", recflname);
221 errorc("Error reading supersnark input file at ", string);
225 if (fgets(string, sizeof(string), stdin) == NULL)
227 fprintf(stdout, "input error: end of file reached\n");
230 while (isSkip(string)) // skip comment lines and blank lines
232 if (fgets(string, sizeof(string), stdin) == NULL)
234 fprintf(stdout, "input error: end of file reached\n");
238 if (strncasecmp(string, "ana", 3) == 0)
240 sscanf(string, "%*s %s", anaflname);
244 errorc("Error reading supersnark input file at ", string);
248 supersnk(nexp, expflg, nelem, pixsz, navel, nphan, nrun, ensflname,
249 projflname, recflname, anaflname, progName, seed);
254 // this function checks for invalid inputs
255 void errorchk1(int nexp, int expflg, int nphan1, int nrun1)
257 if (nexp != 1 && nexp != 2)
259 errorc("Invalid number of experiments. ", "See EXPERIMENT command");
262 if (expflg != 0 && expflg != 1)
264 errorc("Invalid entry for exp-flg. ", "See EXPERIMENT command");
267 if (nphan1 <= 0 || nrun1 <= 0)
269 errorc("Invalid number of phantoms and/or runs ", "for experiment 1");