FUNCTION MKFILEPOS, fichfits, fichimg, hdeb

    reponse = 'Yes'
    ; verifie si le fichier existe deja
    fichposi = MOD_NRHFILE( fichimg, CONTENT='s', HEURE=hdeb, DIRECTORY='Current')
    r = FINDFILE(fichposi)
    IF r(0) NE '' THEN BEGIN    ; le fichier existe
        text = 'Add positions to the existing file ?'
        reponse = DIALOG_MESSAGE(text, /QUESTION, /CANCEL)
        IF reponse EQ 'No' THEN BEGIN 
            text = 'Replace the existing file ?'
            reponse = DIALOG_MESSAGE(text, /QUESTION, /CANCEL)
            ; initialise le fichier si remplacement
            IF reponse EQ 'Yes' THEN create_nrh_pfile, fichposi, fichimg
        ENDIF
    ENDIF
    IF reponse EQ 'Yes' THEN BEGIN
        ; recupere le nombre de positions figurant dans le fichier temporaire
        hprim = HEADFITS(fichfits)
        nbposi = FXPAR(hprim, 'N_EXTEND')
        FOR pos=0, nbposi-1 DO BEGIN
            hext = HEADFITS(fichfits, EXTEN=pos+1)
            nbhits = FXPAR(hext, 'NAXIS1')/(FXPAR(hext, 'TFIELDS')*4)
            posi = REPLICATE({temps:0L, source:{GAUSS}, flux:0.0}, nbhits)
            t = rdfilepos(fichfits, 'TIME', pos+1)
            posi.temps = t
            posi.source.max = rdfilepos(fichfits, 'INTENSITY', pos+1)
            posi.source.xmax = rdfilepos(fichfits, 'EWPOS', pos+1)
            posi.source.ymax = rdfilepos(fichfits, 'NSPOS', pos+1)
            posi.source.gra = rdfilepos(fichfits, 'MAJAXIS', pos+1)
            posi.source.grb = rdfilepos(fichfits, 'MINAXIS', pos+1)
            posi.source.tet = rdfilepos(fichfits, 'ANGLE', pos+1)
            posi.flux = rdfilepos(fichfits, 'FLUX', pos+1)
            WRITE_POSINRH, fichposi, fichimg, posi
        ENDFOR
    ENDIF ELSE fichposi = ''

    RETURN, fichposi
END