
macro wait
      pause
end macro

macro plot_path 1 "color=black"
 ff2chi($1,  group=p$1)
 fftf(real = p$1.chi)
 plot( p$1.r,  -p$1.chir_mag, $2)
end macro

macro plot_fit
  newplot( data.r, data.chir_mag,xmin=0.,xmax=7)
  ff2chi(1,2,3,group=fit) 
  fftf(real =  fit.chi)
  plot(fit.r, fit.chir_mag)
  plot(fit.r, abs(data.chir_mag-fit.chir_mag),xmax=6)
end macro


read_data(../data/cu_chi.dat, group = data, type=chi)

guess  s02   = 1.
guess  e0    = 1.

guess  ss2   = 0.002
guess  ss2_2 = 0.002

guess  dr    = 0.001
guess  dr_2  = 0.01

path(index  = 1, 
     feff   = ../feff/feffcu01.dat, 
     label  = "Cu metal first neighbor", 
     s02    = s02, 
     sigma2 = ss2,
     delr   = dr, 
     e0     = e0 )

path(2,  ../feff/feffcu02.dat,     
    s02 = s02, e0 = e0, 
    sigma2  = ss2_2,      delr=dr_2)

kmin = 2, kmax=17, kweight=2, dk1 = 3, dk2 = 3
$kwindow = kaiser
rmin = 1.6, rmax =3.8
rmax_out = 8


ff2chi(1,2, group=init) 
fftf(real = data.chi)


# feffit(chi = data.chi, k=data.k,group = fit, 1,2)
# 
# show @variables, r_factor, chi_square
# 
# pause 

feffit(chi = data.chi, k=data.k,group = fit1, 1,2,
       data_set=1, data_total=3, kweight =1 )
 
feffit(chi = data.chi, k=data.k,group = fit2, 1,2,
	   kweight = 2, data_set=2)

feffit(chi = data.chi, k=data.k,group = fit3, 1,2,
	   kweight = 3, data_set=3)

show @variables, r_factor, chi_square


# feffit(chi = data.chi, k=data.k,group = fit2, 1,2,
#        rmin=1.63, kweight=1, data_set=2, data_total=2 , macro=wait)

# feffit(chi = data.chi, k=data.k,group = fit2, 1,2,
#        kweight=1, rmin=1.9, data_set=2, data_total=2 , macro=wait)
# 

