; ------------------------------------------------------------------
;                             Formatage RH
; ------------------------------------------------------------------
;
;INPUTS:
; c :	compression
; nof:	numero de frequence
; h:	[hr, min, sec, cent]
; itg:	points a formatter
;
;INPUT/OUTPUT:
; rec:	structure formatee
;
; ------------------------------------------------------------------
;
; ------------------------------------------------------------------
;                            Calcul du gain
; ------------------------------------------------------------------
; Permet de cadrer sur 16 bits 
; gain = rh_gain(pt)
; ------------------------------------------------------------------

FUNCTION RH_GAIN, pt

 M = MAX(ABS(pt))
 G = 0. 
 IF M NE 0 THEN G = (ALOG(M)-ALOG(32767))/ALOG(2)
 IF G GT 0 THEN c = 1. ELSE c = 0.
 RETURN, FIX(G+c)
END

; ------------------------------------------------------------------
;                            RH_FORMAT
; 04 dec 2003 : Version antennes anti-alias, un seul gain pour
;               l'ensemble des correlations
; ------------------------------------------------------------------

PRO rh_format, rec, c, nof, h, itg      

@rh_common.inc
       
   rec.c = c
   rec.nof = nof
   rec.h = h
   CASE n_elements(rec) OF
     '1': BEGIN
          g = rh_gain(itg)
          CASE entFI.typ OF
             '1' : rec.g = g
             '2' : rec.g = [g, g, g]
          ENDCASE
          g = 1./(2.^g)
          rec.pt=fix(g*itg)
          END
    ELSE: BEGIN
          FOR i=0, n_ELEMENTS(rec)-1 DO BEGIN
              g = rh_gain(itg(*,*, i))
              CASE entFI.typ OF
                '1' : rec(i).g = g
                '2' : rec(i).g = [g, g, g]
              ENDCASE
              g = 1./(2.^g)
              rec(i).pt=fix(g*itg(*,*,i))
          ENDFOR
          END
    ENDCASE
    IF entFI.endian EQ 1 THEN rec = SWAP_ENDIAN(rec)
    RETURN
END
