Added original CSH script from HEAD-20110409.
authorAxel Jacobs <axel@jaloxa.eu>
Sat, 09 Apr 2011 17:55:16 +0100
changeset 0 0aa115157c9c
child 1 869909d14a39
Added original CSH script from HEAD-20110409.
orig/anim.csh
orig/anim2.csh
orig/colorcal.csh
orig/compamb.csh
orig/dayfact.csh
orig/debugcal.csh
orig/falsecolor.csh
orig/fieldcomb.csh
orig/genambpos.csh
orig/genbackg.csh
orig/genpine.csh
orig/genwindow.csh
orig/glare.csh
orig/glaze.csh
orig/help2roff.csh
orig/illumcal.csh
orig/ivpict.csh
orig/ivprep.csh
orig/makeall.csh
orig/markpath.csh
orig/mkhtmlman.csh
orig/normpat.csh
orig/objline.csh
orig/objpict.csh
orig/objview.csh
orig/optics2rad.csh
orig/pacuity.csh
orig/pbilat.csh
orig/pdelta.csh
orig/pdfblur.csh
orig/pgblur.csh
orig/phisteq.csh
orig/phisto.csh
orig/pmblur.csh
orig/pmdblur.csh
orig/psquish.csh
orig/pveil.csh
orig/ra_pfm.csh
orig/raddepend.csh
orig/ran2tiff.csh
orig/reinhard.csh
orig/rlux.csh
orig/runscript.csh
orig/tradinstall.csh
orig/vinfo.csh
orig/vlpic.csh
orig/xyzimage.csh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/anim.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,18 @@
+#!/bin/csh
+
+set tempfile=/usr/tmp/pict.$$
+set destfile=~/ray/spool/anim/model
+set sunrise=6
+set sunset=18
+set nframes=12
+set i=0
+while ($i < $nframes)
+	oconv -i model.dark.oct "\!gensky 6 17 `ev $sunrise+\($sunset-$sunrise\)\*$i/$nframes` | xform -rz -90 -rx -90" skywindow \
+	| rpict -vp 8 36 -27 -vd -.56 -.23 .79 -vu 0 1 0 -vh 39.9 -vv 27.5 \
+		-x 300 -y 203 -ps 1 -ab 1 -ad 32 -ar 64 -ds .5 \
+		-t 3600 -e model.day.err \
+	| pfilt -1 -x 300 -y 203 -e 1.5 > $tempfile
+	ra_pr $tempfile $destfile.$i
+	rm $tempfile
+	@ i++
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/anim2.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,16 @@
+#!/bin/csh
+
+set tempfile=/usr/tmp/pict.$$
+set destdir=/usr2/greg/ras/anim/model2
+set nframes=$1
+mkdir $destdir
+set i=0
+while ($i < $nframes)
+	set view=(`ev $i/$nframes\*6.28 | rcalc -f anim2.cal`)
+	rpict -vp $view[1-3] -vd $view[4-6] -vu 0 1 0 -vh 38 -vv 30 \
+		-x 512 -y 400 -t 3600 -e anim2.err model.oct \
+	| pfilt -1 -x 512 -y 400 -e -2 > $tempfile
+	ra_pr $tempfile $destdir/$i
+	rm $tempfile
+	@ i++
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/colorcal.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,38 @@
+#!/bin/csh -f
+# RCSid: $Id: colorcal.csh,v 1.1 2003/02/22 02:07:21 greg Exp $
+#
+# Compute CIE chromaticities from spectral reflectance data
+#
+if ( $#argv < 1 ) goto userr
+set cal = .
+if ( $argv[1] == "-i" ) then
+	if ( $#argv < 3 ) goto userr
+	shift argv
+	set illum=$argv[1]
+	shift argv
+	foreach r ( $argv[*] )
+		tabfunc -i rf < $r > /tmp/rf$$.cal
+		rcalc -f $cal/cieresp.cal -f /tmp/rf$$.cal \
+			-e 'r=rf($1);ty=$2*triy($1)' \
+			-e '$1=ty;$2=$2*r*trix($1);$3=r*ty' \
+			-e '$4=$2*r*triz($1)' \
+			-e 'cond=if($1-359,831-$1,-1)' \
+			$illum | total -m >> /tmp/rc$$.dat
+	end
+	rm -f /tmp/rf$$.cal
+else
+	foreach r ( $argv[*] )
+		rcalc -f $cal/cieresp.cal -e 'ty=triy($1);$1=ty' \
+		-e '$2=$2*trix($1);$3=$2*ty;$4=$2*triz($1)' \
+		-e 'cond=if($1-359,831-$1,-1)' $r \
+			| total -m >> /tmp/rc$$.dat
+	end
+endif
+rcalc -e 'X=$2/$1;Y=$3/$1;Z=$4/$1' \
+	-e 'x=X/(X+Y+Z);y=Y/(X+Y+Z);u=4*X/(X+15*Y+3*Z);v=9*Y/(X+15*Y+3*Z)' \
+	-o $cal/color.fmt /tmp/rc$$.dat
+rm -f /tmp/rc$$.dat
+exit 0
+userr:
+echo "Usage: $0 [-i illum.dat] refl.dat .."
+exit 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/compamb.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,47 @@
+#!/bin/csh -f
+# RCSid: $Id: compamb.csh,v 3.7 2008/08/25 04:50:32 greg Exp $
+#
+# Compute best ambient value for a scene and append to rad input file
+#
+while ( $#argv > 1 )
+	switch ( $argv[1] )
+	case -e:
+		set doexpos
+		breaksw
+	case -c:
+		set docolor
+		breaksw
+	default:
+		goto userr
+	endsw
+	shift argv
+end
+userr:
+if ( $#argv != 1 ) then
+	echo Usage: $0 [-e][-c] rad_input_file
+	exit 1
+endif
+onintr quit
+set td=`mktemp -d /tmp/ca.XXXXXX`
+set tf=$td/compamb
+set oct=`rad -w -s -e -v 0 $argv[1] QUA=High AMB=$tf.amb OPT=$tf.opt | sed -n 's/^OCTREE= //p'`
+rad -n -s -V $argv[1] \
+	| rpict @$tf.opt -av 0 0 0 -aw 16 -dv- -S 1 -x 16 -y 16 -ps 1 $oct \
+	| ra_rgbe - '\!pvalue -h -H -d' > $tf.dat
+echo \# Rad input file modified by $0 `date` >> $argv[1]
+if ( $?doexpos ) then
+	(echo -n 'EXPOSURE= '; \
+		total -u $tf.dat | rcalc -e '$1=2/(.265*$1+.670*$2+.065*$3)') \
+		>> $argv[1]
+endif
+lookamb -h -d $tf.amb | rcalc -e '$1=$10;$2=$11;$3=$12' >> $tf.dat
+set lavg=`rcalc -e '$1=lum;lum=.265*$1+.670*$2+.065*$3;cond=lum-1e-5' $tf.dat | total -m -p`
+if ( $?docolor ) then
+	set cavg=(`total -m $tf.dat`)
+	set av=(`rcalc -n -e "r=$cavg[1];g=$cavg[2];b=$cavg[3];sf=$lavg/(.265*r+.670*g+.065*b)" -e '$1=sf*r;$2=sf*g;$3=sf*b'`)
+else
+	set av=($lavg $lavg $lavg)
+endif
+echo "render= -av $av" >> $argv[1]
+quit:
+exec rm -r $td
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/dayfact.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,166 @@
+#!/bin/csh -f
+# RCSid: $Id: dayfact.csh,v 2.9 2008/11/10 19:08:19 greg Exp $
+#
+# Interactive script to calculate daylight factors
+#
+set nofile="none"
+set illumpic=$nofile
+set octree=$nofile
+set dfpict=$nofile
+set ilpict=$nofile
+set dspict=$nofile
+set nodaysav=1
+set fcopts=($*)
+set designlvl=500
+set wporig=(0 0 0)
+set wpsize=(1 1)
+set rtargs=(-ab 1 -ad 256 -as 128 -aa .15 -av .3 .3 .3)
+set maxres=128
+set td=`mktemp -d /tmp/df.XXXXXX`
+
+alias readvar 'echo -n Enter \!:1 "[$\!:1]: ";set ans="$<";if("$ans" != "")set \!:1="$ans"'
+
+cat <<_EOF_
+			DAYLIGHT FACTOR CALCULATION
+
+This script calculates daylight factors, illuminance levels, and/or
+energy savings due to daylight on a rectangular workplane and produces
+a contour plot from the result.  The input is a Radiance scene description
+(and octree) and the output is one or more color Radiance pictures.
+
+_EOF_
+echo "Have you already calculated an illuminance picture using dayfact?"
+readvar illumpic
+if ( $illumpic != $nofile ) then
+	if ( ! -r $illumpic ) then
+		echo "Cannot read $illumpic"
+		exit 1
+	endif
+	set title=$illumpic:r
+	set gotillumpic
+	goto getgenskyf
+endif
+
+readvar octree
+if ( $octree == $nofile || ! -f $octree ) then
+	echo "You must first create an octree with"
+	echo "oconv before running this script."
+	exit 1
+endif
+set title="$octree:r"
+echo -n "Is the z-axis your zenith direction? "
+if ( "$<" !~ [yY]* ) then
+	echo "I'm sorry, you cannot use this script"
+	exit 1
+endif
+echo "What is the origin (smallest x y z coordinates) of the workplane?"
+readvar wporig
+set wporig=($wporig)
+echo "What is the x and y size (width and length) of the workplane?"
+readvar wpsize
+set wpsize=($wpsize)
+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]"`)
+set rtargs=($rtargs -ar `getinfo -d<$octree|rcalc -e '$1=floor(16*$4/'"($wpsize[1]+$wpsize[2]))"`)
+echo "What calculation options do you want to give to rtrace?"
+echo "(It is very important to set the -a* options correctly.)"
+readvar rtargs
+echo "Do you want to save the illuminance picture for later runs?"
+readvar illumpic
+############
+getgenskyf:
+set genskyf=$nofile
+echo "In what scene file is the gensky command located?"
+readvar genskyf
+if ( $genskyf == $nofile ) then
+	echo "You will not be able to compute daylight factors"
+	echo "or energy savings since there is no gensky file."
+else
+	xform -e $genskyf > $td/gsf
+	grep '^# gensky ' $td/gsf
+	if ( $status ) then
+		echo "The file $genskyf does not contain a gensky command\!"
+		rm -f $td/gsf
+		goto getgenskyf
+	endif
+	set title=$title\ `sed -n 's/^# gensky  *\([0-9][0-9]*  *[0-9][0-9]*  *[0-9][0-9.]*\).*$/\1/p' $td/gsf`
+	set extamb=`sed -n 's/^# Ground ambient level: //p' $td/gsf`
+	grep -s '^# gensky .* -c' $td/gsf
+	set nodaysav=$status
+	rm -f $td/gsf
+	if ( $nodaysav ) then
+		echo "The gensky command was not done for an overcast sky"
+		echo "(-c option), so energy savings cannot be calculated."
+		echo -n "Continue anyway? "
+		if ( "$<" =~ [nN]* ) then
+			exit 0
+		endif
+	endif
+endif
+echo "Illuminance contour picture if you want one"
+readvar ilpict
+if ( $?extamb ) then
+	echo "Daylight factor contour picture if you want one"
+	readvar dfpict
+endif
+if ( ! $nodaysav ) then
+	echo "Energy savings contour picture if you want one"
+	readvar dspict
+	if ( $dspict != $nofile ) then
+		echo "Workplane design level (lux)"
+		readvar designlvl
+	endif
+endif
+if ( $ilpict == $nofile && $dfpict == $nofile && $dspict == $nofile ) then
+	echo "Since you don't want any output, I guess we're done."
+	exit 0
+endif
+echo "Title for output picture"
+readvar title
+set sctemp=$td/sc.csh
+cat <<'_EOF_' > $sctemp
+if ( $illumpic != $nofile ) then
+	set iltemp=""
+else
+	set iltemp=$td/il.hdr
+	set illumpic=$iltemp
+endif
+set tltemp=$td/tl.hdr
+set dstemp=$td/ds.hdr
+set temp1=$td/tfa
+echo "Your dayfact job is finished."
+echo "Please check for error messages below."
+echo ""
+set echo
+if ( ! $?gotillumpic ) then
+	cnt $wpres[2] $wpres[1] \
+	| rcalc -e '$1=($2+.5)/'"$wpres[1]*$wpsize[1]+$wporig[1]" \
+		-e '$2=(1-($1+.5)/'"$wpres[2])*$wpsize[2]+$wporig[2]" \
+		-e '$3='"$wporig[3]" -e '$4=0;$5=0;$6=1' \
+	| rtrace $rtargs -h+ -I+ -ov -fac -x $wpres[1] -y $wpres[2] $octree \
+	> $temp1
+	pfilt -h 20 -n 0 -x 300 -y 300 -p 1 -r 1 $temp1 > $illumpic
+endif
+set maxval=`getinfo < $illumpic | rcalc -i 'EXPOSURE=${e}' -e '$1=3/e'`
+if ("$maxval" == "") set maxval=3
+psign -h 42 " $title " | pfilt -1 -x /2 -y /2 > $tltemp
+'_EOF_'
+if ( $ilpict != $nofile ) then
+	echo 'falsecolor -cb -l Lux -s "$maxval*179" \\
+		$fcopts -m 179 -ip $illumpic \\
+		| pcompos -a 1 - $tltemp > $ilpict' >> $sctemp
+endif
+if ( $dfpict != $nofile ) then
+	echo 'falsecolor -cb -l DF -s 16 \\
+		$fcopts -m "100/PI/$extamb" -ip $illumpic \\
+		| pcompos -a 1 - $tltemp > $dfpict' >> $sctemp
+endif
+if ( $dspict != $nofile ) then
+	echo 'pcomb -e "lo=1-$designlvl/20000*3.1416*$extamb/li(1)" \\
+		-o $illumpic | falsecolor -cb -l "%Save" -s 100 \\
+		$fcopts -m 100 -p $illumpic \\
+		| pcompos -a 1 - $tltemp > $dspict' >> $sctemp
+endif
+echo 'rm -r $td' >> $sctemp
+(source $sctemp) |& mail `whoami` &
+echo "Your job is started in the background."
+echo "You will be notified by mail when it is done."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/debugcal.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,33 @@
+#!/bin/csh -f
+# RCSid: $Id: debugcal.csh,v 2.6 2003/02/22 02:07:30 greg Exp $
+#
+# Script to debug cal files for Radiance
+#
+# Takes octree and rcalc options as arguments.
+# One of the rcalc options should be -f calfile.
+# Note that the real arguments A1, A2, etc must also be given.
+# Input is a ray origin and direction, such as that produced by ximage.
+#
+if ( $#argv < 2 ) then
+	echo "Usage: $0 octree [rcalc options]"
+	exit 1
+endif
+if ( ! $?RAYPATH ) then
+	set RAYPATH=.:/usr/local/lib/ray
+endif
+set initfile=
+foreach d (`echo $RAYPATH | sed 's/:/ /g'`)
+	if ( -r $d/rayinit.cal ) then
+		set initfile="-f $d/rayinit.cal"
+		break
+	endif
+end
+
+rtrace -h- -x 1 -odNplL $1 | rcalc -u -e 'Dx=$1;Dy=$2;Dz=$3' \
+		-e 'Nx=$4;Ny=$5;Nz=$6;Px=$7;Py=$8;Pz=$9' \
+		-e 'T=$10;Ts=$11' -e 'S:1;Tx:0;Ty:0;Tz:0' \
+		-e 'Ix:1;Iy:0;Iz:0;Jx:0;Jy:1;Jz:0;Kx:0;Ky:0;Kz:1' \
+		-e 'Rdot=-Dx*Nx-Dy*Ny-Dz*Nz' -e 'RdotP=Rdot' \
+		-e 'NxP=Nx;NyP=Ny;NzP=Nz' -e 'CrP=A1;CgP=A2;CbP=A3' \
+		-e 'DxA:0;DyA:0;DzA:0' \
+		$initfile $argv[2-]:q
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/falsecolor.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,227 @@
+#!/bin/csh -fe
+# RCSid: $Id: falsecolor.csh,v 2.19 2008/11/10 19:08:19 greg Exp $
+#
+# Create false color image with legend
+#
+# Added user-definable legend 2004/01/20 Rob Guglielmetti
+
+onintr quit
+set td=`mktemp -d /tmp/fc.XXXXXX`
+set mult=179
+set label=Nits
+set scale=1000
+set decades=0
+set redv='def_red(v)'
+set grnv='def_grn(v)'
+set bluv='def_blu(v)'
+set ndivs=8
+set picture='-'
+set cpict=
+set loff=0
+set legwidth=100
+set legheight=200
+while ($#argv > 0)
+	switch ($argv[1])
+	case -lw:
+		shift argv
+		set legwidth="$argv[1]"
+		breaksw
+	case -lh:
+		shift argv
+		set legheight="$argv[1]"
+		breaksw
+	case -m:
+		shift argv
+		set mult="$argv[1]"
+		breaksw
+	case -s:
+		shift argv
+		set scale="$argv[1]"
+		if ("$scale" =~ [aA]*) set needfile
+		breaksw
+	case -l:
+		shift argv
+		set label="$argv[1]"
+		breaksw
+	case -log:
+		shift argv
+		set decades=$argv[1]
+		breaksw
+	case -r:
+		shift argv
+		set redv="$argv[1]"
+		breaksw
+	case -g:
+		shift argv
+		set grnv="$argv[1]"
+		breaksw
+	case -b:
+		shift argv
+		set bluv="$argv[1]"
+		breaksw
+	case -spec:
+		set redv='1.6*v-.6'
+		set grnv='if(v-.375,1.6-1.6*v,8/3*v)'
+		set bluv='1-8/3*v'
+		breaksw
+	case -i:
+		shift argv
+		set picture="$argv[1]"
+		breaksw
+	case -p:
+		shift argv
+		set cpict="$argv[1]"
+		breaksw
+	case -ip:
+	case -pi:
+		shift argv
+		set picture="$argv[1]"
+		set cpict="$argv[1]"
+		breaksw
+	case -cl:
+		set docont=a
+		set loff=12
+		breaksw
+	case -cb:
+		set docont=b
+		set loff=13
+		breaksw
+	case -e:
+		set doextrem
+		set needfile
+		breaksw
+	case -n:
+		shift argv
+		set ndivs="$argv[1]"
+		breaksw
+	default:
+		echo bad option "'$argv[1]'"
+		exit 1
+	endsw
+	shift argv
+end
+if ($?needfile && "$picture" == '-') then
+	cat > $td/picture
+	set picture=$td/picture
+endif
+if ("$scale" =~ [aA]*) then
+	set LogLmax=`phisto $picture | tail -2 | sed -n '1s/	[0-9]*$//p'`
+	set scale=`ev "$mult/179*10^$LogLmax"`
+endif
+cat > $td/pc0.cal <<_EOF_
+PI : 3.14159265358979323846 ;
+scale : $scale ;
+mult : $mult ;
+ndivs : $ndivs ;
+
+or(a,b) : if(a,a,b);
+EPS : 1e-7;
+neq(a,b) : if(a-b-EPS,1,b-a-EPS);
+btwn(a,x,b) : if(a-x,-1,b-x);
+clip(x) : if(x-1,1,if(x,x,0));
+frac(x) : x - floor(x);
+boundary(a,b) : neq(floor(ndivs*a+.5),floor(ndivs*b+.5));
+
+interp_arr2(i,x,f):(i+1-x)*f(i)+(x-i)*f(i+1);
+interp_arr(x,f):if(x-1,if(f(0)-x,interp_arr2(floor(x),x,f),f(f(0))),f(1));
+def_redp(i):select(i,0.18848,0.05468174,
+0.00103547,8.311144e-08,7.449763e-06,0.0004390987,0.001367254,
+0.003076,0.01376382,0.06170773,0.1739422,0.2881156,0.3299725,
+0.3552663,0.372552,0.3921184,0.4363976,0.6102754,0.7757267,
+0.9087369,1,1,0.9863);
+def_red(x):interp_arr(x/0.0454545+1,def_redp);
+def_grnp(i):select(i,0.0009766,2.35501e-05,
+0.0008966244,0.0264977,0.1256843,0.2865799,0.4247083,0.4739468,
+0.4402732,0.3671876,0.2629843,0.1725325,0.1206819,0.07316644,
+0.03761026,0.01612362,0.004773749,6.830967e-06,0.00803605,
+0.1008085,0.3106831,0.6447838,0.9707);
+def_grn(x):interp_arr(x/0.0454545+1,def_grnp);
+def_blup(i):select(i,0.2666,0.3638662,0.4770437,
+0.5131397,0.5363797,0.5193677,0.4085123,0.1702815,0.05314236,
+0.05194055,0.08564082,0.09881395,0.08324373,0.06072902,
+0.0391076,0.02315354,0.01284458,0.005184709,0.001691774,
+2.432735e-05,1.212949e-05,0.006659406,0.02539);
+def_blu(x):interp_arr(x/0.0454545+1,def_blup);
+
+isconta = if(btwn(0,v,1),or(boundary(vleft,vright),boundary(vabove,vbelow)),-1);
+iscontb = if(btwn(0,v,1),btwn(.4,frac(ndivs*v),.6),-1); 
+
+ra = 0;
+ga = 0;
+ba = 0;
+
+in = 1;
+
+ro = if(in,clip($redv),ra);
+go = if(in,clip($grnv),ga);
+bo = if(in,clip($bluv),ba);
+_EOF_
+cat > $td/pc1.cal <<_EOF_
+norm : mult/scale/le(1);
+
+v = map(li(1)*norm);
+
+vleft = map(li(1,-1,0)*norm);
+vright = map(li(1,1,0)*norm);
+vabove = map(li(1,0,1)*norm);
+vbelow = map(li(1,0,-1)*norm);
+
+map(x) = x;
+
+ra = ri(nfiles);
+ga = gi(nfiles);
+ba = bi(nfiles);
+_EOF_
+set pc0args=(-f $td/pc0.cal)
+set pc1args=(-f $td/pc1.cal)
+if ($?docont) then
+	set pc0args=($pc0args -e "in=iscont$docont")
+endif
+if ("$cpict" == "") then
+	set pc1args=($pc1args -e 'ra=0;ga=0;ba=0')
+else if ("$cpict" == "$picture") then
+	set cpict=
+endif
+if ("$decades" != "0") then
+	set pc1args=($pc1args -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)")
+	set imap="imap(y)=10^((y-1)*$decades)"
+else
+	set imap="imap(y)=y"
+endif
+if ( $legwidth > 20 && $legheight > 40 ) then
+pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v' \
+		-e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres' \
+		-x $legwidth -y $legheight > $td/scol.hdr
+( echo "$label"; cnt $ndivs \
+		| rcalc -e '$1='"($scale)*imap(($ndivs-.5-"'$1'")/$ndivs)" \
+		-e "$imap" | sed -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/' ) \
+	| psign -s -.15 -cf 1 1 1 -cb 0 0 0 \
+		-h `ev "floor($legheight/$ndivs+.5)"` > $td/slab.hdr
+else
+	set legwidth=0
+	set legheight=0
+	(echo "" ; echo "-Y 1 +X 1" ; echo "aaa" ) > $td/scol.hdr
+	cp $td/scol.hdr $td/slab.hdr
+endif
+if ( $?doextrem ) then
+	pextrem -o $picture > $td/extrema
+	set minpos=`sed 2d $td/extrema | rcalc -e '$2=$2;$1=$1+'"$legwidth"`
+	set minval=`rcalc -e '$1=($3*.27+$4*.67+$5*.06)*'"$mult" $td/extrema | sed -e 2d -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/'`
+	set maxpos=`sed 1d $td/extrema | rcalc -e '$2=$2;$1=$1+'"$legwidth"`
+	set maxval=`rcalc -e '$1=($3*.27+$4*.67+$5*.06)*'"$mult" $td/extrema | sed -e 1d -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/'`
+	psign -s -.15 -a 2 -h 16 $minval > $td/minv.hdr
+	psign -s -.15 -a 2 -h 16 $maxval > $td/maxv.hdr
+	pcomb $pc0args $pc1args $picture $cpict \
+		| pcompos $td/scol.hdr 0 0 \
+			+t .1 "\!pcomb -e 'lo=1-gi(1)' $td/slab.hdr" \
+			`ev 2 $loff-1` -t .5 $td/slab.hdr 0 $loff \
+		  - $legwidth 0 $td/minv.hdr $minpos $td/maxv.hdr $maxpos
+else
+	pcomb $pc0args $pc1args $picture $cpict \
+		| pcompos $td/scol.hdr 0 0 \
+			+t .1 "\!pcomb -e 'lo=1-gi(1)' $td/slab.hdr" \
+			`ev 2 $loff-1` -t .5 $td/slab.hdr 0 $loff \
+			- $legwidth 0
+endif
+quit:
+rm -rf $td
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/fieldcomb.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,81 @@
+#!/bin/csh -f
+# RCSid $Id: fieldcomb.csh,v 2.7 2008/11/10 19:08:19 greg Exp $
+#
+# Combine alternate lines in full frames for field rendering
+#
+# Expects numbered frames on command line, as given by ranimate
+#
+# If an odd number of frames is provided, the spare frame at the
+# end is linked to $spare_name for the next run
+#
+# Written by Greg Ward for Iebele Abel in August 2005
+#
+set spare_name=spare_fieldcomb_frame.hdr
+set odd_first=0
+while ($#argv > 1)
+	switch ($argv[1])
+	case -r*:
+		set remove_orig
+		breaksw
+	case -o*:
+		set odd_first=1
+		breaksw
+	case -e*:
+		set odd_first=0
+		breaksw
+	case -f*:
+		shift argv
+		set outfile="$argv[1]"
+		breaksw
+	default:
+		if ("$argv[1]" !~ -*) break
+		echo "Unknown option: $argv[1]"
+		exit 1
+	endsw
+	shift argv
+end
+if ($#argv < 2) then
+	echo "Usage: $0 [-e|-o][-r] [-f combined.hdr] field1.hdr field2.hdr .."
+	exit 1
+endif
+if ($?outfile && $#argv > 2) then
+	echo "Cannot use -f option with more than two input files"
+	exit 1
+endif
+set f1=$argv[1]:q
+set ext=$f1:e
+set basenm="`echo $f1:q | sed 's/[0-9]*\.'$ext'//'`"
+set curfi=`echo $f1:q | sed 's/^[^1-9]*\(.[0-9]*\)\.'$ext'$/\1/'`
+set fields=($argv[*]:q)
+if (-r $spare_name) then
+	set fields=($spare_name $fields:q)
+	@ curfi--
+endif
+@ curfr = $curfi / 2
+set curfi=1
+while ($curfi < $#fields)
+	@ nextfi = $curfi + 1
+	if ($curfr < 10) then
+		set fid=000$curfr
+	else if ($curfr < 100) then
+		set fid=00$curfr
+	else if ($curfr < 1000) then
+		set fid=0$curfr
+	else
+		set fid=$curfr
+	endif
+       	set outf="${basenm}C$fid.$ext"
+	if ($?outfile) then
+		set outf=$outfile:q
+	endif
+	pcomb -e 'ro=ri(fld); go=gi(fld); bo=bi(fld)' \
+		-e 'yd=yres-1-y; odd=.5*yd-floor(.5*yd)-.25' \
+		-e "fld=if(odd,2-$odd_first,1+$odd_first)" \
+		$fields[$curfi]:q $fields[$nextfi]:q \
+		> $outf:q
+	if ($?remove_orig) rm $fields[$curfi]:q $fields[$nextfi]:q
+	@ curfr++
+	@ curfi = $nextfi + 1
+end
+rm -f $spare_name
+if ($curfi == $#fields) ln "${basenm}$curfi.$ext" $spare_name
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/genambpos.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,100 @@
+#!/bin/csh -f
+# RCSid $Id: genambpos.csh,v 3.2 2004/05/17 16:35:14 greg Exp $
+
+# Mark ambient locations 
+#
+# John Mardaljevic                     
+# Institute of Energy and Sustainable Development
+# De Montfort University
+# The Gateway
+# Leicester
+# LE1 9BH, UK
+# +44 (0) 116 257 7972   
+# +44 (0) 116 257 7981 (fax)
+# 
+# jm@dmu.ac.uk   
+# http://www.iesd.dmu.ac.uk/~jm
+
+
+
+set ambdat=none
+set radius=0.05
+
+alias readvar 'echo -n Enter \!:1 "[$\!:1]: ";set ans="$<";if("$ans" != "")set \!:1="$ans"'
+
+cat <<_EOF_
+
+            CREATE SCENE DESCRIPTION MARKERS FOR
+                 AMBIENT SAMPLING LOCATIONS
+
+This script puts coloured markers (spheres) at points where hemispherical
+sampling was initiated.  The locations and levels are taken from the binary
+ambient file.  The levels are colour coded -
+
+       Level 0 = red
+       Level 1 = green
+       Level 2 = blue
+       Level 3 = yellow
+       Level 4 = cyan
+       Level 5 = magenta
+       Level 6 = pink 
+
+To view the locations, include the file "amb_pos.rad" when re-creating
+the octree.
+
+_EOF_
+
+rm -f amb_pos.rad
+
+echo "Input ambient file"
+readvar ambdat
+
+echo "Input marker sphere radius"
+readvar radius
+
+getinfo $ambdat
+lookamb -d -h $ambdat > af$$.tmp
+
+set red=(1 0 0 1 0 1 1)
+set grn=(0 1 0 1 1 0 0.5)
+set blu=(0 0 1 0 1 1 0.5)
+
+foreach j (1 2 3 4 5 6 7)
+
+@ i = $j - 1
+
+rcalc -e 'cond=eq($7,'"$i"');eq(a,b)=if(a-b+1e-7,b-a+1e-7,-1);$1=$1;$2=$2;$3=$3' af$$.tmp > amb_pos_lev$i
+
+set empt=`wc -l < amb_pos_lev$i`
+
+if ($empt !~ 0) then
+
+echo "$empt ambient locations for level $i"
+
+cat > sph_lev$i.fmt << _EOF_
+
+mat_lev$i sphere sph_lev$i.\${recno}
+0
+0
+4     \${ x1 } \${ y1 } \${ z1 }     $radius
+_EOF_
+
+cat >> amb_pos.rad << _EOF_
+void plastic mat_lev$i
+0
+0
+5   $red[$j]  $grn[$j]   $blu[$j]   0    0
+
+!rcalc -e 'x1=\$1;y1=\$2;z1=\$3' -o sph_lev$i.fmt amb_pos_lev$i
+
+_EOF_
+
+else
+
+rm amb_pos_lev$i
+
+endif
+
+end  
+
+rm af$$.tmp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/genbackg.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,157 @@
+#!/bin/csh -f
+# RCSid: $Id: genbackg.csh,v 2.2 2008/08/25 04:50:32 greg Exp $
+#
+# Generate height field to surround a mesh with an irregular border
+#
+#	4/16/2002	Greg Ward
+#
+if ( $#argv < 3 ) goto userr
+# Get arguments
+set mat = $1
+set nam = $2
+set mesh = $3
+# Get options
+set smooth=""
+set i = 4
+while ( $i <= $#argv )
+	switch ($argv[$i])
+	case -c:
+		@ i++ ; set a=$i
+		@ i++ ; set b=$i
+		@ i++ ; set c=$i
+		set c00=($argv[$a] $argv[$b] $argv[$c])
+		@ i++ ; set a=$i
+		@ i++ ; set b=$i
+		@ i++ ; set c=$i
+		set c01=($argv[$a] $argv[$b] $argv[$c])
+		@ i++ ; set a=$i
+		@ i++ ; set b=$i
+		@ i++ ; set c=$i
+		set c11=($argv[$a] $argv[$b] $argv[$c])
+		@ i++ ; set a=$i
+		@ i++ ; set b=$i
+		@ i++ ; set c=$i
+		set c10=($argv[$a] $argv[$b] $argv[$c])
+		unset a b c
+		breaksw
+	case -r:
+		@ i++
+		set step = $argv[$i]
+		breaksw
+	case -b:
+		@ i++
+		set bord = $argv[$i]
+		breaksw
+	case -s:
+		set smooth="-s"
+		breaksw
+	default:
+		goto userr
+	endsw
+	@ i++
+end
+# Get corner points
+set lim=(`getbbox -h $mesh`)
+if (! $?bord ) then
+	set bord=`ev "($lim[2]-$lim[1]+$lim[4]-$lim[3])/20"`
+endif
+if (! $?c00 ) then
+	set c00=(`ev "$lim[1]-$bord" "$lim[3]-$bord" "($lim[5]+$lim[6])/2"`)
+	set c01=(`ev "$lim[2]+$bord" "$lim[3]-$bord" "($lim[5]+$lim[6])/2"`)
+	set c10=(`ev "$lim[1]-$bord" "$lim[4]+$bord" "($lim[5]+$lim[6])/2"`)
+	set c11=(`ev "$lim[2]+$bord" "$lim[4]+$bord" "($lim[5]+$lim[6])/2"`)
+endif
+# Get mesh resolution
+if (! $?step ) then
+	set step=`ev "sqrt(($c11[1]-$c00[1])*($c11[1]-$c00[1])+($c11[2]-$c00[2])*($c11[2]-$c00[2]))/70"`
+endif
+set res=(`ev "ceil(sqrt(($c01[1]-$c00[1])*($c01[1]-$c00[1])+($c01[2]-$c00[2])*($c01[2]-$c00[2]))/$step)" "ceil(sqrt(($c10[1]-$c00[1])*($c10[1]-$c00[1])+($c10[2]-$c00[2])*($c10[2]-$c00[2]))/$step)"`)
+set edgef=`mktemp /tmp/edgerad.XXXXXX`
+cat > $edgef << _EOF_
+void sphere c00
+0 0 4
+$c00 .001
+void sphere c01
+0 0 4
+$c01 .001
+void sphere c10
+0 0 4
+$c10 .001
+void sphere c11
+0 0 4
+$c11 .001
+void cylinder ex0
+0 0 7
+$c00 $c10 .001
+void cylinder ex1
+0 0 7
+$c01 $c11 .001
+void cylinder ey0
+0 0 7
+$c00 $c01 .001
+void cylinder ey1
+0 0 7
+$c10 $c11 .001
+_EOF_
+set meshcal=`mkdir /tmp/meshcal.XXXXXX`
+cat > $meshcal << _EOF_
+lerp(x,y0,y1):(1-x)*y0+x*y1;
+and(a,b):if(a,b,-1);
+or(a,b):if(a,1,b);
+not(a):if(a,-1,1);
+max(a,b):if(a-b,a,b);
+min(a,b):if(a-b,b,a);
+EPS:1e-7;
+XR:min(32,floor($res[1]/2));
+YR:8;
+eq(a,b):and(a-b+EPS,b-a+EPS);
+sumfun2x(f,y,x0,x1):if(x1-x0+EPS,f(x0,y)+sumfun2x(f,y,x0+1,x1),0);
+sumfun2(f,x0,x1,y0,y1):if(y1-y0+EPS,
+	sumfun2x(f,y0,x0,x1)+sumfun2(f,x0,x1,y0+1,y1), 0);
+xpos(xf,yf)=lerp(xf,lerp(yf,$c00[1],$c10[1]),lerp(yf,$c01[1],$c11[1]));
+ypos(xf,yf)=lerp(xf,lerp(yf,$c00[2],$c10[2]),lerp(yf,$c01[2],$c11[2]));
+onedge=or(or(eq(x,0),eq(x,xmax-1)),or(eq(y,0),eq(y,ymax-1)));
+z0:$lim[5]-$bord;
+height(xo,yo)=z0+gi(1,xo,yo);
+maxwt(xo,yo):if(and(eq(xo,0),eq(yo,0)),100,1/(xo*xo+yo*yo));
+wt(xo,yo)=if(height(xo,yo)-1e9, 0, maxwt(xo,yo));
+wtv(xo,yo)=wt(xo,yo)*height(xo,yo);
+wts=sumfun2(wt,-XR,XR,-YR,YR);
+sum=sumfun2(wtv,-XR,XR,-YR,YR);
+inmesh=and(not(onedge),eq(sumfun2(wt,-1,1,-1,1),sumfun2(maxwt,-1,1,-1,1)));
+lo=if(inmesh,1e10,if(wts-EPS,sum/wts,($lim[5]+$lim[6])/2));
+_EOF_
+# Generate height image
+set meshoct=`/tmp/meshoct.XXXXXXX`
+xform -m void $mesh | oconv - $edgef > $meshoct
+set meshpic=`mktemp /tmp/meshpic.XXXXXX`
+cnt $res[2] $res[1] \
+	| rcalc -e 'sp=$2/'"($res[1]-1)" -e 'tp=1-$1/'"($res[2]-1)" \
+	-f $meshcal -e "xp=xpos(sp,tp);yp=ypos(sp,tp)" \
+	-e '$1=xp;$2=yp;$3=z0;$4=0;$5=0;$6=1' \
+	| rtrace -w -faf -oL -x $res[1] -y $res[2] $meshoct \
+	| pvalue -r -b -df > $meshpic
+rm $edgef $meshoct
+# Output mesh surround
+cat << _EOF_
+# $0 $argv[*]
+# Corner points:
+#	$c00
+#	$c01
+#	$c11
+#	$c10
+_EOF_
+pflip -v $meshpic \
+	| pcomb -f $meshcal - \
+	| pvalue -h -H -pG -d \
+	| gensurf $mat $nam 'xpos(s,t)' 'ypos(s,t)' - \
+		`ev $res[1]-1 $res[2]-1` \
+		-e 'valid(xf,yf)=1e9-Z`SYS(xf,yf)' \
+		-f $meshcal $smooth
+rm $meshcal $meshpic
+# All done -- exit
+exit 0
+# Usage error message
+userr:
+echo Usage: $0 "mat name mesh_file [-c corners][-b bord_width][-r step_size][-s]"
+exit 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/genpine.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,127 @@
+#!/bin/csh -f
+# RCSid: $Id: genpine.csh,v 2.4 2011/01/24 04:28:06 greg Exp $
+#
+# Generate a tree
+# Pine version 2
+#
+# First send header and parse arguments
+#
+onintr done
+echo \# $0 $*
+set nleaves=150
+set nlevels=4
+set aspect=1.2
+unset needles
+while ($#argv > 0)
+	switch ($argv[1])
+	case -r:
+		shift argv
+		set nlevels=$argv[1]
+		breaksw
+	case -n:
+		shift argv
+		set nleaves=$argv[1]
+		breaksw
+	case -o:
+		shift argv
+		set needles=$argv[1]
+		breaksw
+	case -a:
+		shift argv
+		set aspect=$argv[1]
+		breaksw
+	default:
+		echo bad option $argv[1]
+		exit 1
+	endsw
+	shift argv
+end
+#
+#  Send materials
+#
+cat << _EOF_
+
+void plastic bark_mat
+0
+0
+5 .6 .5 .45 0 0
+
+void plastic leaf_mat
+0
+0
+5 .11 .36 .025 0 0
+_EOF_
+#
+# Next start seedling
+#
+set tree=/tmp/t$$
+set oldtree=/tmp/ot$$
+set thisrad=.035
+cat << _EOF_ > $tree
+
+void colorpict bark_pat
+9 red green blue pinebark.hdr cyl.cal cyl_match_u cyl_match_v -s $thisrad
+0
+2 1.5225225 1
+
+bark_pat alias my_bark_mat bark_mat
+
+my_bark_mat cone top
+0
+0
+8
+	0	0	0
+	0	0	1
+	$thisrad	.02
+
+my_bark_mat sphere tip
+0
+0
+4	0	0	1	.02
+_EOF_
+if ( ! $?needles ) set needles=n.$nleaves.oct
+if ( ! -f $needles ) then
+oconv -f "\!cnt $nleaves | rcalc -e nl=$nleaves -o needle.fmt" > $needles
+endif
+echo leaf_mat instance needles 1 $needles 0 0 >> $tree
+#
+# Now grow tree:
+#
+#	1) Save oldtree
+#	2) Move tree up and extend trunk
+#	3) Duplicate oldtree at branch positions
+#	4) Repeat
+#
+@ i=0
+while ($i < $nlevels)
+	mv -f $tree $oldtree
+	set lastrad=$thisrad
+	set move=`ev "(2*$aspect)^($i+1)"`
+	set thisrad=`ev "$lastrad+$move*.015"`
+	xform -ry `ev "25/($i+1)"` -t 0 0 $move $oldtree > $tree
+	echo void colorpict bark_pat 9 red green blue pinebark.hdr \
+			cyl.cal cyl_match_u cyl_match_v -s $thisrad >> $tree
+	echo 0 2 1.5225225 1 bark_pat alias my_bark_mat bark_mat >> $tree
+	echo my_bark_mat cone level$i 0 0 8 0 0 0 0 0 \
+			$move $thisrad $lastrad >> $tree
+	set spin=(`ev "rand($i)*360" "rand($i+$nlevels)*360" "rand($i+2*$nlevels)*360" "rand($i+3*$nlevels)*360" "rand($i+4*$nlevels)*360" "rand($i+5*$nlevels)*360" "rand($i+6*$nlevels)*360"`)
+	xform -n b1 -s 1.1 -rz $spin[2] -ry -80 -rz $spin[1] -rz 5 -t 0 0 \
+		`ev "$move*.42"` $oldtree >> $tree
+	xform -n b2 -s 1.1 -rz $spin[3] -ry -78 -rz $spin[1] -rz 128 -t 0 0 \
+		`ev "$move*.44"` $oldtree >> $tree
+	xform -n b3 -s 1.1 -rz $spin[4] -ry -75 -rz $spin[1] -rz 255 -t 0 0 \
+		`ev "$move*.40"` $oldtree >> $tree
+	xform -n b4 -rz $spin[5] -ry -80 -rz $spin[1] -rz 58 -t 0 0 \
+		`ev "$move*.92"` $oldtree >> $tree
+	xform -n b5 -rz $spin[6] -ry -78 -rz $spin[1] -rz 181 -t 0 0 \
+		`ev "$move*.84"` $oldtree >> $tree
+	xform -n b6 -rz $spin[7] -ry -75 -rz $spin[1] -rz 297 -t 0 0 \
+		`ev "$move*.88"` $oldtree >> $tree
+	@ i++
+end
+#
+# Send final tree
+#
+cat $tree
+done:
+rm -f $tree $oldtree
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/genwindow.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,244 @@
+#!/bin/csh -f
+# RCSid: $Id: genwindow.csh,v 2.2 2003/02/22 02:07:23 greg Exp $
+#
+#  Generate source description for window with venetian blinds.
+#
+#	1/11/88		Greg Ward
+#
+#  Usage: genwindow shellfile
+#
+#  Takes as input the following shell variables from file $1:
+#
+#	worient		Window orientation (degrees from south)
+#	wwidth		Window width
+#	wheight		Window height
+#	wtrans		Window transmission
+#	bdepth		Blind depth
+#	bspac		Blind vertical spacing
+#	gap		Gap between blinds and window
+#	brcurv		Blind curvature radius (negative upward, zero none)
+#	bangle		Blind inclination (degrees from horizontal, up and out)
+#	material	Blind material type (metal or plastic)
+#	ucolor		Blind up side color ("red green blue")
+#	uspec		Blind up side specularity (0 to 1)
+#	urough		Blind up side roughness (0 to .2)
+#	dcolor		Blind down side color (opt)
+#	dspec		Blind down side specularity (opt)
+#	drough		Blind down side roughness (opt)
+#	lat		Site latitude (degrees)
+#	long		Site longitude (degrees)
+#	mer		Site standard meridian (degrees)
+#	hour		Hour (standard 24hr time)
+#	day		Day (of month)
+#	month		Month (of year)
+#	grefl		Ground plane reflectance
+#	sky		Sky conditions (sunny, clear, cloudy)
+#	nsources	Number of sources to divide window
+#
+#  Creates the following output files:
+#
+#	stdout		Window description for Radiance
+#	$1.d$$		Window output distribution
+#
+
+if ( $#argv != 1 ) then
+	echo Usage: $0 input
+	exit 1
+endif
+
+#	Set input and output files
+set input = $1
+set distrib = $1.d$$
+set tmpdir = /tmp
+set descrip = $tmpdir/gw$$.des
+set distoct = $tmpdir/gw$$.oct
+set skydesc = $tmpdir/gw$$.sky
+set remove = ( $distoct $skydesc $descrip )
+set removerr = ( $remove $distrib )
+onintr error
+
+#	Set default values
+set worient = 0.
+set wtrans = ( .96 .96 .96 )
+set bdepth = 0.025
+set bspac = 0.0155
+set gap = 0.
+set brcurv = 0.
+set bangle = 0.
+set material = plastic
+set ucolor = ( 0.5 0.5 0.5 ) 
+set uspec = 0.
+set urough = 0.05
+set lat = 37.8
+set long = 122
+set mer = 120
+set hour = 12
+set day = 21
+set month = 10
+set grefl = .2
+set sky = sunny
+set nsources = 6
+
+#	Get input
+source $input
+if ( $status ) goto error
+
+#	Create window
+cat > $descrip <<_EOF_
+
+void glass clear_glass
+0
+0
+3 $wtrans
+
+clear_glass polygon window
+0
+0
+12
+	0	0	0
+	0	0	$wheight
+	$wwidth	0	$wheight
+	$wwidth	0	0
+
+void $material blind_upmat
+0
+0
+5 $ucolor $uspec $urough
+_EOF_
+if ( $status ) goto error
+
+#	Blinds
+genblinds blind_upmat blind_up $bdepth $wwidth $wheight \
+		`ev "ceil($wheight/$bspac)"` $bangle -r $brcurv \
+	| xform -t $gap -$wwidth 1e-4 -rz 90 >> $descrip
+if ( $status ) goto error
+if ( $?dcolor ) then
+	cat >> $descrip <<_EOF_
+
+	void $material blind_dnmat
+	0
+	0
+	5 $dcolor $dspec $drough
+_EOF_
+	genblinds blind_dnmat blind_down $bdepth $wwidth $wheight \
+			`ev "ceil($wheight/$bspac)"` $bangle -r $brcurv \
+		| xform -t $gap -$wwidth 0 -rz 90 >> $descrip
+	if ( $status ) goto error
+endif
+
+#	Make sky
+switch ($sky)
+case sun*:
+	set skysw = +s
+	breaksw
+case clear:
+	set skysw = -s
+	breaksw
+case cloud*:
+	set skysw = -c
+	breaksw
+endsw
+dosky:
+gensky $month $day $hour $skysw -a $lat -o $long -m $mer -g $grefl \
+	| xform -rz `ev "-($worient)"` > $skydesc
+if ( $skysw == +s ) then
+	if ( `sed -n 13p $skydesc | rcalc -e '$1=if($3,-1,1)'` < 0 ) then
+		set skysw = -s
+		goto dosky
+	endif
+endif
+cat >> $skydesc <<_EOF_
+
+skyfunc glow skyglow
+0
+0
+4 1 1 1 0
+
+skyglow source sky
+0
+0
+4 0 -1 0 180
+_EOF_
+
+#	Make distribution
+oconv $skydesc $descrip > $distoct
+if ( $status ) goto error
+echo 2 5 85 9 0 340 18 > $distrib
+makedist -h -d -x1 0 1 0 -x2 0 0 1 -x3 1 0 0 -alpha 5-85:10 -beta 0-340:20 \
+		-tw $bspac -th $bspac -td `ev "2*($bdepth+$gap)"` \
+		-tc `ev "$wwidth/2" "$bdepth+$gap" "$wheight/2"` \
+		-ab 2 -aa .1 -ad 64 -as 64 \
+		-x 16 -y 16 $distoct >> $distrib
+if ( $status ) goto error
+
+set wsgrid = (`ev "floor(sqrt($nsources*$wwidth/$wheight)+.5)" "floor(sqrt($nsources*$wheight/$wwidth)+.5)"`)
+@ nsources = $wsgrid[1] * $wsgrid[2]
+#	Print header
+cat <<_EOF_
+#
+#  Window with venetian blinds
+#  Created from $input `date`
+#
+#	Window orientation (degrees from south):	$worient
+#	Window height:					$wheight
+#	Window width:					$wwidth
+#	Window transmission:				$wtrans
+#	Blind depth:					$bdepth
+#	Blind spacing:					$bspac
+#	Gap to window:					$gap
+#	Blind curvature radius:				$brcurv
+#	Blind inclination (degrees altitude):		$bangle
+#	Blind material:					$material
+#	Up side color:					$ucolor
+#	Up side specularity:				$uspec
+#	Up side roughness:				$urough
+_EOF_
+if ( $?dcolor ) then
+	cat <<_EOF_
+#	Down side color:				$dcolor
+#	Down side specularity:				$dspec
+#	Down side roughness:				$drough
+_EOF_
+else
+	echo \#\	Down side same as up
+endif
+cat <<_EOF_
+#	Latitude (degrees):				$lat
+#	Longitude (degrees):				$long
+#	Standard Meridian (degrees):			$mer
+#	Month Day Hour:					$month $day $hour
+#	Ground plane reflectance:			$grefl
+#	Sky condition:					$sky
+#	Number of window sources:			$nsources
+#
+_EOF_
+
+#	Send sources
+xform -e -rz $worient <<_EOF_
+
+void brightdata wdistrib
+10 noop $distrib source.cal src_theta src_phi -rx 90 -ry -90 -mx
+0
+0
+
+wdistrib illum willum
+0
+0
+3 1 1 1
+
+!gensurf willum wsource "$wwidth*t" $bdepth "$wheight*s" $wsgrid[2] $wsgrid[1]
+_EOF_
+if ( $status ) goto error
+
+#	Send window
+xform -rz $worient $descrip
+if ( $status ) goto error
+
+#	All done, print and exit
+rm -f $remove
+exit 0
+
+#	Error exit
+error:
+	rm -f $removerr
+	exit 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/glare.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,219 @@
+#!/bin/csh -f
+# RCSid: $Id: glare.csh,v 2.4 2003/02/22 02:07:30 greg Exp $
+#
+# Interactive program for calculating glare values
+#
+set fgargs=(-v)
+set nofile="none"
+set octree=$nofile
+set picture=$nofile
+set glarefile=$nofile
+if ($#argv >= 1) then
+	set glarefile=$argv[1]
+	if ($#argv >= 2) then
+		set picture=$argv[2]
+		if ($#argv >= 3) then
+			set octree=$argv[3]
+		endif
+	endif
+endif
+set rtargs=
+set view=
+set threshold=300
+set maxangle=0
+set stepangle=10
+
+set gndxfile="glr$$.ndx"
+set plotfile="glr$$.plt"
+set tempfiles=($gndxfile $plotfile)
+
+alias readvar 'echo -n Enter \!:1 "[$\!:1]: ";set ans="$<";if("$ans" != "")set \!:1="$ans"'
+
+onintr quit
+
+cat <<_EOF_
+This script provides a convenient interface to the glare calculation
+and analysis programs.  It works on a single output file from findglare,
+which you must either create here or have created already before.
+_EOF_
+while ( $glarefile == $nofile )
+	echo ""
+	echo "Please specify a glare file, or use ^C to exit."
+	readvar glarefile
+end
+if ( ! -f $glarefile ) then
+	echo ""
+	echo -n "The glare file '$glarefile' doesn't exist -- shall we create it? "
+	if ("$<" =~ [nN]*) exit 0
+	cat <<_EOF_
+
+A glare file can be created from a wide-angle Radiance picture (preferably
+a fisheye view), an octree, or both.  Computing glare source locations
+from a finished image is faster, but using an octree is more reliable
+since all of the scene information is there.  Whenever it is possible,
+you should use both a picture and an octree to compute the glare file.
+
+You must also have a viewpoint and direction for the glare calculation.
+If the viewpoint is not the same as the picture, an error will result.
+If no view is specified, the view parameters are taken from the picture,
+so the view specification is optional unless you are starting from an
+octree.
+
+_EOF_
+	if ( $picture == $nofile ) then
+		readvar picture
+	endif
+	if ( $octree == $nofile ) then
+		readvar octree
+	endif
+	readvar view
+	if ( $picture == $nofile && $octree == $nofile ) then
+		echo "You must specify a picture or an octree"
+		exit 1
+	endif
+	if ( $picture == $nofile && "$view" == "" ) then
+		echo "You must give a view if there is no picture"
+		exit 1
+	endif
+	if ( $picture != $nofile ) then
+		if ( ! -r $picture ) then
+			echo "Cannot read $picture"
+			exit 1
+		endif
+		set fgargs=($fgargs -p $picture)
+		if ( "$view" != "" ) then
+			set view=(-vf $picture $view)
+		endif
+	endif
+	set fgargs=($fgargs $view)
+	if ( $octree != $nofile ) then
+		if ( ! -r $octree ) then
+			echo "Cannot read $octree"
+			exit 1
+		endif
+		cat <<_EOF_
+
+With an octree, you should give the same options for -av, -ab and
+so forth as are used to render the scene.  Please enter them below.
+
+_EOF_
+		if ($picture != $nofile) then
+			echo "These are the parameters from the picture:"
+			getinfo $picture
+		endif
+		readvar rtargs
+		set fgargs=($fgargs $rtargs $octree)
+	endif
+	echo ""
+	echo -n "Do you expect glare sources in the scene to be small? "
+	if ("$<" =~ [yY]) then
+		echo -n "Very small? "
+		if ("$<" =~ [yY]) then
+			set fgargs=(-r 400 $fgargs)
+		else
+			set fgargs=(-r 250 $fgargs)
+		endif
+		echo -n "Are these sources relatively bright? "
+		if ("$<" =~ [nN]*) then
+			set fgargs=(-c $fgargs)
+		endif
+	endif
+	cat <<_EOF_
+
+Glare sources are determined by a threshold level.  Any part of the
+view that is above this threshold is considered to be part of a glare
+source.  If you do not choose a threshold value, it will be set auto-
+matically to 7 times the average field luminance (in candelas/sq.meter).
+
+_EOF_
+	echo -n "Do you wish to set the glare threshold manually? "
+	if ("$<" =~ [yY]) then
+		readvar threshold
+		set fgargs=(-t $threshold $fgargs)
+	endif
+	cat <<_EOF_
+
+It is often desirable to know how glare changes as a function of
+viewing direction.  If you like, you can compute glare for up
+to 180 degrees to the left and right of the view center.  Enter
+the maximum angle that you would like to compute below.
+
+_EOF_
+	readvar maxangle
+	if ( $maxangle >= $stepangle ) then
+		set fgargs=(-ga $stepangle-$maxangle\:$stepangle $fgargs)
+	endif
+	echo ""
+	echo "Starting calculation..."
+	echo findglare $fgargs
+	findglare $fgargs > $glarefile
+	if ($status) then
+		echo "Uh-oh.  Something went wrong with findglare\!"
+		rm $glarefile
+		exit 1
+	endif
+endif
+if ($?DISPLAY && $picture != $nofile) then
+	echo ""
+	echo "Displaying glare sources in '$picture'..."
+	xglaresrc $picture $glarefile
+endif
+set ndxnam=("Guth Visual Comfort Probability" "Guth Disability Glare Ratio" "CIE Glare Index" "BRS Glare Index" "Unified Glare Rating" "Daylight Glare Index")
+set ndxcom=("glarendx -t guth_vcp" "glarendx -t guth_dgr" "glarendx -t cie_cgi" "glarendx -t brs_gi" "glarendx -t ugr" "glarendx -t dgi")
+set bcdlvl=(50 124 18.5 18.5 18.5 21.7)
+while ( 1 )
+	echo ""
+	echo "	0.  Quit"
+	set i=1
+	while ($i <= $#ndxnam)
+		echo "	$i.  $ndxnam[$i]"
+		@ i++
+	end
+	echo ""
+	set choice=0
+	readvar choice
+	if ($choice < 1 || $choice > $#ndxcom) goto quit
+	$ndxcom[$choice] $glarefile > $gndxfile
+	echo ""
+	echo $ndxnam[$choice]
+	echo "Angle		Value"
+	getinfo - < $gndxfile
+	echo ""
+	set save_file=$nofile
+	readvar save_file
+	if ($save_file != $nofile) then
+		cp -i $gndxfile $save_file
+	endif
+	if ( `getinfo - < $gndxfile | wc -l` > 4 ) then
+		echo ""
+		echo -n "Do you want to plot this data? "
+		if ( "$<" =~ [yY]* ) then
+			set subtitle="$view"
+			if ($picture != $nofile) then
+				set subtitle="$picture $subtitle"
+			else if ($octree != $nofile) then
+				set subtitle="$subtitle $octree"
+			endif
+			if ( "$subtitle" == "" ) then
+				set subtitle="`getinfo < $glarefile | grep findglare`"
+			endif
+			cat <<_EOF_ > $plotfile
+include=line.plt
+include=polar.plt
+title="$ndxnam[$choice]"
+subtitle="$subtitle"
+Bdata=
+	0	$bcdlvl[$choice]
+	360	$bcdlvl[$choice]
+;
+Blabel="BCD level"
+Adata=
+_EOF_
+			getinfo - < $gndxfile >> $plotfile
+			igraph $plotfile
+		endif
+	endif
+end
+quit:
+rm -f $tempfiles
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/glaze.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,441 @@
+#!/bin/csh -f
+# RCSid: $Id: glaze.csh,v 2.8 2009/11/05 19:00:50 greg Exp $
+#
+# Complex glazing model (goes with glaze1.cal and glaze2.cal)
+#
+# Oct. 2002 Greg Ward
+# Aug. 2004 GW (added -f option to read glazings from file)
+# Funding for this development generously provided by Visarc, Inc.
+# (http://www.visarc.com)
+#
+# Nov. 2009 Jack de Valpine - Visarc, Inc.
+#     -f option now clears the internal demo database and accepts
+#        a clear glass definition as the first entry
+#        in the database file
+#         
+
+#################################################################
+#
+# The general assumption is that one surface is uncoated, and
+# reflectances and transmittances are computed from this fact.
+# If the user tries to enter two coated surfaces on the same
+# pane, the script complains and exits.
+#
+# Supported surface types (clear glass prepended below):
+#
+set sn_arr=("VE1-2M low-E coating" "PVB laminated" "V-175 white frit" "V-933 warm gray frit")
+# Glass-side hemispherical reflectances for each surface type:
+set rg_r_arr=(0.065 .11 0.33 0.15)
+set rg_g_arr=(0.058 .11 0.33 0.15)
+set rg_b_arr=(0.067 .11 0.33 0.15)
+# Coating-side hemispherical reflectance for each surface type:
+set rc_r_arr=(0.042 .11 0.59 0.21)
+set rc_g_arr=(0.049 .11 0.59 0.21)
+set rc_b_arr=(0.043 .11 0.59 0.21)
+# Hemispherical (normal) transmittance for each surface type:
+set tn_r_arr=(0.756 0.63 0.21 0.09)
+set tn_g_arr=(0.808 0.63 0.21 0.09)
+set tn_b_arr=(0.744 0.63 0.21 0.09)
+# Boolean whether coatings can have partial coverage:
+set part_arr=(0 0 1 1)
+
+set gfiles=()
+while ($#argv > 0)
+	set header="Surface	Tr	Tg	Tb	Rcr	Rcg	Rcb	Rgr	Rgg	Rgb	Part"
+	if ($#argv < 2 || "$argv[1]" != '-f') then
+		echo "Usage: $0 [-f glazing.dat ..]"
+		exit 1
+	endif
+	shift argv
+	# Clear internal default database
+	set sn_arr=()
+	set rg_r_arr=() ; set rg_g_arr=() ; set rg_b_arr=()
+	set rc_r_arr=() ; set rc_g_arr=() ; set rc_b_arr=()
+	set tn_r_arr=() ; set tn_g_arr=() ; set tn_b_arr=()
+	set part_arr=()
+	set gf="$argv[1]"
+	shift argv
+	set gfiles=($gfiles:q $gf:q)
+	if ("`sed -n 1p $gf:q`" != "$header") then
+		echo "Bad header in $gf -- Expected: $header"
+		exit 1
+	endif
+	echo "Adding glazing types from file $gf :"
+	set nl=`wc -l < $gf:q`
+	@ i=2
+	while ($i <= $nl)
+		set ln=(`sed -n ${i}p $gf:q`)
+		if ($#ln != 11) then
+			echo "Expected 11 words in line: $ln"
+			exit 1
+		endif
+		echo $ln[1]
+		set sn_arr=($sn_arr:q $ln[1])
+		set tn_r_arr=($tn_r_arr $ln[2])
+		set tn_g_arr=($tn_g_arr $ln[3])
+		set tn_b_arr=($tn_b_arr $ln[4])
+		set rc_r_arr=($rc_r_arr $ln[5])
+		set rc_g_arr=($rc_g_arr $ln[6])
+		set rc_b_arr=($rc_b_arr $ln[7])
+		set rg_r_arr=($rg_r_arr $ln[8])
+		set rg_g_arr=($rg_g_arr $ln[9])
+		set rg_b_arr=($rg_b_arr $ln[10])
+		set part_arr=($part_arr $ln[11])
+		@ i++
+	end
+end
+if (! $#gfiles) then
+	unset gfiles
+	echo "###"
+	echo "### NOTE: Using internal demo database!"
+	echo "###"
+	echo
+endif
+#
+# Make sure we have a clear glazing definition
+#
+if (`rcalc -n -e 'ad(a,b)=if(a-b,a-b,b-a);$1=if('"ad($rg_r_arr[1],$rc_r_arr[1])+ad($rg_g_arr[1],$rc_g_arr[1])+ad($rg_b_arr[1],$rc_b_arr[1])-.005,1,0)"`) then
+	set sn_arr=("clear glass" $sn_arr:q)
+	set rg_r_arr=(0.074 $rg_r_arr)
+	set rg_g_arr=(0.077 $rg_g_arr)
+	set rg_b_arr=(0.079 $rg_b_arr)
+	set rc_r_arr=(0.074 $rc_r_arr)
+	set rc_g_arr=(0.077 $rc_g_arr)
+	set rc_b_arr=(0.079 $rc_b_arr)
+	set tn_r_arr=(0.862 $tn_r_arr)
+	set tn_g_arr=(0.890 $tn_g_arr)
+	set tn_b_arr=(0.886 $tn_b_arr)
+	set part_arr=(0 $part_arr)
+endif
+
+#################################################################
+#
+# Get user input
+#
+echo -n "Enter the number of panes in the system: "
+set np="$<"
+if ($np != 1 && $np != 2) then
+	echo "Must be 1 or 2 pane system"
+	exit 1
+endif
+echo ""
+echo "Window normal faces interior"
+echo ""
+if ($np == 1) then
+echo "  | |"
+echo "  | |"
+echo "  | |"
+echo "  | |-->"
+echo "  | |"
+echo "  | |"
+echo "  | |"
+echo " s1 s2"
+else
+echo "  | |    | |"
+echo "  | |    | |"
+echo "  | |    | |"
+echo "  | |    | |-->"
+echo "  | |    | |"
+echo "  | |    | |"
+echo "  | |    | |"
+echo " s1 s2  s3 s4"
+endif
+echo ""
+echo "Supported surface types are:"
+set i=1
+while ($i <= $#sn_arr)
+	echo "  " $i - $sn_arr[$i]
+	@ i++
+end
+echo ""
+echo -n "What is the type of s1? "
+set s1t="$<"
+echo -n "What is the type of s2? "
+set s2t="$<"
+if ($s1t != 1 && $s2t != 1) then
+	echo "One surface of each pane must be $sn_arr[1]"
+	exit 1
+endif
+if ($part_arr[$s1t]) then
+	echo -n "Enter fraction coverage for s1 (0-1): "
+	set s1c="$<"
+endif
+if ($part_arr[$s2t]) then
+	echo -n "Enter fraction coverage for s2 (0-1): "
+	set s2c="$<"
+endif
+if ($np == 2) then
+echo -n "What is the type of s3? "
+set s3t="$<"
+echo -n "What is the type of s4? "
+set s4t="$<"
+if ($s3t != 1 && $s4t != 1) then
+	echo "One surface of each pane must be $sn_arr[1]"
+	exit 1
+endif
+if ($part_arr[$s3t]) then
+	echo -n "Enter fraction coverage for s3 (0-1): "
+	set s3c="$<"
+endif
+if ($part_arr[$s4t]) then
+	echo -n "Enter fraction coverage for s4 (0-1): "
+	set s4c="$<"
+endif
+endif
+
+#################################################################
+#
+# Begin material comments
+#
+echo ""
+echo "############################################"
+echo "# Glazing produced by Radiance glaze script"
+echo '# $Revision: 2.8 $'
+if ($?gfiles) then
+	echo "# Loaded: $gfiles:q"
+	echo -n "# " ; date
+endif
+echo "# Material surface normal points to interior"
+echo "# Number of panes in system: $np"
+
+if ($np == 2) goto glaze2
+#################################################################
+#
+# Compute single glazing
+#
+set sc=1
+echo "# Exterior surface s1 type: $sn_arr[$s1t]"
+if ($?s1c) then
+	echo "# s1 coating coverage: $s1c"
+	set sc=$s1c
+endif
+echo "# Interior surface s2 type: $sn_arr[$s2t]"
+if ($?s2c) then
+	echo "# s2 coating coverage: $s2c"
+	set sc=$s2c
+endif
+if ($s1t != 1) then
+	set ct=$s1t
+	echo -n "# Exterior normal hemispherical reflectance: "
+	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])"
+	echo -n "# Interior normal hemispherical reflectance: "
+	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])"
+else
+	set ct=$s2t
+	echo -n "# Exterior normal hemispherical reflectance: "
+	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])"
+	echo -n "# Interior normal hemispherical reflectance: "
+	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])"
+endif
+echo -n "# Normal hemispherical transmittance: "
+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])"
+echo "#"
+echo "void BRTDfunc glaze1_unnamed"
+if ($part_arr[$s1t] || $part_arr[$s2t]) then
+### Frit glazing
+echo "10"
+echo "	sr_frit_r sr_frit_g sr_frit_b"
+echo "	st_frit_r st_frit_g st_frit_b"
+echo "	0 0 0"
+echo "	glaze1.cal"
+echo "0"
+echo "11"
+if ($s2t == 1) then
+	ev "$s1c*($rg_r_arr[$s1t]-$rg_r_arr[1])" \
+		"$s1c*($rg_g_arr[$s1t]-$rg_g_arr[1])" \
+		"$s1c*($rg_b_arr[$s1t]-$rg_b_arr[1])"
+	ev "$s1c*$rc_r_arr[$s1t]" "$s1c*$rc_g_arr[$s1t]" "$s1c*$rc_b_arr[$s1t]"
+	ev "$s1c*$tn_r_arr[$s1t]" "$s1c*$tn_g_arr[$s1t]" "$s1c*$tn_b_arr[$s1t]"
+	echo "	1	$s1c"
+else
+	ev "$s2c*$rc_r_arr[$s2t]" "$s2c*$rc_g_arr[$s2t]" "$s2c*$rc_b_arr[$s2t]"
+	ev "$s2c*($rg_r_arr[$s2t]-$rg_r_arr[1])" \
+		"$s2c*($rg_g_arr[$s2t]-$rg_g_arr[1])" \
+		"$s2c*($rg_b_arr[$s2t]-$rg_b_arr[1])"
+	ev "$s2c*$tn_r_arr[$s2t]" "$s2c*$tn_g_arr[$s2t]" "$s2c*$tn_b_arr[$s2t]"
+	echo "	-1	$s2c"
+endif
+else
+### Low-E glazing
+echo "10"
+echo "	sr_clear_r sr_clear_g sr_clear_b"
+echo "	st_clear_r st_clear_g st_clear_b"
+echo "	0 0 0"
+echo "	glaze1.cal"
+echo "0"
+echo "19"
+echo "	0 0 0"
+echo "	0 0 0"
+echo "	0 0 0"
+if ($s2t == 1) then
+	echo "	1"
+	set st=$s1t
+else
+	echo "	-1"
+	set st=$s2t
+endif
+echo "	$rg_r_arr[$st] $rg_g_arr[$st] $rg_b_arr[$st]"
+echo "	$rc_r_arr[$st] $rc_g_arr[$st] $rc_b_arr[$st]"
+echo "	$tn_r_arr[$st] $tn_g_arr[$st] $tn_b_arr[$st]"
+endif
+echo ""
+exit 0
+
+glaze2:
+#################################################################
+#
+# Compute double glazing
+#
+if ($s2t != 1) then
+	set s2r_rgb=($rc_r_arr[$s2t] $rc_g_arr[$s2t] $rc_b_arr[$s2t])
+	set s1r_rgb=($rg_r_arr[$s2t] $rg_g_arr[$s2t] $rg_b_arr[$s2t])
+	set s12t_rgb=($tn_r_arr[$s2t] $tn_g_arr[$s2t] $tn_b_arr[$s2t])
+else
+	set s2r_rgb=($rg_r_arr[$s1t] $rg_g_arr[$s1t] $rg_b_arr[$s1t])
+	set s1r_rgb=($rc_r_arr[$s1t] $rc_g_arr[$s1t] $rc_b_arr[$s1t])
+	set s12t_rgb=($tn_r_arr[$s1t] $tn_g_arr[$s1t] $tn_b_arr[$s1t])
+endif
+if ($s4t != 1) then
+	set s4r_rgb=($rc_r_arr[$s4t] $rc_g_arr[$s4t] $rc_b_arr[$s4t])
+	set s3r_rgb=($rg_r_arr[$s4t] $rg_g_arr[$s4t] $rg_b_arr[$s4t])
+	set s34t_rgb=($tn_r_arr[$s4t] $tn_g_arr[$s4t] $tn_b_arr[$s4t])
+else
+	set s4r_rgb=($rg_r_arr[$s3t] $rg_g_arr[$s3t] $rg_b_arr[$s3t])
+	set s3r_rgb=($rc_r_arr[$s3t] $rc_g_arr[$s3t] $rc_b_arr[$s3t])
+	set s34t_rgb=($tn_r_arr[$s3t] $tn_g_arr[$s3t] $tn_b_arr[$s3t])
+endif
+set s12c=1
+echo "# Exterior surface s1 type: $sn_arr[$s1t]"
+if ($?s1c) then
+	echo "# s1 coating coverage: $s1c"
+	set s12c=$s1c
+endif
+echo "# Inner surface s2 type: $sn_arr[$s2t]"
+if ($?s2c) then
+	echo "# s2 coating coverage: $s2c"
+	set s12c=$s2c
+endif
+set s34c=1
+echo "# Inner surface s3 type: $sn_arr[$s3t]"
+if ($?s3c) then
+	echo "# s3 coating coverage: $s3c"
+	set s34c=$s3c
+endif
+echo "# Interior surface s4 type: $sn_arr[$s4t]"
+if ($?s4c) then
+	echo "# s4 coating coverage: $s4c"
+	set s34c=$s4c
+endif
+# Approximate reflectance and transmittance for comment using gray values
+set rglass=`ev ".265*$rg_r_arr[1]+.670*$rg_g_arr[1]+.065*$rg_b_arr[1]"`
+set tglass=`ev ".265*$tn_r_arr[1]+.670*$tn_g_arr[1]+.065*$tn_b_arr[1]"`
+set s1r_gry=`ev "$s12c*(.265*$s1r_rgb[1]+.670*$s1r_rgb[2]+.065*$s1r_rgb[3])+(1-$s12c)*$rglass"`
+set s2r_gry=`ev "$s12c*(.265*$s2r_rgb[1]+.670*$s2r_rgb[2]+.065*$s2r_rgb[3])+(1-$s12c)*$rglass"`
+set s12t_gry=`ev "$s12c*(.265*$s12t_rgb[1]+.670*$s12t_rgb[2]+.065*$s12t_rgb[3])+(1-$s12c)*$tglass"`
+set s3r_gry=`ev "$s34c*(.265*$s3r_rgb[1]+.670*$s3r_rgb[2]+.065*$s3r_rgb[3])+(1-$s34c)*$rglass"`
+set s4r_gry=`ev "$s34c*(.265*$s4r_rgb[1]+.670*$s4r_rgb[2]+.065*$s4r_rgb[3])+(1-$s34c)*$rglass"`
+set s34t_gry=`ev "$s34c*(.265*$s34t_rgb[1]+.670*$s34t_rgb[2]+.065*$s34t_rgb[3])+(1-$s34c)*$tglass"`
+echo -n "# Exterior normal hemispherical reflectance: "
+ev "$s1r_gry + $s12t_gry^2*$s3r_gry"
+echo -n "# Interior normal hemispherical reflectance: "
+ev "$s4r_gry + $s34t_gry^2*$s2r_gry"
+echo -n "# Normal hemispherical transmittance: "
+ev "$s12t_gry*$s34t_gry"
+echo "#"
+echo "void BRTDfunc glaze2_unnamed"
+
+if ($part_arr[$s3t] || $part_arr[$s4t]) then
+### Front pane has frit
+if ($part_arr[$s1t] || $part_arr[$s2t]) then
+	echo "Only one pane can have frit"
+	exit 1
+endif
+if ($?s3c) then
+	set sc=$s3c
+	set s3g=`ev "1-$s3c"`
+else
+	set s3c=0
+	set s3g=1
+endif
+if ($?s4c) then
+	set sc=$s4c
+	set s4g=`ev "1-$s4c"`
+else
+	set s4c=0
+	set s4g=1
+endif
+echo "10"
+echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[1])),cr(fr($s1r_rgb[1]),ft($s12t_rgb[1]),$s3g*rclr))"
+echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[2])),cr(fr($s1r_rgb[2]),ft($s12t_rgb[2]),$s3g*rclr))"
+echo "if(Rdot,cr($s4g*rclr,$s3g*$s4g*tclr,fr($s2r_rgb[3])),cr(fr($s1r_rgb[3]),ft($s12t_rgb[3]),$s3g*rclr))"
+echo "$s3g*$s4g*ft($s12t_rgb[1])*tclr"
+echo "$s3g*$s4g*ft($s12t_rgb[2])*tclr"
+echo "$s3g*$s4g*ft($s12t_rgb[3])*tclr"
+echo "	0 0 0"
+echo "	glaze2.cal"
+echo "0"
+echo "9"
+ev "$sc*$s4r_rgb[1]-$s3c*$rg_r_arr[1]" \
+	"$sc*$s4r_rgb[2]-$s3c*$rg_g_arr[1]" \
+	"$sc*$s4r_rgb[3]-$s3c*$rg_b_arr[1]"
+ev "$s12t_rgb[1]^2*($sc*$s3r_rgb[1]-$s4c*$rg_r_arr[1])" \
+	"$s12t_rgb[2]^2*($sc*$s3r_rgb[2]-$s4c*$rg_g_arr[1])" \
+	"$s12t_rgb[3]^2*($sc*$s3r_rgb[3]-$s4c*$rg_b_arr[1])"
+ev "$sc*$s12t_rgb[1]*$s34t_rgb[1]" \
+	"$sc*$s12t_rgb[2]*$s34t_rgb[2]" \
+	"$sc*$s12t_rgb[3]*$s34t_rgb[3]"
+else if ($part_arr[$s1t] || $part_arr[$s2t]) then
+### Back pane has frit
+if ($?s1c) then
+	set sc=$s1c
+	set s1g=`ev "1-$s1c"`
+else
+	set s1c=0
+	set s1g=1
+endif
+if ($?s2c) then
+	set sc=$s2c
+	set s2g=`ev "1-$s2c"`
+else
+	set s2c=0
+	set s2g=1
+endif
+echo "10"
+echo "if(Rdot,cr(fr($s4r_rgb[1]),ft($s34t_rgb[1]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[1])))"
+echo "if(Rdot,cr(fr($s4r_rgb[2]),ft($s34t_rgb[2]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[2])))"
+echo "if(Rdot,cr(fr($s4r_rgb[3]),ft($s34t_rgb[3]),$s2g*rclr),cr($s1g*rclr,$s1g*$s2g*tclr,fr($s3r_rgb[3])))"
+echo "$s1g*$s2g*ft($s34t_rgb[1])*tclr"
+echo "$s1g*$s2g*ft($s34t_rgb[2])*tclr"
+echo "$s1g*$s2g*ft($s34t_rgb[3])*tclr"
+echo "	0 0 0"
+echo "	glaze2.cal"
+echo "0"
+echo "9"
+ev "$s34t_rgb[1]^2*($sc*$s2r_rgb[1]-$s1c*$rg_r_arr[1])" \
+	"$s34t_rgb[2]^2*($sc*$s2r_rgb[2]-$s1c*$rg_g_arr[1])" \
+	"$s34t_rgb[3]^2*($sc*$s2r_rgb[3]-$s1c*$rg_b_arr[1])"
+ev "$sc*$s1r_rgb[1]-$s2c*$rg_r_arr[1]" \
+	"$sc*$s1r_rgb[2]-$s2c*$rg_g_arr[1]" \
+	"$sc*$s1r_rgb[3]-$s2c*$rg_b_arr[1]"
+ev "$sc*$s34t_rgb[1]*$s12t_rgb[1]" \
+	"$sc*$s34t_rgb[2]*$s12t_rgb[2]" \
+	"$sc*$s34t_rgb[3]*$s12t_rgb[3]"
+else
+### Low-E and regular glazing only
+echo "10"
+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])))"
+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])))"
+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])))"
+echo "ft($s34t_rgb[1])*ft($s12t_rgb[1])"
+echo "ft($s34t_rgb[2])*ft($s12t_rgb[2])"
+echo "ft($s34t_rgb[3])*ft($s12t_rgb[3])"
+echo "	0 0 0"
+echo "	glaze2.cal"
+echo "0"
+echo "9"
+echo "	0 0 0"
+echo "	0 0 0"
+echo "	0 0 0"
+endif
+echo ""
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/help2roff.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,14 @@
+#!/bin/csh -f
+# RCSid: $Id: help2roff.csh,v 3.1 2003/02/22 02:07:30 greg Exp $
+# Convert Tcl/Tk help file (used by gethelp.tcl) to troff/nroff format
+# for printing.
+#
+
+cat << _EOF_
+.ds RH "$1:r help
+.TL 
+`head -1 $1`
+.LP
+_EOF_
+exec sed -e 1d \
+-e 's/^\.\([a-zA-Z][a-zA-Z0-9]*\)\.\([a-zA-Z][a-zA-Z0-9]*\)$/.B "\1 \2"/' $1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/illumcal.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,21 @@
+#!/bin/csh -f
+# RCSid: $Id: illumcal.csh,v 1.2 2006/04/05 06:22:29 greg Exp $
+#
+# Compute color characteristics of light sources
+#
+# Each input file should contain evenly-spaced pairs of wavelength (nm) and
+# power values (watts/nm), one per line.
+#
+if ( $#argv < 1 ) then
+	echo Usage: $0 illum.dat ..
+	exit 1
+endif
+set cal = .
+foreach illum ($*)
+set spc=(`sed -e 1d -e 's/^[ 	]*\([1-9][.0-9]*\)[ 	].*$/\1/' -e 3q $illum`)
+rcalc -f $cal/cieresp.cal -f $cal/stdrefl.cal -e "intvl=abs($spc[2]-$spc[1])" \
+	-f $cal/conv1.cal $illum | total >> /tmp/il$$.dat
+end
+rcalc -f $cal/conv2.cal -f $cal/cct.cal -f $cal/cri.cal \
+	-o $cal/illum.fmt /tmp/il$$.dat
+rm -f /tmp/il$$.dat
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/ivpict.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,12 @@
+#!/bin/csh -f
+# RCSid: $Id: ivpict.csh,v 2.3 2008/11/10 19:08:19 greg Exp $
+#
+# Render requested Instant View
+#
+if ( $#argv < 1 ) then
+	echo Usage: $0 directory '[options]'
+	exit 1
+endif
+set dir=$argv[1]
+set opt="$argv[2-]"
+exec pinterp $opt $dir/pvw_{x,X,y,Y,z,Z}l.{hdr,z}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/ivprep.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,22 @@
+#!/bin/csh -fe
+# RCSid: $Id: ivprep.csh,v 2.2 2003/02/22 02:07:30 greg Exp $
+#
+# Prepare Instant View directory
+#
+if ( $#argv != 1 && $#argv != 2 ) then
+	echo Usage: $0 radfile '[directory]'
+	exit 1
+endif
+set radfile=$1
+if ( $#argv == 2 ) then
+	set dir=$2
+else
+	set dir=$radfile:r.ivd
+endif
+if ( ! -d $dir ) then
+	mkdir $dir
+endif
+foreach vw ( xl Xl yl Yl zl Zl )
+	rad -w -v $vw $radfile PIC=$dir/pvw QUA=L RES=768 \
+			"render=-z $dir/pvw_$vw.z -pj 0"
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/makeall.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,240 @@
+#!/bin/csh -f
+# RCSid $Id: makeall,v 1.25 2010/11/29 17:22:44 greg Exp $
+# 
+# Make all the Radiance programs
+#
+if ( $#argv < 1 ) then
+	echo "Usage: makeall install [clean] [make options]"
+	echo "   or: makeall clean"
+	echo "   or: makeall library"
+	exit 1
+endif
+if ( "$1" == library ) then
+	source installib
+	cp -f src/*/*.{cal,tab,hex} $ldir
+	echo ""
+	echo "Set the environment variable RAYPATH=.:$ldir"
+	echo 'For C-shell users, put the following into ~/.cshrc'
+	echo "	setenv RAYPATH .:$ldir"
+	echo 'For Bourne shell users, put the following into $HOME/.profile'
+	echo "	RAYPATH=.:$ldir"
+	echo "	export RAYPATH"
+	echo ""
+	exit 0
+endif
+set srcdirs=( common rt meta cv gen ot px hd util cal )
+if ( "$1" == install ) then
+	cat << _EOF_
+
+		`cat src/rt/VERSION` INSTALLATION
+
+This script rebuilds all of the Radiance programs and installs
+them on your system.  You should read the file README before running
+this script.  You can type ^C (followed by return) at any time to abort.
+
+You must first answer the following questions.
+
+_EOF_
+if ( ! $?EDITOR ) then
+	echo -n "What is your preferred editor [vi]? "
+	set ans="$<"
+	if ( "$ans" != "" ) then
+		setenv EDITOR "$ans"
+	else
+		setenv EDITOR vi
+	endif
+endif
+again1:
+echo -n "Where do you want the executables [/usr/local/bin]? "
+set idir=$<
+(echo $idir) >/dev/null
+if ( $status ) then
+	goto again1
+endif
+set idir=$idir
+if ( "$idir" == "" ) then
+	set idir=/usr/local/bin
+else if ( "$idir" !~ /* ) then
+	echo "Directory must be relative to root, please reenter"
+	goto again1
+endif
+if ( ! -d $idir ) then
+	mkdir $idir
+	if ( $status ) then
+		echo "Cannot create directory, please reenter"
+		goto again1
+	endif
+endif
+if ( ! -d $idir/dev ) then
+	mkdir $idir/dev
+	if ( $status ) then
+		echo "Cannot create subdirectory, please reenter"
+		goto again1
+	endif
+endif
+set inpath=0
+foreach i ( $path )
+	if ( "$i" == "$idir" ) then
+		set inpath=1
+		break
+	endif
+end
+set rmake=$idir/rmake
+if ( "`ls -tL $rmake $0 |& head -1`" == $rmake ) then
+	goto gotrmake
+endif
+set newrmake
+more src/common/copyright.h
+echo -n "Do you understand and accept the terms of this agreement [n]? "
+set ans="$<"
+if ( "$ans" !~ [yY]* ) exit
+set special=
+set arch=
+set opt=
+set mach=
+set compat=
+set extras=
+set esuffix=
+cat << _EOF_
+
+Please select your system type from the following list:
+
+	1)	Sun Solaris
+	2)	Linux
+	3)	MacOS X
+	4)	FreeBSD
+	5)	Cygwin
+	6)	Other
+
+_EOF_
+echo -n "Choice? "
+set arch="$<"
+switch ("$arch")
+case 1:			# SPARC Station
+	set arch=sun
+	set mach="-I/usr/openwin/include -L/usr/openwin/lib -DNOSTEREO"
+	set opt="-O"
+	set compat="strcmp.o timegm.o"
+	breaksw
+case 2:			# Linux
+	set mach="-Dlinux -D_FILE_OFFSET_BITS=64 -L/usr/X11R6/lib -I/usr/include/X11 -DNOSTEREO"
+	set opt="-O2"
+	set arch=IBMPC
+	set compat="erf.o"
+	set extras=CC=gcc
+	breaksw
+case 3:			# MacOS X
+	set mach="-DBSD -DNOSTEREO -Dfreebsd -I/usr/X11R6/include -L/usr/X11R6/lib"
+	set opt="-O2"
+	set arch=Intel
+	set extras="CC=cc CONFIGURE_ARCH=i386"
+	set special="ogl"
+	breaksw
+case 4:			# FreeBSD
+	set mach="-DBSD -DNOSTEREO -Dfreebsd -I/usr/X11R6/include -L/usr/X11R6/lib"
+	set opt="-O"
+	set compat="erf.o"
+	set extras='CC=cc MLIB="-lcompat -lm"'
+	set arch=IBMPC
+	breaksw
+case 5:			# Cygwin
+	set mach="-Dfreebsd -L/usr/lib -L/usr/X11R6/lib -I/usr/include/X11 -I/usr/X11R6/include -DNOSTEREO"
+	set opt="-O2"
+	set arch=IBMPC
+	set compat="erf.o"
+	set extras="CC=gcc"
+	set special="ogl"
+	set esuffix=".exe"
+	breaksw
+case 6:			# Other
+	set opt="-O"
+	set compat="erf.o strcmp.o"
+	echo -n "Are you using the GNU C compiler [n]? "
+	if ( "$<" =~ [yY]* ) then
+		set extras="CC=gcc"
+	else
+		set compat="$compat timegm.o"
+	endif
+	set arch=other
+	breaksw
+default:
+	echo "Illegal choice\!"
+	echo "Installation aborted."
+	exit 1
+	breaksw
+endsw
+source installib
+sed 's/[ 	]*$//' > $rmake << _EOF_
+#!/bin/sh
+exec make "SPECIAL=$special" \
+	"OPT=$opt" \
+	"MACH=$mach" \
+	ARCH=$arch "COMPAT=$compat" \
+	INSTDIR=$idir \
+	LIBDIR=$ldir \
+	ESUFFIX=$esuffix \
+	$extras "\$@" -f Rmakefile
+_EOF_
+chmod 755 $rmake
+chmod 644 src/*/Rmakefile src/rt/devtable.c
+gotrmake:
+echo "Current rmake command is:"
+cat $rmake
+echo -n "Do you want to change it? "
+set ans="$<"
+if ( "$ans" =~ [yY]* ) then
+	cp $rmake /tmp/rmake$$
+	$EDITOR $rmake
+	if ( `cat $rmake /tmp/rmake$$ | grep OPT= | uniq | wc -l` == 2 ) set newrmake
+	rm -f /tmp/rmake$$
+endif
+if ( ! -d src/lib ) then
+	mkdir src/lib
+endif
+if ( $?newrmake ) then
+	echo 'New rmake command -- running "makeall clean"...'
+	csh -f $0 clean
+endif
+cd src
+echo "Making programs..."
+set errs=0
+foreach i ( $srcdirs )
+	pushd $i
+	echo "In directory $i..."
+	$rmake -k $*
+	@ errs += $status
+	popd
+end
+if ( $errs ) then
+	echo "There were some errors."
+else
+	echo "Done."
+endif
+cd ..
+if (! $inpath ) then
+	echo ""
+	echo "Add $idir to the beginning of your execution path:"
+	echo 'For C-shell users, put the following into ~/.cshrc'
+	echo "	set path=( $idir "'$path )'
+	echo 'For Bourne shell users, put the following into $HOME/.profile'
+	echo "	PATH=$idir"':$PATH'
+	echo "	export PATH"
+endif
+else
+cd src
+foreach i ( $srcdirs )
+	pushd $i
+	echo "In directory $i..."
+	make -f Rmakefile $*
+	popd
+end
+cd ..
+foreach i ( $* )
+	if ( "$i" == clean ) then
+		echo "Removing library archives..."
+		rm -f src/lib/*.{a,o,la}
+	endif
+end
+echo "Done."
+endif
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/markpath.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,43 @@
+#!/bin/csh -f
+# RCSid: $Id: markpath.csh,v 2.2 2004/01/01 19:44:07 greg Exp $
+#
+# Put right trianglar markers down a path at the given intervals.
+# Use with replmarks to place regular-sized objects along a path.
+# Shorter (y-side) of triangles is always horizontal (perp. to z).
+#
+# Input is an ordered list of 3-D points defining the path.
+# We interpolate the path and align our markers with it.
+# Triangles are sized and aligned so tip of one meets butt of next
+#
+if ($#argv < 2) then
+	echo "Usage: $0 3d.pts spacing [markmat]"
+	exit 1
+endif
+set pts=$1
+set step=$2
+set mat=mark
+if ($#argv > 2) set mat=$3
+set npts=`wc -l < $pts`
+(head -1 $pts ; cat $pts) | rlam - $pts \
+	| rcalc -e '$1=d($1,$2,$3,$4,$5,$6)' -e "cond=$npts+.5-recno" \
+	-e 's(x):x*x;d(x0,y0,z0,x1,y1,z1):sqrt(s(x1-x0)+s(y1-y0)+s(z1-z0))' \
+	| total -1 -r > /tmp/run$$.dat
+rlam /tmp/run$$.dat $pts | tabfunc -i xp yp zp > /tmp/path$$.cal
+set tmax=`tail -1 /tmp/run$$.dat`
+set nsteps=`ev "floor($tmax/$step)"`
+echo $mat > /tmp/tri$$.fmt
+cat >> /tmp/tri$$.fmt << '_EOF_'
+polygon marker.${recno}
+0
+0
+9
+	${   x0    } ${   y0    } ${   z0   }
+	${   x1    } ${   y1    } ${   z1   }
+	${   x2    } ${   y2    } ${   z2   }
+
+'_EOF_'
+cnt $nsteps | rcalc -o /tmp/tri$$.fmt -f /tmp/path$$.cal -e st=$step \
+	-e 't=$1*st;x0=xp(t);y0=yp(t);z0=zp(t)' \
+	-e 'x1=xp(t+st);y1=yp(t+st);z1=zp(t+st)' \
+	-e 'x2=x0+.5*(y0-y1);y2=y0+.5*(x1-x0);z2=z0'
+rm /tmp/run$$.dat /tmp/path$$.cal /tmp/tri$$.fmt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/mkhtmlman.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,20 @@
+#!/bin/csh -fe
+# RCSid $Id: mkhtmlman.csh,v 1.1 2005/10/26 23:56:21 greg Exp $
+#
+# Build man pages in HTML for Radiance website
+#
+cd man
+mkdir man_html
+foreach sect (1 3 5)
+cd man$sect
+foreach mpage (*.$sect)
+	nroff -man $mpage \
+		| man2html -title "Radiance $mpage:r program" -nodepage \
+			     -cgiurl '$title.$section.html' \
+		> ../man_html/$mpage.html
+end
+cd ..
+end
+tar czf ../man_html.tar.gz man_html
+echo "Pages in man_html.tar.gz"
+exec rm -r man_html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/normpat.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,147 @@
+#!/bin/csh -f
+# RCSid: $Id: normpat.csh,v 2.7 2008/08/25 04:50:32 greg Exp $
+#
+# Normalize a pattern for tiling (-b option blends edges) by removing
+# lowest frequencies from image (-f option) and reducing to
+# standard size (-r option)
+#
+set ha=$0
+set ha=$ha:t
+set pf="pfilt -e 2"
+while ($#argv > 0)
+	switch ($argv[1])
+	case -r:
+		shift argv
+		set pf="$pf -x $argv[1] -y $argv[1] -p 1 -r .67"
+		breaksw
+	case -f:
+		set ha="$ha -f"
+		set dofsub
+		breaksw
+	case -b:
+		set ha="$ha -b"
+		set blend
+		breaksw
+	case -v:
+		set verb
+		breaksw
+	case -*:
+		echo bad option $argv[1]
+		exit 1
+	default:
+		goto dofiles
+	endsw
+	shift argv
+end
+dofiles:
+onintr quit
+set td=`mktemp -d /tmp/np.XXXXXX`
+goto skipthis
+cat > $td/coef.fmt << '_EOF_'
+   rm:${  $25   };    gm:${  $26   };    bm:${  $27   };
+  rcx:${   $1   };   gcx:${   $9   };   bcx:${  $17   };
+  rcy:${   $2   };   gcy:${  $10   };   bcy:${  $18   };
+  rsx:${   $3   };   gsx:${  $11   };   bsx:${  $19   };
+  rsy:${   $4   };   gsy:${  $12   };   bsy:${  $20   };
+rcxcy:${   $5   }; gcxcy:${  $13   }; bcxcy:${  $21   };
+rcxsy:${   $6   }; gcxsy:${  $14   }; bcxsy:${  $22   };
+rsxcy:${   $7   }; gsxcy:${  $15   }; bsxcy:${  $23   };
+rsxsy:${   $8   }; gsxsy:${  $16   }; bsxsy:${  $24   };
+'_EOF_'
+cat > $td/coef.cal << '_EOF_'
+$1=$3*2*cx; $2=$3*2*cy; $3=$3*2*sx; $4=$3*2*sy;
+$5=$3*4*cx*cy; $6=$3*4*cx*sy; $7=$3*4*sx*cy; $8=$3*4*sx*sy;
+$9=$4*2*cx; $10=$4*2*cy; $11=$4*2*sx; $12=$4*2*sy;
+$13=$4*4*cx*cy; $14=$4*4*cx*sy; $15=$4*4*sx*cy; $16=$4*4*sx*sy;
+$17=$5*2*cx; $18=$5*2*cy; $19=$5*2*sx; $20=$5*2*sy;
+$21=$5*4*cx*cy; $22=$5*4*cx*sy; $23=$5*4*sx*cy; $24=$5*4*sx*sy;
+$25=$3; $26=$4; $27=$5;
+cx=cos(wx); cy=cos(wy);
+sx=sin(wx); sy=sin(wy);
+wx=2*PI/xres*($1+.5); wy=2*PI/yres*($2+.5);
+'_EOF_'
+cat > $td/fsub.cal << '_EOF_'
+PI:3.14159265358979323846;
+ro=ri(1)*rm/(rm+rcx*cx+rcy*cy+rsx*sx+rsy*sy
+		+rcxcy*cx*cy+rcxsy*cx*sy+rsxcy*sx*cy+rsxsy*sx*sy);
+go=gi(1)*gm/(gm+gcx*cx+gcy*cy+gsx*sx+gsy*sy
+		+gcxcy*cx*cy+gcxsy*cx*sy+gsxcy*sx*cy+gsxsy*sx*sy);
+bo=bi(1)*bm/(bm+bcx*cx+bcy*cy+bsx*sx+bsy*sy
+		+bcxcy*cx*cy+bcxsy*cx*sy+bsxcy*sx*cy+bsxsy*sx*sy);
+cx=cos(wx); cy=cos(wy);
+sx=sin(wx); sy=sin(wy);
+wx=2*PI/xres*(x+.5); wy=2*PI/yres*(y+.5);
+'_EOF_'
+skipthis:
+foreach f ($*)
+	if ( $?verb ) then
+		echo $f\:
+		echo adjusting exposure/size...
+	endif
+	$pf $f > $td/pf
+	getinfo < $td/pf > $f
+	ed - $f << _EOF_
+i
+$ha
+.
+w
+q
+_EOF_
+	set resolu=`getinfo -d < $td/pf | sed 's/-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)/\2 \1/'`
+	if ( ! $?dofsub ) then
+		mv $td/pf $td/hf
+		goto donefsub
+	endif
+	# if ( $?verb ) then
+	#	echo computing Fourier coefficients...
+	# endif
+	# pfilt -1 -x 32 -y 32 $td/pf | pvalue -h \
+	#	| rcalc -e 'xres:32;yres:32' -f $td/coef.cal \
+	#	| total -m | rcalc -o $td/coef.fmt \
+	#	> $td/coef
+	if ( $?verb ) then
+		# cat $td/coef
+		echo removing low frequencies...
+	endif
+	pgblur -r `ev "sqrt($resolu[1]*$resolu[2])/8"` $td/pf > $td/lf
+	pcomb -e 's=1/li(2);ro=s*ri(1);go=s*gi(1);bo=s*bi(1)' \
+			$td/pf $td/lf > $td/hf
+	# pcomb -f $td/coef -f $td/fsub.cal $td/pf > $td/hf
+	donefsub:
+	if ( $?blend ) then
+		if ( $?verb ) then
+			echo blending edges...
+		endif
+		@ mar= $resolu[1] - 3
+		@ les= $resolu[1] - 1
+		pcompos -x 1 $td/hf 0 0 | pfilt -1 -x 3 > $td/left
+		pcompos $td/hf -$les 0 | pfilt -1 -x 3 > $td/right
+		pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
+			-e 'f(p)=(3-x)/7*p(1)+(4+x)/7*p(2)' \
+			$td/right $td/left > $td/left.patch
+		pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
+			-e 'f(p)=(1+x)/7*p(1)+(6-x)/7*p(2)' \
+			$td/left $td/right > $td/right.patch
+		pcompos $td/hf 0 0 $td/left.patch 0 0 $td/right.patch $mar 0 \
+			> $td/hflr
+		@ mar= $resolu[2] - 3
+		@ les= $resolu[2] - 1
+		pcompos -y 1 $td/hflr 0 0 | pfilt -1 -y 3 > $td/bottom
+		pcompos $td/hflr 0 -$les | pfilt -1 -y 3 > $td/top
+		pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
+			-e 'f(p)=(3-y)/7*p(1)+(4+y)/7*p(2)' \
+			$td/top $td/bottom > $td/bottom.patch
+		pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
+			-e 'f(p)=(1+y)/7*p(1)+(6-y)/7*p(2)' \
+			$td/bottom $td/top > $td/top.patch
+		pcompos $td/hflr 0 0 $td/bottom.patch 0 0 $td/top.patch 0 $mar \
+			| getinfo - >> $f
+	else
+		getinfo - < $td/hf >> $f
+	endif
+	if ( $?verb ) then
+		echo $f done.
+	endif
+end
+quit:
+rm -rf $td
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/objline.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,40 @@
+#!/bin/csh -f
+# RCSid: $Id: objline.csh,v 2.6 2008/11/30 19:56:02 greg Exp $
+# Create four standard views of scene and present as line drawings
+#
+set oblqxf="-rz 45 -ry 45"
+onintr quit
+set d=`mktemp -d /tmp/ol.XXXXXX`
+if ($#argv) then
+	set origf=""
+	set oblqf=""
+	foreach f ($argv)
+		set fn="$f:t"
+		set fn="$fn:r"
+		xform $f:q > $d/$fn:q.orig
+		rad2mgf $d/$fn:q.orig > $d/$fn:q.orig.mgf
+		set origf=($origf:q $fn:q.orig.mgf)
+		echo i $fn:q.orig.mgf $oblqxf > $d/$fn:q.oblq.mgf
+		set oblqf=($oblqf:q $fn:q.oblq.mgf)
+	end
+else
+	set origf=stdin.orig.mgf
+	set oblqf=stdin.oblq.mgf
+	xform > $d/stdin.orig
+	rad2mgf $d/stdin.orig > $d/stdin.orig.mgf
+	echo i stdin.orig.mgf $oblqxf > $d/stdin.oblq.mgf
+endif
+cd $d
+set rce='xm=($1+$2)/2;ym=($3+$4)/2;zm=($5+$6)/2;\
+max(a,b):if(a-b,a,b);r=max(max($2-$1,$4-$3),$6-$5)*.52;\
+$1=xm-r;$2=xm+r;$3=ym-r;$4=ym+r;$5=zm-r;$6=zm+r'
+set origdim=`getbbox -h *.orig | rcalc -e $rce:q`
+set oblqdim=`xform $oblqxf *.orig | getbbox -h | rcalc -e $rce:q`
+mgf2meta -t .005 x $origdim $origf > x.mta
+mgf2meta -t .005 y $origdim $origf > y.mta
+mgf2meta -t .005 z $origdim $origf > z.mta
+mgf2meta -t .005 x $oblqdim $oblqf > o.mta
+plot4 {x,y,z,o}.mta
+quit:
+cd
+exec rm -rf $d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/objpict.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,76 @@
+#!/bin/csh -f
+# RCSid: $Id: objpict.csh,v 2.7 2009/07/22 17:48:07 greg Exp $
+#
+# Make a nice multi-view picture of an object
+# Command line arguments contain materials and object files
+#
+set tmpdir=/tmp/objv$$
+mkdir $tmpdir
+set xres=1024
+set yres=1024
+set rpict="rpict -av .2 .2 .2 -x $xres -y $yres"
+set inprad=op$$.rad
+set testroom=$tmpdir/testroom.rad
+set octree=$tmpdir/op.oct
+onintr quit
+if ( $#argv ) then
+	cat $* > $inprad
+else
+	cat > $inprad
+endif
+cat > $testroom << '_EOF_'
+void plastic wall_mat 0 0 5 .681 .543 .686 0 .2
+void light bright 0 0 3 3000 3000 3000
+bright sphere lamp0 0 0 4 4 4 -4 .1
+bright sphere lamp1 0 0 4 4 0 4 .1
+bright sphere lamp2 0 0 4 0 4 4 .1
+wall_mat polygon box.1540 0 0 12
+                  5                 -5                 -5
+                  5                 -5                  5
+                 -5                 -5                  5
+                 -5                 -5                 -5
+wall_mat polygon box.4620 0 0 12
+                 -5                 -5                  5
+                 -5                  5                  5
+                 -5                  5                 -5
+                 -5                 -5                 -5
+wall_mat polygon box.2310 0 0 12
+                 -5                  5                 -5
+                  5                  5                 -5
+                  5                 -5                 -5
+                 -5                 -5                 -5
+wall_mat polygon box.3267 0 0 12
+                  5                  5                 -5
+                 -5                  5                 -5
+                 -5                  5                  5
+                  5                  5                  5
+wall_mat polygon box.5137 0 0 12
+                  5                 -5                  5
+                  5                 -5                 -5
+                  5                  5                 -5
+                  5                  5                  5
+wall_mat polygon box.6457 0 0 12
+                 -5                  5                  5
+                 -5                 -5                  5
+                  5                 -5                  5
+                  5                  5                  5
+'_EOF_'
+set dims=`getbbox -h $inprad`
+set siz=`rcalc -n -e 'max(a,b):if(a-b,a,b);$1='"max($dims[2]-$dims[1],max($dims[4]-$dims[3],$dims[6]-$dims[5]))"`
+set vw1="-vtl -vp 2 .5 .5 -vd -1 0 0 -vh 1 -vv 1"
+set vw2="-vtl -vp .5 2 .5 -vd 0 -1 0 -vh 1 -vv 1"
+set vw3="-vtl -vp .5 .5 2 -vd 0 0 -1 -vu -1 0 0 -vh 1 -vv 1"
+set vw4="-vp 3 3 3 -vd -1 -1 -1 -vh 20 -vv 20"
+
+xform -t `ev "-($dims[1]+$dims[2])/2" "-($dims[3]+$dims[4])/2" "-($dims[5]+$dims[6])/2"` \
+		-s `ev 1/$siz` -t .5 .5 .5 $inprad \
+	| oconv $testroom - > $octree
+pcompos "\!$rpict $vw3 $octree" 0 $yres \
+	"\!$rpict $vw4 $octree" $xres $yres \
+	"\!$rpict $vw1 $octree" 0 0 \
+	"\!$rpict $vw2 $octree" $xres 0 \
+	| pfilt -1 -r .6 -x /2 -y /2
+
+quit:
+rm -r $tmpdir $inprad
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/objview.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,113 @@
+#!/bin/csh -f
+# RCSid: $Id: objview.csh,v 2.12 2009/01/13 22:19:25 greg Exp $
+#
+# Make a nice view of an object
+# Arguments are scene input files
+#
+set tmpdir=/tmp
+set octree=$tmpdir/ov$$.oct
+set lights=$tmpdir/lt$$.rad
+set rif=$tmpdir/ov$$.rif
+set ambf=$tmpdir/af$$.amb
+set tmpfiles="$octree $lights $rif $ambf"
+set raddev="x11"
+set up="Z"
+set vw="XYZ"
+set rendopts=""
+set opts=""
+while ($#argv > 0)
+	switch ($argv[1])
+	case -g*:
+		set usegl
+		breaksw
+	case -u:
+		shift argv
+		set up=$argv[1]
+		breaksw
+	case -s:
+	case -w:
+		set opts=($opts $argv[1])
+		breaksw
+	case -b*:
+		set rendopts=($rendopts -bv)
+		breaksw
+	case -v:
+		shift argv
+		set vw="$argv[1]"
+		breaksw
+	case -N:
+		shift argv
+		set opts=($opts -N $argv[1])
+		set radopt
+		breaksw
+	case -o:
+		shift argv
+		set raddev="$argv[1]"
+		set radopt
+		breaksw
+	case -V:
+	case -e:
+		set opts=($opts $argv[1])
+		set radopt
+		breaksw
+	case -S:
+		set opts=($opts $argv[1])
+		set glradopt
+		breaksw
+	case -*:
+		echo "Bad option: $argv[1]"
+		exit 1
+	default:
+		break
+	endsw
+	shift argv
+end
+if ( $#argv == 0 ) then
+	echo "No input files specified"
+	exit 1
+endif
+if ( $?usegl ) then
+	if ( $?radopt ) then
+		echo "bad option for glrad"
+		glrad
+		exit 1
+	endif
+else
+	if ( $?glradopt ) then
+		echo "bad option for rad"
+		rad
+		exit 1
+	endif
+endif
+
+onintr quit
+
+cat > $lights <<_EOF_
+void glow dim 0 0 4 .1 .1 .15 0
+dim source background 0 0 4 0 0 1 360
+void light bright 0 0 3 1000 1000 1000
+bright source sun1 0 0 4 1 .2 1 5
+bright source sun2 0 0 4 .3 1 1 5
+bright source sun3 0 0 4 -1 -.7 1 5
+_EOF_
+
+cat > $rif <<_EOF_
+scene= $argv[*]:q $lights
+EXPOSURE= .5
+UP= $up
+view= $vw
+OCTREE= $octree
+oconv= -f
+AMBF= $ambf
+render= $rendopts
+_EOF_
+
+if ( $?usegl ) then
+	glrad $opts $rif
+else
+	rad -o $raddev $opts $rif
+endif
+
+quit:
+rm -f $tmpfiles
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/optics2rad.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,97 @@
+#!/bin/csh -f
+# RCSid $Id: optics2rad.csh,v 2.3 2008/08/25 04:50:31 greg Exp $
+#
+# Convert Optics 5 output to correct Radiance input
+#
+if ($#argv < 1) then
+	echo "Usage: $0 optics.mat .."
+	exit 1
+endif
+set optf=`mktemp /tmp/optfmt.XXXXXXX`
+cat > $optf << '_EOF_'
+void glass $(name)_glass
+0
+0
+3 ${Rtn} ${Gtn} ${Btn}
+
+void BRTDfunc $(name)_front
+10
+	${fRrho} ${fGrho} ${fBrho}
+	${Rtau} ${Gtau} ${Btau}
+     0 0 0
+     .
+0
+9 0 0 0 0 0 0 0 0 0
+
+void BRTDfunc $(name)_back
+10
+	${bRrho} ${bGrho} ${bBrho}
+	${Rtau} ${Gtau} ${Btau}
+     0 0 0
+     .
+0
+9 0 0 0 0 0 0 0 0 0
+'_EOF_'
+
+echo "# Output generated by $0 from $*"
+sed -e '/^[^#]/d' -e '/^$/d' $*
+
+set outf=`mktemp /tmp/outfmt.XXXXXX`
+cat > $outf << '_EOF_'
+
+void glass $(name)
+0
+0
+3 ${Rtn} ${Gtn} ${Btn}
+'_EOF_'
+
+rcalc -l -e 'abs(x):if(x,x,-x);and(a,b):if(a,b,a);not(x):if(x,-1,1)' \
+	-e 'lum(r,g,b):.265*r+.670*g+.065*b' \
+	-e 'trans=lum(Rtau,Gtau,Btau)' \
+	-e 'rfront=lum(fRrho,fGrho,fBrho);rback=lum(bRrho,bGrho,bBrho)' \
+	-e 'cond=0.005-abs(rfront-rback)' \
+	-i $optf -o $outf $*
+
+cat > $outf << '_EOF_'
+
+void BRTDfunc $(name)
+10
+	rR_clear rG_clear rB_clear
+	${Rtau}*tR_clear ${Gtau}*tG_clear ${Btau}*tB_clear
+     0 0 0
+     window.cal
+0
+15 0 0 0 0 0 0 0 0 0
+	${fRrho} ${fGrho} ${fBrho}
+	${bRrho} ${bGrho} ${bBrho}
+'_EOF_'
+
+rcalc -l -e 'abs(x):if(x,x,-x);and(a,b):if(a,b,a);not(x):if(x,-1,1)' \
+	-e 'lum(r,g,b):.265*r+.670*g+.065*b' \
+	-e 'trans=lum(Rtau,Gtau,Btau)' \
+	-e 'rfront=lum(fRrho,fGrho,fBrho);rback=lum(bRrho,bGrho,bBrho)' \
+	-e 'cond=and(trans-.645, not(0.005-abs(rfront-rback)))' \
+	-i $optf -o $outf $*
+
+cat > $outf << '_EOF_'
+
+void BRTDfunc $(name)
+10
+	rR_bronze rG_bronze rB_bronze
+	${Rtau}*tR_bronze ${Gtau}*tG_bronze ${Btau}*tB_bronze
+     0 0 0
+     window.cal
+0
+15 0 0 0 0 0 0 0 0 0
+	${fRrho} ${fGrho} ${fBrho}
+	${bRrho} ${bGrho} ${bBrho}
+'_EOF_'
+
+rcalc -l -e 'abs(x):if(x,x,-x);and(a,b):if(a,b,a);not(x):if(x,-1,1)' \
+	-e 'lum(r,g,b):.265*r+.670*g+.065*b' \
+	-e 'trans=lum(Rtau,Gtau,Btau)' \
+	-e 'rfront=lum(fRrho,fGrho,fBrho);rback=lum(bRrho,bGrho,bBrho)' \
+	-e 'cond=and(not(trans-.645), not(0.005-abs(rfront-rback)))' \
+	-i $optf -o $outf $*
+
+rm -f $optf $outf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pacuity.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,79 @@
+#!/bin/csh -f
+# RCSid: $Id: pacuity.csh,v 3.6 2008/11/10 19:08:19 greg Exp $
+#
+# Adjust picture acuity according to human visual abilities
+#
+if ($#argv != 1) then
+	echo "Usage: $0 input.hdr > output.hdr"
+	exit 1
+endif
+set td=/tmp
+set tfc1=$td/ac$$.cal
+set tf=($td/c{1,2,4,8,16,32}d$$.hdr $tfc1)
+set ifile=$1
+onintr quit
+tabfunc -i acuity > $tfc1 << EOF
+# Log10 luminance vs. visual acuity in cycles/degree
+-2.804	2.09
+-2.363	3.28
+-2.076	3.79
+-1.792	4.39
+-1.343	6.11
+-1.057	8.83
+-0.773	10.94
+-0.371	18.66
+-0.084	23.88
+0.2	31.05
+0.595	37.42
+0.882	37.68
+1.166	41.60
+1.558	43.16
+1.845	45.30
+2.129	47.00
+2.577	48.43
+2.864	48.32
+3.148	51.06
+3.550	51.09
+EOF
+set pres=(`getinfo -d < $ifile | sed 's/^-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)$/\2 \1/'`)
+set vp=`vwright V < $ifile`
+set aext=(`pextrem -o $ifile | rcalc -f $tfc1 -e 'max(a,b):if(a-b,a,b);$1=acuity(log10(max(179*(.265*$3+.67*$4+.065*$5),1e-4)))'`)
+( rcalc -e "$vp" -e "A:3438*sqrt(Vhn/$pres[1]*Vvn/$pres[2])" \
+	-e 'f=60/A/2/$1;cond=if(1.5-$1,1,if(1-f,-1,if($1-'"$aext[2]"',-1,$1-'"$aext[1])))" \
+	-o 'pfilt -1 -r 2 -x /${f} -y /${f} '"$ifile | pfilt -1 -r 1 -x $pres[1] -y $pres[2] > $td/"'c${$1}d'$$.hdr \
+	| csh -f ) << EOF
+1
+2
+4
+8
+16
+32
+EOF
+cat >> $tfc1 << _EOF_
+max(a,b) : if(a-b, a, b);
+target_acuity = acuity(log10(max(WE/le(1)*li(1),1e-4)));
+findfuzzy(i) = if(target_acuity-picture_acuity(i),i,if(i-1.5,findfuzzy(i-1),1));
+fuzzy_picture = findfuzzy(nfiles-1);
+clear_picture = fuzzy_picture + 1;
+clarity_ex = (target_acuity-picture_acuity(fuzzy_picture)) /
+		(picture_acuity(clear_picture)-picture_acuity(fuzzy_picture));
+clarity = if(clarity_ex-1, 1, if(-clarity_ex, 0, clarity_ex));
+ro = clarity*ri(clear_picture) + (1-clarity)*ri(fuzzy_picture);
+go = clarity*gi(clear_picture) + (1-clarity)*gi(fuzzy_picture);
+bo = clarity*bi(clear_picture) + (1-clarity)*bi(fuzzy_picture);
+picture_acuity(n) : select(n,1,
+_EOF_
+set pf=($td/c1d$$.hdr)
+foreach i (2 4 8 16 32)
+	if ( -f $td/c${i}d$$.hdr ) then
+		set pf=( $pf $td/c${i}d$$.hdr )
+		echo -n "$i," >> $tfc1
+	endif
+end
+set pf=( $pf $ifile )
+rcalc -n -e "$vp" -e "A:3879*sqrt(Vhn/$pres[1]*Vvn/$pres[2])" \
+	-o '${60/A});' >> $tfc1
+getinfo < $ifile | egrep '^((VIEW|EXPOSURE|PIXASPECT|PRIMARIES|COLORCORR)=|[^ ]*(rpict|rview|pinterp) )'
+pcomb -f $tfc1 $pf
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pbilat.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,56 @@
+#!/bin/csh -f
+# RCSid $Id: pbilat.csh,v 1.3 2008/11/10 19:08:19 greg Exp $
+#
+# Bilateral Filter (fixed parameters for now)
+#
+set bfrac=0.02
+set sigma=0.4
+set vmin=1e-7
+if ( $#argv != 1 ) then
+	goto userr
+endif
+set inp="$1"
+set rad=`getinfo -d < $inp:q | rcalc -i '-Y ${yr} +X ${xr}' -e '$1=sqrt(xr*yr)*'$bfrac`
+set extrem=`pextrem -o $inp:q | rcalc -e "vmin:$vmin" -e 'max(a,b):if(a-b,a,b);$1=max($3*.265+$4*.670+$5*.065,vmin)'`
+set nseg=`ev "ceil(log10($extrem[2]/$extrem[1])/$sigma)"`
+if ( $nseg > 20 ) set nseg=20
+onintr done
+set tdir=`mktemp -d /tmp/blf.XXXXXX`
+set gfunc="sq(x):x*x;gfunc(x):if(sq(x)-sq($sigma),0,sq(1-sq(x/$sigma)))"
+set i=0
+set imglist=()
+while ( $i <= $nseg )
+	set intens=`ev "$extrem[1]*($extrem[2]/$extrem[1])^($i/$nseg)"`
+	pcomb -e $gfunc:q -e "vmin:$vmin" \
+			-e 'max(a,b):if(a-b,a,b);l1=max(li(1),vmin)' \
+			-e "lo=gfunc(log10(l1)-log10($intens))" \
+			-o $inp > $tdir/gimg.hdr
+	pcomb -e 'sf=gi(2);ro=sf*ri(1);go=sf*gi(1);bo=sf*bi(1)' \
+			-o $inp $tdir/gimg.hdr > $tdir/g_p.hdr
+	pgblur -r $rad $tdir/g_p.hdr \
+		| pcomb -e 'sf=if(gi(2)-1e-6,1/gi(2),1e6)' \
+			-e 'ro=sf*ri(1);go=sf*gi(1);bo=sf*bi(1)' \
+			- "\!pgblur -r $rad $tdir/gimg.hdr" \
+		> $tdir/gimg$i.hdr
+	set imglist=($imglist $tdir/gimg$i.hdr)
+	@ i++
+end
+cat > $tdir/interp.cal << _EOF_
+{ Segmented intensity image interpolation }
+max(a,b) : if(a-b, a, b);
+NSEG : $nseg;
+l1 = max(li(1), $vmin);
+val = NSEG / log($extrem[2]/$extrem[1]) * (log(l1) - log($extrem[1]));
+iv = floor(val);
+ival = if(iv - (NSEG-1), NSEG-1, max(iv, 0));
+xval = val - ival;
+ro = (1-xval)*ri(ival+2) + xval*ri(ival+3);
+go = (1-xval)*gi(ival+2) + xval*gi(ival+3);
+bo = (1-xval)*bi(ival+2) + xval*bi(ival+3);
+_EOF_
+pcomb -h -f $tdir/interp.cal -o $inp:q $imglist
+done:
+rm -rf $tdir
+exit 0
+userr:
+echo Usage: $0 input.hdr
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pdelta.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,33 @@
+#!/bin/csh -f
+# RCSid: $Id: pdelta.csh,v 3.3 2008/11/10 19:08:19 greg Exp $
+#
+# Compute 1976 CIE Lab deltaE* between two Radiance pictures
+#
+if ($#argv != 2) then
+	echo "Usage: $0 picture1 picture2 > output.hdr"
+	exit 1
+endif
+set cielab='sq(x):x*x;Ls(Yi):if(Yi/Yw-.01,116*(Yi/Yw)^(1/3)-16,903.3*Yi/Yw);as(Xi,Yi,Zi):500*((Xi/Xw)^(1/3)-(Yi/Yw)^(1/3));bs(Xi,Yi,Zi):200*((Yi/Yw)^(1/3)-(Zi/Zw)^(1/3));dE(X1,Y1,Z1,X2,Y2,Z2):sqrt(sq(Ls(Y1)-Ls(Y2))+sq(as(X1,Y1,Z1)-as(X2,Y2,Z2))+sq(bs(X1,Y1,Z1)-bs(X2,Y2,Z2)));'
+# The following is for Radiance RGB -> XYZ
+set rgb2xyz='X(R,G,B):92.03*R+57.98*G+28.99*B;Y(R,G,B):47.45*R+119.9*G+11.6*B;Z(R,G,B):4.31*R+21.99*G+152.7*B'
+# The following is for sRGB -> XYZ
+# set rgb2xyz='X(R,G,B):73.82*R+64.01*G+32.31*B;Y(R,G,B):38.06*R+128*G+12.92*B;Z(R,G,B):3.46*R+21.34*G+170.15*B'
+set f1="$1"
+set inp1='x1=ri(1);y1=gi(1);z1=bi(1)'
+set f2="$2"
+set inp2='x2=ri(2);y2=gi(2);z2=bi(2)'
+if ( "`getinfo < $f1:q | grep '^FORMAT=32-bit_rle_xyze'`" == "" ) then
+	set inp1='x1=X(ri(1),gi(1),bi(1));y1=Y(ri(1),gi(1),bi(1));z1=Z(ri(1),gi(1),bi(1))'
+endif
+if ( "`getinfo < $f2:q | grep '^FORMAT=32-bit_rle_xyze'`" == "" ) then
+	set inp2='x2=X(ri(2),gi(2),bi(2));y2=Y(ri(2),gi(2),bi(2));z2=Z(ri(2),gi(2),bi(2))'
+endif
+set tempf=`mktemp /tmp/tf.XXXXXX`
+pfilt -1 -x 128 -y 128 -p 1 $f1:q | pvalue -o -h -H -d > $tempf
+set wht=(`total -u $tempf`)
+set avg=`rcalc -e '$1=$2' $tempf | total -m`
+rm $tempf
+pcomb -e $cielab:q -e $rgb2xyz:q \
+	-e "Yw:179*3*$avg; Xw:$wht[1]*Yw/$wht[2]; Zw:$wht[3]*Yw/$wht[2]" \
+	-e $inp1:q -e $inp2:q -e 'lo=dE(x1,y1,z1,x2,y2,z2)' \
+	-o $f1:q -o $f2:q
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pdfblur.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,23 @@
+#!/bin/csh -f
+# RCSid: $Id: pdfblur.csh,v 2.6 2005/01/18 01:37:43 greg Exp $
+#
+# Generate views for depth-of-field blurring on picture
+#
+if ($#argv != 3) then
+	echo "Usage: $0 aperture nsamp viewfile"
+	exit 1
+endif
+set a = "$1"
+set n = "$2"
+set vf = "$3"
+cnt $n | rcalc -e `vwright i < $vf` \
+-e "M:$n/5+1;a:$a/2;N:$n;" -e 'tmax:PI*a*(M+1)' \
+-e 't=tmax/N*($1+rand($1))' \
+-e 'theta=2*M*PI/(M-1)*(M-sqrt(M*M-(M-1)/(PI*a)*t))' \
+-e 'r=a*(1-(M-1)/(2*M*M*PI)*theta)' \
+-e 'rcost=r*cos(theta);rsint=r*sin(theta)' \
+-e 'opx=ipx+rcost*ihx+rsint*ivx' \
+-e 'opy=ipy+rcost*ihy+rsint*ivy' \
+-e 'opz=ipz+rcost*ihz+rsint*ivz' \
+-e 'os=is-rcost/(id*ihn);ol=il-rsint/(id*ivn)' \
+-o 'VIEW= -vp ${opx} ${opy} ${opz} -vs ${os} -vl ${ol}'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pgblur.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,29 @@
+#!/bin/csh -f
+# RCSid $Id: pgblur.csh,v 1.2 2008/11/10 19:08:19 greg Exp $
+#
+# Apply Gaussian blur without resizing image
+# More efficient than straight pfilt for large blurs
+#
+if ( $#argv != 3 ) then
+	goto userr
+endif
+if ( "$1" != "-r" ) then
+	goto userr
+endif
+if ( "$2" !~ [1-9]* ) then
+	goto userr
+endif
+set rad = $2
+set inp = "$3"
+set reduc = `ev "floor($rad/1.8)"`
+if ( $reduc <= 1 ) then
+	exec pfilt -1 -r $rad $inp:q
+endif
+set filt = `ev "$rad/$reduc"`
+set pr=`getinfo -d < $inp:q | sed 's/^-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)$/\2 \1/'`
+pfilt -1 -x /$reduc -y /$reduc $inp:q \
+	| pfilt -1 -r $filt -x $pr[1] -y $pr[2]
+exit 0
+userr:
+echo Usage: "$0 -r radius input.hdr"
+exit 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/phisteq.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,116 @@
+#!/bin/csh -f
+# RCSid: $Id: phisteq.csh,v 3.4 2008/11/10 19:08:19 greg Exp $
+set Ldmin=1		# minimum display luminance
+set Ldmax=100		# maximum display luminance
+set nsteps=100		# number of steps in perceptual histogram
+set cvratio=0.08	# fraction of pixels to ignore in envelope clipping
+set td=/tmp
+set tf1=$td/hist$$
+set tf1b=$td/hist$$.new
+set tf2=$td/cumt$$
+set tf3=$td/histeq$$.cal
+set tf4=$td/cf$$.cal
+set tf=($tf1 $tf1b $tf2 $tf3 $tf4)
+if ( $#argv != 1 ) then
+	echo "Usage: $0 input.hdr > output.hdr"
+	exit 1
+endif
+set ifile=$1
+set ibase=$ifile:t
+if ( "$ibase" =~ *.pic ) set ibase=$ibase:r
+set ibase=$ibase:t
+onintr quit
+cat > $tf3 << _EOF_
+WE : 179;			{ Radiance white luminous efficacy }
+Lmin : .0001;			{ minimum allowed luminance }
+Ldmin : $Ldmin ;		{ minimum output luminance }
+Ldmax : $Ldmax ;		{ maximum output luminance }
+Stepsiz : 1/ $nsteps ;		{ brightness step size }
+			{ Daly local amplitude nonlinearity formulae }
+sq(x) : x*x;
+c1 : 12.6;
+b : .63;
+Bl(L) : L / (L + (c1*L)^b);
+Lb(B) : (c1^b*B/(1-B))^(1/(1-b));
+BLw(Lw) : Bl(Ldmin) + (Bl(Ldmax)-Bl(Ldmin))*cf(Bl(Lw));
+			{ first derivative functions }
+Bl1(L) : (c1*L)^b*(1-b)/sq(L + (c1*L)^b);
+Lb1(B) : c1^b/(1-b)/sq(1-B) * (c1^b*B/(1-B))^(b/(1-b));
+			{ derivative clamping function }
+clamp2(L, aLw) : Lb(aLw) / L / Lb1(aLw) / (Bl(Ldmax)-Bl(Ldmin)) / Bl1(L);
+clamp(L) : clamp2(L, BLw(L));
+			{ histogram equalization function }
+lin = li(1);
+Lw = WE/le(1) * lin;
+Lout = Lb(BLw(Lw));
+mult = if(Lw-Lmin, (Lout-Ldmin)/(Ldmax-Ldmin)/lin, 0) ;
+ro = mult * ri(1);
+go = mult * gi(1);
+bo = mult * bi(1);
+_EOF_
+# Compute brightness histogram
+pfilt -1 -p 1 -x 128 -y 128 $ifile | pvalue -o -b -d -h -H \
+	| rcalc -f $tf3 -e 'Lw=WE*$1;$1=if(Lw-Lmin,Bl(Lw),-1)' \
+	| histo 0 1 $nsteps | sed '/[ 	]0$/d' > $tf1
+# Clamp frequency distribution
+set totcount=`sed 's/^.*[ 	]//' $tf1 | total`
+set tst=1
+while ( $totcount > 0 )
+	sed 's/^.*[ 	]//' $tf1 | total -1 -r \
+		| rcalc -e '$1=$1/'$totcount | rlam $tf1 - \
+		| tabfunc -i 0 cf > $tf4
+	if ( $tst <= 0 ) break
+	rcalc -f $tf4 -f $tf3 -e "T:$totcount*Stepsiz" \
+			-e 'clfq=floor(T*clamp(Lb($1)))' \
+			-e '$1=$1;$2=if($2-clfq,clfq,$2)' $tf1 > $tf1b
+	set newtot=`sed 's/^.*[ 	]//' $tf1b | total`
+	set tst=`ev "floor((1-$cvratio)*$totcount)-$newtot"`
+	mv -f $tf1b $tf1
+	set totcount=$newtot
+end
+if ( $totcount < 1 ) then
+	# Fits in display range nicely already -- just normalize
+	pfilt -1 -e `pextrem $ifile | rcalc -e 'cond=recno-1.5;$1=1/(.265*$3+.67*$4+.065*$5)'` $ifile
+else
+	# Plot the mapping function if we are in debug mode
+	if ( $?DEBUG ) then
+		cat > ${ibase}_histo.plt << _EOF_
+include=curve.plt
+title="Brightness Frequency Distribution"
+subtitle= $ibase
+ymin=0
+xlabel="Perceptual Brightness B(Lw)"
+ylabel="Frequency Count"
+Alabel="Histogram"
+Alintype=0
+Blabel="Envelope"
+Bsymsize=0
+Adata=
+_EOF_
+		(cat $tf1; echo \;; echo Bdata=) >> ${ibase}_histo.plt
+		rcalc -f $tf4 -f $tf3 -e "T:$totcount*Stepsiz" \
+			-e '$1=$1;$2=T*clamp(Lb($1))' $tf1 \
+			>> ${ibase}_histo.plt
+		cat > ${ibase}_brmap.plt << _EOF_
+include=line.plt
+title="Brightness Mapping Function"
+subtitle= $ibase
+xlabel="World Luminance (log cd/m^2)"
+ylabel="Display Luminance (cd/m^2)"
+ymax= $Ldmax
+Adata=
+_EOF_
+		cnt 100 | rcalc -f $tf4 -f $tf3 -e '$1=lx;$2=Lb(BLw(10^lx))' \
+			-e Lmin:Lb\(`sed -n '1s/[ 	].*$//p' $tf1`\) \
+			-e Lmax:Lb\(`sed -n '$s/[ 	].*$//p' $tf1`\) \
+			-e 'lx=$1/99*(log10(Lmax)-log10(Lmin))+log10(Lmin)' \
+			>> ${ibase}_brmap.plt
+		if ( $?DISPLAY ) then
+			bgraph ${ibase}_histo.plt ${ibase}_brmap.plt | x11meta &
+		endif
+	endif
+	# Map our picture
+	pcomb -f $tf4 -f $tf3 $ifile
+endif
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/phisto.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,24 @@
+#!/bin/csh -f
+# RCSid: $Id: phisto.csh,v 3.5 2008/08/25 04:50:32 greg Exp $
+#
+# Compute foveal histogram for picture set
+#
+set tf=`mktemp /tmp/phdat.XXXXX`
+onintr quit
+if ( $#argv == 0 ) then
+	pfilt -1 -x 128 -y 128 -p 1 \
+			| pvalue -o -h -H -d -b > $tf
+else
+	rm -f $tf
+	foreach i ( $* )
+		pfilt -1 -x 128 -y 128 -p 1 $i \
+				| pvalue -o -h -H -d -b >> $tf
+		if ( $status ) exit 1
+	end
+endif
+set Lmin=`total -l $tf | rcalc -e 'L=$1*179;$1=if(L-1e-7,log10(L)-.01,-7)'`
+set Lmax=`total -u $tf | rcalc -e '$1=log10($1*179)+.01'`
+rcalc -e 'L=$1*179;cond=L-1e-7;$1=log10(L)' $tf \
+	| histo $Lmin $Lmax 100
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pmblur.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,20 @@
+#!/bin/csh -f
+# RCSid: $Id: pmblur.csh,v 2.3 2005/01/18 03:59:41 greg Exp $
+#
+# Generate views for motion blurring on picture
+#
+if ($#argv != 4) then
+	echo "Usage: $0 speed nsamp v0file v1file"
+	exit 1
+endif
+set s = "$1"
+set n = "$2"
+set vc = "$3"
+set vn = "$4"
+cnt $n | rcalc -e `vwright C < $vc` -e `vwright N < $vn` \
+-e "t=$s/$n"'*($1+rand($1))' \
+-e 'opx=(1-t)*Cpx+t*Npx;opy=(1-t)*Cpy+t*Npy;opz=(1-t)*Cpz+t*Npz' \
+-e 'odx=(1-t)*Cdx*Cd+t*Ndx*Nd;ody=(1-t)*Cdy*Cd+t*Ndy*Nd;odz=(1-t)*Cdz*Cd+t*Ndz*Nd' \
+-e 'oux=(1-t)*Cux+t*Nux;ouy=(1-t)*Cuy+t*Nuy;ouz=(1-t)*Cuz+t*Nuz' \
+-e 'oh=(1-t)*Ch+t*Nh;ov=(1-t)*Cv+t*Nv' \
+-o 'VIEW= -vp ${opx} ${opy} ${opz} -vd ${odx} ${ody} ${odz} -vu ${oux} ${ouy} ${ouz} -vh ${oh} -vv ${ov}'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pmdblur.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,37 @@
+#!/bin/csh -f
+# RCSid $Id: pmdblur.csh,v 3.1 2005/01/18 03:59:41 greg Exp $
+#
+# Generate views for motion and depth blurring on picture
+#
+if ($#argv != 5) then
+	echo "Usage: $0 speed aperture nsamp v0file v1file"
+	exit 1
+endif
+set s = "$1"
+set a = "$2"
+set n = "$3"
+set vc = "$4"
+set vn = "$5"
+if (`ev "if($s-.01,0,1)"`) then
+	pdfblur $a $n $vc
+	exit
+endif
+if (`ev "if($a,0,1)"`) then
+	pmblur $s $n $vc $vn
+	exit
+endif
+cnt $n | rcalc -e `vwright C < $vc` -e `vwright N < $vn` \
+-e "t=$s/$n"'*($1+rand($1))' \
+-e "r=$a/2"'*sqrt(rand(182+7*$1));theta=2*PI*rand(-10-$1)' \
+-e 'rcost=r*cos(theta);rsint=r*sin(theta)' \
+-e 'opx= (1-t)*(Cpx+rcost*Chx+rsint*Cvx) + t*(Npx+rcost*Nhx+rsint*Nvx)' \
+-e 'opy= (1-t)*(Cpy+rcost*Chy+rsint*Cvy) + t*(Npy+rcost*Nhy+rsint*Nvy)' \
+-e 'opz= (1-t)*(Cpz+rcost*Chz+rsint*Cvz) + t*(Npz+rcost*Nhz+rsint*Nvz)' \
+-e 'odx= (1-t)*Cdx*Cd + t*Ndx*Nd' \
+-e 'ody= (1-t)*Cdy*Cd + t*Ndy*Nd' \
+-e 'odz= (1-t)*Cdz*Cd + t*Ndz*Nd' \
+-e 'oux=(1-t)*Cux+t*Nux;ouy=(1-t)*Cuy+t*Nuy;ouz=(1-t)*Cuz+t*Nuz' \
+-e 'oh=(1-t)*Ch+t*Nh;ov=(1-t)*Cv+t*Nv' \
+-e 'os= (1-t)*(Cs-rcost/(Cd*Chn)) + t*(Ns-rcost/(Nd*Nhn))' \
+-e 'ol= (1-t)*(Cl-rsint/(Cd*Cvn)) + t*(Nl-rsint/(Nd*Nvn))' \
+-o 'VIEW= -vp ${opx} ${opy} ${opz} -vd ${odx} ${ody} ${odz} -vu ${oux} ${ouy} ${ouz} -vh ${oh} -vv ${ov} -vs ${os} -vl ${ol}'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/psquish.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,197 @@
+#!/bin/csh -f
+# RCSid: $Id: psquish.csh,v 3.5 2008/11/10 19:08:19 greg Exp $
+set Lmin=.0001		# minimum visible world luminance
+set Ldmin=1		# minimum display luminance
+set Ldmax=100		# maximum display luminance
+set nsteps=100		# number of steps in perceptual histogram
+set cvratio=0.05	# fraction of pixels to ignore in envelope clipping
+set td=/tmp
+set tf0=$td/tf$$
+set tf1=$td/hist$$
+set tf1b=$td/hist$$.diff
+set tf2=$td/cumt$$
+set tf3=$td/histeq$$.cal
+set tf4=$td/cf$$.cal
+set tf=($tf0 $tf1 $tf1b $tf2 $tf3 $tf4)
+if ( "$argv[1]" == "-a" ) then
+	set adaptive
+	shift argv
+endif
+if ( $#argv != 1 ) then
+	echo "Usage: $0 [-a] input.hdr > output.hdr"
+	exit 1
+endif
+set ifile=$1
+set ibase=$ifile:t
+if ( "$ibase" =~ *.hdr ) set ibase=$ibase:r
+set ibase=$ibase:t
+onintr quit
+pextrem -o $ifile > $tf0
+set Lmin=`rcalc -e 'L=179*(.265*$3+.67*$4+.065*$5)' -e 'cond=1.5-recno;$1=if('L-$Lmin,L,$Lmin')' $tf0`
+set Lmax=`rcalc -e 'L=179*(.265*$3+.67*$4+.065*$5)' -e 'cond=recno-1.5;$1=if('$Ldmax-L,$Ldmax,L')' $tf0`
+cat > $tf3 << _EOF_
+min(a,b) : if(a-b, b, a);
+WE : 179;			{ Radiance white luminous efficacy }
+Lmin : $Lmin ;			{ minimum visible luminance }
+Lmax : $Lmax ;			{ maximum picture luminance }
+Ldmin : $Ldmin ;		{ minimum output luminance }
+Ldmax : $Ldmax ;		{ maximum output luminance }
+Stepsiz : (Bl(Lmax)-Bl(Lmin))/ $nsteps ;	{ brightness step size }
+			{ Logarithmic brightness function }
+Bl(L) : log(L);
+Lb(B) : exp(B);
+BLw(Lw) : Bl(Ldmin) + (Bl(Ldmax)-Bl(Ldmin))*cf(Bl(Lw));
+			{ first derivative functions }
+Bl1(L) : 1/L;
+Lb1(B) : exp(B);
+			{ histogram equalization function }
+lin = li(1);
+Lw = WE/le(1) * lin;
+Lout = Lb(BLw(Lw));
+mult = if(Lw-Lmin, (Lout-Ldmin)/(Ldmax-Ldmin)/lin, 0) ;
+_EOF_
+if ( $?adaptive ) then
+	cat >> $tf3 << _EOF_
+			{ Ferwerda contrast sensitivity function }
+				{ log10 of cone threshold luminance }
+ltp(lLa) : if(-2.6 - lLa, -.72, if(lLa - 1.9, lLa - 1.255,
+		(.249*lLa + .65)^2.7 - .72));
+				{ log10 of rod threshold luminance }
+lts(lLa) : if(-3.94 - lLa, -2.86, if(lLa - -1.44, lLa - .395,
+		(.405*lLa + 1.6)^2.18 - 2.86));
+				{ threshold is minimum of rods and cones }
+ldL2(lLa) : min(ltp(lLa),lts(lLa));
+dL(La) : 10^ldL2(log10(La));
+			{ derivative clamping function }
+clamp2(L, bLw) : dL(Lb(bLw))/dL(L)/Lb1(bLw)/(Bl(Ldmax)-Bl(Ldmin))/Bl1(L);
+clamp(L) : clamp2(L, BLw(L));
+			{ shift direction for histogram }
+shiftdir(B) : if(cf(B) - (B - Bl(Lmin))/(Bl(Ldmax) - Bl(Lmin)), 1, -1);
+			{ Scotopic/Photopic color adjustment }
+sL(r,g,b) : .062*r + .608*g + .330*b;	{ approx. scotopic brightness }
+BotMesopic : 10^-2.25;		{ top of scotopic range }
+TopMesopic : 10^0.75;		{ bottom of photopic range }
+incolor = if(Lw-TopMesopic, 1, if(BotMesopic-Lw, 0,
+		(Lw-BotMesopic)/(TopMesopic-BotMesopic)));
+slf = (1 - incolor)*sL(ri(1),gi(1),bi(1));
+ro = mult*(incolor*ri(1) + slf);
+go = mult*(incolor*gi(1) + slf);
+bo = mult*(incolor*bi(1) + slf);
+_EOF_
+else
+	cat >> $tf3 << _EOF_
+			{ derivative clamping function }
+clamp2(L, bLw) : Lb(bLw)/L/Lb1(bLw)/(Bl(Ldmax)-Bl(Ldmin))/Bl1(L);
+clamp(L) : clamp2(L, BLw(L));
+			{ shift direction for histogram }
+shiftdir(B) : -1;
+ro = mult*ri(1);
+go = mult*gi(1);
+bo = mult*bi(1);
+_EOF_
+endif
+# Compute brightness histogram
+pfilt -1 -p 1 -x 128 -y 128 $ifile | pvalue -o -b -d -h -H \
+	| rcalc -f $tf3 -e 'Lw=WE*$1;$1=if(Lw-Lmin,Bl(Lw),-1)' \
+	| histo `ev "log($Lmin)" "log($Lmax)"` $nsteps > $tf1
+# Clamp frequency distribution
+set totcount=`sed 's/^.*[ 	]//' $tf1 | total`
+set margin=`ev "floor($totcount*$cvratio+.5)"`
+while ( 1 )
+	# Compute mapping function
+	sed 's/^.*[ 	]//' $tf1 | total -1 -r \
+		| rcalc -e '$1=$1/'$totcount | rlam $tf1 - \
+		| tabfunc -i 0 cf > $tf4
+	# Compute difference with visible envelope
+	rcalc -f $tf4 -f $tf3 -e "T:$totcount*Stepsiz" \
+			-e 'clfq=floor(T*clamp(Lb($1))+.5)' \
+			-e '$1=$2-clfq;$2=shiftdir($1)' $tf1 > $tf1b
+	if (`sed 's/[	 ].*$//' $tf1b | total` >= 0) then
+		# Nothing visible? -- just normalize
+		pfilt -1 -e `pextrem $ifile | rcalc -e 'cond=recno-1.5;$1=1/(.265*$3+.67*$4+.065*$5)'` $ifile
+		goto quit
+	endif
+	# Check to see if we're close enough
+	if (`rcalc -e '$1=if($1,$1,0)' $tf1b | total` <= $margin) break
+	# Squash frequency distribution
+	set diffs=(`sed 's/[ 	].*$//' $tf1b`)
+	set shftd=(`sed 's/^.*[ 	]//' $tf1b`)
+	while ( 1 )
+		set maxi=0
+		set maxd=0
+		set i=$nsteps
+		while ( $i > 0 )
+			if ( $diffs[$i] > $maxd ) then
+				set maxd=$diffs[$i]
+				set maxi=$i
+			endif
+			@ i--
+		end
+		if ( $maxd == 0 ) break
+		set i=0
+	tryagain:
+		set r=$shftd[$maxi]
+		while ( $i == 0 )
+			@ t= $maxi + $r
+			if ( $t < 1 || $t > $nsteps ) then
+				@ shftd[$maxi]= -($shftd[$maxi])
+				goto tryagain
+			endif
+			if ( $diffs[$t] < 0 ) set i=$t
+			@ r+= $shftd[$maxi]
+		end
+		if ( $diffs[$i] <= -$diffs[$maxi] ) then
+			@ diffs[$i]+= $diffs[$maxi]
+			set diffs[$maxi]=0
+		else
+			@ diffs[$maxi]+= $diffs[$i]
+			set diffs[$i]=0
+		endif
+	end
+	# Mung histogram
+	echo $diffs | tr ' ' '\012' | rlam $tf1 - \
+		| rcalc -f $tf4 -f $tf3 -e "T:$totcount*Stepsiz" \
+			-e 'clfq=floor(T*clamp(Lb($1))+.5)' \
+			-e '$1=$1;$2=$3+clfq' > $tf1b
+	mv -f $tf1b $tf1
+end
+# Plot the mapping function if we are in debug mode
+if ( $?DEBUG ) then
+	cat > ${ibase}_histo.plt << _EOF_
+include=curve.plt
+title="Brightness Frequency Distribution"
+subtitle= $ibase
+ymin=0
+xlabel="Perceptual Brightness B(Lw)"
+ylabel="Frequency Count"
+Alabel="Histogram"
+Alintype=0
+Blabel="Envelope"
+Bsymsize=0
+Adata=
+_EOF_
+	(cat $tf1; echo \;; echo Bdata=) >> ${ibase}_histo.plt
+	rcalc -f $tf4 -f $tf3 -e "T:$totcount*Stepsiz" \
+		-e '$1=$1;$2=T*clamp(Lb($1))' $tf1 \
+		>> ${ibase}_histo.plt
+	cat > ${ibase}_brmap.plt << _EOF_
+include=line.plt
+title="Brightness Mapping Function"
+subtitle= $ibase
+xlabel="World Luminance (log cd/m^2)"
+ylabel="Display Luminance (cd/m^2)"
+ymax= $Ldmax
+Adata=
+_EOF_
+	cnt 100 | rcalc -f $tf4 -f $tf3 -e '$1=lx;$2=Lb(BLw(10^lx))' \
+		-e 'lx=$1/99*(log10(Lmax)-log10(Lmin))+log10(Lmin)' \
+		>> ${ibase}_brmap.plt
+	if ( $?DISPLAY ) then
+		bgraph ${ibase}_histo.plt ${ibase}_brmap.plt | x11meta &
+	endif
+endif
+# Map our picture
+getinfo < $ifile | egrep '^((VIEW|PIXASPECT|PRIMARIES)=|[^ ]*(rpict|rview|pinterp) )'
+pcomb -f $tf4 -f $tf3 $ifile
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/pveil.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,42 @@
+#!/bin/csh -f
+# RCSid: $Id: pveil.csh,v 3.4 2008/11/10 19:08:19 greg Exp $
+#
+# Add veiling glare to picture
+#
+if ($#argv != 1) then
+	echo "Usage: $0 input.hdr > output.hdr"
+	exit 1
+endif
+set ifile=$1
+set td=/tmp
+set gf=$td/av$$.gs
+set cf=$td/av$$.cal
+set tf=($gf $cf)
+onintr quit
+findglare -r 400 -c -p $ifile \
+	| sed -e '1,/^BEGIN glare source$/d' -e '/^END glare source$/,$d' \
+	> $gf
+if ( -z $gf ) then
+	cat $ifile
+	goto quit
+endif
+( rcalc -e '$1=recno;$2=$1;$3=$2;$4=$3;$5=$4*$5' $gf \
+	| tabfunc SDx SDy SDz I ; cat ) > $cf << '_EOF_'
+N : I(0);
+K : 9.2;	{ should be 9.6e-3/PI*(180/PI)^2 == 10.03 ? }
+bound(a,x,b) : if(a-x, a, if(x-b, b, x));
+Acos(x) : acos(bound(-1,x,1));
+sq(x) : x*x;
+mul(ct) : if(ct-cos(.5*PI/180), K/sq(.5), K/sq(180/PI)*ct/sq(Acos(ct)));
+Dx1 = Dx(1); Dy1 = Dy(1); Dz1 = Dz(1);		{ minor optimization }
+cosa(i) = SDx(i)*Dx1 + SDy(i)*Dy1 + SDz(i)*Dz1;
+sum(i) = if(i-.5, mul(cosa(i))*I(i)+sum(i-1), 0);
+veil = le(1)/WE * sum(N);
+ro = ri(1) + veil;
+go = gi(1) + veil;
+bo = bi(1) + veil;
+'_EOF_'
+getinfo < $ifile | egrep '^((VIEW|EXPOSURE|PIXASPECT|PRIMARIES|COLORCORR)=|[^ ]*(rpict|rview|pinterp) )'
+pcomb -f $cf $ifile
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/ra_pfm.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,87 @@
+#!/bin/csh -f
+# RCSid $Id: ra_pfm.csh,v 2.5 2006/11/17 19:14:54 greg Exp $
+#
+# Convert to/from Poskanzer Float Map image format using pvalue
+#
+if (`uname -p` == powerpc) then
+	set machend=big
+else
+	set machend=little
+endif
+while ($#argv > 0)
+	if ("$argv[1]" == "-r") then
+		set reverse
+	else if (! $?inp) then
+		set inp="$argv[1]"
+	else if (! $?out) then
+		set out="$argv[1]"
+	else
+		goto userr
+	endif
+	shift argv
+end
+if ($?reverse) then
+	if (! $?inp) then
+		goto userr
+	endif
+	set opt=""
+	set hl="`head -3 $inp:q`"
+	if ("$hl[1]" == "Pf") then
+		set opt=($opt -b)
+	else if ("$hl[1]" != "PF") then
+		echo "Input not a Poskanzer Float Map"
+		exit 1
+	endif
+	if (`ev "if($hl[3],1,0)"`) then
+		set filend=big
+	else
+		set filend=little
+	endif
+	if ($filend != $machend) then
+		set opt=($opt -dF)
+	else
+		set opt=($opt -df)
+	endif
+	set res=($hl[2])
+	if ($?out) then
+		tail +4 $inp:q | pvalue -r -h $opt +y $res[2] +x $res[1] > $out:q
+	else
+		tail +4 $inp:q | pvalue -r -h $opt +y $res[2] +x $res[1]
+	endif
+	exit $status
+endif
+if (! $?inp) then
+	goto userr
+endif
+set res=(`getinfo -d < $inp:q`)
+if ($?out) then
+	( echo PF ; echo $res[4] $res[2] ) > $out:q
+	if ($machend == little) then
+		echo "-1.000000" >> $out:q
+	else
+		echo "1.000000" >> $out:q
+	endif
+	if ("$res[1]" == "-Y") then
+		pflip -v $inp:q | pvalue -h -H -df >> $out:q
+	else
+		pvalue -h -H -df $inp:q >> $out:q
+	endif
+else
+	echo PF
+	echo $res[4] $res[2]
+	if ($machend == little) then
+		echo "-1.000000"
+	else
+		echo "1.000000"
+	endif
+	if ("$res[1]" == "-Y") then
+		pflip -v $inp:q | pvalue -h -H -df
+	else
+		pvalue -h -H -df $inp:q
+	endif
+endif
+exit $status
+userr:
+echo "Usage: $0 input.hdr [output.pfm]"
+echo "   or: $0 -r input.pfm [output.hdr]"
+exit 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/raddepend.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,22 @@
+#!/bin/csh -f
+# RCSid: $Id: raddepend.csh,v 2.8 2008/08/25 04:50:32 greg Exp $
+#
+# Find scene dependencies in this directory
+#
+set es=1
+onintr quit
+rm -f EMPTY
+echo -n > EMPTY
+sleep 2
+set sedf=`mktemp /tmp/sed.XXXXXX`
+( ls $* | sed -e 's~/~\\/~g' -e 's@^@/^@' -e 's@$@$/d@' ; echo '/^EMPTY$/,$d' ) > $sedf
+getbbox -w $* >/dev/null
+set es=$status
+if ( $es == 0 ) then
+	sync
+	sleep 2
+	ls -tuL | sed -f $sedf | sort
+endif
+quit:
+rm -f $sedf EMPTY
+exit $es
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/ran2tiff.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,113 @@
+#!/bin/csh -fe
+# Convert Radiance animation frames to TIFF output
+#
+set histosiz=200
+set pfwt=0.9
+set outdir=""
+set pcopts=()
+set tfopts=()
+if (! $#argv) set argv=(DUMMY)
+# Process options for pcond and ra_tiff
+while ("$argv[1]" =~ -*)
+	switch ("$argv[1]")
+	case -W:
+		shift argv
+		set pfwt=$argv[1]
+		breaksw
+	case -H:
+		shift argv
+		set histof=$argv[1]:q
+		breaksw
+	case -D:
+		shift argv
+		if (! -d $argv[1]:q ) then
+			echo "Directory $argv[1] does not exist"
+			exit 1
+		endif
+		set outdir=$argv[1]:q/
+		breaksw
+	case -h*:
+	case -a*:
+	case -v*:
+	case -s*:
+	case -c*:
+	case -l*:
+		set pcopts=($pcopts $argv[1])
+		breaksw
+	case -u:
+	case -d:
+	case -f:
+		set pcopts=($pcopts $argv[1-2])
+		shift argv
+		breaksw
+	case -p:
+		shift argv
+		set pcopts=($pcopts -p $argv[1-6])
+		shift argv; shift argv; shift argv; shift argv; shift argv
+		breaksw
+	case -z:
+	case -b:
+	case -w:
+		set tfopts=($tfopts $argv[1])
+		breaksw
+	case -g:
+		shift argv
+		set tfopts=($tfopts -g $argv[1])
+		breaksw
+	default:
+		echo "$0: bad option: $argv[1]"
+		exit 1
+	endsw
+	shift argv
+end
+if ($#argv < 2) then
+	echo Usage: "$0 [-W prev_frame_wt][-H histo][-D dir][pcond opts][ra_tiff opts] frame1 frame2 .."
+	exit 1
+endif
+# Get shrunken image luminances
+set vald=`mktemp -d /tmp/val.XXXXXX`
+foreach inp ($argv:q)
+	set datf="$inp:t"
+	set datf="$vald/$datf:r.dat"
+	pfilt -1 -x 128 -y 128 -p 1 $inp:q \
+		| pvalue -o -h -H -b -df \
+		| rcalc -if1 -e 'L=$1*179;cond=L-1e-7;$1=log10(L)' \
+		> $datf:q
+end
+# Get Min. and Max. log values
+set Lmin=`cat $vald/*.dat | total -l | rcalc -e '$1=$1-.01'`
+set Lmax=`cat $vald/*.dat | total -u | rcalc -e '$1=$1+.01'`
+if ($?histof) then
+	if (-r $histof) then
+		# Fix min/max and translate histogram
+		set Lmin=`sed -n '1p' $histof | rcalc -e 'min(a,b):if(a-b,b,a);$1=min($1,'"$Lmin)"`
+		set Lmax=`sed -n '$p' $histof | rcalc -e 'max(a,b):if(a-b,a,b);$1=max($1,'"$Lmax)"`
+		tabfunc -i hfunc < $histof > $vald/oldhist.cal
+		cnt $histosiz \
+			| rcalc -e "L10=$Lmin+($Lmax-$Lmin)/$histosiz"'*($1+.5)' \
+				-f $vald/oldhist.cal -e '$1=L10;$2=hfunc(L10)' \
+			> $vald/oldhisto.dat
+	endif
+endif
+foreach inp ($argv:q)
+	set datf="$inp:t"
+	set datf="$vald/$datf:r.dat"
+	set outp="$inp:t"
+	set outp="$outdir$outp:r.tif"
+	endif
+	histo $Lmin $Lmax $histosiz < $datf > $vald/newhisto.dat
+	if (-f $vald/oldhisto.dat) then
+		rlam $vald/newhisto.dat $vald/oldhisto.dat \
+			| rcalc -e '$1=$1;$2=$2+$4*'$pfwt \
+			> $vald/histo.dat
+	else
+		mv $vald/{new,}histo.dat
+	endif
+	pcond $pcopts -I $inp:q < $vald/histo.dat \
+		| ra_tiff $tfopts - $outp:q
+	mv $vald/{,old}histo.dat
+end
+if ($?histof) then
+	cp -f $vald/oldhisto.dat $histof
+endif
+rm -rf $vald
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/reinhard.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,12 @@
+#!/bin/csh -f
+#
+# Apply Reinhard's simple tone operator
+#
+if ($#argv != 3) then
+	echo Usage: $0 key input.hdr output.tif
+	exit 1
+endif
+set lavg=`pvalue -h -H -b -d $argv[2]:q | total -p -m`
+set lmax=`pextrem $argv[2]:q | sed -n '2s/^[1-9][0-9]* [1-9][0-9]*	[^ ]* \([^ ]*\) .*$/\1/p'`
+pcomb -e "Lavg:$lavg;Lwht:$lmax;a:$argv[1]" -f reinhard.cal $argv[2]:q \
+	| ra_tiff - $argv[3]:q
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/rlux.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,10 @@
+#!/bin/csh -f
+# RCSid: $Id: rlux.csh,v 2.5 2003/02/22 02:07:30 greg Exp $
+#
+# Compute illuminance from ray origin and direction
+#
+if ( $#argv < 1 ) then
+	echo "Usage: $0 [rtrace args] octree"
+	exit 1
+endif
+rtrace -i+ -dv- -h- -x 1 $argv[*]:q | rcalc -e '$1=47.4*$1+120*$2+11.6*$3' -u
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/runscript.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,17 @@
+#!/bin/csh -f
+goto cont
+oconv -i summercabin.oct -f ext1.rad > ext1sum.oct
+rad -v 'cor -vf vf/corner' -w insummer.rif PIC=ext1sum OCT=ext1sum.oct EXP=-1
+rm ext1sum.oct
+oconv -i summercabin.oct -f ext2.rad > ext2sum.oct
+rad -v 'cor -vf vf/corner' -w insummer.rif PIC=ext2sum OCT=ext2sum.oct EXP=-1
+rm ext2sum.oct
+cont:
+oconv -f summer0_env.rad ext1.rad > ext1env.oct
+rad -v 'cor -vf vf/corner' -w insummer.rif QUA=Hi PIC=ext1env \
+	RAW=ext1raw ZF=ext1raw OCT=ext1env.oct EXP=-1 'render=-ab 1'
+rm ext1env.oct
+oconv -f summer0_env.rad ext2.rad > ext2env.oct
+rad -v 'cor -vf vf/corner' -w insummer.rif QUA=Hi PIC=ext2env \
+	RAW=ext2raw ZF=ext2raw OCT=ext2env.oct EXP=-1 'render=-ab 1'
+rm ext2env.oct
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/tradinstall.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,47 @@
+#!/bin/csh -fe
+# RCSid: $Id: tradinstall.csh,v 2.7 2003/02/22 02:07:30 greg Exp $
+# Install correct version of trad for wish or wish4.0
+#
+set instdir = $1
+set libdir = $2
+
+set TLIBFILES = ( *[a-z].tcl *.hlp trad.icon tclIndex )
+
+set TDIFFS = (`ls | sed -n 's/3\.6\.tcl$//p'`)
+
+set WISHCOMS = ( wish4.{3,2,1,0} wish8.0 wish )
+
+foreach w ( $WISHCOMS )
+	foreach d ($path)
+		if (-x $d/$w) then
+			set wishcom = $d/$w
+			break
+		endif
+	end
+	if ( $?wishcom ) break
+end
+if (! $?wishcom) then
+	echo "Cannot find wish executable in current path -- trad not installed."
+	exit 1
+endif
+# if ( $wishcom:t == wish ) then
+#	set wishcom="$wishcom -f"
+#	set oldwish
+# endif
+
+echo "Installing trad using $wishcom"
+
+sed -e "1s|/usr/local/bin/wish4\.0|$wishcom|" \
+	-e "s|^set radlib .*|set radlib $libdir|" trad.wsh > $instdir/trad
+chmod 755 $instdir/trad
+if (! -d $libdir) then
+	mkdir $libdir
+endif
+(cd $libdir ; rm -f $TLIBFILES)
+cp $TLIBFILES $libdir
+if ($?oldwish) then
+	foreach i ($TDIFFS)
+		rm -f $libdir/$i.tcl
+		cp ${i}3.6.tcl $libdir/$i.tcl
+	end
+endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/vinfo.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,39 @@
+#!/bin/csh -f
+# RCSid: $Id: vinfo.csh,v 3.2 2004/11/19 23:00:49 greg Exp $
+#
+# Edit information header in Radiance file
+#
+set plist=()
+set ilist=()
+foreach f ($*)
+	if (! -f $f:q) then
+		echo "${f}: no such file or directory"
+		continue
+	endif
+	if (! -w $f:q) then
+		echo "$f is read-only"
+		sleep 1
+		continue
+	endif
+	set info="$f.info"
+	getinfo < $f:q > $info:q
+	set plist=($plist:q $f:q)
+	set ilist=($ilist:q $info:q)
+end
+vi $ilist:q
+set i=1
+while ( $i <= $#plist )
+	set f=$plist[$i]:q
+	set info=$ilist[$i]:q
+	if ("`tail -1 $info:q`" != "") then
+		echo "" >> $info:q
+	endif
+	getinfo < $f:q | cmp -s - $info:q
+	if ($status != 0) then
+		getinfo - < $f:q >> $info:q
+		mv $info:q $f:q
+	else
+		rm $info:q
+	endif
+	@ i++
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/vlpic.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,90 @@
+#!/bin/csh -f
+# RCSid: $Id: vlpic.csh,v 3.4 2008/08/25 04:50:32 greg Exp $
+#
+# Compute falsecolor image of visibility level
+# using the wacky formulas of Werner Adrian.
+#
+set age=40			# default age (years)
+set tim=.2			# default time (seconds)
+while ($#argv > 1)
+	switch ($argv[1])
+	case -a:
+		shift argv
+		set age="$argv[1]"
+		breaksw
+	case -t:
+		shift argv
+		set tim="$argv[1]"
+		breaksw
+	default:
+		echo bad option "'$argv[1]'"
+		exit 1
+	endsw
+	shift argv
+end
+set tc=`mktemp /tmp/vlcal.XXXXXXX`
+set tp1=`mktemp /tmp/vlpic.XXXXXX`
+set tp2=`mktemp /tmp/vlr2pic.XXXXXX`
+set tp4=`mktemp /tmp/vlr4pic.XXXXXX`
+set tp8=`mktemp /tmp/vlr8pic.XXXXXX`
+set tf=($tc $tp1 $tp2 $tp4 $tp8)
+set inpic=$argv[1]
+onintr quit
+set pr=(`getinfo -d < $inpic | sed 's/^-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)$/\2 \1/'`)
+# ( vwright V < $inpic ; cat ) > $tc << _EOF_
+cat > $tc << _EOF_
+{ A : 3438 * sqrt(Vhn/xmax*Vvn/ymax);	{ pixel size (in minutes) } }
+PI : 3.14159265358979323846;
+A = 180*60/PI * sqrt(S(1)/PI);
+sq(x) : x*x;
+max(a,b) : if(a-b, a, b);
+Lv : 0;		{ veiling luminance {temporarily zero} }
+		{ find direction of maximum contrast }
+xoff(d) = select(d, 1, 1, 0, -1, -1, -1, 0, 1);
+yoff(d) = select(d, 0, 1, 1, 1, 0, -1, -1, -1);
+cf(lf, lb) = (lf - lb)/(lb + Lv);
+contrast(d) = cf(li(1,xoff(d),yoff(d)), li(1,-xoff(d),-yoff(d)));
+cwin(d1, d2) = if(contrast(d1) - contrast(d2), d1, d2);
+bestdir(d) = if(d-1.5, cwin(d, bestdir(d-1)), d);
+maxdir = bestdir(8);
+Lt = WE*li(1,xoff(maxdir),yoff(maxdir)) + Lv;
+La = WE*li(1,-xoff(maxdir),-yoff(maxdir)) + Lv;
+LLa = log10(La);
+F = if(La-.6, log10(4.1925) + LLa*.1556 + .1684*La^.5867,
+	if(La-.00418, 10^(-.072 + LLa*(.3372 + LLa*.0866)),
+		10^(.028 + .173*LLa)));
+L = if(La-.6, .05946*La^.466,
+	if(La-.00418, 10^(-1.256 + .319*LLa),
+		10^(-.891 + LLa*(.5275 + LLa*.0227))));
+LAt = log10(A) + .523;
+AA = .36 - .0972*LAt*LAt/(LAt*(LAt - 2.513) + 2.7895);
+LLat = LLa + 6;
+AL = .355 - .1217*LLat*LLat/(LLat*(LLat - 10.4) + 52.28);
+AZ = sqrt(AA*AA + AL*AL)/2.1;
+DL1 = 2.6*sq(F/A + L);
+M = if(La-.004, 10^-(10^-(if(La-.1,.125,.075)*sq(LLa+1) + .0245)), 0);
+TGB = .6*La^-.1488;
+FCP = 1 - M*A^-TGB/(2.4*(DL1*(AZ+2)/2));
+DL2 = DL1*(AZ + T)/T;
+FA = if(Age-64, sq(Age-56.6)/116.3 + 1.43, sq(Age-19)/2160 + .99);
+DL3 = DL2 * FA;
+DL4 = if(La-Lt, DL3*FCP, DL3);
+lo = (Lt - La)/DL4;		{ Output VL }
+_EOF_
+pcomb -w -e "Age:$age;T:$tim" -f $tc -o $inpic > $tp1
+pfilt -1 -x /2 -y /2 $inpic \
+	| pcomb -w -e "Age:$age;T:$tim" -f $tc -o - \
+	| pfilt -1 -r 1 -x $pr[1] -y $pr[2] > $tp2
+pfilt -1 -x /4 -y /4 $inpic \
+	| pcomb -w -e "Age:$age;T:$tim" -f $tc -o - \
+	| pfilt -1 -r 1 -x $pr[1] -y $pr[2] > $tp4
+pfilt -1 -x /8 -y /8 $inpic \
+	| pcomb -w -e "Age:$age;T:$tim" -f $tc -o - \
+	| pfilt -1 -r 1 -x $pr[1] -y $pr[2] > $tp8
+pcomb -e 'max(a,b):if(a-b,a,b)' -e 'lo=max(gi(1),max(gi(2),max(gi(3),gi(4))))' \
+	$tp1 $tp2 $tp4 $tp8 \
+	| falsecolor -l VL -s 56 -m 1 -r 'if(v-1/8,1.6*8/7*(v-1/8)-.6,0)' \
+		-g 'if(v-1/8,if(v-.453125,1.6-1.6*8/7*(v-1/8),8/3*8/7*(v-1/8)),0)' \
+		-b 'if(v-1/8,1-8/3*8/7*(v-1/8),0)'
+quit:
+rm -f $tf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orig/xyzimage.csh	Sat Apr 09 17:55:16 2011 +0100
@@ -0,0 +1,72 @@
+#!/bin/csh -f
+# RCSid: $Id: xyzimage.csh,v 2.5 2008/08/25 04:50:32 greg Exp $
+#
+# Display one or more CIE XYZE pictures using ximage
+#
+set popt=""
+if ( $?DISPLAY_PRIMARIES ) then
+	set popt="-p $DISPLAY_PRIMARIES"
+endif
+set xiargs=""
+set i=1
+set firstarg=0
+while ( $i <= $#argv && ! $firstarg )
+	@ i1= $i + 1
+	switch ( $argv[$i] )
+	case -ge*:
+	case -di*:
+	case -g:
+	case -c:
+	case -e:
+		if ( $i1 > $#argv ) goto notenough
+		set xiargs=($xiargs $argv[$i] $argv[$i1])
+		@ i1++
+		breaksw
+	case -d:
+	case -b:
+	case -m:
+	case -f:
+	case -s:
+	case =*:
+	case -o*:
+		set xiargs=($xiargs $argv[$i])
+		breaksw
+	case -p:
+		set popt="-p"
+		while ( $i1 <= $i + 8 )
+			if ( $i1 > $#argv ) goto notenough
+			set popt="$popt $argv[$i1]"
+			@ i1++
+		end
+		breaksw
+	case -*:
+		echo "Unknown option: $argv[$i]"
+		exit 1
+	default:
+		set firstarg=$i
+		breaksw
+	endsw
+	set i=$i1
+end
+set ecode=1
+onintr quit
+set td=`mktemp -d /tmp/xyz.XXXXXX`
+if ( ! $firstarg ) then
+	ra_xyze -r -u $popt > $td/stdin
+	if ( $status ) goto quit
+else
+	set i=$firstarg
+	while ( $i <= $#argv )
+		ra_xyze -r -u $popt $argv[$i] $td/$argv[$i]:t
+		if ( $status ) goto quit
+		@ i++
+	end
+endif
+ximage $xiargs $td/*
+set ecode=$status
+quit:
+	rm -rf $td
+	exit $ecode
+notenough:
+	echo "Missing arguments for $argv[$i] option"
+	exit 1