      INTEGERIFUN(20),ISELE(20),STATUS
      INTEGERI,II,II1,IAV,IP,KUN,KNUL,ISTAT,DUN
      INTEGERMADRID(1),NAMLEN
      CHARACTER*80P1,NAME
      CHARACTER*16MSG
      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   
      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/
      DATANAMLEN/80/
      DATAISELE/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0/
      DATAMSG/'ERR:FUNCREAxxxx'/
      CALLSTSPRO('FITSELE')
      CALLFITBL
      CALLSTKRDC('P1',1,1,NAMLEN,IAV,P1,KUN,KNUL,ISTAT)
      CALLSTKRDI('INPUTI',1,16,IAV,IFUN,KUN,KNUL,ISTAT)
      DO10,I=1,16
      II=IFUN(I)
      IF(II.NE.0)THEN
      IF(II.GT.0.AND.II.LE.16)THEN
      ISELE(II)=1
      ELSE
      CALLSTTPUT(' Error in function number... ',ISTAT)
      GOTO30
      ENDIF
      ELSE
      GOTO20
      ENDIF
   10 CONTINUE
   20 II1=INDEX(P1,'.')
      IF(II1.NE.0)THEN
      NAME=P1
      ELSE
      II=INDEX(P1,' ')-1
      NAME=P1(1:II)//'.fit'
      ENDIF
      CALLSTFOPN(NAME,DR4FOT     ,0,FFITTE    ,IP,ISTAT)
      CALLSTDWRI(IP,'FITSELE',ISELE,1,20,DUN,ISTAT)
   30 IF(ISTAT.NE.0)THEN
      WRITE(MSG(13:16),9000)ISTAT
      CALLTDERRR(ISTAT,MSG,STATUS)
      ENDIF
      CALLSTSEPI
 9000 FORMAT(I4)
      END
