# Usage:
# Ls = "40 60 80 100 120 140 160 200 500 1000"
# bc = bcc; nu = 1 ; load "scale_binder.gpl";
# Ls: the values of L used in te collapse
# bc: the critical temperature used in the calculation of t=(beta_c-beta)/beta_c
# nu: the exponent used in the calculation of x=L^{1/nu} t


## for the plot in the text see: load "scale_binder_eps.gpl"

bcc   = 0.5*log(1.0+sqrt(2.0)); #the exact critical temperature (use bc=bcc is you wish)
NLs   = words(Ls);  # The number of lattice sizes used in the calculation
LL(i) = word (Ls,i);# Returns the i_th lattice size
cplot(i) = sprintf("<grep '^%s ' allem|sort -k 2.2g|awk -v L=%s -v bc=%f -v nu=%f  '($20/$19)<0.0001{print $2,(1.0-$19/3.0),$20}'",LL(i),LL(i),bc,nu);
#cplot(i) = sprintf("<grep '^%s ' allem|sort -k 2.2g|awk -v L=%s -v bc=%f -v nu=%f  '($20/$19)<0.0001{print $2,$19,$20}'",LL(i),LL(i),bc,nu);
#cplot(i) = sprintf("<grep '^%s ' allem|sort -k 2.2g|awk -v L=%s -v bc=%f -v nu=%f  '($20/$19)<0.002{print L^(1.0/nu)*(bc-$2)/bc,(1.0-$19/3.0),$20}'",LL(i),LL(i),bc,nu);

## Scales as v=1.875=(beta+gamma)/nu = y_h (empirically, prove it)
## V = 2/3 + c L^{-y_h}
## argue more on that and publish it next version.
# cplot(i) = sprintf("<grep '^%s ' allem|sort -k 2.2g|awk -v L=%s -v bc=%f -v nu=%f  -v v=%f '($20/$19)<0.0001{print L^(1.0/nu)*(bc-$2)/bc,L^v*($19-1),L^v*$20}'",LL(i),LL(i),bc,nu,v);

set macros
set term qt enhanced


set title sprintf("{/Symbol b}_c= %f {/Symbol n}= %f",bc,nu)
set xlabel "x=L^{1/{/Symbol n}} t"
set xlabel "{/Symbol b}"
set ylabel "V"
set key right bottom
plot for[i=1:NLs] cplot(i) u 1:2:3 w e t sprintf("L=%s",LL(i)),2./3. t "2/3"
#replot for[i=1:NLs] cplot(i) u 1:2:3 smooth bezier notitle

set title ""
# set key left
set term  post eps enha color solid 18 #uncomment if saving to ps
set out  "V.eps"      #uncomment if saving to eps
replot

set out
set term qt enhanced
set key
#  ---------------------------------------------------------------------
#  Copyright by Konstantinos N. Anagnostopoulos (2004-2014)
#  Physics Dept., National Technical University,
#  konstant@mail.ntua.gr, www.physics.ntua.gr/~konstant
#  
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, version 3 of the License.
#  
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#  
#  You should have received a copy of the GNU General Public Liense along
#  with this program.  If not, see <http://www.gnu.org/licenses/>.
#  -----------------------------------------------------------------------
