Use of COMMON blocks in fitfun, ffn80src

R. Ghosh March 2013 <


This note describes version 8.0 of fitfun

Summary
Fitfun is a fitting library written in Fortran77 for non-linear least squares fitting of data to parametrised models. The programmer must supply a MAIN routine (essentially to name parameters and scales, a data read routine, and a calculation routine. Fitfun then minimises the difference between the model and data by adjusting the values of the parameters. It can also obtain read-in control instructions from a data file allowing it to treat a sequence of data. The principal routine is ftfuns which sets up and calls the other functions. To allow for easy extension almost all useful variables are held in COMMON in ftfuns which thus helps a maintainer identify the variable and its use.


      PARAMETER (MAXDAT=21000)
c***** maximum no of input data
      PARAMETER (MAXPAR=40)
c***** maximum number of parameters
      PARAMETER (MAXPAT=4000)
c***** sequences
      EXTERNAL READIN,CALSUB
               read-in and calculation routines
      COMMON blocks likely to be used in READIN and CALSUB
      common/guiuse/ignum,insta,iosta,irsta
          Controls communications with clickfit
      common/comin/bufin
      character*150 
            with data from clickfit
          ftfuns,ftprld.fttcmd,ftvall
      common/reply/resout
         ftfuns,ftfffff,ftglnk,ftprld,ftdatn
         reply to clickfit - error message starts with ERR:
      COMMON/TITLES/INAMES(MAXPAR),NX,NY
         used in ftfuns,forfit,ftlist,ftprld,ftvals
            contains the name of each parameter
      COMMON/REDINC/DFIND
         ftfuns,mread
            character*80 string for input routine to find data
      COMMON/REDIT4/OBS4IN(MAXDAT)
         ftdatn,mread
            fourth column is left here by READIN
      COMMON/OBSDA4/USE4(MAXDAT)
         ftfuns,ftlimt,ftlist
            contains fourth column input for calculation

             Internal fitfun COMMON blocks
      COMMON/LIMITF/ VERZHN,MAXIND,MAXPNM
         ftfuns
      COMMON/TITLEP/NPARAS
         used in ftfuns,forfit,ftgetp,ftglnk,ftlist,ftumap
      COMMON/FUNCTS/NAMSS
         ftfuns
      COMMON/WORK/W
         used in ftfuns,ftlist
            workspace for fits, contains deviations after fits
      COMMON/EXTPLT/XPL(200),YPL(200),WERR(200),
     1WRK(200),WRK1(200),INDPX(200),
     1INDTMP(MAXDAT),NEXTRA
         ftfuns,ftlimt,ftlist,ftxset
      COMMON/EXPLT4/XDVL(200)
         ftfuns
      COMMON/FLAGS/ DATSET,PARSET,NEWDAT,PLTSET
       ftfuns,ftcalf,ftdatn,fteras,ftffff,ftlimt,ftlist,ftvals,ftxset
         logical flags for status of read-in etc.
      COMMON/FLAGS4/INCOL4
         ftfuns.ftlimt,ftxset
            set in READIN if fourth column is available
      COMMON/TIN/INTTY,IOTTY,NMO,IERT,VARIN(10)
         ftfuns,ftcalf,ftextp,ftffff,ftgech,ftglnk,ftlimt,ftlist,
         ftplfl,ftttcmd,ftvals,ftxset,ftyset
            terminal input and free format results
      COMMON/TINC/PNAMM,RET(80)
         ftfuns,ftcalf,ftextp,ftffff,ftgech,ftglnk,ftlimt,ftlist,
         ftplfl,ftttcmd,ftvals,ftxset,ftyset
            program name and stripped input buffer from terminal
      COMMON/FUNCTN/NPAR,PARM,STEP,SCALE,NUPAR
         ftfuns,forfit,ftcalf,ftlist
            internal parameters in fitting
      COMMON/FUNCTC/NAMES
         ftfuns,forfit,ftcalf,ftlist,ftprld,ftsave
            derived parameter names
      COMMON/CNSTRN/IINDEX(MAXPAR)
         ftfuns,ftcalf,ftffff,ftlist
            maps parameters to fitted variables
      COMMON/REDITC/ XOBS,YOBS,YROBS,YER,NDIN
         ftfuns,ftxset
            contains the raw data read from the user routine READIN
      COMMON/OBSDAT/ NPNT,XUSE,YUSE,YUSR
         ftfuns,ftlist
            contains the data to be fitted in the user routine CALSUB
      COMMON/CALDAT/YCALC,F,IITER
         ftfuns,ftcalf,ftlist
            results from fitting
      COMMON/FITCON/H,DMAX,ACC,FUNMAX,VPRINT
         ftfuns,forfit,ftffff,ftlist,ftprld,ftsave,ftvall,ftvals
            fitting control parameters
      COMMON/FITLIM/XLIMS(6),NSET,MINF,MAXF,NFIT
         ftfuns,forfit,ftcalf,ftffff,ftlimt,ftlist,ftprld,ftsave,ftvall,ftvals,ftxset
            exclusion zones for fits
      COMMON/SPLTC/VARS(32)
         ftfuns,ftcalf,ftlist,rsplt,tdlmr(/i>
            graphical control
      COMMON/PLTLIM/XMIN,XMAX,YMIN,YMAX,XSCALE(2),YSCALE(2)
         ftfuns,ftdatn,ftlist,ftplfl,ftprld,ftsave,ftvall,ftvals,ftxset,ftyset
            plotting scale limits
      COMMON/PLTLIC/NTX,NTY,NTEX
         ftfuns,ftdatn,ftlimt,ftlist,ftplfl,ftvall,ftvals
            plot titles
      COMMON/PLTFLE/PLFILE
         ftfuns,ftplfl
            plot file name
      COMMON/PLTFILD/XFL(200),YFL(200)
        ftfuns
          plot file calculated values
      COMMON/ERRORC/SDEV(MAXPAR),SDEW(MAXPAR)
     1,COVAR(MAXPAR*MAXPAR),COVAW(MAXPAR*MAXPAR),IPAR
          ftfuns,ftffff,ftlist,ftprld,ftvall,ftvals
            deviations after fitting
      COMMON/TEKENV/TEKTRO
         ftfuns,fteras,fthelp,ftlist,ftvall,ftvals
            controls scrolling
      COMMON/TITLEX/EXTRAT
         ftfuns,ftlist
      COMMON/TITLEI/IEXTRT
         ftfuns,
            additional title on graph
      COMMON/CHICHI/RF,RFOLD,CHI,CHIOLD,PROB,NFREE,NFITNO
         ftfuns,ftchsq,ftdatn,ftlist
            statistical test
      COMMON/FCLOSE/ICLOSE,ISTART
         ftfuns
            control re-entry without re-reading parameters etc.
      COMMON/STOPCY/IXV
         ftfuns
            variable is non-zero after control-c is given
      COMMON/FILIN/INDEX1,INDEX2,IFLAG1,IFLAG2
         ftfuns
      COMMON/FILINC/FTXT
         (i>ftfuns
      COMMON/QUIET/KQUIET
         ftfuns,ftffff
      COMMON/COMNAM/COMCMD,COMREP,COMINF
         ftfuns
      LOGICAL CHAR,TEKTRO,RETRUN
      LOGICAL DATSET,PARSET,NEWDAT,PLTSET,INCOL4
      CHARACTER*1 COMM(20),ANS
      CHARACTER PNAMM*4,RET*1
      CHARACTER*4 PNAME,PNAM,PARFR,UNSET,VERSHN,VPRINT
      CHARACTER PLFILE*10,LOGFIL*10,STR*30,PLFILX*10
      CHARACTER PARFL*4
      CHARACTER PARFLL*20
      CHARACTER FTXT*120
      COMMON/VERSION/VERP,VERS
      CHARACTER*8 INAMES,NAMES(MAXPAR)
      CHARACTER*20 NX,NY,NTX,NTY
      CHARACTER*50 NTEX,EXTRAT
      CHARACTER*8 FITNO
      CHARACTER*80 DFIND
      CHARACTER*11 COMCMD,COMREP,COMINF
      CHARACTER*80 RESOUT
      CHARACTER*20 TM
C
      DIMENSION FITPAR(MAXPAR),DD(2)
      DIMENSION F(MAXDAT),W(200000)
      DIMENSION XOBS(MAXDAT),YOBS(MAXDAT),YROBS(MAXDAT),YCALC(MAXDAT)
     1,XUSE(MAXDAT),YUSE(MAXDAT),YER(MAXDAT),YUSR(MAXDAT)
      DIMENSION PARM(MAXPAR),STEP(MAXPAR),SCALE(MAXPAR),OLD(MAXPAR)
      DIMENSION FITDIF(MAXDAT)
      DIMENSION USE4(MAXDAT),OBS4(MAXDAT)
      DIMENSION UUSE4(MAXDAT)

Principal Routines
forfit.for  allows initial paramters to be setup if no ffm file is found
ftcalf.for  calls the calculation routine CALSUB 
ftchsq.for  evaluates CHI-squared if errors are provided in data
ftdatn.for  calls the readin routine MYREAD
fteras.for  clears graphics and text
ftextp.for  external routine (dummy in library)
ftfdcd.for  free-format input routine
ftffff.for  sets up fitting
ftfuns.for  MAIN STEERING ROUTINE
ftgech.for  reads in terminal input 
ftgetp.for  gets parameters for a specified data set
fthelp.for  help information
ftlimt.for  places data in arrays for fitting and plotting in limits
ftlist.for  outputs listing
ftmb11.for  matrix inversion for fitting
ftplfl.for  outputs data in file for subsequent plotting
ftplnm.for  plots sets of data
ftplst.for  plots sets of data
ftprob.for  calculates probability of fit at minimum
ftpval.for  mapping of parametrs to inputs sets
ftsave.for  saves current parameters
ftserr.for  extracts errors from workspace after fit
fttcmd.for  decodes command line
ftumap.for  remaps local copy of parameters, steps etc
ftva05.for  non-linear fitting routine
ftvall.for  displays current parameters, steps etc
ftvals.for  displays current paramteres, steps etc
ftxhlp.for  additional help information (dummy in library)
ftyset.for  shows or sets y scale limits	
ftxset.for  shows or sets x scale limits
ftprld.for  sets up dialogue with external control program (clickfit)
ftglnk.for  sets up links between parameters
ftsort.for  sorts input data into increasing x-values

utilities

iniwin.for	once used to control switching graphical/text modes 
lpendf.for	closes printer output file
lpout.for	open printer output file
poscur.for	draws cursor on display
pubess.for	logo routine
rsplt.for	plotiing program
userlog.for	log generator
erase.for	clears graphics
flusht.for	empties terminal buffer
tdlmr.for	sets scale limits
trimmd.for	strips trailing blanks in string

gtst.for	test program
inread.for	test readin routine
gauss.for	test calculation routine

February 2008 - fourth column read in and treatment If a fourth data column is read into the array in /REDIT4/ and the /FLAGS4/ variable INCOL4 is set to .TRUE. the program suite will propagate this through to the calculation routine which will find appropriate selected values in /OBSDA4/USE4 This maintains compatibility with previous three column data read-in.

February 2008 - data are re-sequenced in order of increasing x This is performed by the heap-sort in ftsort.

March 2013 - data arrays extended to 21000

Small adjustments made to forfit and ftfuns

Interrupts to fitting introduced