source: util/average_result.sh@ 5bef9d

Last change on this file since 5bef9d was a0bcf1, checked in by Frederik Heber <heber@…>, 17 years ago

-initial commit
-Minimum set of files needed from ESPACK SVN repository
-Switch to three tantamount package parts instead of all relating to pcp (as at some time Ralf's might find inclusion as well)

  • Property mode set to 100755
File size: 4.4 KB
Line 
1#!/bin/sh
2#
3# Averages over all ion types
4
5. suffix
6
7if [ -z "$2" ]; then
8 echo "Usage: $0 <molecule dir> <variable> [element] <columns> <destfile> [SUFFIX]"
9 echo "e.g. ./$0 ../defaults/C2H6 sigma C 4 _rezi"
10 echo "would extract sigma for all ions of type carbon, column 1 to 4 of reciprocal calculation out of dir ../defaults/C2H6"
11 exit 1
12fi
13
14# gather possible ecuts
15case $2 in
16 "sigma")
17 if [ -z "$5" ]; then
18 echo "Usage: $0 <molecule dir> <variable> <element> <columns> <destfile> [SUFFIX]"
19 echo "e.g. ./$0 ../defaults/C2H6 sigma C 4 result${suf} _rezi"
20 echo "would extract sigma for all ions of type carbon, column 1 to 4 of reciprocal calculation out of dir ../defaults/C2H6"
21 exit 1
22 fi
23
24 RES="$5"
25 SUFFIX="$6"
26 ecuts="`awk -F' ' {'print $1'} ${1}/results-${2}_i0_${3}${SUFFIX}${suf} | grep -v ^#`"
27
28 i=-1
29 FILES=""
30 while [ "$i" -lt 200 ]; do
31 let i=$i+1
32 if [ -e "${1}/results-${2}_i${i}_${3}${SUFFIX}${suf}" ];then
33 FILES="$FILES ${1}/results-${2}_i${i}_${3}${SUFFIX}${suf}"
34 fi
35 done
36 i=1
37 columns="1"
38 while [ "$i" -lt "$4" ]; do
39 let i=$i+1
40 columns="$columns $i"
41 done
42 ;;
43 "chi")
44 echo "You can't average chi, it's for the whole molecule!"
45 exit 1
46 ;;
47 "seed"|"vol")
48 if [ "$2" == "seed" ]; then
49 type="Seed"
50 if [ -z "$5" ]; then
51 echo "Usage: $0 <molecule dir> <variable> <element> <columns> <destfile> [SUFFIX]"
52 echo "e.g. $0 ${configdir}/tms/ seed chi 9 pcp.chi_seed${suf}"
53 echo " $0 ${configdir}/tms/ seed H 9 results-sigma_H_rezi_avg_seed${suf} _rezi"
54 echo " $0 ${configdir}/tms/ seed C 9 results-sigma_C_rezi_avg_seed${suf} _rezi"
55 echo "would extract sigma C columns 1 to 9 from dir $1 for all found seeds, averaging it and putting average and standard deviation into $5"
56 exit 1
57 fi
58 else
59 type="au"
60 if [ -z "$5" ]; then
61 echo "Usage: $0 <molecule dir> <variable> <element> <columns> <destfile> [SUFFIX]"
62 echo "e.g. $0 ${configdir}/tms/ vol chi 9 pcp.chi_vol${suf}"
63 echo " $0 ${configdir}/tms/ vol H 9 results-sigma_H_rezi_avg_vol${suf} _rezi"
64 echo " $0 ${configdir}/tms/ vol C 9 results-sigma_C_rezi_avg_vol${suf} _rezi"
65 echo "would extract sigma C columns 1 to 9 from dir $1 for all found volumes, averaging it and putting average and standard deviation into $5"
66 exit 1
67 fi
68 fi
69
70
71 if [ "$3" == "chi" ]; then
72 variable="chi"
73 else
74 variable="sigma"
75 fi
76
77 # Generate "_seed"/"_vol" files and gather in a list for averager
78 RES="$1/$5"
79 SUFFIX="$6"
80 FILES=""
81 case $variable in
82 "chi")
83 rm -f "$RES"
84 j=1
85 FILES=""
86 while [ "$j" -lt 100 ]; do
87 if [ -e "$1/${j}${type}/pcp.chi${SUFFIX}${suf}" ]; then
88 tail -n 1 "$1/${j}${type}/pcp.chi${SUFFIX}${suf}" | awk -F"\t" {"print $j"'"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10'} >>"$RES"
89 fi
90 let j=$j+1
91 done
92 exit 0
93 i=1
94 columns="1"
95 while [ "$i" -lt "$4" ]; do
96 let i=$i+1
97 columns="$columns $i"
98 done
99 ;;
100 "sigma")
101 i=0
102 while [ "$i" -lt 200 ]; do
103 rm -f "$1/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}"
104 j=1
105 while [ "$j" -lt 100 ]; do
106 if [ -e "$1/${j}${type}/pcp.sigma_i${i}_${3}${SUFFIX}${suf}" ]; then
107 if [ "$i" == 0 ]; then
108 ecuts="$ecuts $j"
109 fi
110 tail -n 1 "$1/${j}${type}/pcp.sigma_i${i}_${3}${SUFFIX}${suf}" | awk -F"\t" {"print $j"'"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10'} >>"$1/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}"
111 fi
112 let j=$j+1
113 done
114 if [ -e "$1/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}" ];then
115 FILES="$FILES ${1}/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}"
116 fi
117 let i=$i+1
118 done
119 i=1
120 columns="1"
121 while [ "$i" -lt "$4" ]; do
122 let i=$i+1
123 columns="$columns $i"
124 done
125 ;;
126 esac
127 ;;
128 *)
129 echo "Unknown variable"
130 exit 1
131 ;;
132esac
133
134#echo $ecuts
135#exit 1
136AVERAGER=${bindir}/stochastik
137DATE="`date`"
138
139# empty result file and start with header
140echo "# Results averaged for element ${2} on $DATE" >$RES
141for i in $ecuts; do
142 echo -e -n "Averaging ${i} ... "
143 #echo $FILES
144 echo -e -n "${i}\t" >>$RES
145 for col in $columns; do
146 echo -n `${AVERAGER} ${col} $i ${FILES} | awk -F"\t" {'print $1'}` >>$RES
147 echo -e -n "\t" >>$RES
148 done
149 for col in $columns; do
150 echo -n `${AVERAGER} ${col} $i ${FILES} | awk -F"\t" {'print $2'}` >>$RES
151 echo -e -n "\t" >>$RES
152 done
153 echo -e -n "\n" >>$RES
154 echo -e -n "done\n"
155done
156
157exit 0
Note: See TracBrowser for help on using the repository browser.