      INTEGERPL,TID,SEQ,STATUS,KUN,KNUL
      INTEGERIAV,ISTAT,I,NCOL,I2,NC1
      INTEGERICOL(100),NAMLEN
      INTEGERMADRID(1),EC,EL,ED
      REALVAL(100)
      LOGICALISEL,NULL(100)
      CHARACTER*16MSG,UNIT
      CHARACTER*80TABLE,NAME
      CHARACTER*8FORM
      CHARACTER*80COM
      CHARACTER*16LABEL(100)
      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
      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   
      CHARACTER*64TPARBF(8)
      INTEGERERRILL
      INTEGERERRSEM
      INTEGERERRSOV
      INTEGERERRSOP
      INTEGERERRPAR
      INTEGERERRCOD
      INTEGERERRFMT
      INTEGERERRRED
      INTEGERERRSCL
      INTEGERERRCOL
      INTEGERERRREF
      INTEGERERRALG
      INTEGERERRGNP
      INTEGERERRGAL
      COMMON/TBLCM1/TPARBF
      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 )
      COMMON/VMR/MADRID
      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/
      DATAERRILL/-100/
      DATAERRSEM/-104/
      DATAERRSOV/-107/
      DATAERRSOP/-108/
      DATAERRPAR/-500/
      DATAERRCOD/-501/
      DATAERRFMT/-502/
      DATAERRRED/-503/
      DATAERRSCL/-504/
      DATAERRCOL/-505/
      DATAERRREF/-506/
      DATAERRALG/-507/
      DATAERRGNP/-600/
      DATAERRGAL/-601/
      DATAMSG/'ERR:FITCOPYxxxx'/,UNIT/' '/
      DATAFORM/'G14.6'/
      DATANAMLEN/80/
      CALLSTSPRO('FITCOPY')
      CALLFITBL
      CALLSTKRDC('P1',1,1,NAMLEN,IAV,TABLE,KUN,KNUL,ISTAT)
      CALLSTKRDC('P3',1,1,NAMLEN,IAV,NAME,KUN,KNUL,ISTAT)
      CALLSTKRDI('INPUTI',1,1,IAV,SEQ,KUN,KNUL,ISTAT)
      CALLSTKRDC('MID$CMND',1,1,4,IAV,COM,KUN,KNUL,ISTAT)
      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
      CALLFTINIT(NAME,ISTAT)
      IF(COM(1:1).EQ.'M')THEN
      DO10I=1,FZNPTT 
      PL=FZPLEN(I)
      LABEL(I)=FZPTON  (I)(1:PL)//'_GUESS'
   10 CONTINUE
      NCOL=FZNPTT 
      ELSE
      DO20I=1,FZNPTT 
      I2=2*I
      PL=FZPLEN(I)
      LABEL(I2-1)=FZPTON  (I)
      LABEL(I2)=FZPTON  (I)(1:PL)//'_ERROR'
   20 CONTINUE
      NCOL=2*FZNPTT 
      ENDIF
      CALLSTECNT('GET',EC,EL,ED)
      CALLSTECNT('PUT',1,0,0)
      CALLTBTOPN(TABLE,FIOMOE   ,TID,ISTAT)
      CALLSTECNT('PUT',EC,EL,ED)
      IF(ISTAT.NE.0)CALLTBTINI(TABLE,FTRANS ,FOMODE  ,NCOL,10,TID,ISTAT)
      DO30I=1,NCOL
      CALLTBLSER(TID,LABEL(I),ICOL(I),ISTAT)
      IF(ICOL(I).LE.0)THEN
      ICOL(I)=0
      IF(COM(1:1).EQ.'S')THEN
      CALLTBCINI(TID,DR4FOT     ,1,FORM,UNIT,LABEL(I),ICOL(I),ISTAT)
      ENDIF
      ENDIF
   30 CONTINUE
      IF(COM(1:1).EQ.'M')THEN
      CALLTBSGET(TID,SEQ,ISEL,ISTAT)
      IF(.NOT.ISEL)THEN
      CALLSTTPUT(' Non selected row ',ISTAT)
      GOTO70
      ENDIF
      DO40I=1,NCOL
      IF(ICOL(I).NE.0.AND.FZFIXD (I).LT.0)THEN
      CALLTBERDR(TID,SEQ,ICOL(I),VAL(I),NULL(I),ISTAT)
      FZVALE (I)=VAL(I)
      ENDIF
   40 CONTINUE
      ELSE
      NC1=NCOL/2
      DO50I=1,NC1
      I2=2*I
      VAL(I2-1)=FZVALE (I)
      VAL(I2)=FZERRR (I)
   50 CONTINUE
      CALLTBRWRR(TID,SEQ,NCOL,ICOL,VAL,ISTAT)
      ENDIF
      CALLTBTCLO(TID,ISTAT)
      CALLFTEXIT(NAME,ISTAT)
   70 IF(ISTAT.NE.0)THEN
      WRITE(MSG(13:16),9000)ISTAT
      CALLTDERRR(ISTAT,MSG,STATUS)
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
      END
