Initial snark14m import
[snark14.git] / src / snark / projection.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/projection.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:
11  /*--------------------------------------------------------------------------
12  Super Snark V 1.0
13  Written by Jingsheng Zheng... November 1992
14
15  Modified by Jolyon Browne... June 1993
16  ----------------------------------------------------------------------------*/
17
18 #include <strings.h>
19
20 #include "experimenter.h"
21 #include "errorc.h"
22 #include "projection.h"
23
24 /*--------------------------------------------------------------------------
25
26  This function echos the information stored in the file specified on
27  line 3 of the SuperSNARK input sequence. This information is sent to the
28  SNARK input stream.
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 used in the random number generator.
35
36  OUTPUTS:
37  none.
38  ----------------------------------------------------------------------------*/
39
40 /**
41  * 20140618 - BPRO: BUG 288 QUICK-FIX
42  *
43  * Replace current version of void projection(char* proj_flname, long seed)
44  * with the version from tar-ball: snark14.11.02.23
45  *
46  * Reason:
47  * The current version (tar-ball: snark14.14.04.10) should verify the
48  * input file of the projection command regarding its validity, but is missing
49  * some options (e.g. NITERS).
50  * The old version (tar-ball: snark14.11.02.23) does not perform any checks but
51  * copies all lines into the snark_e[runNo].in file.
52  *
53  * The file projection.c of the current version has been added as
54  * projection_snark14.14.04.10.c
55  * to SVN --> it can be used as basis for a "real" bug fix of bug 288
56  */
57 void projection(char* proj_flname, long seed)
58 {
59         char string[MAXLINESIZE];
60         FILE *projfl;
61
62         //seed = -1; // bug 176 - swr - 11/8/05
63         // bug 269, Joanna Klukowska, Feb. 13, 2011
64         // projection seed is generated randomly based on the seed in the input file
65         long projection_seed = (long) (100000000 * drand48());
66
67         if ((projfl = fopen(proj_flname, "r")) == NULL)
68         {
69                 errorc("error in opening file", proj_flname);
70         }
71
72         while ((fgets(string, sizeof(string), projfl)) != NULL)
73         {
74                 while (isSkip(string)) //it's a comment line,
75                 {                    //echo it to output and read next line
76                         if (isComment(string))
77                                 fprintf(pstream, "%s", string);
78                         if (fgets(string, sizeof(string), projfl) == NULL)
79                                 break;
80                 }
81                 if (strncasecmp(string, "seed", 4) == 0)
82                 {
83                         fprintf(pstream, "seed %ld\n", projection_seed);
84                 }
85                 else
86                 {
87                         fprintf(pstream, "%s", string);
88                 }
89         }
90
91         fclose(projfl);
92 }