R. Ghosh, November 2007
This guide shows the components of clickfit programs which are created automatically or which are included with each clickfit pogram but which may then be edited to suit local needs.
The main aim of clickfit was to offer an easy usage of programs written with the fitfun library. The latter offers an easy method of re-using user-supplied read-in and calculation routines which are integrated into a powerful fitting engine with integrated graphics.
Clickfit is an example written in tcl/tk script to drive fitfun model fitting programs with a modern graphical interface. Each program has a text configuration file which manages the program location, help files, and layout of the prompt windows which then are sent to the fitfun program. There are two variants:
clickfit - which treats single or sequences of data clickfit_m which treats simultaneously several sets of data In the following description clickfit will be used as being the generally applicable name, and variants will be mentioned for clickfit_m.
A brief technical description of the communications may help resolve running problems, as may the log files.
Nach oben
Clickfit is a text file which is read by the wish program on unix-like systems (clickfit.tcl or clickfit_m.tcl) and for windows is a batch file (clickfit.bat, clickfit_m.bat)which assumes the wish program is available.
For unix/linux/OsX (adding any necessary path names): % wish -f clickfit.tcl The current clickfit configuration is stored in $HOME/clickfit/ffn (or $HOME/clickfit/ffm)
For Windows: clickfit.bat The first line in this file contains the path to the wish program required to execute the script. If clickfit.bat is inserted in the program directory of the Windows Prop program launcher this should work directly. The current clickfit configuration is stored in %APPDAT%\clickfit\ffn (or ffm).
If the configuration file is not found (or has been deliberately deleted) clickfit prompts for two important pieces of information
The location of the graphics components of the PGPLOT library (font files, graphics server etc). If defined it will use the environment variable PGPLOT_DIR by default. The default location of program files: this allows help files for related programs to be shared, as well as enableing sets of programs and configuration files to be transferred to other systems easily by using this as a default path. Select the line (left click) and press the edit button to modify the line.

The programs are introduced into the selection list using the Add fit program btton. Each program has a configuration file which sets up the input boxes and help files for clickfit. If the configuration file (eg f24s.fcl) is found it is added to the list. The default directory is the program directory.
Separate sets of programs may be selected by manually renaming these configuration files.
Nach oben
After the initialisation the window shows the programs available. Clicking on a program name launches it directly.
This then brings up the prelude window (if used). The prelude obtains information which is required throughout the analysis.
The labels and fields are defined in the configuration file, and are passed to the program as a string which has to be interpreted to obtain the separate fields as shown in the source example below. Some field types can check that the input is within valid limits, or that files named actually exist.
The main clickfit window is then shown. Individual parameters may be modified by double clicking the line and then modifying the value. A non-zero step must be set if a parameter is to be varied. Typically the step is set to 1.0 (qv the fitfun description
Fitting starts by reading in data using the Read data button. This brings up the data read-in panel.
The initial fit can then be viewed pressing the trial fit button
The paramters may be modified by hand to improve the starting point, or if satisfactory a number of iterations can be set off.
The result may be viewed with the trial fit button again.
This program includes an extension routine FTEXTP which can produce a better annotated final plot. This "external" (i.e. not in the fitfun library) is called using the "J" command. One way to use this is to set it in the Memo menu, which can store up to four useful manual commands. An alternative way is to configure the j-command with an input box in the configuration file. This is then invoked using the "extras/special command menu. The input has to be read by the programmers routine FTEXTP from the buffer. (In the example "J H" will produce a PostScript plot in addition. This improved plot is shown below.
The fitfun library allows considerable flexibility for the programmer to "mix and match" routines for reading data, calculation and extra displays. The principal components of a program are illustrated below for the program f24s which will fit up to four peaks to diffraction data.
an initial, prelude section In this case the detector efficiency corrections can be read-in, together with modified off-set angles. Typically this information is passed through "private" commons for re-use, e.g. in the read-in routine later. a data read-in routine in this case the remainder of the R command line is used to find one spectrum number and frame number for treatment the calculation routine This calculates the sum of several peak shapes with the measured resolution function, allowing fitfun to optimise the parameters given a non-zero step.
Essentially the same GUI interface routines can control either single data fits (using library fitfun v7.0) or simultaneous fitting of several sets (fitfun_m v7.1) This section offers most of the original features of the fitfun command line which remain available in the menu Extras/Command
Menu options
File Save parameters into a *.ffn or *.ffm file, used on restart. Append to list file outputs current fit information to listfile Read in brings up data input panel Exit terminates program Parameters edit parameter edit parameter and step Link steps parameters grouped to be varied with the same step Copy parameter set* copies parameters from one dataset for another Fitting Limit x Ranges Restrict fitting to three x ranges (max) Step size The fractional step multiplied by the parameter step size for numerical derivatives Graphics Set scales sets scale limits for x and y Append PostScript plot add a plot of the current fit to file Cursor toggle cursor on/off in next display Title Add title to next plots Write plot datafile Write out fits and data as ascii file View View log Displays current log file View sets* lists current sets Extras Special Function (J command - often a display/output option Command Access to basic fitfun command line Debug Toggles on and off - shows comms Memo up to 4 manual commands can be stored/recalled Help Help file (or other file if configured)
Modify parameters Double click on parameter line Buttons Clear data* resets all sets Show all parameters* displays parameters for all sets Select set for display* give set number for current display Fit Sequence+ fit a sequence of data using input control file Make Sequence+ will filter a sequence of filenames to treat SAVE SAVE current parameter (reread at next start) Restart when configured - restart prgram Display Data display current data (with/without cursor) Trial Fit Show current model calculation Fit Iterations iterate the indicated (max) number of times EXIT EXIT program (please AVOID terminating window)
+ Clickfit * Clickfit_m The above example f24s shows how a production program can be developed from a prototype, using the additional J command. The programmer can supply the routines
FTPXTP to do more elegant plotting of final results etc. FTXHLP to give addditional help information (terminal version) FTQSOP to write out additional (e.g. in spreadsheet format) (called after fitting sequences of data (not clickfit_m)
Dummy routines are included in the library which are then replaced by the programmer's own routines.
When the data read is only a simple filename the "fit sequence" button is enabled, and a file browser is shown allowing sets of data to be selected for fitting after the names have been filtered, and an output file namme has been set for the results (a full copy of the parameters for each file). The FTQSOP routine may also be provided by the programmer to perform a more selective output as shown here. When more than one parameter is required (as here in dealing with multi-run/multi-frame data) the control file for the sequence fits has to be constructed by the user. For f24s a short tcl script program can generate this file xprep_f24s.bat or xprep_f24s.tcl
Once the 2d scan has been set up the file is written and then entered in the clickfit sequence file box to fit the sequence.
A control file has the form shown below:
D20 data fitting out_1.out U 50 1000 1 1000 2 1000 3 1001 1 1001 2 1001 3 line 1 is a title line 2 is the output file name for all parameters line 3 is U or T (update parameters after each fit or hold as at start) line 4 is the maximummnumber of iterations lines 5 onwards are the information sent in the R (read data) command
This program reads data from the D20 neutron multidetector diffractometer at the ILL and fits up to for peaks with a choice of model peak shapes for selected regions of data. The instrument is often used scanning temperature or other environment constraints and it is useful to treat sequences of measurements.
MAIN Program and extra help information (FTXHLP)
program f24s c**** Fits up to 4 peaks to sequences of D20 data c g77 -o f24s f24s.f calskp.f calskpx.f libfitfun.a \ c librlib.a libpgplot.a -lX11 c c MinGW c g77 -o f24s f24s.f calskp.f calskpx.f d:/libm/libffn70m.a c d:/libm/librlib.a d:/libm/libpggw520.a -mconsole -mwindows c c note version of calskp has background at centre of first peak c (parameter 8), and Gaussian then Lorentzian....
EXTERNAL DIFIN,CALSKP C calskp calculates sum of up to four peaks
COMMON/WORK/W(160000) COMMON/TITLES/NAMES(40),TX,TY COMMON/TITLEP/NPARAS COMMON/VERSION/VERP COMMON/TTYIO/INTY,INTTY,IERT COMMON/FCLOSE/ICLOSE,ISTART COMMON/PROGCH/PNAMC common/guiuse/ignum,insta,iosta,irsta common/comin/bufin character*150 bufin CHARACTER*8 NAMES CHARACTER*4 PNAM,PNAMC CHARACTER*20 TX,TY DATA NAMES/ 'FLAT BGD','slope BG','(spare)','FACTOR F', 1'P1 type ','P1 area ','P1 width','P1 posn ','P1 modif', 1'P2 type ','P2 area ','P2 width','P2 posn ','P2 modif', 1'P3 type ','P3 area ','P3 width','P3 posn ','P3 modif', 1'P4 type ','P4 area ','P4 width','P4 posn ','P4 modif', 116*' '/ DATA TX /'Two_Theta'/ DATA TY /'Counts'/ INTY=5 INTTY=6 NPARAS=24 VERP=4.0 WRITE(6,1) VERP 1 FORMAT(' f24s - version ',f4.1,' June 2007 (R.E. Ghosh, ILL)' 1//' Fits up to 4 peaks in sequences of D20 datasets '/) PNAM='f24s' PNAMC=PNAM C***** LEAVE OPEN DATA FILES ICLOSE=0 c***** plotting is closed only here, not by fitfun routines call prelude(pnam) if(ignum.gt.0) call innorc c***** clickfit prelude info from inbuf used to set up normalisation if(ignum.gt.0) go to 8888 CALL INNOR c***** detector normalisations read in at start WRITE(6,11) 11 FORMAT(/' Fits up to 4 peaks in sequences of D20 datasets '/ 1//' Manual peak fitting and parameter initialisation'// 1' Peak type :'/ 1' 1 Single Gaussian'/ 1' 2 Single Lorenztian'/ 1' 3 Voigt - Lorenztian width shown'/ 1' 4 Skewed Gaussian'/ 1' Modifier parameter for Voigt is Gaussian width '/ 1' Modifier parameter for Skewed Gaussian is LHS-width/RHS'/ 1' Width values are half width at half height'/ 1' Background is value at centre of first peak'/)
8888 continue C***** LEAVE OPEN DATA FILES ICLOSE=0 c***** plotting is closed only here, not by fitfun routines CALL FTFUNS(PNAM,DIFIN,CALskp) CALL LPENDF C***** CLOSE ANY LISTING FILE... c CALL SSEND C***** CLOSE ANY Spreadsheet FILE... CALL PGNEND(1) CALL PGNEND(2) C***** CLOSE OPEN GRAPHICS end
SUBROUTINE FTXHLP(IOTTY) WRITE(IOTTY,1) 1 FORMAT(/' f24s'/ 1' fitting peaks to diffraction data'// 1' PEAK TYPE 1 Single Gaussian'/ 1' 2 Single Lorentzian'/ 1' 3 Voigt - Lorentzian width shown'/ 1' 4 Skewed Gaussian'/ 1' Modifier parameter for Voigt is Gaussian width '/ 1' Modifier parameter for Skewed Gaussian is LHS-width/RHS'/ 1' Width values are half width at half height'/ 1/' Command J for component plots'/) RETURN END
The prelude routine sees whether the program has been started manually (ignum=0) or by clickfit. In the latter case there will be the input box results in the string bufin. The routines innor or innorc are then called to read the efficiency data, the first prompting the terminal user, the second reading bufin. The call to prelude may be omitted if no information is required (it is included in the main library automatically) Treating the prelude information
One routine INNOR, used in the terminal version prompts for input data. The second reads the buffer filled with the prelude window information.
subroutine innor c***** reads either efficiency file or vanadium run c the efficiency multipliers are returned in array v parameter (maxdat=2100) character*1 text(480) character*10 nomexp character*20 ddate character opt,str1*80,str*60,mm*1 character titn*50,fnamn*50,fnamb*50 common /ind20p/dor,pmm,pdm,pdd,paq,sam,scn real dor(30),pmm(25),pdm(30),pdd(15),paq(55),sam(15) real xob(maxdat),yob(maxdat),yrob(maxdat),yer(maxdat) real scn(35) common /ind20c/text common /ind20u/nunit common /difitr/ num,nsp,nsu common /difnor/ v(1600),nnor common /difzer/zang common /difmon/xmon common /difnorc/titn,fnamn common /outtty/kout integer idon(1600) kout=6 nnor=0 C**** There does not seem to be a 30 deg. offset now (Apr. 2001) zang=0. xmon=0. do i=1,1600 v(i)=1. end do fnamb=' Not used' fnamn=fnamb 1003 write(6,1005) 1005 format(/' Initial options to read and normalise subspectrum: '/ 1' C Continue now to data fitting'/ 1' V n Set vanadium run n'/ 1' N name Set efficiency file name'/ 1' M m Monitor renormalisation (o=none)'/ 1' Z a modify zero angle (0.0) '/ 1' L i j List run i subspectrum j'/ 1' H Help'//) 1000 if(nnor.eq.0) write(kout,10) 10 format(' No vanadium normalisation run ') if(nnor.gt.0) write(6,42) nnor,sum,dev 42 format(' Vanadium Normalisation run ',i6,' Average: ',f14.2, 1' deviation ',f10.3) 11 format(' Normalisation run: ',i6) write(kout,12) zang 12 format(' Zero angle : ',f8.3) write(kout,9) fnamn 9 format(' Efficiency file name ',a) if(fnamn.ne.fnamb) write(kout,13) titn 13 format(' Efficiency file title :',a) write(kout,14) xmon 14 format(' New monitor value :',f10.1) str1=' ' write(6,212) 212 format(' Type option C,V,Z,M,N,L,D,HELP : ',$) read(5,200,end=600) opt,str1 200 format(2a) str1(61:80)=' 0 0 0 0 0 0 /' if(opt.eq.'H'.or.opt.eq.'h') go to 1003 if(opt.eq.'L'.or.opt.eq.'l') go to 30 if(opt.eq.'V'.or.opt.eq.'v') go to 40 if(opt.eq.'Z'.or.opt.eq.'z') go to 50 if(opt.eq.'M'.or.opt.eq.'m') go to 80 if(opt.eq.'N'.or.opt.eq.'n') go to 90 if(opt.eq.'C'.or.opt.eq.'c') go to 500 if(opt.eq.'E'.or.opt.eq.'e') stop go to 1000 c c***** L list run...sub c 30 read(str1,*,err=1000) nnumr,nnums if(nnumr.le.0) go to 1003 if(nnums.le.0) nnums=1 call ind20(ier,nnumr,nomexp,ddate,text 1,dor,pmm,pdm,pdd,paq,sam,nsu,nsp) if(ier.ne.0) go to 39 write(kout,301) nnumr,nsu,nsp 301 format(' Run ',i6,' has ',i4,' subspectra starting at #',i4) if(nnums.le.0.or.nnums.ge.nsp+nsu) go to 1000 call ind20s(nnums,scn,idon,ier) call ind20x c***** close file if(ier.eq.0) go to 305 go to 1000 305 sum=0 do i=1,1600 sum=sum+idon(i) end do write(kout,32)idon 32 format(10i7) write(kout,33) nnumr,nnums,sum 33 format(' Run',i8,' sub',i4,' sum = ',f16.0) go to 1000 39 write(6,38) 38 format(' Error reading data') call ind20x go to 1000 c c c***** V Normalisation c 40 read(str1,*,err=1000) nnum if(nnum.lt.0) go to 1003 c***** cancel any efficiency file fnamn=fnamb nnor=nnum if(nnor.gt.0) go to 41 do i=1,1600 v(i)=1. end do nnor=0 go to 1000 41 continue ninum=num c***** save current open numor call ind20(ier,nnor,nomexp,ddate,text 1,dor,pmm,pdm,pdd,paq,sam,nsu,nsp) if(ier.ne.0) go to 49 nget=1 call ind20s(nget,scn,idon,ier) if(ier.ne.0) go to 49 sum=0 do i=500,1300 sum=sum+idon(i) end do sum=sum/800. dev=0 if(sum.eq.0) go to 49 do i=1,1600 if(i.gt.500.and.i.le.1300)dev=dev+(sum-idon(i))**2 v(i)=0. if(idon(i).gt.0) v(i)=sum/idon(i) c***** v will be used as a multiplier end do dev=sqrt(dev)/800. call ind20x c***** close file go to 1000 49 write(6,48) 48 format(' Error reading vanadium normalisation data') nnor=0 call ind20x go to 1000 c c***** Z set zero angle... c 50 read(str1,*,err=1000)zang go to 1000 c c***** Monitor renormalisation c 80 read(str1,*,err=1000) xxmon xmon=0. if(xxmon.gt.0) xmon=xxmon c***** note: d20 counts only on time preset ('cos of strobe electronics) c sometimes monitor is not written correctly c normal option if xmon is 0 is to ignore monitor renormalisation go to 1000 c c c***** N efficiency normalisation file c 90 j=0 do i=1,50 j=i if(str1(i:i).ne.' ') go to 91 end do 92 write(6,93) 93 format(' No efficiency file will be used') nnor=0 go to 1000 91 call trimmd(str1(j:50),lf) fnamn=str1(j:lf+j) open(8,file=str1(j:lf+j),status='old',err=96) read(8,94,err=96,end=96) titn 94 format(a) write(6,95) titn 95 format(' Normalisation file : ',a)
c first contains angles, second multipliers read(8,*,err=96,end=96) v read(8,*,err=96,end=96) v
close(unit=8) nnor=1 go to 1000 96 write(6,97) str1(j:j+lf) 97 format(' Error reading efficiency file :',a//) titn='Not used' close(unit=8) do i=1,1600 v(i)=1. end do go to 1000 C C***** continue to fit section C 500 return 600 stop end
subroutine innorc c***** version for clickfit using data from bufin c this contains c "V|N| " "filename" Monitor Zero_angle c***** reads either efficiency file or vanadium run c the efficiency multipliers are returned in array v parameter (maxdat=2100) character*1 text(480) character*10 nomexp character*20 ddate character opt,str1*80,str*60,mm*1 character titn*50,fnamn*50,fnamb*50 common /ind20p/dor,pmm,pdm,pdd,paq,sam,scn real dor(30),pmm(25),pdm(30),pdd(15),paq(55),sam(15) real xob(maxdat),yob(maxdat),yrob(maxdat),yer(maxdat) real scn(35) common /comin/bufin common /ind20c/text common /ind20u/nunit common /difitr/ num,nsp,nsu common /difnor/ v(1600),nnor common /difzer/zang common /difmon/xmon common /difnorc/titn,fnamn common /outtty/kout character*150 bufin character*1 nortyp character*50 nfile integer idon(1600) read(bufin,*) nortyp,nfile,xxmon,zangg c***** a * format is necessary because clickfit gives quoted c list of text fields c the prelude info is listed in the log file kout=6 nnor=0 C**** There does not seem to be a 30 deg. offset now (Apr. 2001) zang=0. xmon=0. do i=1,1600 v(i)=1. end do fnamb=' Not used' fnamn=fnamb if(nortyp.eq.'V'.or.nortyp.eq.'v') go to 40 if(nortyp.eq.'N'.or.nortyp.eq.'n') go to 90 go to 500
c***** V Normalisation c 40 read(nfname,*,err=49) nnum if(nnum.lt.0) go to 500 c***** cancel any efficiency file fnamn=fnamb nnor=nnum if(nnor.gt.0) go to 41 do i=1,1600 v(i)=1. end do nnor=0 go to 500 41 continue ninum=num c***** save current open numor call ind20(ier,nnor,nomexp,ddate,text 1,dor,pmm,pdm,pdd,paq,sam,nsu,nsp) if(ier.ne.0) go to 49 nget=1 call ind20s(nget,scn,idon,ier) if(ier.ne.0) go to 49 sum=0 c***** avoid beamstop region... do i=500,1300 sum=sum+idon(i) end do sum=sum/800. dev=0 if(sum.eq.0) go to 49 do i=1,1600 if(i.gt.500.and.i.le.1300)dev=dev+(sum-idon(i))**2 v(i)=0. if(idon(i).gt.0) v(i)=sum/idon(i) c***** v will be used as a multiplier end do dev=sqrt(dev)/800. call ind20x c***** close file go to 500 49 write(6,48) 48 format(' Error reading vanadium normalisation data') nnor=0 call ind20x go to 500 c c***** N efficiency normalisation file c 90 j=0 do i=1,50 j=i if(nfile(i:i).ne.' ') go to 91 end do 92 write(6,93) 93 format(' No efficiency file will be used') nnor=0 go to 500 91 call trimmd(nfile(j:50),lf) fnamn=str1(j:lf+j) open(8,file=nfile(j:lf+j),status='old',err=96) read(8,94,err=96,end=96) titn 94 format(a) write(6,95) titn 95 format(' Normalisation file : ',a) c first contains angles, second multipliers read(8,*,err=96,end=96) v read(8,*,err=96,end=96) v
close(unit=8) nnor=1 go to 500 96 write(6,97) str1(j:j+lf) 97 format(' Error reading efficiency file :',a//) titn='Not used' close(unit=8) do i=1,1600 v(i)=1. end do 500 continue c c***** Z set zero angle... c 50 zang=zangg go to 80 c c***** Monitor renormalisation c 80 xmon=0. if(xxmon.gt.0) xmon=xxmon c***** note: d20 counts only on time preset ('cos of strobe electronics) c sometimes monitor is not written correctly c normal option if xmon is 0 is to ignore monitor renormalisation return C***** continue to fit section end
Data Reading routine
subroutine difinn(ier,ir,is,npnts,xobs,yobs,yrobs) c***** reads in one spectrum... run ir, subspectrum is parameter (maxdat=2100) real xobs(maxdat),yobs(maxdat),yrobs(maxdat),yer(maxdat) real bl(40) integer idon(1600) real dor(30),pmm(25),pdm(30),pdd(15),paq(55),sam(15) real scn(35) common /ind20p/dor,pmm,pdm,pdd,paq,sam,scn common /ind20c/text common /ind20u/nunit common /ind20m/xm,xt common /difitr/ num,nsp,nsu common /difmon/xmon common /difnor/ v(1600),nnor common /difzer/ zang COMMON/PROGCH/PNAMC character txt*50,pnamc*4 character*10 nomexp character*20 ddate character*1 text(480) npnts=0 ier=0 if(ir.ne.num) call ind20x c***** close any preopened file if(ir.ne.num) call ind20(ier,ir,nomexp,ddate,text 1,dor,pmm,pdm,pdd,paq,sam,nsu,nsp) if(ier.eq.0) go to 2 write(6,1) ir 1 format(' Run ',i6,' not found ') ier=-1 return 2 num=ir c write(*,*) 'is,nsu,nsp',is,nsu,nsp if(is.lt.nsp.or.is.ge.nsu+nsp) go to 8 call ind20s(is,scn,idon,ier) if(ier.eq.0) go to 5 8 write(6,3) is,nsp,nsu 3 format 1(' Error reading subsp',i5,' Subsp start',i5,i5,' present') ier=-1 return 5 continue xang0=sam(5)-zang c***** 30 deg out at present.....June '97 if(scn(15).ne.0) xang0=scn(15)-zang c***** note: d20 counts only on time preset ('cos of strobe electronics) c sometimes monitor is not written correctly c normal option if xmon is 0 is to ignore monitor renormalisation rat=1. if(xmon.gt.0.and.xm.gt.0.) rat=xmon/xm if(rat.gt.10..or.rat.lt.0.1) write(6,15) ir,is,rat,xm 15 format(' ? warning - run ',i6,' /',i3, 1' monitor ratio is ',f10.5,' stored value is ',g12.5) do i=1,1600 xobs(i)=(i-1)*.1+xang0 yobs(i)=idon(i) yrobs(i)=rat*sqrt(yobs(i)) yobs(i)=rat*yobs(i) end do ndin=1600 if(nnor.eq.0) go to 10 do i=1,1600 yobs(i)=yobs(i)*v(i) yrobs(i)=yrobs(i)*v(i) end do 10 npnts=1600 return end
subroutine difin(npnts,xobs,yobs,yrobs,txt) parameter (maxdat=2100) common /ind20c/text common/tinc/pname,ret80 real xobs(maxdat),yobs(maxdat),yrobs(maxdat),yer(maxdat) common /difitr/ num,nsp,nsu character pname*4,ret80*80,str1*80 character txt*50 character*1 text(480) npnts=0 c***** used to show errors in reads str1=ret80 2 format(a) str1(60:80)='0 0 0 0 0 /' read(str1,*) ir,is if(ir.le.0) return if(is.le.0) is=1 call difinn(ier,ir,is,nnpnts,xobs,yobs,yrobs) if(ier.eq.0) go to 10 return 10 npnts=nnpnts write(6,12) nsu,nsp 12 format(' There are ',i4,' subspectra present, starting at #',i4) txt=' ' write(txt(1:15),15) ir,is 15 format('Run ',i6,'/',i3,':') do i=1,35 j=15+i txt(j:j)=text(i+20) end do return end
Calculation routine Note that the component curves are conserved in COMMON storage.
SUBROUTINE CALSKP(NP,P,NFIT,ANG,YUSE,YRUSE,YCALC,F) C***** Calculates sum of four peaks for fitfun fit to diff data C INPUT PARAMETERS C P 1 Flat background C P 2 slope C P 3 spare C P 4 Factor F weighting control C P 5 PEAK TYPE (1=LOR,2=GAU,3=Voigt,4=Skewed Gaussian) C P 6 PEAK HEIGHT C P 7 PEAK WIDTH C P 8 PEAK POSN C p 9 PEAK MODIFIER (Gauss width for Voigt or C skewness (Gauss_width_LHS/RHS ratio) for Skewed peak C P 10 PEAK TYPE FOR 2ND COMPONENT... ETC... C C all widths are HWHM C C***** simplified example program derived from FIRR and TAPPIT COMMON/EXTPC/YY(2100,5),YYIN(4),INPK C***** Save calculated curves for additional treatment... DIMENSION P(NP),ANG(NFIT),YUSE(NFIT),YRUSE(NFIT),YCALC(NFIT) 1,F(NFIT) DIMENSION Y(2100) C C***** Calculate y - no resolution effects C ALN2=ALOG(2.0) SLN2=SQRT(ALN2) ASIG=SQRT(2*ALN2) PI=3.141592 SPI=SQRT(PI) YYIN(1)=0. YYIN(2)=0. YYIN(3)=0. YYIN(4)=0. DO 1000 I=1,NFIT YY(I,1)=0. YY(I,2)=0. YY(I,3)=0. YY(I,4)=0. YY(I,5)=0. YCALC(I)=0. 1000 CONTINUE 1 CONTINUE INPK=0 DO 2 III=5,20,5 C***** FOR ANY PEAKS PRESENT INPK=INPK+1 IF(P(III).EQ.0) GO TO 2 C***** NOT THIS ONE YYIN(INPK)=1. IH=III+1 C***** Area IW=III+2 C***** Width IP=III+3 C***** Position IPMOD=III+4 C***** Modifier J=P(III) C***** peak type IF(J.LT.1.OR.J.GT.4) GO TO 2 C***** Other types of peak not treated GO TO (30,20,40,50) J 20 CONTINUE C***** Lorentzian function DO 21 I=1,NFIT Y(I)=0. ANGF=ANG(I) FF=(ANGF-P(IP))**2 Y(I)=Y(I)+P(IH)*P(IW)/(FF+P(IW)**2)/PI 21 CONTINUE GO TO 202 30 CONTINUE C***** Gaussian function DO 31 I=1,NFIT Y(I)=0. ANGF=ANG(I) FF=(ANGF-P(IP))**2 Y(I)=Y(I)+P(IH)*EXP(-FF*ALN2/P(IW)**2)*SLN2/(SPI*P(IW)) 31 CONTINUE GO TO 202 40 CONTINUE c***** Voigt DO 41 I=1,NFIT Y(I)=0. ANGF=ANG(I)-P(IP) SIGMA=P(IPMOD)/ASIG c***** gaussian width component XLOR=2.*P(IW) c***** Lorenztian component full width as input CALL VOIGT(ANGF,SIGMA,XLOR,YVAL,DERX,DERS,DERG) Y(I)=P(IH)*YVAL 41 CONTINUE GO TO 202 50 CONTINUE C***** skewed Gaussians (2 curves LHS/RHS) C***** Join centre is offset from CofG which is P(IP) ALF=P(IPMOD) XJOIN=P(IP)+0.5*P(IW)*(1.-ALF)/(SPI*SLN2) widlhs=P(IW)*2./(1.+ALF) widrhs=ALF*widlhs c write(6,666) xjoin,p(ip),p(iw),p(ih),alf,widlhs,widrhs c666 format(' xjoin ',f10.5,' cen/wid/area/a/l/r',6f10.5) DO 51 I=1,NFIT Y(I)=0 ANGF=ANG(I) FF=(ANGF-XJOIN)**2 IF(ANGF.LT.XJOIN) Y(I)=+P(IH)*(2./(1.+alf))*SLN2 1 *EXP(-FF*ALN2/widlhs**2)/(SPI*widlhs) IF(ANGF.GT.XJOIN) Y(I)=P(IH)*(alf*2./(1.+alf))*SLN2 1 *EXP(-FF*ALN2/widrhs**2)/(SPI*widrhs) 51 CONTINUE GO TO 202
202 DO 204 I=1,NFIT YY(I,INPK)=Y(I) C***** Each component is saved for possible later use 204 CONTINUE 2 CONTINUE c***** background is defined at centre of first peak DO 170 I=1,NFIT YY(I,5)=P(1)+P(2)*(ANG(I)-P(8)) C***** Flat background+slope YCALC(I)=YY(I,1)+YY(I,2)+YY(I,3)+YY(I,4)+YY(I,5) 170 CONTINUE DO 200 I=1,NFIT FFFF=YUSE(I)-YCALC(I) F(I)=FFFF IF(P(4).EQ.0..and.YRUSE(I).NE.0.) F(I)=FFFF/YRUSE(I) C***** Invoke weighting 200 CONTINUE RETURN END C LEVEL 2 SUBROUTINE VOIGT(X,SIGMA,GAMMA,YVAL,DERX,DERS,DERG) SUBROUTINE VOIGT(X,SIGMA,GAMMA,YVAL,DERX,DERS,DERG) C C *** VOIGT by WIFD Jun 84 *** C CC 9C CH Calculates normalised Voigt function C CD... VOIGT is the normalised VOIGT function; a convolution of a CD normalised Gaussian (half-width= sigma) and Lorentzian CD (Cauchy) function (full-width at half-height= width). The CD function is calculated by noting that the VOIGT function CD is, to within a scale factor, equal to the real part of the CD complex error function. C W.I.F.David 6-JUN-84 C Neutron Division C RAL ext. 5179 C DOUBLE PRECISION WR,WI,XX,YY C OVRTPI=0.564189584 OVRT2=0.707106781 BTEM=OVRT2/SIGMA ATEM=OVRTPI*BTEM XTEM=X*BTEM YTEM=0.5*GAMMA*BTEM XX= DBLE(XTEM) YY= DBLE(YTEM) CALL WERF(WR,WI,XX,YY) SWR=SNGL(WR) SWI=SNGL(WI) CTEM=ATEM*BTEM YVAL=ATEM*SWR DWRDX=-2.*(XTEM*SWR-YTEM*SWI) DWRDY= 2.*(YTEM*SWR+XTEM*SWI-OVRTPI) DERX=CTEM*DWRDX DERS=-ATEM*(SWR+DWRDX*XTEM+DWRDY*YTEM)/SIGMA DERG=0.5*CTEM*DWRDY C RETURN END C LEVEL 1 SUBROUTINE WERF(RS1,RS2,XX,YY) SUBROUTINE WERF(RS1,RS2,XX,YY) C C *** WERF by WIFD 25 May 84 *** C CC 9C CH Weighted error function ??? C IMPLICIT DOUBLE PRECISION (A-H,O-Z) DOUBLE PRECISION LAMBDA LOGICAL B C X=DABS(XX) Y=DABS(YY) IF (Y .LT. 4.29 .AND. X .LT. 5.33) GO TO 1 H= 0. NC= 0 NU= 8 LAMBDA= 0. B= .TRUE. GO TO 2 1 S=(1.0-Y/4.29)*DSQRT(1.0-X**2/28.41) H=1.6*S H2=2.0*H NC=6+IDINT(23.0*S) NU=9+IDINT(21.0*S) LAMBDA=H2**NC B=LAMBDA .EQ. 0. 2 R1=0. R2=0. S1=0. S2=0. N=NU+1 3 N=N-1 FN=N+1 T1=Y+H+FN*R1 T2=X-FN*R2 C=0.5/(T1**2+T2**2) R1=C*T1 R2=C*T2 IF (H .LE. 0.0 .OR. N .GT. NC) GO TO 4 T1= LAMBDA+S1 S1=R1*T1-R2*S2 S2=R2*T1+R1*S2 LAMBDA=LAMBDA/H2 4 IF (N .GT. 0) GO TO 3 IF (B) GO TO 6 RS1=S1 RS2=S2 GO TO 7 6 RS1=R1 RS2=R2 7 RS1= 1.12837916709551*RS1 IF (Y .EQ. 0.0) RS1= DEXP(-X**2) RS2= 1.12837916709551*RS2 IF (XX .LT. 0) RS2= -RS2 RETURN END
Output from fitting sequences - table for spreadsheets
subroutine ftsqop parameter (maxpar=40) parameter (maxpat=4000) COMMON/SSOUTCC/LOUT COMMON/SSOUTCH/FNAM COMMON/SSUSED/KEEP CHARACTER*11 FNAM common/seqtxt/text common /found/ tab(maxpat,maxpar),etab(maxpat,maxpar), 1idxx(maxpat,3),nseq real parm(maxpar),sdev(maxpar) real back(4),backerr(4),ratio(4),raterr(4) character*50 text write(6,106) write(16,106) C**** This format is changed to give similiar output to fd21 106 format(' run ext Backgr % Area % Width %', 1' Position % B-Slope B-Con. fit ') do 900 k=1,nseq do n=1,maxpar parm(n)=tab(k,n) sdev(n)=etab(k,n) end do ir=idxx(k,1) is=idxx(k,2) ifited=idxx(k,3) jjjj = 0 do i=5,20,5 jjjj = jjjj + 1 back(jjjj) = 0.0 backerr(jjjj) = 0.0 ratio(jjjj) = 0.0 raterr(jjjj) = 0.0 if(parm(i).gt.0) then C***** Try to output bgd at centre of each peak as first data column back(jjjj) = parm(1) + parm(2)*(parm(i+3)-parm(8)) C***** Let's try to combine errors for the background bslop = parm(2) * parm(i+3) err1sq = (sdev(1) * parm(1) / 100.0)**2 err2sq = (sdev(2)**2 + sdev(i+3)**2) 1 * bslop*bslop/10000.0 backerr(jjjj) = sqrt(err1sq+err2sq) * 100.0 / abs(back(jjjj)) write(16,20) ir,is,back(jjjj),backerr(jjjj), 1 parm(i+1),sdev(i+1), 1 parm(i+2),sdev(i+2),parm(i+3),sdev(i+3), 1 parm(2),parm(1),ifited c***** run.ext.back.back%.Area.are%.Width.Width%,Pos.Pos%.Bslo.Bcon.ft write(6,20) ir,is,back(jjjj),backerr(jjjj), 1 parm(i+1),sdev(i+1), 1 parm(i+2),sdev(i+2),parm(i+3),sdev(i+3), 1 parm(2),parm(1),ifited 20 format(i7,i5,f10.1,f6.1,f10.1,f6.2,f7.3,f6.2, 1 f8.2,f6.2,f9.3,f9.1,i4) If ( back(jjjj) .ne. 0. ) ratio(jjjj) = parm(i+1)/back(jjjj) C**** This is an error in counts not per cent raterr(jjjj) = sqrt(backerr(jjjj)*backerr(jjjj) + sdev(i+1) 1 *sdev(i+1) ) * ratio(jjjj)/100. end if end do C**** putting the parameters out in a file with C**** fixed format
WRITE(LOUT,201)ir,is,(parm(i),sdev(i),i=1,24), 1 (ratio(j),raterr(j),j=1,4) 201 FORMAT(I6,I4,48(2x,E12.4),8(2x,E12.4)) KEEP=1 900 continue return end
Additional output can be provided using the J command and the routine FTEXTP: SUBROUTINE FTEXTP C***** EXTERNAL SUBROUTINE TO PLOT Component RESULTS PARAMETER(MMM=2100) COMMON/PLTLIM/XMIN,XMAX,YMIN,YMAX,XSCALE(2),YSCALE(2) COMMON/PLTLIC/NTX,NTY,NTEX COMMON/FUNCTN/NPAR,PARM(20),STEP(20),SCALE(20) COMMON/OBSDAT/NPNT,XUSE(MMM),YUSE(MMM),YUSR(MMM) COMMON/CALDAT/YCALC(MMM),F(MMM),IITER COMMON/REDITC/XOBS(MMM),YOBS(MMM),YROBS(MMM),YER(MMM),NDIN COMMON/INDIFC/FNAME COMMON/TITLES/NAMES(20),TX,TY COMMON/CHICHI/RF,RFOLD,CHI,CHIOLD,PROB,NFREE,NFITNO COMMON/TITLEX/EXTRAT COMMON/EXTPC/YY(MMM,5),YYIN(4),INPK COMMON/TINC/PNAM,ret80
c***** other commons with useful data are COMMON/EXTPLT/XPL(200),YPL(200),WERR(200),WRK(200),WK1(200),NEXTRA COMMON/FITLIM/XLIMS(6),NSET,MINF,MAXF,NFIT c***** which have the x range limits "O", and extrapolated values CHARACTER*8 NAMES CHARACTER*20 TX,TY CHARACTER*20 FNAME CHARACTER NTX*20,NTY*20,NTEX*50,NTDUM*50,EXTRAT*50 CHARACTER*1 ANS CHARACTER PNAM*4,ret80*80 CHARACTER*100 PLTXT(4),BTXT CHARACTER*4 PTYP(4),ACTTYP CHARACTER*6 COLS(4) INTEGER MAPCOL(4) REAL YLOC(MMM),FLOC(MMM),YDIF(MMM) DATA MAPCOL/2,3,4,6/ DATA PTYP/'GAUS','LOR_','Voig','SkwG'/ DATA COLS/'red ','green ','blue ','pink '/ PLTXT(1)=' ' PLTXT(2)=' ' PLTXT(3)=' ' PLTXT(4)=' ' BTXT=' ' NTDUM=' ' C***** perform calculation for all points once again CALL CALSKP(NPAR,PARM,NDIN,XOBS,YOBS,YROBS,YCALC,F) OFFSET=0.8*(YSCALE(2)-YSCALE(1))+YSCALE(1) C***** Difference DO 6000 I=1,NDIN YDIF(I)=OFFSET+YCALC(I)-YOBS(I) YY(I,1)=YY(I,1)+YY(I,5) YY(I,2)=YY(I,2)+YY(I,5) YY(I,3)=YY(I,3)+YY(I,5) YY(I,4)=YY(I,4)+YY(I,5) C***** PLot components on top of notional background 6000 CONTINUE C***** Load up titles LIN=0 IPARAT=5 DO 7000 I=1,4 IF(YYIN(I).EQ.0.) GO TO 7000 C***** Component absent LIN=LIN+1 ITYPX=PARM(IPARAT) ACTTYP=' ' IF(ITYPX.GT.0.AND.ITYPX.LE.4) ACTTYP=PTYP(ITYPX) WRITE(PLTXT(LIN),7001) ACTTYP, 1NAMES(IPARAT+1),PARM(IPARAT+1), 1NAMES(IPARAT+2),PARM(IPARAT+2), 1NAMES(IPARAT+3),PARM(IPARAT+3), 1NAMES(IPARAT+4),PARM(IPARAT+4),COLS(I) 7001 FORMAT(A4,4(1X,A8,F10.5),2X,A6) IPARAT=IPARAT+5 7000 CONTINUE IF(CHI.NE.0.) WRITE(BTXT,7010)NFITNO,CHI 7010 FORMAT(' FIT #',I3,40X,'CHISQUARED ',F8.2) C***** Graph out C***** Frame and text IER=0 CALL RSPLT(XSCALE,YSCALE,YSCALE,2,0,IER,NTDUM,NTY,NTDUM) C***** Data points CALL RSPLT(XOBS,YOBS,YROBS,NDIN,-2,IER,NTX,NTY,NTEX) C***** Fit CALL RSPLT(XOBS,YCALC,YCALC,NDIN,-100,IER,NTX,NTY,NTEX) C***** Difference CALL RSPLT(XOBS,YDIF,YDIF,NDIN,-100,IER,NTX,NTY,NTEX) C***** First component red CALL PGQCI(IOLD) C***** Save initial colours DO 7500 I=1,4 IF(YYIN(I).EQ.0.) GO TO 7500 CALL PGSCI(MAPCOL(I)) IF(YYIN(1).NE.0) 1CALL RSPLT(XOBS,YY(1,I),YY(1,I),NDIN,-100, 1IER,NTX,NTY,NTEX) 7500 CONTINUE CALL PGSCI(IOLD) C***** Background CALL RSPLT(XOBS,YY(1,3),YY(1,3) 1,NDIN,-200,IER,NTX,NTY,NTEX) c***** titles CALL PGMTXT('T',7.,-.1,0.,NTEX) CALL PGMTXT('T',5.,-.1,0.,PLTXT(1)) CALL PGMTXT('T',4.,-.1,0.,PLTXT(2)) CALL PGMTXT('T',3.,-.1,0.,PLTXT(3)) CALL PGMTXT('T',2.,-.1,0.,PLTXT(4)) CALL PGMTXT('B',3.5,-.1,0.,EXTRAT) CALL PGMTXT('B',2.5,0.0,0.5,NTX) CALL PGMTXT('T',.75,0.5,0.5,BTXT) CALL PGSCI(IOLD) ANS=ret80(1:1) c***** J command: user requires hardcopy "J H" ret80(80:80)='/' read(ret80,*) ans IF(ANS.EQ.'H'.OR.ANS.EQ.'h') GO TO 303 RETURN 303 CONTINUE CALL PGNSEL(2,LAST,IER) C***** Graph out C***** FRAME AND TEXT IER=0 CALL RSPLT(XSCALE,YSCALE,YSCALE,2,0,IER,NTDUM,NTY,NTDUM) C***** Data points CALL RSPLT(XOBS,YOBS,YROBS,NDIN,-2,IER,NTX,NTY,NTEX) C***** Fit CALL RSPLT(XOBS,YCALC,YCALC,NDIN,-100,IER,NTX,NTY,NTEX) C***** Difference CALL RSPLT(XOBS,YDIF,YDIF,NDIN,-100,IER,NTX,NTY,NTEX) CALL PGQCI(IOLD) DO 7600 I=1,4 IF(YYIN(I).EQ.0.) GO TO 7600 CALL PGSCI(MAPCOL(I)) IF(YYIN(1).NE.0) 1CALL RSPLT(XOBS,YY(1,I),YY(1,I),NDIN,-100, 1IER,NTX,NTY,NTEX) 7600 CONTINUE CALL PGSCI(IOLD) C***** Background CALL RSPLT(XOBS,YY(1,3),YY(1,3) 1,NDIN,-200,IER,NTX,NTY,NTEX) C***** Titles CALL PGMTXT('T',7.,-.1,0.,NTEX) CALL PGMTXT('T',5.,-.1,0.,PLTXT(1)) CALL PGMTXT('T',4.,-.1,0.,PLTXT(2)) CALL PGMTXT('T',3.,-.1,0.,PLTXT(3)) CALL PGMTXT('T',2.,-.1,0.,PLTXT(4)) CALL PGMTXT('B',3.5,-.1,0.,EXTRAT) CALL PGMTXT('B',2.5,0.5,0.5,NTX) CALL PGMTXT('T',.75,0.5,0.5,BTXT) CALL PGNSEL(LAST,LLAST,IER) RETURN END
The configuration f24s.fcl file contains:
vers|1.0 prog|d:/2006/newf/f24s.exe prpt|f24s prld|wntle|f24s-prelude prld|title|Data Normalisation and instrument parameters prld|Normalisation type : V (vanadium run) N (eff. file) or empty (none) prld|Give a filename|text|eff.eff prld|Renormalise Monitor - monitor value |float|0.0|0.0 prld|New zero offset angle |float|0.0|0.0 prld|help|f24s.fcl rcmd|wntle|Reading new data rcmd|title|Reading ascii input D20 ASCII raw data rcmd|Run number|float|564323|0|999999| rcmd|Sub-spectrum number|float|1|1|99999 hcmd|wntle|f24s hcmd|title|f24s fitting D20 data- hcmd|Helpfile name |filer|d:/2006/newf/f24s.hhh jcmd|wntle|component plots jcmd|title|Superpose peak plots jcmd|For PostScript hardcopy type H|text|
The help file f24s.hhh is simply a text file: Fits up to 4 peaks in sequences of D20 datasets
Manual peak fitting and parameter initialisation
Peak type : 1 Single Gaussian 2 Single Lorenztian 3 Voigt - Lorenztian width shown 4 Skewed Gaussian Modifier parameter for Voigt is Gaussian width Modifier parameter for Skewed Gaussian is LHS-width/RHS Width values are half width at half height Background is value at centre of first peak
Library Components The graphics library routines beginning with the letters PG are described in the PGPLOT library page . RSPLT in the fitfun library is identical to that in the librlib.a library.
When building and testing the program it is greatly advantageous to use the simple terminal mode of the program to monitor the results. This terminal output is actually retained in the clickfit version as a log file which can be viewed from the view/log menu.
The script for the test session follows:
D:\2006\NewF>f24s f24s - version 4.0 June 2007 (R.E. Ghosh, ILL)
Fits up to 4 peaks in sequences of D20 datasets
Initial options to read and normalise subspectrum: C Continue now to data fitting V n Set vanadium run n N name Set efficiency file name M m Monitor renormalisation (o=none) Z a modify zero angle (0.0) L i j List run i subspectrum j H Help
No vanadium normalisation run Zero angle : 0.000 Efficiency file name Not used New monitor value : 0.0 Type option C,V,Z,M,N,L,D,HELP : c
Fits up to 4 peaks in sequences of D20 datasets
Manual peak fitting and parameter initialisation
Peak type : 1 Single Gaussian 2 Single Lorenztian 3 Voigt - Lorenztian width shown 4 Skewed Gaussian Modifier parameter for Voigt is Gaussian width Modifier parameter for Skewed Gaussian is LHS-width/RHS Width values are half width at half height Background is value at centre of first peak
f24s version 4.0 TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>564323 1 COMMAND NOT KNOWN - TYPE H FOR HELP Please do manual fit of one spectrum to set parameters TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>r 564323 1 There are 283 subspectra present, starting at # 1 1600 data have been read in THERE ARE 40 DATA POINTS IN CURRENT FITTING RANGE TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>f TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>v 8 .3 1 TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>f 20 FITTING.....
.....ENDED TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>v FITFUN 7.0 TITLE:Run 564323/ 1:VanaChieux 10mm 1.87AA FITTING Y : Counts VERSUS X : Two_Theta NUMBER PARAMETER VALUE ( OLD VALUE ) STEP % DEVIATION 1 FLAT BGD 53.98 ( 46.35 ) 1.000 8.62 2 slope BG 0.000 ( 0.000 ) 0.000 0.00 3 (spare) 0.000 ( 0.000 ) 0.000 0.00 4 FACTOR F 0.000 ( 0.000 ) 0.000 0.00 5 P1 type 1.000 ( 1.000 ) 0.000 0.00 6 P1 area 591.6 ( 619.7 ) 1.000 2.92 7 P1 width 0.7130 ( 0.7389 ) 1.000 2.62 8 P1 posn 0.7606E-01( 0.3000 ) 1.000 3.96 9 P1 modif 0.000 ( 0.000 ) 0.000 0.00 10 P2 type 0.000 ( 0.000 ) 0.000 0.00 : 22 P4 width 0.000 ( 0.000 ) 0.000 0.00 23 P4 posn 0.000 ( 0.000 ) 0.000 0.00 24 P4 modif 0.000 ( 0.000 ) 0.000 0.00 100 MAXIMUM STEP 100.0 300 SUBSTEP 0.01000 200 ACCURACY 0.1000E-01 THERE ARE 40 POINTS IN THE CURRENT RANGE SET BY "ONLY" COMMAND. CURRENT LIMITS (IF RANGE IS NON-ZERO) ARE : -2.00 TO 2.00 0.00 TO 0.00 0.00 TO 0.00 TYPE HELP OR OPTION: H,R,D,X,Y,V,F,O,P,L,W,C,E,J,S,T,M,G,Z f24s>e %PGPLOT, Closing file f24s006.ps
D:\2006\NewF>
|