      INTEGERCODE,STATUS,IAV,KUN,KNUL,I,II
      INTEGERINDEX,IND,ISTAT,II1,NAMLEN
      CHARACTER*80NAME,FILE,MASK,LINE
      CHARACTER*1IAC
      CHARACTERPARS*80,LINE1*34,LINE2*80,REFIMA*80
      CHARACTER*16MSG
      CHARACTER*80P1,P2,P3,P4
      CHARACTER*80HISTOR,FILENA
      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 )
      DATANAMLEN/80/
      DATAMSG/'ERR:FUNCREAxxxx'/
      CALLSTSPRO('FUNCREA')
      CALLFITBL
      CALLSTKRDC('HISTORY',1,1,80,I,FILENA,KUN,KNUL,ISTAT)
      IND=INDEX(FILENA,'?')-1
      IF(IND.LE.0)IND=80
      HISTOR=FILENA(1:IND)
      CALLSTKRDC('P1',1,1,80,IAV,P1,KUN,KNUL,ISTAT)
      CALLSTKRDC('P2',1,1,80,IAV,P2,KUN,KNUL,ISTAT)
      CALLSTKRDC('P3',1,1,80,IAV,P3,KUN,KNUL,ISTAT)
      CALLSTKRDC('P4',1,1,80,IAV,P4,KUN,KNUL,ISTAT)
      IF(P2(1:1).EQ.'=')THEN
      FILENA=P1
      IAC='I'
      FILE=P1
      II=INDEX(P3,'(')
      IF(II.EQ.0)THEN
      CALLSTTPUT(' Missing function arguments ',ISTAT)
      GOTO20
      ENDIF
      NAME=P3(1:II-1)
      II1=INDEX(P3,')')
      IF(II1.EQ.0)THEN
      CALLSTTPUT(' Missing right parenthesis',ISTAT)
      GOTO20
      ENDIF
      LINE2=P3(II+1:II1-1)
      LINE=P3
      ELSE
      IND=INDEX(P1//' ',' ')-1
      FILENA=P1(1:IND)//'.tbl'
      IAC='T'
      FILE=P1
      LINE1=P2
      II=INDEX(P4,'(')
      IF(II.EQ.0)THEN
      CALLSTTPUT(' Missing function arguments ',ISTAT)
      GOTO20
      ENDIF
      NAME=P4(1:II-1)
      II1=INDEX(P4,')')
      IF(II1.EQ.0)THEN
      CALLSTTPUT(' Missing right parenthesis',ISTAT)
      GOTO20
      ENDIF
      LINE2=P4(II+1:II1-1)
      LINE=P4
      ENDIF
      II1=INDEX(LINE2,';')
      IF(II1.EQ.0)THEN
      REFIMA=LINE2
      PARS=' '
      ELSE
      REFIMA=LINE2(1:II1-1)
      PARS=LINE2(II1+1:)
      ENDIF
      CALLFTDCFN(NAME,CODE)
      IF(CODE.GT.0.OR.PARS(1:1).NE.' ')THEN
      CALLFTINIF(LINE,ISTAT)
      DO10I=1,20
      FZSELE(I)=1
   10 CONTINUE
      ELSE
      CALLFTINIT(NAME,ISTAT)
      ENDIF
      CALLFTCPGV(ISTAT)
      IF(IAC.EQ.'I')THEN
      MASK=' '
      CALLFTDIVI(REFIMA,ISTAT)
      CALLFTDDVI(FILE,MASK,ISTAT)
      ELSE
      CALLFTDIVT(FILE,REFIMA,ISTAT)
      CALLFTDDVT(FILE,LINE1,ISTAT)
      ENDIF
      CALLFTCOMP(ISTAT)
   20 IF(ISTAT.NE.0)THEN
      WRITE(MSG(13:16),9000)ISTAT
      CALLTDERRR(ISTAT,MSG,STATUS)
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
      END
