#!/bin/sh # # Averages over all ion types . suffix if [ -z "$2" ]; then echo "Usage: $0 [element] [SUFFIX]" echo "e.g. ./$0 ../defaults/C2H6 sigma C 4 _rezi" echo "would extract sigma for all ions of type carbon, column 1 to 4 of reciprocal calculation out of dir ../defaults/C2H6" exit 1 fi # gather possible ecuts case $2 in "sigma") if [ -z "$5" ]; then echo "Usage: $0 [SUFFIX]" echo "e.g. ./$0 ../defaults/C2H6 sigma C 4 result${suf} _rezi" echo "would extract sigma for all ions of type carbon, column 1 to 4 of reciprocal calculation out of dir ../defaults/C2H6" exit 1 fi RES="$5" SUFFIX="$6" ecuts="`awk -F' ' {'print $1'} ${1}/results-${2}_i0_${3}${SUFFIX}${suf} | grep -v ^#`" i=-1 FILES="" while [ "$i" -lt 200 ]; do let i=$i+1 if [ -e "${1}/results-${2}_i${i}_${3}${SUFFIX}${suf}" ];then FILES="$FILES ${1}/results-${2}_i${i}_${3}${SUFFIX}${suf}" fi done i=1 columns="1" while [ "$i" -lt "$4" ]; do let i=$i+1 columns="$columns $i" done ;; "chi") echo "You can't average chi, it's for the whole molecule!" exit 1 ;; "seed"|"vol") if [ "$2" == "seed" ]; then type="Seed" if [ -z "$5" ]; then echo "Usage: $0 [SUFFIX]" echo "e.g. $0 ${configdir}/tms/ seed chi 9 pcp.chi_seed${suf}" echo " $0 ${configdir}/tms/ seed H 9 results-sigma_H_rezi_avg_seed${suf} _rezi" echo " $0 ${configdir}/tms/ seed C 9 results-sigma_C_rezi_avg_seed${suf} _rezi" 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" exit 1 fi else type="au" if [ -z "$5" ]; then echo "Usage: $0 [SUFFIX]" echo "e.g. $0 ${configdir}/tms/ vol chi 9 pcp.chi_vol${suf}" echo " $0 ${configdir}/tms/ vol H 9 results-sigma_H_rezi_avg_vol${suf} _rezi" echo " $0 ${configdir}/tms/ vol C 9 results-sigma_C_rezi_avg_vol${suf} _rezi" 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" exit 1 fi fi if [ "$3" == "chi" ]; then variable="chi" else variable="sigma" fi # Generate "_seed"/"_vol" files and gather in a list for averager RES="$1/$5" SUFFIX="$6" FILES="" case $variable in "chi") rm -f "$RES" j=1 FILES="" while [ "$j" -lt 100 ]; do if [ -e "$1/${j}${type}/pcp.chi${SUFFIX}${suf}" ]; then 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" fi let j=$j+1 done exit 0 i=1 columns="1" while [ "$i" -lt "$4" ]; do let i=$i+1 columns="$columns $i" done ;; "sigma") i=0 while [ "$i" -lt 200 ]; do rm -f "$1/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}" j=1 while [ "$j" -lt 100 ]; do if [ -e "$1/${j}${type}/pcp.sigma_i${i}_${3}${SUFFIX}${suf}" ]; then if [ "$i" == 0 ]; then ecuts="$ecuts $j" fi 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}" fi let j=$j+1 done if [ -e "$1/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}" ];then FILES="$FILES ${1}/pcp.sigma_i${i}_${3}${SUFFIX}_${2}${suf}" fi let i=$i+1 done i=1 columns="1" while [ "$i" -lt "$4" ]; do let i=$i+1 columns="$columns $i" done ;; esac ;; *) echo "Unknown variable" exit 1 ;; esac #echo $ecuts #exit 1 AVERAGER=${bindir}/stochastik DATE="`date`" # empty result file and start with header echo "# Results averaged for element ${2} on $DATE" >$RES for i in $ecuts; do echo -e -n "Averaging ${i} ... " #echo $FILES echo -e -n "${i}\t" >>$RES for col in $columns; do echo -n `${AVERAGER} ${col} $i ${FILES} | awk -F"\t" {'print $1'}` >>$RES echo -e -n "\t" >>$RES done for col in $columns; do echo -n `${AVERAGER} ${col} $i ${FILES} | awk -F"\t" {'print $2'}` >>$RES echo -e -n "\t" >>$RES done echo -e -n "\n" >>$RES echo -e -n "done\n" done exit 0