      INTEGERIVAR(8),FIX(20),KUN,KNUL,NP
      INTEGERISTAT,I,II,IAV,NIND,NPAR
      INTEGERNFUN,NDAT,N,J,IDVAR,NL,NACT,NAMLEN,MM,IVAL
      REALCHISQ,VAL1,VAL2
      DOUBLEPRECISIONPAR(20),ERR(20),DVAL
      CHARACTER*80FNAME,NAME,FILE,MASK,LINE1
      CHARACTERIAC*1,AUX*30,AUX1*30
      CHARACTERLINE2*80,TYPE*4,LINE*80
      CHARACTERLINE3*80
      CHARACTER*80HEAD,OUT,HEADER
      CHARACTER*16MSG
      CHARACTER*4PPRINT
      INTEGERFZFUNX  
      INTEGERFZINDX  
      INTEGERFZPARX  
      INTEGERFZDEFX  
      INTEGERFZNCHR 
      INTEGERFZNING 
      INTEGERFZNREL 
      INTEGERFZCING 
      INTEGERFZCREL 
      PARAMETER(FZFUNX  =128)
      PARAMETER(FZINDX  =3)
      PARAMETER(FZPARX  =128)
      PARAMETER(FZDEFX  =50)
      PARAMETER(FZNCHR =28)
      PARAMETER(FZNING =14)
      PARAMETER(FZNREL =109)
      PARAMETER(FZCREL =103)
      PARAMETER(FZCING =5)
      CHARACTER*12FZNAME
      CHARACTER*4FZTYPE
      CHARACTER*12FZMASK
      CHARACTER*12FZRIMA
      CHARACTER*8FZFNAM(FZDEFX  )
      CHARACTER*80FZSPEC(FZFUNX  )
      CHARACTER*8FZPTON  (FZPARX  )
      INTEGERFZNFUN
      INTEGERFZNITR 
      INTEGERFZNDAT
      INTEGERFZNPTT 
      INTEGERFZFLAG
      INTEGERFZDVAR
      INTEGERFZWEIT  
      INTEGERFZNIND
      INTEGERFZIVAR(FZINDX  )
      INTEGERFZNPIX(FZINDX  )
      INTEGERFZFIXD (FZPARX  )
      INTEGERFZFCOE (FZFUNX  )
      INTEGERFZACTR  (FZFUNX  )
      INTEGERFZPLEN(FZPARX  )
      INTEGERFZNAXS 
      INTEGERFZPPRN
      INTEGERFZIWGT
      INTEGERFZIBND
      INTEGERFZIMET
      REALFZRELX 
      REALFZCCHS 
      REALFZCHIQ 
      REALFZCHI(100)
      DOUBLEPRECISIONFZSTAT (FZINDX  )
      DOUBLEPRECISIONFZSTEP(FZINDX  )
      DOUBLEPRECISIONFZERRR (FZPARX  )
      DOUBLEPRECISIONFZVALE (FZPARX  )
      DOUBLEPRECISIONFZGUES (FZPARX  )
      DOUBLEPRECISIONFZDUMM
      REALFZUNCR (FZPARX  )
      REALFZPFAC(FZPARX  )
      INTEGER  FZPTRI
      INTEGER  FZPTRM
      INTEGERFZMAPD  
      INTEGERFZFPAR(FZDEFX  )
      INTEGERFZSELE(FZFUNX  )
      CHARACTER*28FZCHAR
      INTEGERFZINTG(FZNING )
      REALFZREAL(FZNREL )
      REALFZMETR  (10)
      DOUBLEPRECISIONFZLOWB(FZPARX  )
      DOUBLEPRECISIONFZUPPB(FZPARX  )
      INTEGERFZNRPX  
      INTEGERFERPAR
      INTEGERFERFUN
      INTEGERFERTAB
      INTEGERFERDAT
      INTEGERFERPFU
      INTEGERFERDUP
      INTEGERFERCON
      INTEGERFZIDEN
      COMMON/FITCM0/FZNAME,FZTYPE,FZMASK,FZRIMA,FZFNAM,FZSPEC,FZPTON  
      COMMON/FITCM1/FZSTAT ,FZSTEP,FZERRR ,FZVALE ,FZGUES ,FZNFUN,FZNITR
     + ,FZNDAT,FZNPTT ,FZFLAG,FZDVAR,FZWEIT  ,FZNIND,FZIVAR,FZNPIX,FZFIX
     +D ,FZFCOE ,FZACTR  ,FZPLEN,FZRELX ,FZCCHS ,FZCHIQ ,FZCHI,FZUNCR ,F
     +ZPFAC,FZMAPD  ,FZFPAR,FZSELE
      COMMON/FITCM2/FZMETR  ,FZLOWB,FZUPPB,FZNRPX  ,FZPPRN,FZIWGT,FZIBND
     +,FZIMET
      COMMON/FITCM3/FERPAR,FERFUN,FERTAB,FERDAT,FERPFU,FERDUP,FERCON,FZI
     +DEN
      COMMON/FITCM4/FZPTRI,FZPTRM
      EQUIVALENCE(FZNAXS ,FZNIND)
      EQUIVALENCE(FZCHAR,FZNAME)
      EQUIVALENCE(FZINTG,FZNFUN)
      EQUIVALENCE(FZREAL,FZRELX )
      EQUIVALENCE(FZDUMM,FZGUES )
      DOUBLEPRECISIONOURSTT  (FZINDX  ),OURSTP (FZINDX  )
      DATANAMLEN/80/
      DATAMSG/'ERR:FITIMAGxxxx'/
      DATAHEAD/' Parameter Initial Guess      Actual Value       Error'/
      CALLSTSPRO('FITIMAG')
      CALLFITBL
      CALLSTKRDC('P2',1,1,NAMLEN,I,LINE3,KUN,KNUL,ISTAT)
      II=INDEX(LINE3,',')
      IF(II.EQ.0)THEN
      FILE=LINE3
      MASK=' '
      ELSE
      FILE=LINE3(1:II-1)
      MASK=LINE3(II+1:)
      ENDIF
      CALLSTKRDC('P3',1,1,NAMLEN,II,LINE1,KUN,KNUL,ISTAT)
      IF(LINE1(1:1).EQ.':'.OR.LINE1(1:1).EQ.'#')THEN
      IAC='T'
      CALLSTKRDC('P4',1,1,80,IAV,LINE2,KUN,KNUL,ISTAT)
      CALLSTKRDC('P5',1,1,NAMLEN,IAV,NAME,KUN,KNUL,ISTAT)
      ELSE
      IAC='I'
      NAME=LINE1
      ENDIF
      IF(NAME(1:1).EQ.'?')THEN
      CALLSTKRDC('FITNAME',1,1,NAMLEN,IAV,NAME,KUN,KNUL,ISTAT)
      ELSE
      CALLSTKWRC('FITNAME',1,NAME,1,NAMLEN,KUN,ISTAT)
      ENDIF
      CALLSTKRDR('INPUTR',1,9,IAV,FZMETR  (2),KUN,KNUL,ISTAT)
      CALLSTKRDC('FITCHAR',1,21,4,IAV,PPRINT,KUN,KNUL,ISTAT)
      CALLGENCNV(PPRINT,2,1,IVAL,FZMETR  (1),DVAL,MM)
      VAL1=0.0
      VAL2=0.0
      IF(IAC.EQ.'I')THEN
      CALLFTIMAG(FILE,MASK,ISTAT)
      ELSE
      CALLFTTABL(FILE,LINE1,LINE2,ISTAT)
      ENDIF
      DO100,I=1,FZINDX  
      OURSTT  (I)=FZSTAT (I)
      OURSTP (I)=FZSTEP(I)
  100 CONTINUE
      CALLFTINIT(NAME,ISTAT)
      DO200,I=1,FZINDX  
      FZSTAT (I)=OURSTT  (I)
      FZSTEP(I)=OURSTP (I)
  200 CONTINUE
      CALLFTDODO(NINT(FZMETR  (2)),FZMETR  (4),FZMETR  (3),VAL1,VAL2,NAC
     +T,CHISQ,ISTAT)
      CALLFTINFO(FILE,TYPE,IDVAR,NIND,NFUN,NDAT,ISTAT)
      LINE=' No. of data points '
      WRITE(LINE(25:32),9030)NDAT
      CALLSTTPUT(LINE,ISTAT)
      CALLSTTPUT(' ',ISTAT)
      IF(TYPE.EQ.'TBL ')THEN
      LINE=' Dependent variable '
      WRITE(LINE(25:28),9000)IDVAR
      CALLSTTPUT(LINE,ISTAT)
      ENDIF
      LINE=' No. of ind. variables '
      WRITE(LINE(25:28),9000)NIND
      CALLSTTPUT(LINE,ISTAT)
      IF(NIND.GT.0)THEN
      CALLFTRDIN(NIND,IVAR,N,ISTAT)
      IF(TYPE.EQ.'BDF ')THEN
      LINE=' variable .... is axis   ....'
      ELSE
      IF(TYPE.EQ.'TBL ')THEN
      LINE=' variable .... is column ....'
      ELSE
      NIND=0
      ENDIF
      ENDIF
      DO20I=1,NIND
      WRITE(LINE(11:14),9000)I
      WRITE(LINE(26:29),9000)IVAR(I)
      CALLSTTPUT(LINE,ISTAT)
   20 CONTINUE
      ENDIF
      CALLSTTPUT(' ',ISTAT)
      LINE=' No. of functions '
      WRITE(LINE(25:28),9000)NFUN
      CALLSTTPUT(LINE,ISTAT)
      NP=0
      DO40I=1,NFUN
      CALLSTTPUT(' ',ISTAT)
      CALLFTRDFN(I,LINE,ISTAT)
      II=INDEX(LINE,')')
      CALLSTTPUT(LINE(1:II),ISTAT)
      CALLSTTPUT(HEAD,ISTAT)
      CALLFTRDPR(I,FNAME,NPAR,PAR,ERR,FIX,ISTAT)
      LINE=FZSPEC(I)
      IF(NPAR.GT.0)THEN
      DO30J=1,NPAR
      NP=NP+1
      NL=FZPLEN(NP)
      AUX=FZPTON  (NP)
      AUX1=AUX(1:NL)//'='
      II=INDEX(LINE,AUX1(1:NL+1))
      IF(II.EQ.0)THEN
      AUX1='-'
      ELSE
      AUX=LINE(II+NL+1:)
      II=INDEX(AUX,' ')-1
      AUX1=AUX(1:II)
      ENDIF
      WRITE(OUT,9010)FZPTON  (NP),AUX1(1:16),PAR(J),ERR(J)
      CALLSTTPUT(OUT,ISTAT)
   30 CONTINUE
      ENDIF
   40 CONTINUE
      CALLSTTPUT(' ',ISTAT)
      CALLSTTPUT('     Red. Chisq      Act. Nr. F. Eval.',ISTAT)
      WRITE(HEADER,9020)FZCCHS ,FZNITR 
      CALLSTTPUT(HEADER,ISTAT)
      CALLSTTPUT(' ',ISTAT)
      CALLFTEXIT(NAME,ISTAT)
      IF(ISTAT.NE.0)THEN
      WRITE(MSG(13:16),9000)ISTAT
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
 9010 FORMAT(1X,A,2X,A,1X,E14.6,1X,E14.6)
 9020 FORMAT(3X,1PE12.4,12X,I6)
 9030 FORMAT(I8)
      END
