# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

!read var.prep
!read $type.var

!if $demo_num>0
 data=!record $demo_num of $type
!endif
!if $demo_num=$empty or $data=$empty or $vname=$empty
 !exit
!endif

ins_anim_loop=$[1-$set_loop]
!if $set_transparent=1
 insplot_transparent=255,255,255
!endif

!if $set_rotate=1
 rot=+180*s
!endif

tt0=-1.3
tt1=1.3
bar_height=0.13
size_x=$size_base
size_y=$[$size_base*1.3]

formula=!line 1 of $data
plotsrc=!line 2 of $data
desc   =!line 3 of $data
bound  =!line 4 of $data
samples=!line 5 of $data
desc=!trim $desc
!for i=1 to 5
 b$i=!item $i of $bound
!next i
!for i=1 to 2
 ss=!item $i of $samples
 s$i=$[rint($ss*$tram_density)]
!next i

plotsrc=!mathsubst t=($[$tt1-($tt0)]*(s-0.500001)) in $plotsrc
plotsrc=!replace , by $ notitle, in $plotsrc

arrb=$[$b5*1.2]
nomargin=bmargin 1; tmargin 1; lmargin 1; rmargin 1; noxtics
coord=arrow 1 from -$arrb,0,0 to $arrb,0,0 linetype 3; arrow 2 from 0,-$arrb,0 to 0,$arrb,0 linetype 3; arrow 3 from 0,0,-$arrb to 0,0,$arrb linetype 3; label 1 "x" at $arrb*1.05,0,0; label 2 "y" at 0,$arrb*1.05,0; label 3 "z" at 0,0,$arrb*1.05
nocoord=noarrow 1; noarrow 2; noarrow 3; nolabel 1; nolabel 2; nolabel 3; bmargin

insplot_set=size $size_x,$[$size_y+$bar_height]; \
	noborder; noxtics; noytics; noztics;\
	isosamples $s1,$s2; hidden3d;\
	view (floor(90-$angle1)%180+180)%180,floor($angle2 $rot)%360,1.4
insplot_split=size $size_x*0.95,$bar_height; origin 0,0; noparametric; noytics; $nocoord; label 1 "t" at $tt1+($tt1-($tt0))*0.03,0.5; xtics nomirror\
	size $size_x,$size_y; origin 0,$bar_height; parametric; nolabel 1; $nomargin; $coord
insplot_parm_2=3D [$b1:$b2] [$b3:$b4] [-$b5:$b5] [-$b5:$b5] [-$b5:$b5] $plotsrc notitle
insplot_parm_1=2D [$tt0:$tt1] [0:1] x<s*($tt1-($tt0))+($tt0) || x>(s+1/$ins_anim_frames.0)*($tt1-($tt0))+($tt0) ? 0:1 notitle with impulses 6

wims_module_log=$type $demo_num
