      INTEGERSTATUS,KUN,KNUL,ISTAT,IND,INDEX
      INTEGERI,II,II1,NAMLEN
      CHARACTER*80NAME,FILE,MASK
      CHARACTERIAC*1
      CHARACTERLINE1*34,LINE2*80,REFIMA*80
      CHARACTER*16MSG
      CHARACTER*80P1,P2,P3,P4
      CHARACTER*80HISTOY ,FTABLE
      CHARACTER*81LINE
      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  =16)
      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)
      REALFZSTAT (FZINDX  )
      REALFZSTEP(FZINDX  )
      DOUBLEPRECISIONFZERRR (FZPARX  )
      DOUBLEPRECISIONFZVALE (FZPARX  )
      DOUBLEPRECISIONFZGUES (FZPARX  )
      DOUBLEPRECISIONFZDUMM
      REALFZUNCR (FZPARX  )
      REALFZPFAC(FZPARX  )
      INTEGERFZPTRI
      INTEGERFZPTRM
      INTEGERFZMAPD  
      INTEGERFZFPAR(FZDEFX  )
      INTEGERFZSELE(20)
      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/FZERRR ,FZVALE ,FZGUES ,FZNFUN,FZNITR ,FZNDAT,FZNPTT
     + ,FZFLAG,FZDVAR,FZWEIT  ,FZNIND,FZIVAR,FZNPIX,FZFIXD ,FZFCOE ,FZAC
     +TR  ,FZPLEN,FZRELX ,FZCCHS ,FZCHIQ ,FZCHI,FZSTAT ,FZSTEP,FZUNCR ,F
     +ZPFAC,FZPTRI,FZPTRM,FZMAPD  ,FZFPAR,FZSELE
      COMMON/FITCM2/FZMETR  ,FZLOWB,FZUPPB,FZNRPX  ,FZPPRN,FZIWGT,FZIBND
     +,FZIMET
      COMMON/FITCM3/FERPAR,FERFUN,FERTAB,FERDAT,FERPFU,FERDUP,FERCON,FZI
     +DEN
      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/
      DATAMSG/'ERR:FITCREAxxxx'/
      CALLSTSPRO('FITCREA')
      CALLFITBL
      CALLSTKRDC('HISTORY',1,1,80,I,FTABLE,KUN,KNUL,ISTAT)
      IND=INDEX(FTABLE,'?')-1
      IF(IND.LE.0)IND=80
      HISTOY =FTABLE(1:IND)
      CALLSTKRDC('P1',1,1,80,I,P1,KUN,KNUL,ISTAT)
      CALLSTKRDC('P2',1,1,80,I,P2,KUN,KNUL,ISTAT)
      CALLSTKRDC('P3',1,1,80,I,P3,KUN,KNUL,ISTAT)
      CALLSTKRDC('P4',1,1,80,I,P4,KUN,KNUL,ISTAT)
      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(ISTAT.NE.0)THEN
      WRITE(MSG(13:16),9000)ISTAT
      CALLTDERRR(ISTAT,MSG,STATUS)
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
      END
