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