subroutine gridls(x,y,sigmay,npts,nterms,mode,a,deltaa, & sigmaa,yfit,chisqr) c c This subroutine is a slightly modified version of GRIDLS in c "Data Reduction and Error Analysis for the Physical Sciences" by c P.R. Bevington (1969), p.212 c parameter (maxp=8) real x(maxp),y(maxp),sigmay(maxp),yfit(maxp) real a(nterms),deltaa(nterms),sigmaa(nterms) character text*80 nfree=npts-nterms chisqr=0. if(nfree.le.0)goto 100 do 90 j=1,nterms c c Evaluate chi square at first two search points c call fixell(x,y,npts,a,yfit) chisq1=fchisq(y,sigmay,npts,nfree,mode,yfit) fn=0. delta=deltaa(j) 41 a(j)=a(j)+delta call fixell(x,y,npts,a,yfit) chisq2=fchisq(y,sigmay,npts,nfree,mode,yfit) if(chisq1-chisq2.eq.0)goto 41 if(chisq1-chisq2.gt.0)goto 61 c c reverse direction of search if chi square increases c delta=-delta a(j)=a(j)+delta save=chisq1 chisq1=chisq2 chisq2=save c c increment a(j) until chi square increases c 61 fn=fn+1. if(fn.gt.50)then write(text,1)j 1 format('Model parameter',i2,' did not converge', & ' in 50 iterations!!') call putout(text) return endif a(j)=a(j)+delta call fixell(x,y,npts,a,yfit) chisq3=fchisq(y,sigmay,npts,nfree,mode,yfit) if(chisq3-chisq2.ge.0)goto 81 chisq1=chisq2 chisq2=chisq3 goto 61 c c find minimum of parabola defined by last three points c 81 delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) a(j)=a(j)-delta sigmaa(j)=deltaa(j) & *sqrt(2./(float(nfree)*(chisq3-2.*chisq2+chisq1))) deltaa(j)=deltaa(j)*fn/3. 90 continue c c evaluate fit and chi square for final parameters c call fixell(x,y,npts,a,yfit) chisqr=fchisq(y,sigmay,npts,nfree,mode,yfit) 100 return end