#!/bin/sh
# 1-band version!! expects input from stdin
# computes quasiparticle mass from Im Sigma(i pi T)
# parameters: skip  (default: skip=3)
START=`expr ${1:-3} + 1`
TMP=`mktemp`

# awk script extracts Im Sigma at first 3 Matsubara frequencies (only first will be used)
awk '{if ($2=="Pick1:") {dt=$3; U=$5}; if(NR==4) w_old=$1; if (NR==5) {dw=$1-w_old; beta=2*3.1415926535/dw};if(NR>5) {if (($1/dw-0.5)^2<0.001) Sw1=-$3; if (($1/dw-1.5)^2<0.001) Sw2=-$3; if (($1/dw-2.5)^2<0.001) {Sw3=-$3; print beta,U,dt, Sw1, Sw2, Sw3}}}'> ${TMP}

BETA=`head -1 $TMP | printcol.sh 1`
U=`head -1 $TMP | printcol.sh 2`
DT0=`head -1 ${TMP} | printcol.sh 3`
DT=`echo ${BETA} ${DT0} | awk '{printf "%s  %1.0f", $1, $1/$2}' | awk '{printf "%8.6f\n", 1.0*$1/$2}'`

cat $TMP | awk '{print 1.0/(1+'$BETA'*sqrt($4*$4)/3.1415926535)}' \
| tail -n +$START | stats -s | awk '{print "'$BETA'  '$U'  '$DT'  ", $1,"  " $2 }' 
rm ${TMP}
