      INTEGERKUN,KNUL,ISTAT,IND,INDEX
      INTEGERI,II,II1,HLEN,NAMLEN,IMNOC
      CHARACTER*80NAME,FILE,MASK
      CHARACTERIAC*1
      CHARACTERLINE1*34,LINE2*80,REFIMA*80,HISTOY *160
      CHARACTER*80P1,P2,P3,P4,FTABLE
      CHARACTER*82LINE
      INTEGERFIMODE  
      INTEGERFOMODE  
      INTEGERFIOMOE   
      INTEGERFUMODE  
      INTEGERFXMODE  
      INTEGERFDMODE  
      INTEGERFXDPAM   
      INTEGERFFITSM     
      INTEGERFOLDTE    
      INTEGERFIMATE    
      INTEGERFTBLTE    
      INTEGERFFITTE    
      INTEGERFASCTE    
      INTEGERDOLDFT      
      INTEGERDI1FOT     
      INTEGERDI2FOT     
      INTEGERDUI2FT      
      INTEGERDI4FOT     
      INTEGERDR4FOT     
      INTEGERDR8FOT     
      INTEGERDL1FOT     
      INTEGERDL2FOT     
      INTEGERDL4FOT     
      INTEGERDCFORT    
      INTEGERDXFORT    
      INTEGERDPFORT    
      INTEGERFTRANS 
      INTEGERFRECOD  
      INTEGERXYPLAE   
      INTEGERXZPLAE   
      INTEGERZYPLAE   
      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 )
      DATAFOMODE  /1/
      DATAFIOMOE   /2/
      DATAFIMODE  /0/
      DATAFUMODE  /2/
      DATAFXMODE  /9/
      DATAFDMODE  /2/
      DATAFXDPAM   /0/
      DATAFFITSM     /2/
      DATAFOLDTE    /0/
      DATAFIMATE    /1/
      DATAFTBLTE    /3/
      DATAFFITTE    /4/
      DATAFASCTE    /9/
      DATADOLDFT      /0/
      DATADI1FOT     /1/
      DATADI2FOT     /2/
      DATADUI2FT      /102/
      DATADI4FOT     /4/
      DATADR4FOT     /10/
      DATADR8FOT     /18/
      DATADL1FOT     /21/
      DATADL2FOT     /22/
      DATADL4FOT     /24/
      DATADCFORT    /30/
      DATADXFORT    /40/
      DATADPFORT    /50/
      DATAFTRANS /0/
      DATAFRECOD  /1/
      DATAXYPLAE   /10/
      DATAXZPLAE   /11/
      DATAZYPLAE   /12/
      DATANAMLEN/80/
      CALLSTSPRO('FITCREA')
      CALLFITBL
      HISTOY (1:)='COMPUTE/FIT '
      CALLSTKRDC('P1',1,1,80,I,P1,KUN,KNUL,ISTAT)
      I=INDEX(P1,' ')
      HISTOY (13:)=P1(1:I)//' '
      HLEN=I+15
      CALLSTKRDC('P2',1,1,80,I,P2,KUN,KNUL,ISTAT)
      I=INDEX(P2,' ')
      II=HLEN+I+2
      IF(II.LE.160)THEN
      HISTOY (HLEN:)=P2(1:I)//' '
      HLEN=II
      ENDIF
      CALLSTKRDC('P3',1,1,80,I,P3,KUN,KNUL,ISTAT)
      I=INDEX(P3,' ')
      II=HLEN+I+2
      IF(II.LE.160)THEN
      HISTOY (HLEN:)=P3(1:I)//' '
      HLEN=II
      ENDIF
      CALLSTKRDC('P4',1,1,80,I,P4,KUN,KNUL,ISTAT)
      I=INDEX(P4,' ')
      II=HLEN+I+2
      IF(II.LE.160)THEN
      HISTOY (HLEN:)=P4(1:I)//' '
      HLEN=II
      ENDIF
      IF(P2(1:1).EQ.':'.OR.P2(1:1).EQ.'#')THEN
      P3='='
      ELSE
      P2='='
      ENDIF
      IF(P2(1:1).EQ.'=')THEN
      FTABLE=P1
      IAC='I'
      II=INDEX(P1,',')
      IF(II.EQ.0)THEN
      FILE=P1
      MASK=' '
      ELSE
      FILE=P1(1:II-1)
      MASK=P1(II+1:)
      ENDIF
      II=INDEX(P3,'(')
      IF(II.EQ.0)THEN
      NAME=P3
      REFIMA='?'
      ELSE
      NAME=P3(1:II-1)
      LINE=P3//')'
      II1=INDEX(LINE,')')
      REFIMA=P3(II+1:II1-1)
      ENDIF
      ELSE
      IND=INDEX(P1,' ')-1
      FTABLE=P1(1:IND)//'.TBL'
      IAC='T'
      FILE=P1
      LINE1=P2
      II=INDEX(P4,'(')
      IF(II.EQ.0)THEN
      NAME=P4
      LINE2='?'
      ELSE
      NAME=P4(1:II-1)
      LINE=P4//')'
      II1=INDEX(LINE,')')
      LINE2=P4(II+1:II1-1)
      ENDIF
      ENDIF
      IF(NAME(1:1).EQ.'?')THEN
      CALLSTKRDC('FITNAME',1,1,NAMLEN,I,NAME,KUN,KNUL,ISTAT)
      ELSE
      CALLSTKWRC('FITNAME',1,NAME,1,NAMLEN,KUN,ISTAT)
      ENDIF
      CALLFTINIT(NAME,ISTAT)
      IF(IAC.EQ.'I')THEN
      IF(REFIMA(1:1).NE.'?')CALLFTDIVI(REFIMA,ISTAT)
      CALLFTDDVI(FILE,MASK,ISTAT)
      ELSE
      IF(LINE2(1:1).NE.'?')CALLFTDIVT(FILE,LINE2,ISTAT)
      CALLFTDDVT(FILE,LINE1,ISTAT)
      ENDIF
      CALLFTCOMP(ISTAT)
      IF(IAC.EQ.'I')THEN
      CALLSTFOPN(FILE,DOLDFT      ,0,FOLDTE    ,IMNOC,ISTAT)
      IF(HLEN.LT.81)THEN
      HLEN=80
      ELSE
      HLEN=160
      ENDIF
      CALLSTDWRC(IMNOC,'HISTORY',1,HISTOY ,1,HLEN,KUN,ISTAT)
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
      END
