
;+ ***********************************************************************
; NAME:
;	LITPOS1D
;
; PURPOSE:
;	Cette procedure lit une position d'un fichier de position de
;	centroid (positions 1D ou positions 2D)
;
; CATEGORY:
;	NRH1 positions
;
; CALLING SEQUENCE:
;	LITPOS1D,Unit, Valeurs, Vinfo, Numero
;
; INPUTS:
;	UNIT	unite logique associee au fichier
;
;	NUMERO	Numero de la position
;	
; KEYWORD PARAMETERS:
;	TEMPDB	Temps de debut
;
;	TEMPFI	Temps de fin
; 
;	DEUX_D	Lecture de positions 2 dimensions
;	
;
; OUTPUTS:
;	VALEURS	Valeurs de la position
;
;	VINFO	Structure contenant les informations associees a la position
;
; COMMON BLOCKS:
;	NRH1_GLOBAL
;
; MODIFICATION HISTORY: (bonmartin@obspm.fr)
;	20/11/98	adapte du logiciel XHELIO (JB)
;-*******************************************************************

PRO Litpos1d ,n,img, vinfo, numim,TEMPDB=tempdb,TEMPFI=tempfi, DEUX_D=deux_d
COMMON NRH1_GLOBAL,NomFich,FichInfo

IF N_PARAMS() LE 2 THEN BEGIN
   Print, 'L''unite logique n''a pas ete specifie, ou les variables de sortie  '
   Print, 'ont ete omises..'
   Print,''
   MESSAGE,' erreur.'
ENDIF
IF N_ELEMENTS(tempfi) EQ 0 THEN tempfi=FichInfo(n).Heurfin
IF N_ELEMENTS(tempdb) EQ 0 THEN tempdb=FichInfo(n).Heurdeb 
t=0l
hchaine = ''
tempo = 0.0
NomFichier=NomFich(n)
;
;
;
hdeb= FLOAT(FichInfo(n).heurdeb)     ; conversion de l'heure de debut en reel
dt=FichInfo(n).paspix(0)             ; Pas temporel entre deux 'file'
ind1=LONG((tempdb-hdeb)/dt)          ; Indice temporel. dans l'image
tempdb=LONG(dt*(ind1)+hdeb)         ; Temps exact de l'image
;
hfin= FLOAT(FichInfo(n).heurfin)     ; conversion de l'heure de fin en reel
ind2=LONG((tempfi-hdeb)/dt)          ; Indice de l'image dans le fichier
tempfi=LONG(dt*(ind2)+hdeb)          ; Temps exact de l'image
;
;
; Pointe sur la premiere image demandee
; 
;
OPENR, n, FichInfo(n).nomfich
;
;   Lecture d'une entete d'image (la premiere)
;
IF FichInfo(n).imint EQ 0 THEN vinfo = FLTARR(FichInfo(n).nbtete)  $
                          ELSE vinfo = LONARR(FichInfo(n).nbtete)
offset=(numim*FichInfo(n).facbloc(1)+FichInfo(n).nblocs)*(FichInfo(n).tenre*4) 
POINT_LUN,n, offset
READU, n, vinfo

;  repositionne vers le debut de l'image demande 
;
POINT_LUN,n,offset   
;
;
;   Lecture des donnees demandees                                   
;
;
nbt = ind2-ind1+1                              ; nbre d'image de la sequence
;                                                  ; Fichier UN D
IF N_ELEMENTS(deux_D) EQ 0 THEN $                   ; tableau des donnees  
BEGIN                                              ;
; vinfo(0) num de la position
; vinfo(1) hdeb de la position
; vinfo(2) nb de points de la position
   nbtete=Fichinfo(n).nbtete
   nbp=fichinfo(n).nbpix(0)
   img   = FLTARR(5,nbp) 
   image = FLTARR(nbp+FichInfo(n).nbtete)
   canal = FLTARR(nbp+FichInfo(n).nbtete)
   ampli = FLTARR(nbp+FichInfo(n).nbtete)
   flux  = FLTARR(nbp+FichInfo(n).nbtete)
   diame = FLTARR(nbp+FichInfo(n).nbtete)
   ;
   
; on lit les positions sur toute la duree du fichier positions
;  

   READU, n, image
   READU, n, canal
   READU, n, ampli
   READU, n, flux
   READU, n, diame
   img(0,*)=image(nbtete:*)
   img(1,*)=canal(nbtete:*)
   img(2,*)=ampli(nbtete:*)
   img(3,*)=flux(nbtete:*)
   img(4,*)=diame(nbtete:*)

ENDIF ELSE $                                            ; Fichier DEUX D
BEGIN                                                   ; 
   ;                                                    ; tableau des donnees  
   nbtete=Fichinfo(n).nbtete
   nbp=fichinfo(n).nbpix(0)
   img    = FLTARR(6,nbp) 
   positx = FLTARR(nbp+nbtete)
   posity = FLTARR(nbp+nbtete)
   fluxew = FLTARR(nbp+nbtete)
   fluxns = FLTARR(nbp+nbtete)
   diamew = FLTARR(nbp+nbtete)
   diamns = FLTARR(nbp+nbtete)
   ;
   READU, n, positx
   READU, n, posity
   READU, n, fluxew
   READU, n, fluxns
   READU, n, diamew
   READU, n, diamns
   ;

   img(0,*) = positx(nbtete:*)
   img(1,*) = posity(nbtete:*)
   img(2,*) = fluxew(nbtete:*)
   img(3,*) = fluxns(nbtete:*)  
   img(4,*) = diamew(nbtete:*)
   img(5,*) = diamns(nbtete:*)

ENDELSE

CLOSE, n
END                       
