subroutine Chi2(iflag, m, n, X, Fvec, Fjac, ldFjac) c*********************************************************************** c Chi2 is designed to be called by snls1. It returns a vector c of deviation Fvec(m) which would be minimized in snls1. c c iflag is assighed by snls1. if iflag = 0, Chi2 only prints, c iflag != 0, chi2 only calculates, doesn't print. c*********************************************************************** c integer i, ner integer n, m, ldfjac double precision er1, er2, ep11, xtol c double precision Diag(3), Qtf(3) c double precision Wa1(3), Wa2(3), Wa3(3), Wa4(450) c integer Nifty, nfit, iflag, Fidx double precision X(n), Xpole(2), Fvec(m), Fjac(ldFjac,n) double precision exp_xs, th_xs, zero, Scale(6) double precision f0,mgb,alpha,c1,c2,Mbare,mpion,Mass,rcbm common /control/ Nifty(15) common /bag/ rcbm,f0,mgb,alpha,c1,c2,Mbare(3),Fidx(3) common /mass/ mpion, Mass(2) common /data/ exp_xs(20, 6), th_xs(20, 6), nfit external Det1Mvg parameter (zero = 0.0d0) data xtol /1.0d-2/, epsfcn /1.0d-6/, ep11 /940.d0/ data Scale /1.d5,1.d6,1.d6,1.d5,1.d5,1.d4/ c********************************************************* call GetFit(x) c print x Fvec if iflag == 0 if (iflag .eq. 0) then write(8, 900) call PrtPot() else c calculate chi-square if iflag != 0 c chi-square from scattering data c nfit is assgined in obs (to be 5) call Obs(er1, er2, ner) do i = 1, nfit Fvec(i) = ((exp_xs(i,6) - th_xs(i,6))/exp_xs(i,6))**2 enddo c constraints from P11 phase shift Fvec(4) = abs((exp_xs(2,3) - th_xs(2,3))/exp_xs(2,3)) Fvec(5) = ((exp_xs(5,3) - th_xs(5,3))/exp_xs(5,3))**2 c chi-square from p11 pole (nucleon mass) Xpole(1) = ep11 - mpion - Mass(1) Xpole(2) = 0. Nifty(6) = 3 call GetPole(Xpole,xtol,epsfcn) Nifty(6) = 6 Fvec(nfit+1) = (Xpole(1)+mpion+Mass(1)-ep11)**2 c Fvec(nfit+2) = (X(2)/ep11)**2 do i = 1, nfit+1 Fvec(i) = Scale(i)*Fvec(i) enddo write(*,999) f0,Mbare(1),Mbare(2), & Xpole(1)+mpion+Mass(1),Fvec(3),Fvec(6) endif 999 format('CHI2::f0,Mbare=',3e12.5,2x,'POLE=',3e12.4) 900 format('0', 10('-'), 'Chi2, Beginning of printing mode ', 10('-')) 940 format('0', 'Chi-Square = ', e13.7, & 3x, 'Chi-Square/per-freedom = ', e13.7) 945 format('0', 'Chi-Square = ', e13.7) return end