Initial snark14m import
[snark14.git] / src / snark / get_seed.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_seed.c $
5  $LastChangedRevision: 118 $
6  $Date: 2014-07-09 14:22:29 -0400 (Wed, 09 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  *
12  * Feb 13, 2011 Joanna Klukowska
13  *     This file is no longer user. A single seed for snark14 experimenter run
14  *     is provided in the input file, or based on time (if the input file does not
15  *     contain it.
16  *
17  */
18
19 #include <strings.h>
20
21 #include "experimenter.h"
22 #include "errorc.h"
23 #include "get_seed.h"
24
25 /*---------------------------- get_seed.c ---------------------------------
26  This function checks the file specified on line 3 of the
27  SuperSNARK input sequence and obtaines the seed value (if it is
28  present).
29
30  INPUTS:
31  proj_flname - name of file containing information about generation of the
32  projection data. This is the file specified on line 3 of the
33  SuperSNARK input sequence.
34  seed - seed generated by current time.
35
36  OUTPUTS:
37  seed - seed to be used in random number generator.
38  ----------------------------------------------------------------------------*/
39
40 void get_seed(char* proj_flname, long* seed)
41 {
42         char string[MAXLINESIZE], line[MAXLINESIZE];
43         FILE *projfl;
44         long inseed;
45
46         if ((projfl = fopen(proj_flname, "r")) == NULL)
47         {
48                 errorc("error in opening file", proj_flname);
49         }
50
51         while ((fgets(string, sizeof(string), projfl)) != NULL)
52         {
53                 if (strncasecmp(string, "seed", 4) == 0)
54                 {
55                         /* if string has 'seed' then ... */
56                         if (sscanf(string, "%s %ld", line, &inseed) == 2)
57                         {
58                                 if (inseed >= 0)
59                                         *seed = inseed;
60                                 //else if inseed < 0  use the current time as seed
61                         }
62                         else
63                         {
64                                 //if number not specified, the default = 0
65                                 *seed = 0;
66                         }
67                 }
68                 else
69                 {
70                         ;
71                 }
72         }
73
74         fclose(projfl);
75 }