ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/glaze.csh
Revision: 2.5
Committed: Wed Aug 25 19:13:30 2004 UTC (19 years, 8 months ago) by greg
Content type: application/x-csh
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad3R6, rad3R6P1, rad3R8
Changes since 2.4: +9 -4 lines
Log Message:
Fixed another bug in addition of -f option

File Contents

# User Rev Content
1 greg 2.1 #!/bin/csh -f
2 greg 2.5 # RCSid: $Id: glaze.csh,v 2.4 2004/08/25 01:40:12 greg Exp $
3 greg 2.1 #
4     # Complex glazing model (goes with glaze1.cal and glaze2.cal)
5     #
6     # Oct. 2002 Greg Ward
7 greg 2.3 # Aug. 2004 GW (added -f option to read glazings from file)
8 greg 2.2 # Funding for this development generously provided by Visarc, Inc.
9 greg 2.4 # (http://www.visarc.com)
10 greg 2.1 #
11    
12     #################################################################
13     #
14 greg 2.5 # The general assumption is that one surface is uncoated, and
15     # reflectances and transmittances are computed from this fact.
16     # If the user tries to enter two coated surfaces on the same
17     # pane, the script complains and exits.
18     #
19 greg 2.1 # Supported surface types:
20     #
21     set sn_arr=("clear glass" "VE1-2M low-E coating" "PVB laminated" "V-175 white frit" "V-933 warm gray frit")
22     # Glass-side hemispherical reflectances for each surface type:
23     set rg_r_arr=(0.074 0.065 .11 0.33 0.15)
24     set rg_g_arr=(0.077 0.058 .11 0.33 0.15)
25     set rg_b_arr=(0.079 0.067 .11 0.33 0.15)
26     # Coating-side hemispherical reflectance for each surface type:
27     set rc_r_arr=(0.074 0.042 .11 0.59 0.21)
28     set rc_g_arr=(0.077 0.049 .11 0.59 0.21)
29     set rc_b_arr=(0.079 0.043 .11 0.59 0.21)
30     # Hemispherical (normal) transmittance for each surface type:
31     set tn_r_arr=(0.862 0.756 0.63 0.21 0.09)
32     set tn_g_arr=(0.890 0.808 0.63 0.21 0.09)
33     set tn_b_arr=(0.886 0.744 0.63 0.21 0.09)
34     # Boolean whether coatings can have partial coverage:
35     set part_arr=(0 0 0 1 1)
36    
37 greg 2.3 while ($#argv > 0)
38 greg 2.4 set header="Surface Tr Tg Tb Rcr Rcg Rcb Rgr Rgg Rgb Part"
39 greg 2.3 if ($#argv < 2 || "$argv[1]" != '-f') then
40     echo "Usage: $0 [-f glazing.dat ..]"
41     exit 1
42     endif
43     shift argv
44     set gf="$argv[1]"
45     shift argv
46     if ("`sed -n 1p $gf:q`" != "$header") then
47     echo "Bad header in $gf -- Expected: $header"
48     exit 1
49     endif
50     echo "Adding glazing types from file $gf :"
51     set nl=`wc -l < $gf:q`
52     @ i=2
53     while ($i <= $nl)
54     set ln=(`sed -n ${i}p $gf:q`)
55 greg 2.4 if ($#ln != 11) then
56     echo "Expected 11 words in line: $ln"
57 greg 2.3 exit 1
58     endif
59     echo $ln[1]
60     set sn_arr=($sn_arr:q $ln[1])
61     set tn_r_arr=($tn_r_arr $ln[2])
62     set tn_g_arr=($tn_g_arr $ln[3])
63     set tn_b_arr=($tn_b_arr $ln[4])
64     set rc_r_arr=($rc_r_arr $ln[5])
65     set rc_g_arr=($rc_g_arr $ln[6])
66     set rc_b_arr=($rc_b_arr $ln[7])
67 greg 2.5 set rg_r_arr=($rg_r_arr $ln[8])
68     set rg_g_arr=($rg_g_arr $ln[9])
69     set rg_b_arr=($rg_b_arr $ln[10])
70 greg 2.4 set part_arr=($part_arr $ln[11])
71 greg 2.3 @ i++
72     end
73     end
74    
75 greg 2.1 #################################################################
76     #
77     # Get user input
78     #
79     echo -n "Enter the number of panes in the system: "
80     set np="$<"
81     if ($np != 1 && $np != 2) then
82     echo "Must be 1 or 2 pane system"
83     exit 1
84     endif
85     echo ""
86     echo "Window normal faces interior"
87     echo ""
88     if ($np == 1) then
89     echo " | |"
90     echo " | |"
91     echo " | |"
92     echo " | |-->"
93     echo " | |"
94     echo " | |"
95     echo " | |"
96     echo " s1 s2"
97     else
98     echo " | | | |"
99     echo " | | | |"
100     echo " | | | |"
101     echo " | | | |-->"
102     echo " | | | |"
103     echo " | | | |"
104     echo " | | | |"
105     echo " s1 s2 s3 s4"
106     endif
107     echo ""
108     echo "Supported surface types are:"
109     set i=1
110     while ($i <= $#sn_arr)
111     echo " " $i - $sn_arr[$i]
112     @ i++
113     end
114     echo ""
115     echo -n "What is the type of s1? "
116     set s1t="$<"
117     echo -n "What is the type of s2? "
118     set s2t="$<"
119     if ($s1t != 1 && $s2t != 1) then
120     echo "One surface of each pane must be $sn_arr[1]"
121     exit 1
122     endif
123     if ($part_arr[$s1t]) then
124     echo -n "Enter fraction coverage for s1 (0-1): "
125     set s1c="$<"
126     endif
127     if ($part_arr[$s2t]) then
128     echo -n "Enter fraction coverage for s2 (0-1): "
129     set s2c="$<"
130     endif
131     if ($np == 2) then
132     echo -n "What is the type of s3? "
133     set s3t="$<"
134     echo -n "What is the type of s4? "
135     set s4t="$<"
136     if ($s3t != 1 && $s4t != 1) then
137     echo "One surface of each pane must be $sn_arr[1]"
138     exit 1
139     endif
140     if ($part_arr[$s3t]) then
141     echo -n "Enter fraction coverage for s3 (0-1): "
142     set s3c="$<"
143     endif
144     if ($part_arr[$s4t]) then
145     echo -n "Enter fraction coverage for s4 (0-1): "
146     set s4c="$<"
147     endif
148     endif
149    
150     #################################################################
151     #
152     # Begin material comments
153     #
154     echo ""
155     echo "############################################"
156     echo "# Glazing produced by Radiance glaze script"
157     echo "# `date`"
158     echo "# Material surface normal points to interior"
159     echo "# Number of panes in system: $np"
160    
161     if ($np == 2) goto glaze2
162     #################################################################
163     #
164     # Compute single glazing
165     #
166     set sc=1
167     echo "# Exterior surface s1 type: $sn_arr[$s1t]"
168     if ($?s1c) then
169     echo "# s1 coating coverage: $s1c"
170     set sc=$s1c
171     endif
172     echo "# Interior surface s2 type: $sn_arr[$s2t]"
173     if ($?s2c) then
174     echo "# s2 coating coverage: $s2c"
175     set sc=$s2c
176     endif
177     if ($s1t != 1) then
178     set ct=$s1t
179     echo -n "# Exterior normal hemispherical reflectance: "
180     ev ".265*($sc*$rc_r_arr[$ct]+(1-$sc)*$rc_r_arr[1])+.670*($sc*$rc_g_arr[$ct]+(1-$sc)*$rc_g_arr[1])+.065*($sc*$rc_b_arr[$ct]+(1-$sc)*$rc_b_arr[1])"
181     echo -n "# Interior normal hemispherical reflectance: "
182     ev ".265*($sc*$rg_r_arr[$ct]+(1-$sc)*$rg_r_arr[1])+.670*($sc*$rg_g_arr[$ct]+(1-$sc)*$rg_g_arr[1])+.065*($sc*$rg_b_arr[$ct]+(1-$sc)*$rg_b_arr[1])"
183     else
184     set ct=$s2t
185     echo -n "# Exterior normal hemispherical reflectance: "
186     ev ".265*($sc*$rg_r_arr[$ct]+(1-$sc)*$rg_r_arr[1])+.670*($sc*$rg_g_arr[$ct]+(1-$sc)*$rg_g_arr[1])+.065*($sc*$rg_b_arr[$ct]+(1-$sc)*$rg_b_arr[1])"
187     echo -n "# Interior normal hemispherical reflectance: "
188     ev ".265*($sc*$rc_r_arr[$ct]+(1-$sc)*$rc_r_arr[1])+.670*($sc*$rc_g_arr[$ct]+(1-$sc)*$rc_g_arr[1])+.065*($sc*$rc_b_arr[$ct]+(1-$sc)*$rc_b_arr[1])"
189     endif
190     echo -n "# Normal hemispherical transmittance: "
191     ev ".265*($sc*$tn_r_arr[$ct]+(1-$sc)*$tn_r_arr[1])+.670*($sc*$tn_g_arr[$ct]+(1-$sc)*$tn_g_arr[1])+.065*($sc*$tn_b_arr[$ct]+(1-$sc)*$tn_b_arr[1])"
192     echo "#"
193     echo "void BRTDfunc glaze1_unnamed"
194     if ($part_arr[$s1t] || $part_arr[$s2t]) then
195     ### Frit glazing
196     echo "10"
197     echo " sr_frit_r sr_frit_g sr_frit_b"
198     echo " st_frit_r st_frit_g st_frit_b"
199     echo " 0 0 0"
200     echo " glaze1.cal"
201     echo "0"
202     echo "11"
203     if ($s2t == 1) then
204     ev "$s1c*($rg_r_arr[$s1t]-$rg_r_arr[1])" \
205     "$s1c*($rg_g_arr[$s1t]-$rg_g_arr[1])" \
206     "$s1c*($rg_b_arr[$s1t]-$rg_b_arr[1])"
207     ev "$s1c*$rc_r_arr[$s1t]" "$s1c*$rc_g_arr[$s1t]" "$s1c*$rc_b_arr[$s1t]"
208     ev "$s1c*$tn_r_arr[$s1t]" "$s1c*$tn_g_arr[$s1t]" "$s1c*$tn_b_arr[$s1t]"
209     echo " 1 $s1c"
210     else
211     ev "$s2c*$rc_r_arr[$s2t]" "$s2c*$rc_g_arr[$s2t]" "$s2c*$rc_b_arr[$s2t]"
212     ev "$s2c*($rg_r_arr[$s2t]-$rg_r_arr[1])" \
213     "$s2c*($rg_g_arr[$s2t]-$rg_g_arr[1])" \
214     "$s2c*($rg_b_arr[$s2t]-$rg_b_arr[1])"
215     ev "$s2c*$tn_r_arr[$s2t]" "$s2c*$tn_g_arr[$s2t]" "$s2c*$tn_b_arr[$s2t]"
216     echo " -1 $s2c"
217     endif
218     else
219     ### Low-E glazing
220     echo "10"
221     echo " sr_lowE_r sr_lowE_g sr_lowE_b"
222     echo " st_lowE_r st_lowE_g st_lowE_b"
223     echo " 0 0 0"
224     echo " glaze1.cal"
225     echo "0"
226     echo "19"
227     echo " 0 0 0"
228     echo " 0 0 0"
229     echo " 0 0 0"
230     if ($s2t == 1) then
231     echo " 1"
232     set st=$s1t
233     else
234     echo " -1"
235     set st=$s2t
236     endif
237     echo " $rg_r_arr[$st] $rg_g_arr[$st] $rg_b_arr[$st]"
238     echo " $rc_r_arr[$st] $rc_g_arr[$st] $rc_b_arr[$st]"
239     echo " $tn_r_arr[$st] $tn_g_arr[$st] $tn_b_arr[$st]"
240     endif
241     echo ""
242     exit 0
243    
244     glaze2:
245     #################################################################
246     #
247     # Compute double glazing
248     #
249     if ($s2t != 1) then
250     set s2r_rgb=($rc_r_arr[$s2t] $rc_g_arr[$s2t] $rc_b_arr[$s2t])
251     set s1r_rgb=($rg_r_arr[$s2t] $rg_g_arr[$s2t] $rg_b_arr[$s2t])
252     set s12t_rgb=($tn_r_arr[$s2t] $tn_g_arr[$s2t] $tn_b_arr[$s2t])
253     else
254     set s2r_rgb=($rg_r_arr[$s1t] $rg_g_arr[$s1t] $rg_b_arr[$s1t])
255     set s1r_rgb=($rc_r_arr[$s1t] $rc_g_arr[$s1t] $rc_b_arr[$s1t])
256     set s12t_rgb=($tn_r_arr[$s1t] $tn_g_arr[$s1t] $tn_b_arr[$s1t])
257     endif
258     if ($s4t != 1) then
259     set s4r_rgb=($rc_r_arr[$s4t] $rc_g_arr[$s4t] $rc_b_arr[$s4t])
260     set s3r_rgb=($rg_r_arr[$s4t] $rg_g_arr[$s4t] $rg_b_arr[$s4t])
261     set s34t_rgb=($tn_r_arr[$s4t] $tn_g_arr[$s4t] $tn_b_arr[$s4t])
262     else
263     set s4r_rgb=($rg_r_arr[$s3t] $rg_g_arr[$s3t] $rg_b_arr[$s3t])
264     set s3r_rgb=($rc_r_arr[$s3t] $rc_g_arr[$s3t] $rc_b_arr[$s3t])
265     set s34t_rgb=($tn_r_arr[$s3t] $tn_g_arr[$s3t] $tn_b_arr[$s3t])
266     endif
267     set s12c=1
268     echo "# Exterior surface s1 type: $sn_arr[$s1t]"
269     if ($?s1c) then
270     echo "# s1 coating coverage: $s1c"
271     set s12c=$s1c
272     endif
273     echo "# Inner surface s2 type: $sn_arr[$s2t]"
274     if ($?s2c) then
275     echo "# s2 coating coverage: $s2c"
276     set s12c=$s2c
277     endif
278     set s34c=1
279     echo "# Inner surface s3 type: $sn_arr[$s3t]"
280     if ($?s3c) then
281     echo "# s3 coating coverage: $s3c"
282     set s34c=$s3c
283     endif
284     echo "# Interior surface s4 type: $sn_arr[$s4t]"
285     if ($?s4c) then
286     echo "# s4 coating coverage: $s4c"
287     set s34c=$s4c
288     endif
289     # Approximate reflectance and transmittance for comment using gray values
290     set rglass=`ev ".265*$rg_r_arr[1]+.670*$rg_g_arr[1]+.065*$rg_b_arr[1]"`
291     set tglass=`ev ".265*$tn_r_arr[1]+.670*$tn_g_arr[1]+.065*$tn_b_arr[1]"`
292     set s1r_gry=`ev "$s12c*(.265*$s1r_rgb[1]+.670*$s1r_rgb[2]+.065*$s1r_rgb[3])+(1-$s12c)*$rglass"`
293     set s2r_gry=`ev "$s12c*(.265*$s2r_rgb[1]+.670*$s2r_rgb[2]+.065*$s2r_rgb[3])+(1-$s12c)*$rglass"`
294     set s12t_gry=`ev "$s12c*(.265*$s12t_rgb[1]+.670*$s12t_rgb[2]+.065*$s12t_rgb[3])+(1-$s12c)*$tglass"`
295     set s3r_gry=`ev "$s34c*(.265*$s3r_rgb[1]+.670*$s3r_rgb[2]+.065*$s3r_rgb[3])+(1-$s34c)*$rglass"`
296     set s4r_gry=`ev "$s34c*(.265*$s4r_rgb[1]+.670*$s4r_rgb[2]+.065*$s4r_rgb[3])+(1-$s34c)*$rglass"`
297     set s34t_gry=`ev "$s34c*(.265*$s34t_rgb[1]+.670*$s34t_rgb[2]+.065*$s34t_rgb[3])+(1-$s34c)*$tglass"`
298     echo -n "# Exterior normal hemispherical reflectance: "
299     ev "$s1r_gry + $s12t_gry^2*$s3r_gry"
300     echo -n "# Interior normal hemispherical reflectance: "
301     ev "$s4r_gry + $s34t_gry^2*$s2r_gry"
302     echo -n "# Normal hemispherical transmittance: "
303     ev "$s12t_gry*$s34t_gry"
304     echo "#"
305     echo "void BRTDfunc glaze2_unnamed"
306    
307     if ($part_arr[$s3t] || $part_arr[$s4t]) then
308     ### Front pane has frit
309     if ($part_arr[$s1t] || $part_arr[$s2t]) then
310     echo "Only one pane can have frit"
311     exit 1
312     endif
313     if ($?s3c) then
314     set sc=$s3c
315     set s3g=`ev "1-$s3c"`
316     else
317     set s3c=0
318     set s3g=1
319     endif
320     if ($?s4c) then
321     set sc=$s4c
322     set s4g=`ev "1-$s4c"`
323     else
324     set s4c=0
325     set s4g=1
326     endif
327     echo "10"
328     echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[1])),cr(fr($s1r_rgb[1]),ft($s12t_rgb[1]),$s3g*rclr))"
329     echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[2])),cr(fr($s1r_rgb[2]),ft($s12t_rgb[2]),$s3g*rclr))"
330     echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[3])),cr(fr($s1r_rgb[3]),ft($s12t_rgb[3]),$s3g*rclr))"
331     echo "$s3g*$s4g*ft($s12t_rgb[1])*tclr"
332     echo "$s3g*$s4g*ft($s12t_rgb[2])*tclr"
333     echo "$s3g*$s4g*ft($s12t_rgb[3])*tclr"
334     echo " 0 0 0"
335     echo " glaze2.cal"
336     echo "0"
337     echo "9"
338     ev "$sc*$s4r_rgb[1]-$s3c*$rg_r_arr[1]" \
339     "$sc*$s4r_rgb[2]-$s3c*$rg_g_arr[1]" \
340     "$sc*$s4r_rgb[3]-$s3c*$rg_b_arr[1]"
341     ev "$s12t_rgb[1]^2*($sc*$s3r_rgb[1]-$s4c*$rg_r_arr[1])" \
342     "$s12t_rgb[2]^2*($sc*$s3r_rgb[2]-$s4c*$rg_g_arr[1])" \
343     "$s12t_rgb[3]^2*($sc*$s3r_rgb[3]-$s4c*$rg_b_arr[1])"
344     ev "$sc*$s12t_rgb[1]*$s34t_rgb[1]" \
345     "$sc*$s12t_rgb[2]*$s34t_rgb[2]" \
346     "$sc*$s12t_rgb[3]*$s34t_rgb[3]"
347     else if ($part_arr[$s1t] || $part_arr[$s2t]) then
348     ### Back pane has frit
349     if ($?s1c) then
350     set sc=$s1c
351     set s1g=`ev "1-$s1c"`
352     else
353     set s1c=0
354     set s1g=1
355     endif
356     if ($?s2c) then
357     set sc=$s2c
358     set s2g=`ev "1-$s2c"`
359     else
360     set s2c=0
361     set s2g=1
362     endif
363     echo "10"
364     echo "if(Rdot,cr(fr($s4r_rgb[1]),ft($s34t_rgb[1]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[1])))"
365     echo "if(Rdot,cr(fr($s4r_rgb[2]),ft($s34t_rgb[2]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[2])))"
366     echo "if(Rdot,cr(fr($s4r_rgb[3]),ft($s34t_rgb[3]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[3])))"
367     echo "$s1g*$s2g*ft($s34t_rgb[1])*tclr"
368     echo "$s1g*$s2g*ft($s34t_rgb[2])*tclr"
369     echo "$s1g*$s2g*ft($s34t_rgb[3])*tclr"
370     echo " 0 0 0"
371     echo " glaze2.cal"
372     echo "0"
373     echo "9"
374     ev "$s34t_rgb[1]^2*($sc*$s2r_rgb[1]-$s1c*$rg_r_arr[1])" \
375     "$s34t_rgb[2]^2*($sc*$s2r_rgb[2]-$s1c*$rg_g_arr[1])" \
376     "$s34t_rgb[3]^2*($sc*$s2r_rgb[3]-$s1c*$rg_b_arr[1])"
377     ev "$sc*$s1r_rgb[1]-$s2c*$rg_r_arr[1]" \
378     "$sc*$s1r_rgb[2]-$s2c*$rg_g_arr[1]" \
379     "$sc*$s1r_rgb[3]-$s2c*$rg_b_arr[1]"
380     ev "$sc*$s34t_rgb[1]*$s12t_rgb[1]" \
381     "$sc*$s34t_rgb[2]*$s12t_rgb[2]" \
382     "$sc*$s34t_rgb[3]*$s12t_rgb[3]"
383     else
384     ### Low-E and regular glazing only
385     echo "10"
386     echo "if(Rdot,cr(fr($s4r_rgb[1]),ft($s34t_rgb[1]),fr($s2r_rgb[1])),cr(fr($s1r_rgb[1]),ft($s12t_rgb[1]),fr($s3r_rgb[1])))"
387     echo "if(Rdot,cr(fr($s4r_rgb[2]),ft($s34t_rgb[2]),fr($s2r_rgb[2])),cr(fr($s1r_rgb[2]),ft($s12t_rgb[2]),fr($s3r_rgb[2])))"
388     echo "if(Rdot,cr(fr($s4r_rgb[3]),ft($s34t_rgb[3]),fr($s2r_rgb[3])),cr(fr($s1r_rgb[3]),ft($s12t_rgb[3]),fr($s3r_rgb[3])))"
389     echo "ft($s34t_rgb[1])*ft($s12t_rgb[1])"
390     echo "ft($s34t_rgb[2])*ft($s12t_rgb[2])"
391     echo "ft($s34t_rgb[3])*ft($s12t_rgb[3])"
392     echo " 0 0 0"
393     echo " glaze2.cal"
394     echo "0"
395     echo "9"
396     echo " 0 0 0"
397     echo " 0 0 0"
398     echo " 0 0 0"
399     endif
400     echo ""
401     exit 0