Title :EELS Keywords :EELS,AEM,CTEM,STEM,BACKGROUND,STATISTICS Computer :DEC LSI-11/73 Operating System :RSX-11M-PLUS Programming Language :DEC-FORTRAN IV Hardware Requirements :None Author(s) :Dr. Pierre TREBBIA Correspondence Address :Laboratoire de Physique des Solides :Bat. 510, F91405 ORSAY CEDEX FRANCE Abstract: We present an unbiased method for the estimation of the background in EELS spectra. It looks for the maximum likelihood of a power law model whose two dependent parameters A and R are estimated together with their variances and covariance. Applying the usual rules of error propagation, core-loss characteristic signals and their variances are estimated. Results can be used as input data for the programs QUANTI and LIMIT which are also provided by the EMMPDL facility. A complete description of the algorithm is given in "Unbiased Method for Signal Estimation in Electron Energy Loss Spectroscopy...", P. TREBBIA, Ultramicroscopy (1988). Title :EELS Keywords :EELS,AEM,CTEM,STEM,BACKGROUND,STATISTICS Computer :DEC LSI-11/73 Operating System :RSX-11M-PLUS Programming Language :DEC-FORTRAN IV Hardware Requirements :None Author(s) :Dr. Pierre TREBBIA Correspondence Address :Laboratoire de Physique des Solides :Bat. 510, F91405 ORSAY CEDEX FRANCE Description : see comments line in the source code text References : see comments line in the source code text Compilation procedure : compile the main program EELS and the 7 functions and/or subroutines FITELS,FITAR,FCTNAR,DERIV,FCHISQ, INV,INDEXC. Linking procedure : Link the 8 resulting object files. Test data : SPECTRUM.DAT is a MgO EELS spectrum (ASCII) which can be used to test the program. FITELS.DAT is the output that EELS should give if the appropriate parameters are entered. General comments : If the compiler is not a DEC-FORTRAN IV compiler, do check the source code : for example, the ! sign in a line means that the remaining text is comments, or the LOG function is implicitely changed to DLOG if the variable is double precision. Title :EELS Keywords :EELS,AEM,CTEM,STEM,BACKGROUND,STATISTICS Computer :DEC LSI-11/73 Operating System :RSX-11M-PLUS Programming Language :DEC-FORTRAN IV Hardware Requirements :None Author(s) :Dr. Pierre TREBBIA Correspondence Address :Laboratoire de Physique des Solides :Bat. 510, F91405 ORSAY CEDEX FRANCE PROGRAM EELS c c LAST VERSION : 15-JUL-1987 09:32:26 c c purpose c ------- c This program is the root of a program set whose task is to compute c the core-loss signal in an EELS spectrum recorded over 1024 channels. c Both intensities and energies values are handled in single precision c floating point format. c It estimates by a fit (see FITELS) the maximum likelihood of a c fitting function (see FCTNAR) in a fit area. Then this function is c extrapolated, and signal & backround are both estimated with their c variances. c The output of this program can be input in either program LIMIT c (to check the detection limit of an element) or in program QUANTI c (to compute confidence intervals on atomic concentrations). c c subroutines and function subprograms required c --------------------------------------------- c c fitels,indexc,fctnar c c comments c -------- c 1) Modify statement PARAMETER (taille =1024) in the whole set of c programs in order to increase the size of computable spectra. c 2) The integration of the signal is made over enrgy windows ranging c from 10 to 200 eV by steps of 10 eV. c 2) For building an executive task, one must : c a) compile the following FORTRAN programs : c EELS,FITELS,FITAR,FCTNAR,DERIV,FCHISQ,INV,INDEXC. c b) link all the resulting object files. c c author : c -------- c Pierre TREBBIA c US 41 : "Microscopie Electronique Analytique Quantitative" c Laboratoire de Physique des Solides, Bat. 510 c Universite Paris-Sud, F91405 ORSAY Cedex c Phone : (33-1) 69 41 53 68 c integer taille parameter (taille=1024) double precision taup ! Error matrix dimension spc(taille),fit(taille),x(taille),taup(2,2) real*8 a(2) logical pr pr=.true. ! enable record of data c c Results storage ? c ----------------- c type 2 2 format(' Do you want a report ? [default : Y] ? ',$) read(5,1010,end=800) rep if ((rep.eq.'n').or.(rep.eq.'N')) pr=.false. if(pr) then open(4,name='FITELS.DAT',status='new') type *,' ** Your report is in the file FITELS.DAT **' endif c c Read the spectrum c ----------------- c c A subroutine must be included here which : c - opens the file containing the data, c - put in SPC array the recorded intensities, c - put in X array the associated energies. c As an exemple : c open(1,type='old',access='direct',name='SPECTRUM.DAT',shared) do 30 i=1,(taille/128) ! read intensities 30 read(1'i,end=1500) (spc(j),j=(i-1)*128+1,i*128) enrj1=451.0 ! energy value of the first channel xpas=1.000 ! energy increment per channel do 40 i=1,taille ! put in X array the energy values 40 x(i)=enrj1+(i-1)*xpas c c Look for the maximum likelihood c ------------------------------- c call fitels(x,spc,fit,ynorm,n1,chi,a,taup,pr) c c Subtract the background & put the result in FIT c ----------------------------------------------- c do 100 i=1,taille 100 fit(i)=spc(i)-fit(i) c c Ask for the lowest integration limit c ------------------------------------ c write(5,150) 150 format(' Signal integration from energy : ',$) read(5,*) enrj ideb=indexc(x,taille,enrj) c c Signal measurement c ------------------ c sign = signal c exper = signal + background c s(signal) = standard deviation c write(5,200) x(ideb),ideb if(pr) write(4,200) x(ideb),ideb 200 format(//,' Signal measurement',/,' ------------------',//, & ' Integration from : ',f10.3,' eV ( channel :',i5, & ' )',//,' DELTA TOTAL SIGNAL BACK ', & 'h S(signal) SNR',/) do 300 i=1,20 xfin=x(ideb)+10.*float(i) if(xfin.gt.x(taille)) go to 1500 ifin=indexc(x,taille,xfin) delta=x(ifin)-x(ideb) sign=0. exper=0. do 230 j=ideb,ifin sign=sign+fit(j) 230 exper=exper+spc(j) sign=sign*xpas exper=exper*xpas back=exper-sign c c Estimate variances c ------------------ c somme1=0. somme2=0. do 240 j=ideb,ifin term1=ynorm*fctnar(x,j,n1,a) term2=term1*(log(x(j)/x(n1))) somme1=somm1+term1 240 somme2=somme2-term2 somme1=somme1*xpas/a(1) somme2=somme2*xpas varar=taup(1,1)*somme1*somme1 varar=varar+taup(2,2)*somme2*somme2 varar=varar+2.*taup(1,2)*somme1*somme2 c c Compute h = 1+var(back)/back c ---------------------------- c h=1.+varar/back ! varar = var(back) varar=varar+exper ! varar = var(signal) c c Sigma = standard deviation of signal c ------------------------------------ c sigma=sqrt(varar) snr=sign/sigma ! signal/noise ratio c c Output the results c ------------------ c write(5,310) delta,exper,sign,back,h,sigma,snr if(pr) write(4,310) delta,exper,sign,back,h,sigma,snr 300 continue 310 format(f7.1,3f11.0,f8.2,f10.0,f8.2) c c Program exit c ------------ c 800 if(pr) then close(5) open(5,status='new') write(5,805) 805 format(10x,'Do you want your report to be printed ? ', & '[default : N] ',$) read(5,1010,end=1500) pri if((pri.eq.'y').or.(pri.eq.'Y')) then close(4,dispose='print') type *,'Don''t forget your report !' endif endif 1010 format(a1) 1500 close(1) close(5) stop end SUBROUTINE FITELS(X,SPC,YFIT,YNORM,N1,CHISQR,A,TAUP,PR) c c LAST DATE : 15-JUL-1987 10:17:26 c c purpose c ------- c Manages a fit between an experimental EELS spectrum recorded on c 1024 channels and a theoretical model AZERO*E**-R c c description of parameters c ------------------------- c input : c ------- c x ------> array of energies c spc ----> array of recorded counts c pr -----> logical flag for results recording c c output : c -------- c yfit ---> array of results c ynorm --> intensities normalization factor c n1 -----> channel number of the high energy limit of the fit area c chisqr -> final (minimum) reduced chi-square c a ------> array of parameters for the fit : A(1) and A(2) c taup ---> error matrix : variances & covariance (2x2) c c subroutines and function subprograms required c --------------------------------------------- c fitar,fctnar,inv c c comments c -------- c 1) The fitting area [N0,N1] must contain less than 1001 channels. c 2) This program calls the FITAR subrooutine until the chi-square c value reaches a constant minimum value (within a precision c given by PRECIS). c 3) In order to get rid of possible overflows, SPC is given to c FITAR subroutine after division by YNORM. c YNORM is such that SPC(N1) = 100. c 4) The fit routine searches for the "best" values of : c A(1) = (AZERO/YNORM)*E(N1)**(-R) A(1) ~ 100. c A(2) = R R ~ 3. c 5) At the beginning of the search, R is estimated by the approximated c Egerton's formula. c 6) A(1) and A(2) are dependent. Their variances and covariance c are computed and stored in the error matrix TAUP. c 7) AMEM(1) & AMEM(2) are stored values of A(1) & A(2) c 8) AMEM(3) & AMEM(4) are stored values of CHI & PRECIS c 9) The program performs some usefull tests on [N0,N1] c 10) From final values of A(1) and A(2), and from matrix TAUP, the c program estimates AZERO and Sigma(AZERO). c c author : c -------- c Pierre TREBBIA c US 41 : "Microscopie Electronique Analytique Quantitative" c Laboratoire de Physique des Solides, Bat. 510 c Universite Paris-Sud, F91405 ORSAY Cedex c Phone : (33-1) 69 41 53 68 c integer taille PARAMETER (TAILLE=1024) double precision taup,xinc real*8 a(2),amem(4),coeff dimension x(1),spc(1),yfit(1),taup(2,2) dimension save(taille),nec(3),nprob(3) logical pr,scale c c SCALE is a logical flag for scaling the error matrix TAUP with c minimum reduced chi-square. c 1 scale=.false. c c Define the fit area c ------------------- c 2 type *,'Define the fit area' write(5,3) 3 format(' Enter the channel numbers : ',$) read(5,*) m0,m1 n0=min(m0,m1) n1=max(m0,m1) if(n0.lt.3) then type *,' Move left edge to the right' go to 2 endif if(mod(n0+n1,2).ne.0) then ! Check fit area can be splitted type *,' Automatic parity adjustment' n0=n0+1 endif npt=n1-n0+1 ! number of data points in fit area if(npt.lt.3) then type *,' Increase the fit area' go to 2 endif if(npt.gt.1000) then type *,' Reduce the fit area' go to 2 endif c c Estimate the confidence interval (alpha = 0.05) for minimum chi-square c ---------------------------------------------------------------------- c nterm=2 ! number of parameters to be estimated nfree=npt-nterm ! number of degree of freedom chimin=2.77/sqrt(float(nfree)) chimax=1.+chimin chimin=max(0.,(1.-chimin)) write(5,10) n0,x(n0),n1,x(n1),npt,chimin,chimax if(pr) write(4,10) n0,x(n0),n1,x(n1),npt,chimin,chimax 10 format(/,' On starting blocks',/, & ' ------------------',/, & ' Fit from channel ',i4,' (',f7.2,' eV) to channel', & i4,' (',f7.2,' eV) : ',i5,' points',/,' At level 0.05, ', & 'reduced chi-square is predicted between ',f6.3,' & ',f6.3) c c Estimation of the initial value of R (Egerton's formula) c -------------------------------------------------------- c nmean=(n0+n1)/2 sum1=0. do 13 i=n0,nmean 13 sum1=sum1+spc(i) sum2=0. do 14 i=nmean,n1 14 sum2=sum2+spc(i) r0=log(sum1/sum2) a(2)=2.*r0/(log(x(n1)/x(n0))) c c Is R good ? c if((a(2).gt.10.).or.(a(2).lt.1.)) then type *,' Initial value of R is 3' a(2)=3. endif c c Copy SPC in SAVE & translate the fit area c ----------------------------------------- c do 20 i=1,taille 20 save(i)=spc(i) x0=x(1) xinc=(x(taille)-x(1))/float(taille-1) ! energy width per channel temp=(spc(n1-1)+3.*spc(n1)+spc(n1+1))/5. do 30 i=1,npt x(i)=x(i+n0-1) 30 spc(i)=spc(i+n0-1) c c Normalization c ------------- c ynorm=spc(npt)/100. do 35 i=1,npt 35 spc(i)=spc(i)/ynorm psimax=chimax/ynorm psimin=chimin/ynorm c c Estimation of the initial value of A c ------------------------------------ c a(1)=temp/ynorm write(5,40) a(1),a(2) if(pr) write(4,40) a(1),a(2) 40 format(' Initial values : A = ',f8.4,' R = ',f7.4) c c Definition of the convergence precision c --------------------------------------- c precis=0.001 write(5,50) 50 format(' Convergence precision [default : 0.001] ? ',$) read(5,90) rep 90 format(f12.8) if(rep.ne.0.0) precis=rep rep=precis precis=precis/ynorm c c Get started for the first fit call c ---------------------------------- c ncall=1 nreset=0 amem(1)=a(1) amem(2)=a(2) amem(3)=0. amem(4)=precis c c Fit call c -------- c 100 continue call fitar(x,spc,npt,nterm,a,yfit,chisqr,amem,ncall,nreset) c c Put in chieg the initial reduced chi-square c ------------------------------------------- c if(ncall.eq.1) then chi0=amem(3) chieg=chi0*ynorm write(5,105) chieg if(pr) write(4,105) chieg 105 format(' Initial value of chi-square : ',f12.4) endif c c Precision test c -------------- c dchi=chisqr-chi0 if(abs(dchi).gt.precis) then chi0=chisqr ncall=ncall+1 amem(1)=a(1) amem(2)=a(2) amem(3)=chi0 go to 100 endif c c Is chi-square within confidence interval ? c ------------------------------------------ c if((chisqr.gt.psimax).or.(chisqr.lt.psimin)) then tstsca=0.0000001/ynorm ! give up below tstsca if(precis.lt.tstsca) then type *,' Impossible to modify chi-square !' scale=.true. ! enable the scaling of matrix TAUP go to 109 endif precis=precis/10. ! test if chi-square is at minimum amem(4)=precis rep=precis*ynorm chi0=chisqr ncall=ncall+1 amem(1)=a(1) amem(2)=a(2) amem(3)=chi0 write(5,108) ynorm*chisqr,rep if(pr) write(4,108) ynorm*chisqr,rep 108 format(' Reduced chi-square out of range : ',f6.3, & /,' => Try with a better precision : ',e10.1) go to 100 endif 109 continue c c Results c ------- c chisqr=chisqr*ynorm ! chisqr = reduced minimum chi-sqare write(5,110) x(1),x(npt),ynorm,nfree,rep,a(1),a(2), & chieg,chisqr,ncall,nreset if(pr) write(4,110) x(1),x(npt),ynorm,nfree,rep,a(1),a(2), & chieg,chisqr,ncall,nreset 110 format(/,' Results', & /,' -------', & /,3x,'Fit between ',f9.3,' eV & ',f9.3,' eV', & /,3x,'Normalization : ',g, & /,3x,'Degree of freedom : ',i3,3x,'Precision : ',e8.1, & //,3x,'Last estimations :',3x, & ' A = ',f12.4,10x,' R = ',f7.4,/,3x,'Chisqr : ',f7.4 & ' -> ',f7.4,4x,'in ',i4,' loop(s) & ',i4,' reset(s)', & //,' Estimation of variances & covariance', & /,' ------------------------------------') c c Compute matrix SIGMA-1 c ---------------------- c d2(chi-deux)/dA2 = taup(1,1) c d2(chi-deux)/dR2 = taup(2,2) c d2(chi-deux)/dAdR = taup(1,2) = taup(2,1) c somme1=0. somme2=0. somme3=0. coeff=-2.*a(2) do 400 i=1,npt ratio=x(i)/x(npt) zlogr=log(ratio) rapp1=yfit(i)/spc(i) rapp2=(2.*yfit(i)-spc(i))/spc(i) somme1=somme1+yfit(i)*rapp1 somme2=somme2+yfit(i)*rapp2*zlogr*zlogr 400 somme3=somme3-yfit(i)*zlogr*rapp2 taup(1,1)=somme1*ynorm/(a(1)*a(1)) taup(2,2)=somme2*ynorm taup(1,2)=somme3*ynorm/a(1) taup(2,1)=taup(1,2) c c Compute matrix SIGMA c -------------------- c call inv(taup,determ) c c Are variances found positive ? c ------------------------------ c if((taup(1,1).lt.0.).or.(taup(2,2).lt.0.)) then write(5,430) taup(1,1),taup(2,2) 430 format(' Negative variance(s) ! : ',2g) call exit endif c c Conditional scaling of matrix TAUP c ---------------------------------- c if((chisqr.gt.1.).and.(scale)) then do 470 i=1,2 do 470 j=1,2 taup(i,j)=taup(i,j)*chisqr 470 continue endif c c Output variances c ---------------- c sq1=sqrt(taup(1,1)) sq2=sqrt(taup(2,2)) write(5,480) taup(1,1),taup(2,2),taup(2,1),sq1,sq2 if(pr) write(4,480) taup(1,1),taup(2,2),taup(2,1),sq1,sq2 480 format(/,3x,'variance(A) : ',e10.3,/,3x,'variance(R) : ',e10.3, & /,3x,'covariance : ',e10.3, & /,3x,'sigma(A) : ',e10.3,/,3x,'sigma(R) : ',e10.3) c c Restore SPC & optimal YFIT c -------------------------- c do 500 i=1,taille spc(i)=save(i) x(i)=x0+xinc*float(i-1) if(i.lt.n0) then yfit(i)=spc(i) else yfit(i)=fctnar(x,i,n1,a)*ynorm endif 500 continue c c Numerical calculation of data area and fit area with standard deviation c ----------------------------------------------------------------------- c c somme1=d(fitarea)/d(A) computed on fit area c somme2=d(fitarea)/d(R) " " " " c aread=0. ! data area areaf=0. ! fit area somme2=0. do 550 i=n0,n1 aread=aread+spc(i) areaf=areaf+yfit(i) term1=yfit(i)*log(x(i)/x(n1)) 550 somme2=somme2-term1 somme1=areaf*xinc/a(1) somme2=somme2*xinc c c Correction of systematic error on fit area c ------------------------------------------ c areaf=areaf+chisqr*float(nfree) varar=taup(1,1)*somme1*somme1 varar=varar+taup(2,2)*somme2*somme2 varar=varar+2.*taup(1,2)*somme1*somme2 ! VARAR = variance(fit area) if(varar.lt.0.) then write(5,600) varar 600 format(' Negative variance (fit area) ! :',g) call exit endif sigar=sqrt(varar) c c Compare data area & fit area c ---------------------------- c darea=abs(areaf-aread)/aread zintg1=aread*xinc zintg2=areaf*xinc write(5,605) if(pr) write(4,605) 605 format(/,' Tests on fit area', & /,' -----------------') write(5,610) aread,areaf,aread-areaf,darea, & zintg1,zintg2,zintg1-zintg2,varar,sigar if(pr) write(4,610) aread,areaf,aread-areaf,darea, & zintg1,zintg2,zintg1-zintg2,varar,sigar 610 format(/,' Summation of Data : ',g,/, & ' Corrected summation of Fit : ',g, & /,' Difference : ',e10.3,/,' Relative difference : ',e10.3, & ///,' Integral of Data : ',g,/,' Integral of Fit : ',g,/, & ' Difference : ',e10.3,//, & ' Variance(Fit Integ.) : ',e10.3,/,' Sigma(Fit Integ.) : ',e10.3) c c Experimental dispersion in fit area c ----------------------------------- c do 650 i=1,3 650 nec(i)=0 nprob(1)=nint(float(n1-n0+1)*0.31731) nprob(2)=nint(float(n1-n0+1)*0.04551) nprob(3)=nint(float(n1-n0+1)*27e-4) do 653 i=n0,n1 ecart=abs(spc(i)-yfit(i))/sqrt(yfit(i)) do 653 j=1,3 if(ecart.gt.float(j)) nec(j)=nec(j)+1 653 continue write(5,655) if(pr) write(4,655) 655 format(/,' Experimental dispersion in fit area',/, & ' -----------------------------------',/) write(5,658) (j,nec(j),nprob(j),j=1,3) if(pr) write(4,658) (j,nec(j),nprob(j),j=1,3) 658 format(' Nber of deviations greater than ',i1,' sigma :',i4, & ' Predicted Nber :',i4) write(5,660) 660 format(/,' Everything OK ? [default : Y] ',$) read(5,1000) rep if((rep.ne.'y').and.(rep.ne.'Y').and.(rep.ne.' ')) go to 1 c c Estimation of AZERO & standard deviation c ---------------------------------------- c a0=ynorm*a(1)*(x(n1)**a(2)) somme1=a0/a(1) somme2=a0*log(x(n1)) varar=taup(1,1)*somme1*somme1 varar=varar+taup(2,2)*somme2*somme2 varar=varar+2.*taup(1,2)*somme1*somme2 if(varar.lt.0.) then write(5,700) varar 700 format(' Negative variance(A0) ! : ',g) call exit endif sigar=sqrt(varar) write(5,715) a0,sigar if(pr) write(4,715) a0,sigar 715 format(/,' ****** Azero : ',e10.4,' sigma(Azero) : ', & e10.4,' ******',/) return 1000 format(a1) end SUBROUTINE FITAR(X,Y,NPTS,NT,A,YFIT,CHISQR,AM,NCALL,NRESET) c c LAST VERSION : 15-JUL-1987 10:00:22 c c purpose c ------- c Makes a least squares fit to a power law function with a linearization c of the fitting function FCTNAR = AZERO*E**-R c c description of parameters c ------------------------- c input : c ------- c x --------> array of data points for independent variable : energies c y --------> array of data points for dependent variable : counts c npts -----> number of pair of data points (<1001) c nt -------> number of parameters : 2 c a --------> array of parameters : size = 2 c am -------> optimal values founded by the previous call c am(1) = a(1) c am(2) = a(2) c am(3) = chisqr c am(4) = precis c ncall ----> number of FITAR calls c nreset ---> number of reset(s) (see comments) c c output : c -------- c a --------> array of parameters c yfit -----> array of calculated values of Y c chisqr ---> reduced chi-square for fit c am -------> optimal values founded by the previous call c am(1) = a(1) c am(2) = a(2) c am(3) = chisqr c am(4) = precis c nreset ---> number of reset(s) (see comments) c c subroutines and function subprograms required c --------------------------------------------- c deriv,fctnar,fchisq,inv c c comments c -------- c 1) This program is adapted from program CURFIT published by c P.R. BEVINGTON in "Data Reduction and Error Analysis for the c Physical Sciences" Ed. McGraw-Hill 1969. c 2) The CURFIT program has been adapted to fit a power law model. c 3) FLAMDA ---> proportion of gradient search included c FLAMDA = 0.0001 at begining of search c 4) Dimensions valid for NT = 2 (A(1) and A(2)) c 5) The fitting function is : c yfit(i) = a(1)*(x(i)/x(npts))**(-a(2)) c 6) A Poisson weighting is used. For the first estimation of c chi-square, the variance used as weight is Y (mode -1). c Then, YFIT is used as variance (mode 1). See program FCHISQ. c 7) NPTS must be < 1001 (DIMENSION statement). c 8) The program checks whether R is within reasonable limits [1,10]. c If not, it forces a reset, starting a new search from c values a(1) = am(1) & a(2) = am(2)*1.001. c c author : c -------- c Pierre TREBBIA c US 41 : "Microscopie Electronique Analytique Quantitative" c Laboratoire de Physique des Solides, Bat. 510 c Universite Paris-Sud, F91405 ORSAY Cedex c Phone : (33-1) 69 41 53 68 c double precision array real*8 a(1),b(2),alpha(2,2),beta(2),deri(2),am(1),aprec dimension x(1),y(1),yfit(1) DIMENSION weight(1000),array(2,2) logical egert,flagr c c FLAGR is a logical flag which is .true. if a reset is needed. c EGERT is a logical flag which is .true. only at the first call. It c enables the estimation of the reduced chi-square for the starting c values of A and R. c flagr=.false. if(ncall.eq.1) egert=.true. 10 flamda=0.0001 nfree=npts-nt ! degree of freedom c c Evaluate weights for alpha and beta matrices c -------------------------------------------- c do 20 i=1,npts 20 weight(i)=1./y(i) c c Evaluate alpha and beta matrices c -------------------------------- c 31 do 34 j=1,nt beta(j)=0. do 34 k=1,j 34 alpha(j,k)=0. do 50 i=1,npts call deriv(x,i,npts,a,deri) do 46 j=1,nt beta(j)=beta(j)+weight(i)*(y(i)-fctnar(x,i,npts,a))*deri(j) do 46 k=1,j 46 alpha(j,k)=alpha(j,k)+weight(i)*deri(j)*deri(k) 50 continue 51 do 53 j=1,nt do 53 k=1,j 53 alpha(k,j)=alpha(j,k) c c Evaluate chisquare at starting point c ------------------------------------ c do 62 i=1,npts 62 yfit(i)=fctnar(x,i,npts,a) if(egert) then mode=-1 chisq1=fchisq(y,y,npts,nfree,mode,yfit) else mode=1 chisq1=fchisq(y,yfit,npts,nfree,mode,yfit) endif c c Store in am(3) chi-square at starting point c ------------------------------------------- c if(egert) then am(3)=chisq1 egert=.false. endif c c In case of reset, did we get it by chance ? c ------------------------------------------- c if(flagr) then test=chisq1-am(3) flagr=.false. if(test.lt.am(4)) then if(test.gt.0.) then a(1)=am(1) a(2)=aprec chisq1=am(3) endif b(1)=a(1) b(2)=a(2) chisqr=chisq1 go to 101 endif endif c c Invert modified curvature matrix to find new parameters c ------------------------------------------------------- c 71 do 74 j=1,nt do 73 k=1,nt 73 array(j,k)=alpha(j,k)/sqrt(alpha(j,j)*alpha(k,k)) 74 array(j,j)=1.+flamda 80 call inv(array,det) 81 do 84 j=1,nt b(j)=a(j) do 84 k=1,nt 84 b(j)=b(j)+beta(k)*array(j,k)/sqrt(alpha(j,j)*alpha(k,k)) c c Is R within acceptable range ? c ------------------------------ c if((b(2).gt.10.).or.(b(2).lt.1.)) then nreset=nreset+1 a(1)=am(1) aprec=am(2) am(2)=am(2)*1.001 a(2)=am(2) flagr=.true. go to 10 endif c c Compute new chi-square c ---------------------- c do 92 i=1,npts 92 yfit(i)=fctnar(x,i,npts,b) 93 mode=1 chisqr=fchisq(y,yfit,npts,nfree,mode,yfit) if(chisq1-chisqr) 95,101,101 c c If chisquare increased, increase flamda and try again c ----------------------------------------------------- c 95 flamda=flamda*2. go to 71 c c Store parameters c ---------------- c 101 continue do 103 j=1,nt 103 a(j)=b(j) 110 return end FUNCTION FCTNAR(X,I,I0,A) c c LAST VERSION : 15-JUL-1987 09:41:42 c c purpose c ------- c Evaluates function AZERO*E(i)**-R at position i. c c description of parameters c ------------------------- c input : c ------- c x -----> array of energies c i -----> location where the function is evaluated c i0 ----> index of origin for data points c a -----> array of parameters c c output : c -------- c FCTNAR(i) = a(1)*(x(i0)**R)*(x(i)**-R) c c subroutines and function subprograms required c --------------------------------------------- c none c c comments c -------- c a(1)=AZERO*E(i0)**-R E(i0)=x(i0) R=a(2) c real*8 a(1) dimension x(1) z1=x(i)/x(i0) z2=z1**(-a(2)) fctnar=a(1)*z2 return end SUBROUTINE DERIV(X,I,I0,A,DERI) c c LAST VERSION : 15-JUL-1987 09:44:54 c c purpose c ------- c c evaluates at location i the 2 partial derivatives of the function c FCTNAR(X,I,I0,A) with respect to a(1) and a(2). c c description of parameters c ------------------------- c input : c ------- c x --------> array of energies c i --------> location of the derivatives calculation c i0 -------> origin point for FCTNAR c a --------> array of parameters : a(1) and a(2) c c output : c -------- c deri ----> array of the two local derivatives c c subroutines and function subprograms required c --------------------------------------------- c fctnar c c comments c -------- c The function to be derived is : c a(1)*(x(i)/x(i0))**(-a(2))=FCTNAR(x,i,i0,a) c c => At location i, c deri(1) = fctnar(x,i,i0,a)/a(1) c deri(2) = fctnar(x,i,i0,a)*(-log(x(i)/x(i0))) c c real*8 a(1),deri(1) dimension x(1) z=fctnar(x,i,i0,a) deri(1)=z/a(1) deri(2)=(-log(x(i)/x(i0)))*z return end FUNCTION FCHISQ(Y,VARY,NPTS,NFREE,MODE,YFIT) c c LAST VERSION : 15-JUL-1987 09:46:58 c c purpose c ------- c Evaluates reduced chi-square for fit to data c fchisq=sum((y-yfit)**2/variance(y))/nfree c c The value used for variance(y) is determined by MODE. c c description of parameters c ------------------------- c input : c ------- c y ------> array of data points c vary ---> array of variances for data points c npts ---> number of data points c nfree --> number of degrees of freedom c mode --> determines method of weighting least-squares fit c +1 : instrumental => 1/vary c 0 : no weighting => 1 c -1 : Poisson => 1/y c yfit --> array of calculated values of y c c output : c -------- c fchisq -> reduced chi-square c c subroutines and function subprograms required c --------------------------------------------- c none c c author : c -------- c P.R. BEVINGTON in "DATA REDUCTION AND ERROR ANALYSIS FOR THE c PHYSICAL SCIENCES", Ed. McGraw-Hill, 1969. c double precision chisq,weight dimension y(1),vary(1),yfit(1) 11 chisq=0. 12 if (nfree) 13,13,20 13 fchisq=0. go to 40 c c Accumulate chi square c --------------------- c 20 do 30 i=1,npts 21 if(mode) 22,27,29 22 if(y(i)) 25,27,23 23 weight=1./y(i) go to 30 25 weight=1./(-y(i)) go to 30 27 weight=1. go to 30 29 weight=1./vary(i) 30 chisq=chisq+weight*(y(i)-yfit(i))**2 c c Divide by number of degrees of freedom c -------------------------------------- c 31 free=nfree 32 fchisq=chisq/free 40 return end SUBROUTINE INV(ARRAY,DET) c c LAST VERSION : 15-JUL-1987 09:54:29 c c purpose c ------- c Computes the inverse of a symmetric 2x2 matrix c c description of parameters c ------------------------- c input: c ------ c array ---> input matrix which is replaced by its inverse c c output: c ------- c array ---> inverse of input matrix c det -----> determinant of input matrix c c subroutines and function subprograms required c --------------------------------------------- c none c c comments c -------- c 1) Matrices are stored in DOUBLE PRECISION format. The determinant c is calculated in double precision format and output in single c precision format. c 2) Use subroutine INVMAT instead of INV for inverting symmetric c matrices whose order is greater than 2. c double precision array,result,determ dimension array(2,2),result(2,2) c c Compute the determinant c ----------------------- c determ=array(1,1)*array(2,2)-array(1,2)*array(2,1) if(determ.eq.0.) then type *,' Matrix is singular !' call exit endif c c Compute the inverse matrix c -------------------------- c result(1,1)=array(2,2) result(2,2)=array(1,1) result(1,2)=-array(1,2) result(2,1)=-array(2,1) do 100 i=1,2 do 100 j=1,2 array(i,j)=result(i,j)/determ 100 continue det=determ return end FUNCTION INDEXC(X,NPTS,VAL) c c LAST VERSION : 15-JUL-1987 09:51:03 c c purpose c ------- c This function inspects array X and finds the index of the X value c which is as closed as possible to the VAL value. c c description of parameters c ------------------------- c input : c ------- c x -----> array c npts --> dimension of array X c val ---> value searched in the array X c c subroutines and function subprograms required c --------------------------------------------- c none c c comments c -------- c 1) It is supposed that all the X values are classified in increasing c order in the array. => X(k) < X(k+1) for all k. c 2) If VAL is EXACTLY the center of 2 possible values of X, the lowest c index is returned. c c author : c -------- c Pierre TREBBIA c US 41 : "Microscopie Electronique Analytique Quantitative" c Laboratoire de Physique des Solides, Bat. 510 c Universite Paris-Sud, F91405 ORSAY Cedex c Phone : (33-1) 69 41 53 68 c dimension x(1) c c Is the job possible ? c --------------------- c if((x(1).gt.val).or.(x(npts).lt.val)) then type *,' Impossible to find index !' go to 90 endif if(x(1).eq.val) then indexc=1 go to 90 endif c c Find VAL in array X c ------------------- c do 20 i=2,npts if(x(i).lt.val) then go to 20 else if(x(i).eq.val) then indexc=i go to 90 else limit=i test1=abs(x(limit-1)-val) test2=abs(x(limit)-val) if(test1.le.test2) then indexc=limit-1 else indexc=limit endif go to 90 endif endif 20 continue 90 return end MGO ELECTRON ENERGY LOSS SPECTRUM 1024 channels from energy 451 eV to energy 1474 eV 31152. 31077. 30398. 29845. 29599. 29690. 28720. 28284. 28257. 27659. 27651. 27748. 26911. 26569. 26374. 26041. 25692. 25030. 24923. 25063. 24405. 24134. 24278. 23912. 23690. 23508. 23423. 22916. 22880. 22751. 22465. 22679. 21880. 21995. 21890. 21812. 21316. 21332. 20992. 20717. 20608. 20692. 20225. 19982. 19916. 19964. 19784. 19263. 19216. 18992. 18791. 18858. 18531. 18490. 18357. 18419. 18093. 17725. 17973. 17348. 17680. 17299. 17280. 17110. 16992. 16945. 16878. 16580. 16575. 16142. 16222. 15941. 15816. 15974. 15444. 15830. 15746. 16360. 17405. 18541. 19554. 20759. 21900. 22640. 22528. 22664. 22262. 21748. 21203. 20426. 18949. 18426. 17447. 17841. 17649. 17624. 17777. 17929. 18219. 18538. 18902. 19335. 19770. 19946. 19864. 20208. 20099. 19714. 19386. 19209. 18817. 18729. 18303. 18422. 18020. 18253. 17767. 18160. 17860. 17876. 17782. 17767. 17550. 17976. 18051. 17661. 17632. 17570. 17747. 18037. 17873. 17721. 17698. 17737. 17568. 17754. 17700. 17535. 17342. 17603. 17411. 17281. 17540. 17152. 17087. 17282. 16755. 16652. 16714. 16470. 16407. 16272. 16330. 16224. 16253. 16060. 16250. 15857. 15882. 15969. 15831. 16047. 15995. 15632. 15911. 15278. 15585. 15075. 15346. 15336. 15243. 15405. 15144. 15164. 15296. 14992. 14815. 14841. 15037. 14806. 14645. 14482. 14273. 14132. 14124. 14288. 14224. 14054. 14168. 14121. 14174. 13877. 13746. 13856. 13798. 13530. 13599. 13544. 13427. 13489. 13349. 13126. 13102. 13046. 13094. 13135. 12897. 12764. 12815. 12839. 12929. 12627. 12712. 12587. 12666. 12585. 12495. 12341. 12208. 12121. 12175. 12082. 12046. 11890. 11845. 11955. 11810. 11894. 11772. 11925. 11634. 11480. 11651. 11647. 11519. 11256. 11388. 11380. 11357. 11389. 11195. 11005. 11053. 10970. 10971. 10967. 10795. 10957. 10809. 10933. 10786. 10705. 10529. 10697. 10634. 10445. 10499. 10082. 10345. 10427. 10165. 10082. 10047. 10276. 10100. 10018. 9883. 10152. 9894. 9925. 9887. 9717. 9622. 9694. 9655. 9653. 9540. 9622. 9601. 9554. 9318. 9349. 9334. 9457. 9280. 9310. 9029. 9207. 9128. 8923. 9226. 9053. 8874. 9000. 8883. 8939. 8847. 8820. 8683. 8748. 8696. 8707. 8521. 8609. 8536. 8377. 8366. 8364. 8375. 8368. 8474. 8224. 8269. 8303. 7985. 8198. 8183. 8160. 8179. 7969. 8000. 7852. 7908. 7951. 7757. 7966. 8032. 7739. 7769. 7666. 7510. 7850. 7613. 7700. 7588. 7511. 7420. 7519. 7435. 7411. 7377. 7253. 7289. 7327. 7221. 7192. 7291. 7199. 6958. 7116. 7112. 7048. 6884. 6908. 6739. 6932. 6607. 6905. 6936. 6909. 6904. 6866. 6615. 6757. 6786. 6741. 6734. 6638. 6574. 6632. 6520. 6610. 6507. 6450. 6495. 6423. 6263. 6302. 6410. 6421. 6416. 6215. 6298. 6278. 6250. 6154. 6314. 6168. 6171. 6188. 6154. 6084. 6096. 6072. 5927. 6114. 6084. 5788. 5950. 5895. 5882. 5843. 5834. 6049. 5776. 5843. 5811. 5799. 5700. 5795. 5698. 5622. 5731. 5722. 5572. 5560. 5505. 5670. 5425. 5442. 5570. 5571. 5379. 5417. 5538. 5407. 5296. 5449. 5430. 5397. 5343. 5235. 5369. 5276. 5252. 5267. 5333. 5136. 5202. 5175. 5277. 5249. 5252. 5025. 5252. 5115. 5108. 5002. 5232. 5146. 4963. 4977. 5063. 4951. 5071. 5063. 5064. 5087. 4880. 4920. 4891. 4872. 4816. 4775. 4788. 4777. 4846. 4862. 4931. 4814. 4892. 4630. 4788. 4649. 4600. 4741. 4576. 4744. 4662. 4688. 4669. 4615. 4653. 4648. 4601. 4446. 4582. 4569. 4434. 4552. 4582. 4550. 4455. 4559. 4487. 4533. 4521. 4456. 4380. 4452. 4439. 4413. 4366. 4272. 4402. 4264. 4320. 4380. 4279. 4294. 4344. 4240. 4295. 4243. 4370. 4169. 4240. 4360. 4182. 4242. 4197. 4152. 4156. 4236. 4140. 4065. 4081. 4183. 4141. 4104. 4082. 4040. 4076. 4107. 4051. 4058. 4097. 3913. 4020. 4005. 3920. 3965. 3944. 3951. 3894. 3953. 4015. 3877. 3838. 3857. 3953. 3799. 3811. 3840. 3779. 3754. 3744. 3839. 3921. 3797. 3883. 3860. 3748. 3719. 3670. 3636. 3635. 3783. 3747. 3687. 3767. 3618. 3640. 3684. 3650. 3616. 3709. 3601. 3696. 3605. 3730. 3597. 3550. 3578. 3645. 3515. 3630. 3638. 3481. 3518. 3522. 3502. 3558. 3594. 3501. 3589. 3507. 3469. 3420. 3582. 3454. 3494. 3470. 3508. 3417. 3499. 3402. 3497. 3445. 3430. 3396. 3343. 3415. 3428. 3437. 3424. 3301. 3295. 3278. 3372. 3434. 3391. 3438. 3376. 3319. 3403. 3326. 3444. 3342. 3290. 3242. 3228. 3239. 3183. 3291. 3305. 3348. 3278. 3158. 3153. 3246. 3282. 3173. 3267. 3122. 3288. 3184. 3118. 3089. 3286. 3220. 3211. 3130. 3110. 3147. 3222. 3159. 3164. 3169. 3107. 3045. 3077. 3038. 3100. 3119. 3175. 3244. 2985. 3168. 3078. 3116. 3087. 3051. 2972. 3039. 3032. 3074. 3108. 3045. 3078. 3092. 2945. 2981. 3021. 3007. 2949. 3039. 2998. 3095. 3046. 2943. 2953. 3067. 3096. 2934. 3011. 2992. 2918. 2911. 2841. 2982. 2878. 2862. 2940. 2861. 2932. 2895. 2900. 2994. 2802. 2799. 2836. 2958. 2936. 2868. 2835. 2917. 2881. 2882. 2962. 2897. 2795. 2734. 2773. 2815. 2862. 2916. 2712. 2708. 2728. 2719. 2776. 2900. 2785. 2732. 2706. 2839. 2857. 2800. 2777. 2750. 2723. 2812. 2755. 2745. 2730. 2746. 2646. 2727. 2680. 2697. 2760. 2707. 2708. 2636. 2747. 2783. 2755. 2641. 2755. 2678. 2688. 2506. 2731. 2686. 2621. 2647. 2702. 2720. 2740. 2720. 2668. 2695. 2607. 2660. 2653. 2658. 2610. 2716. 2611. 2652. 2657. 2661. 2725. 2633. 2558. 2542. 2570. 2532. 2489. 2557. 2628. 2563. 2650. 2620. 2575. 2601. 2588. 2597. 2555. 2605. 2637. 2591. 2602. 2608. 2590. 2630. 2590. 2523. 2587. 2479. 2567. 2634. 2608. 2511. 2450. 2547. 2518. 2520. 2470. 2492. 2483. 2547. 2585. 2444. 2548. 2436. 2451. 2558. 2541. 2560. 2355. 2461. 2585. 2554. 2579. 2540. 2500. 2528. 2441. 2562. 2416. 2500. 2442. 2402. 2464. 2489. 2406. 2508. 2515. 2428. 2468. 2423. 2513. 2468. 2504. 2515. 2643. 2702. 2776. 2749. 2808. 2895. 2958. 2974. 2924. 2939. 3009. 2988. 2948. 2795. 2792. 2759. 2716. 2846. 2785. 2966. 2732. 2832. 2775. 2824. 2842. 2832. 2849. 2777. 2793. 2914. 2807. 2930. 2902. 2910. 2897. 2838. 2882. 2925. 2932. 3022. 2921. 2962. 2979. 3076. 2872. 2981. 2990. 3031. 3077. 3059. 3040. 2921. 2951. 2922. 2880. 2880. 2936. 2879. 2958. 2843. 2969. 2869. 2827. 2877. 2981. 2983. 3066. 2983. 2983. 3002. 2974. 2920. 3107. 2907. 3004. 2990. 3012. 2938. 3060. 2866. 2943. 2946. 2776. 2962. 3002. 3001. 2978. 2879. 2903. 2879. 3045. 2954. 2844. 2995. 2984. 2915. 2778. 3020. 2815. 2936. 2881. 2994. 2927. 2979. 2860. 2981. 2971. 2839. 2828. 2978. 2993. 2887. 2937. 2893. 2941. 2844. 2940. 2996. 2853. 2970. 2961. 2972. 2967. 2871. 2867. 3003. 2873. 2965. 2941. 3052. 2905. 2916. 3005. 2874. 2811. 2941. 2895. 2860. 2876. 2854. 2794. 2943. 2940. 2980. 2923. 2854. 2972. 2871. 2828. 2803. 2914. 2895. 2890. 2796. 2905. 2880. 2783. 2792. 2898. 2804. 2821. 2810. 2837. 2892. 2887. 2778. 2778. DEMONSTRATION OF PROGRAM EELS On starting blocks ------------------ Fit from channel 34 ( 484.00 eV) to channel 74 ( 524.00 eV) : 41 points At level 0.05, reduced chi-square is predicted between 0.556 & 1.444 Initial values : A = 99.1386 R = 4.0949 Initial value of chi-square : 1.2057 Results ------- Fit between 484.000 eV & 524.000 eV Normalization : 159.7400 Degree of freedom : 39 Precision : 0.1E-02 Last estimations : A = 98.7967 R = 4.1409 Chisqr : 1.2057 -> 1.1349 in 2 loop(s) & 0 reset(s) Estimation of variances & covariance ------------------------------------ variance(A) : 0.529E-01 variance(R) : 0.239E-02 covariance : -0.979E-02 sigma(A) : 0.230E+00 sigma(R) : 0.489E-01 Tests on fit area ----------------- Summation of Data : 764715.0 Corrected summation of Fit : 764715.1 Difference : -0.625E-01 Relative difference : 0.817E-07 Integral of Data : 764715.0 Integral of Fit : 764715.1 Difference : -0.625E-01 Variance(Fit Integ.) : 0.765E+06 Sigma(Fit Integ.) : 0.874E+03 Experimental dispersion in fit area ----------------------------------- Nber of deviations greater than 1 sigma : 18 Predicted Nber : 13 Nber of deviations greater than 2 sigma : 1 Predicted Nber : 2 Nber of deviations greater than 3 sigma : 0 Predicted Nber : 0 ****** Azero : 0.2875E+16 sigma(Azero) : 0.8741E+15 ****** Signal measurement ------------------ Integration from : 525.000 eV ( channel : 75 ) DELTA TOTAL SIGNAL BACK h S(signal) SNR 10.0 206707. 41039. 165668. 1.09 471. 87.21 20.0 405322. 100809. 304513. 1.35 716. 140.77 30.0 593226. 160019. 433207. 1.93 998. 160.28 40.0 784133. 231478. 552655. 2.90 1355. 170.83 50.0 963175. 299507. 663668. 4.32 1780. 168.29 60.0 1140419. 373447. 766972. 6.21 2267. 164.74 70.0 1314824. 451602. 863222. 8.59 2805. 161.02 80.0 1480183. 527178. 953005. 11.45 3382. 155.87 90.0 1639617. 602765. 1036852. 14.78 3991. 151.02 100.0 1792489. 677245. 1115244. 18.57 4624. 146.45 110.0 1938636. 750023. 1188613. 22.78 5276. 142.17 120.0 2078942. 821589. 1257353. 27.40 5939. 138.33 130.0 2212248. 890427. 1321822. 32.39 6611. 134.68 140.0 2340219. 957876. 1382343. 37.73 7288. 131.43 150.0 2462007. 1022794. 1439213. 43.38 7966. 128.40 160.0 2579294. 1086593. 1492701. 49.31 8643. 125.73 170.0 2691258. 1148205. 1543053. 55.50 9316. 123.25 180.0 2799070. 1208576. 1590494. 61.91 9984. 121.05 190.0 2901538. 1266307. 1635231. 68.52 10645. 118.96 200.0 2999985. 1322533. 1677452. 75.30 11298. 117.06