| 1 | 
greg | 
1.1 | 
#!/bin/csh -f | 
| 2 | 
  | 
  | 
# SCCSid "$SunId$ LBL" | 
| 3 | 
  | 
  | 
# | 
| 4 | 
  | 
  | 
# Interactive script to calculate daylight factors | 
| 5 | 
  | 
  | 
# | 
| 6 | 
  | 
  | 
set nofile="none" | 
| 7 | 
greg | 
2.2 | 
set illumpic=$nofile | 
| 8 | 
greg | 
1.1 | 
set octree=$nofile | 
| 9 | 
  | 
  | 
set dfpict=$nofile | 
| 10 | 
  | 
  | 
set ilpict=$nofile | 
| 11 | 
greg | 
2.2 | 
set dspict=$nofile | 
| 12 | 
  | 
  | 
set nodaysav=1 | 
| 13 | 
greg | 
1.4 | 
set fcopts=($*) | 
| 14 | 
greg | 
2.2 | 
set designlvl=500 | 
| 15 | 
greg | 
1.1 | 
set wporig=(0 0 0) | 
| 16 | 
  | 
  | 
set wpsize=(1 1) | 
| 17 | 
greg | 
2.2 | 
set rtargs=(-ab 1 -ad 256 -as 128 -aa .15 -av .3 .3 .3) | 
| 18 | 
greg | 
1.3 | 
set maxres=128 | 
| 19 | 
greg | 
1.1 | 
 | 
| 20 | 
  | 
  | 
alias readvar 'echo -n Enter \!:1 "[$\!:1]: ";set ans="$<";if("$ans" != "")set \!:1="$ans"' | 
| 21 | 
  | 
  | 
 | 
| 22 | 
  | 
  | 
cat <<_EOF_ | 
| 23 | 
  | 
  | 
                        DAYLIGHT FACTOR CALCULATION | 
| 24 | 
  | 
  | 
 | 
| 25 | 
greg | 
2.2 | 
This script calculates daylight factors, illuminance levels, and/or | 
| 26 | 
  | 
  | 
energy savings due to daylight on a rectangular workplane and produces | 
| 27 | 
  | 
  | 
a contour plot from the result.  The input is a Radiance scene description | 
| 28 | 
  | 
  | 
(and octree) and the output is one or more color Radiance pictures. | 
| 29 | 
greg | 
1.1 | 
 | 
| 30 | 
  | 
  | 
_EOF_ | 
| 31 | 
greg | 
2.2 | 
echo -n "Have you already calculated an illuminance picture with dayfact? " | 
| 32 | 
  | 
  | 
if ( "$<" =~ [yY]* ) then | 
| 33 | 
  | 
  | 
        readvar illumpic | 
| 34 | 
  | 
  | 
        if ( ! -r $illumpic ) then | 
| 35 | 
  | 
  | 
                echo "Cannot read $illumpic" | 
| 36 | 
  | 
  | 
                exit 1 | 
| 37 | 
  | 
  | 
        endif | 
| 38 | 
  | 
  | 
        set title=$illumpic:r | 
| 39 | 
  | 
  | 
        set gotillumpic | 
| 40 | 
  | 
  | 
        goto getgenskyf | 
| 41 | 
  | 
  | 
endif | 
| 42 | 
  | 
  | 
 | 
| 43 | 
greg | 
1.1 | 
readvar octree | 
| 44 | 
greg | 
2.2 | 
if ( $octree == $nofile || ! -f $octree ) then | 
| 45 | 
greg | 
1.6 | 
        echo "You must first create an octree with" | 
| 46 | 
  | 
  | 
        echo "oconv before running this script." | 
| 47 | 
greg | 
1.1 | 
        exit 1 | 
| 48 | 
  | 
  | 
endif | 
| 49 | 
greg | 
1.5 | 
set title="$octree:r" | 
| 50 | 
greg | 
1.2 | 
echo -n "Is the z-axis your zenith direction? " | 
| 51 | 
  | 
  | 
if ( "$<" !~ [yY]* ) then | 
| 52 | 
greg | 
1.1 | 
        echo "I'm sorry, you cannot use this script" | 
| 53 | 
  | 
  | 
        exit 1 | 
| 54 | 
  | 
  | 
endif | 
| 55 | 
  | 
  | 
echo "What is the origin (smallest x y z coordinates) of the workplane?" | 
| 56 | 
  | 
  | 
readvar wporig | 
| 57 | 
  | 
  | 
set wporig=($wporig) | 
| 58 | 
  | 
  | 
echo "What is the x and y size (width and length) of the workplane?" | 
| 59 | 
greg | 
1.2 | 
readvar wpsize | 
| 60 | 
greg | 
1.1 | 
set wpsize=($wpsize) | 
| 61 | 
  | 
  | 
set wpres=(`rcalc -n -e '$1=if(l,'"floor($maxres*$wpsize[1]/$wpsize[2]),$maxres);"'$2=if(l,'"$maxres,floor($maxres*$wpsize[2]/$wpsize[1]));l=$wpsize[2]-$wpsize[1]"`) | 
| 62 | 
  | 
  | 
set rtargs=($rtargs -ar `getinfo -d<$octree|rcalc -e '$1=floor(16*$4/'"($wpsize[1]+$wpsize[2]))"`) | 
| 63 | 
  | 
  | 
echo "What calculation options do you want to give to rtrace?" | 
| 64 | 
greg | 
1.6 | 
echo "(It is very important to set the -a* options correctly.)" | 
| 65 | 
greg | 
1.1 | 
readvar rtargs | 
| 66 | 
greg | 
2.2 | 
echo "Do you want to save the illuminance picture for later runs?" | 
| 67 | 
  | 
  | 
readvar illumpic | 
| 68 | 
  | 
  | 
############ | 
| 69 | 
  | 
  | 
getgenskyf: | 
| 70 | 
  | 
  | 
set genskyf=$nofile | 
| 71 | 
  | 
  | 
echo "In what scene file is the gensky command located?" | 
| 72 | 
  | 
  | 
readvar genskyf | 
| 73 | 
  | 
  | 
if ( $genskyf == $nofile ) then | 
| 74 | 
  | 
  | 
        echo "You will not be able to compute daylight factors" | 
| 75 | 
  | 
  | 
        echo "or energy savings since there is no gensky file." | 
| 76 | 
  | 
  | 
else | 
| 77 | 
  | 
  | 
        xform -e $genskyf > /usr/tmp/gsf$$ | 
| 78 | 
  | 
  | 
        grep '^# gensky ' /usr/tmp/gsf$$ | 
| 79 | 
  | 
  | 
        if ( $status ) then | 
| 80 | 
  | 
  | 
                echo "The file $genskyf does not contain a gensky command\!" | 
| 81 | 
  | 
  | 
                rm -f /usr/tmp/gsf$$ | 
| 82 | 
  | 
  | 
                goto getgenskyf | 
| 83 | 
  | 
  | 
        endif | 
| 84 | 
  | 
  | 
        set title=$title\ `sed -n 's/^# gensky  *\([0-9][0-9]*  *[0-9][0-9]*  *[0-9][0-9.]*\).*$/\1/p' /usr/tmp/gsf$$` | 
| 85 | 
  | 
  | 
        set extamb=`sed -n 's/^# Ground ambient level: //p' /usr/tmp/gsf$$` | 
| 86 | 
  | 
  | 
        grep -s '^# gensky .* -c' /usr/tmp/gsf$$ | 
| 87 | 
  | 
  | 
        set nodaysav=$status | 
| 88 | 
  | 
  | 
        rm -f /usr/tmp/gsf$$ | 
| 89 | 
  | 
  | 
        if ( $nodaysav ) then | 
| 90 | 
  | 
  | 
                echo "The gensky command was not done for an overcast sky" | 
| 91 | 
  | 
  | 
                echo "(-c option), so energy savings cannot be calculated." | 
| 92 | 
  | 
  | 
                echo -n "Continue anyway? " | 
| 93 | 
  | 
  | 
                if ( "$<" =~ [nN]* ) then | 
| 94 | 
  | 
  | 
                        exit 0 | 
| 95 | 
  | 
  | 
                endif | 
| 96 | 
  | 
  | 
        endif | 
| 97 | 
  | 
  | 
endif | 
| 98 | 
greg | 
1.1 | 
echo "Illuminance contour picture if you want one" | 
| 99 | 
  | 
  | 
readvar ilpict | 
| 100 | 
  | 
  | 
if ( $?extamb ) then | 
| 101 | 
  | 
  | 
        echo "Daylight factor contour picture if you want one" | 
| 102 | 
  | 
  | 
        readvar dfpict | 
| 103 | 
  | 
  | 
endif | 
| 104 | 
greg | 
2.2 | 
if ( ! $nodaysav ) then | 
| 105 | 
  | 
  | 
        echo "Energy savings contour picture if you want one" | 
| 106 | 
  | 
  | 
        readvar dspict | 
| 107 | 
  | 
  | 
        if ( $dspict != $nofile ) then | 
| 108 | 
  | 
  | 
                echo "Workplane design level (lux)" | 
| 109 | 
  | 
  | 
                readvar designlvl | 
| 110 | 
  | 
  | 
        endif | 
| 111 | 
  | 
  | 
endif | 
| 112 | 
  | 
  | 
if ( $ilpict == $nofile && $dfpict == $nofile && $dspict == $nofile ) then | 
| 113 | 
greg | 
1.1 | 
        echo "Since you don't want any output, I guess we're done." | 
| 114 | 
  | 
  | 
        exit 0 | 
| 115 | 
  | 
  | 
endif | 
| 116 | 
greg | 
1.5 | 
echo "Title for output picture" | 
| 117 | 
  | 
  | 
readvar title | 
| 118 | 
greg | 
1.9 | 
set sctemp=/usr/tmp/sc$$.csh | 
| 119 | 
greg | 
1.4 | 
cat <<'_EOF_' > $sctemp | 
| 120 | 
greg | 
2.2 | 
if ( $illumpic != $nofile ) then | 
| 121 | 
  | 
  | 
        set iltemp="" | 
| 122 | 
  | 
  | 
else | 
| 123 | 
  | 
  | 
        set iltemp=/usr/tmp/il$$.pic | 
| 124 | 
  | 
  | 
        set illumpic=$iltemp | 
| 125 | 
  | 
  | 
endif | 
| 126 | 
greg | 
1.5 | 
set tltemp=/usr/tmp/tl$$.pic | 
| 127 | 
greg | 
2.2 | 
set dstemp=/usr/tmp/ds$$.pic | 
| 128 | 
  | 
  | 
set temp1=/usr/tmp/tfa$$ | 
| 129 | 
  | 
  | 
set tempfiles=($iltemp $sctemp $tltemp $dstemp $temp1) | 
| 130 | 
greg | 
1.4 | 
echo "Your dayfact job is finished." | 
| 131 | 
  | 
  | 
echo "Please check for error messages below." | 
| 132 | 
  | 
  | 
echo "" | 
| 133 | 
  | 
  | 
set echo | 
| 134 | 
greg | 
2.2 | 
if ( ! $?gotillumpic ) then | 
| 135 | 
  | 
  | 
        cnt $wpres[2] $wpres[1] \ | 
| 136 | 
greg | 
1.2 | 
        | rcalc -e '$1=($2+.5)/'"$wpres[1]*$wpsize[1]+$wporig[1]" \ | 
| 137 | 
  | 
  | 
                -e '$2=(1-($1+.5)/'"$wpres[2])*$wpsize[2]+$wporig[2]" \ | 
| 138 | 
  | 
  | 
                -e '$3='"$wporig[3]" -e '$4=0;$5=0;$6=1' \ | 
| 139 | 
greg | 
1.8 | 
        | rtrace $rtargs -h+ -I+ -ov -faf $octree \ | 
| 140 | 
greg | 
2.2 | 
        | pvalue -r -y $wpres[2] +x $wpres[1] -df > $temp1 | 
| 141 | 
  | 
  | 
        pfilt -h 20 -n 0 -x 300 -y 300 -p 1 -r 1 $temp1 > $illumpic | 
| 142 | 
  | 
  | 
endif | 
| 143 | 
  | 
  | 
set maxval=`getinfo < $illumpic | rcalc -i 'EXPOSURE=${e}' -e '$1=3/e'` | 
| 144 | 
  | 
  | 
psign -h 42 " $title " | pfilt -1 -x /2 -y /2 > $tltemp | 
| 145 | 
greg | 
1.4 | 
'_EOF_' | 
| 146 | 
greg | 
2.2 | 
if ( $ilpict != $nofile ) then | 
| 147 | 
  | 
  | 
        echo 'falsecolor -cb -l Lux -s "$maxval*179" \\ | 
| 148 | 
  | 
  | 
                $fcopts -m 179 -ip $illumpic \\ | 
| 149 | 
greg | 
1.5 | 
                | pcompos -a 1 - $tltemp > $ilpict' >> $sctemp | 
| 150 | 
greg | 
1.1 | 
endif | 
| 151 | 
greg | 
2.2 | 
if ( $dfpict != $nofile ) then | 
| 152 | 
  | 
  | 
        echo 'falsecolor -cb -l DF -s 50 \\ | 
| 153 | 
  | 
  | 
                $fcopts -m "100/PI/$extamb" -ip $illumpic \\ | 
| 154 | 
greg | 
1.5 | 
                | pcompos -a 1 - $tltemp > $dfpict' >> $sctemp | 
| 155 | 
greg | 
2.2 | 
endif | 
| 156 | 
  | 
  | 
if ( $dspict != $nofile ) then | 
| 157 | 
  | 
  | 
        echo 'pcomb -e "lo=1-$designlvl/20000*3.1416*$extamb/li(1)" \\ | 
| 158 | 
  | 
  | 
                -o $illumpic | falsecolor -cb -l "%Save" -s 100 \\ | 
| 159 | 
  | 
  | 
                $fcopts -m 100 -p $illumpic \\ | 
| 160 | 
  | 
  | 
                | pcompos -a 1 - $tltemp > $dspict' >> $sctemp | 
| 161 | 
greg | 
1.1 | 
endif | 
| 162 | 
greg | 
1.4 | 
echo 'rm -f $tempfiles' >> $sctemp | 
| 163 | 
  | 
  | 
(source $sctemp) |& mail `whoami` & | 
| 164 | 
  | 
  | 
echo "Your job is started in the background." | 
| 165 | 
greg | 
1.6 | 
echo "You will be notified by mail when it is done." |