ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/lookamb.c
Revision: 2.5
Committed: Thu Nov 18 09:43:02 1993 UTC (30 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +1 -0 lines
Log Message:
minor compiler warning fixes

File Contents

# Content
1 /* Copyright (c) 1991 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * lookamb.c - program to examine ambient components.
9 *
10 * 10/8/86
11 */
12
13 #include <stdio.h>
14
15 #ifdef MSDOS
16 #include <fcntl.h>
17 #endif
18
19 #include "color.h"
20
21 #include "ambient.h"
22
23
24 int dataonly = 0;
25 int header = 1;
26 int reverse = 0;
27
28 AMBVAL av;
29
30
31 main(argc, argv) /* load ambient values from a file */
32 int argc;
33 char *argv[];
34 {
35 FILE *fp;
36 int i;
37
38 for (i = 1; i < argc; i++)
39 if (argv[i][0] == '-')
40 switch (argv[i][1]) {
41 case 'd':
42 dataonly = 1;
43 break;
44 case 'r':
45 reverse = 1;
46 break;
47 case 'h':
48 header = 0;
49 break;
50 default:
51 fprintf(stderr, "%s: unknown option '%s'\n",
52 argv[0], argv[i]);
53 return(1);
54 }
55 else
56 break;
57
58 if (i >= argc)
59 fp = stdin;
60 else if ((fp = fopen(argv[i], "r")) == NULL) {
61 fprintf(stderr, "%s: file not found\n", argv[i]);
62 return(1);
63 }
64 if (reverse) {
65 if (header) {
66 if (checkheader(fp, "ascii", stdout) < 0)
67 goto formaterr;
68 } else
69 printargs(argc, argv, stdout);
70 fputformat(AMBFMT, stdout);
71 putchar('\n');
72 #ifdef MSDOS
73 setmode(fileno(stdout), O_BINARY);
74 #endif
75 putambmagic(stdout);
76 writamb(fp);
77 } else {
78 #ifdef MSDOS
79 setmode(fileno(fp), O_BINARY);
80 #endif
81 if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
82 goto formaterr;
83 if (!hasambmagic(fp))
84 goto formaterr;
85 if (header) {
86 fputformat("ascii", stdout);
87 putchar('\n');
88 }
89 lookamb(fp);
90 }
91 fclose(fp);
92 return(0);
93 formaterr:
94 fprintf(stderr, "%s: format error on input\n", argv[0]);
95 exit(1);
96 }
97
98
99 lookamb(fp) /* get ambient values from a file */
100 FILE *fp;
101 {
102 while (readambval(&av, fp)) {
103 if (dataonly) {
104 printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
105 printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
106 printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
107 printf("%e\t%e\t%e\t", colval(av.val,RED),
108 colval(av.val,GRN),
109 colval(av.val,BLU));
110 printf("%f\t%f\t%f\t", av.gpos[0],
111 av.gpos[1], av.gpos[2]);
112 printf("%f\t%f\t%f\n", av.gdir[0],
113 av.gdir[1], av.gdir[2]);
114 } else {
115 printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
116 av.pos[1], av.pos[2]);
117 printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
118 av.dir[1], av.dir[2]);
119 printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
120 av.weight, av.rad);
121 printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
122 colval(av.val,GRN), colval(av.val,BLU));
123 printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
124 av.gpos[1], av.gpos[2]);
125 printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
126 av.gdir[1], av.gdir[2]);
127 }
128 if (ferror(stdout))
129 exit(1);
130 }
131 }
132
133
134 writamb(fp) /* write binary ambient values */
135 FILE *fp;
136 {
137 for ( ; ; ) {
138 if (!dataonly)
139 fscanf(fp, "%*s");
140 if (fscanf(fp, "%f %f %f",
141 &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
142 return;
143 if (!dataonly)
144 fscanf(fp, "%*s");
145 if (fscanf(fp, "%f %f %f",
146 &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
147 return;
148 if (!dataonly)
149 fscanf(fp, "%*s");
150 if (fscanf(fp, "%d %f %f",
151 &av.lvl, &av.weight, &av.rad) != 3)
152 return;
153 if (!dataonly)
154 fscanf(fp, "%*s");
155 if (fscanf(fp, "%f %f %f",
156 &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
157 return;
158 if (!dataonly)
159 fscanf(fp, "%*s");
160 if (fscanf(fp, "%f %f %f",
161 &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
162 return;
163 if (!dataonly)
164 fscanf(fp, "%*s");
165 if (fscanf(fp, "%f %f %f",
166 &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
167 return;
168 av.next = NULL;
169 writambval(&av, stdout);
170 if (ferror(stdout))
171 exit(1);
172 }
173 }