#!/bin/tcsh -f
set runs=$1
set num=1
# this includes time(step) and calculated extension
cut -f 1,3 -d ' ' run1/a8_smd_all.out > time.tmp
while ($num <= $runs)
# column 2 is the end-to-end distance
   cut -f 2 -d ' ' run$num/a8_smd_all.out > col2_run$num.tmp
# column 4 is the force
# we will (re)calculate work even though it is in column 5
   cut -f 4 -d ' ' run$num/a8_smd_all.out > col4_run$num.tmp
   cd run$num
   /usr/bin/tclsh ../write_work.tcl
   cd ..
# this is work. Note the different source file name
   cut -f 4 -d ' ' run$num/a8_work.out > work_run$num.tmp
@ num = $num + 1
end
# paste displacement data
paste col2_run1.tmp col2_run2.tmp col2_run3.tmp col2_run4.tmp col2_run5.tmp col2_run6.tmp col2_run7.tmp col2_run8.tmp col2_run9.tmp col2_run10.tmp > col2.tmp
#col2_run11.tmp col2_run12.tmp col2_run13.tmp col2_run14.tmp col2_run15.tmp col2_run16.tmp 
# paste force data
paste col4_run1.tmp col4_run2.tmp col4_run3.tmp col4_run4.tmp col4_run5.tmp col4_run6.tmp col4_run7.tmp col4_run8.tmp col4_run9.tmp col4_run10.tmp > col4.tmp
#col4_run11.tmp col4_run12.tmp col4_run13.tmp col4_run14.tmp col4_run15.tmp col4_run16.tmp 
# paste time, displacement, force data together
paste time.tmp col2.tmp col4.tmp > da.dat
#  create matrix of work data, re-use displacement data
paste time.tmp col2.tmp work_run1.tmp work_run2.tmp work_run3.tmp work_run4.tmp work_run5.tmp work_run6.tmp work_run7.tmp work_run8.tmp work_run9.tmp work_run10.tmp  > work.dat
# work_run11.tmp work_run12.tmp work_run13.tmp work_run14.tmp work_run15.tmp work_run16.tmp
# remove temporary cruft
rm -rf *.tmp
