; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;
; extract scm sample rate and mode from header
;
; O. Le Contel & P. Robert, CETP, February 2007
;
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  PRO scm_cal_sample_rate, satname, mode, time_thscs_mode_hed, $
                           val_thscs_sfreq, apid_str

; input examples : satname='a'
;                  mode= 'scf'
; output example : time_thscs_mode_hed => time array associated
;                                         with the sample rate values
;                  val_thscs_sfreq => arrays of sample rate in Hz
;                  apid_str='44c'

; ----------------------------------------------------------------------

; compute argument of get_data

  thscs_mode_hed = 'th'+satname+'_'+mode+'_hed'

; extract apid
; Warning: APID is written in decimal (ex. 1092 dec --> 444 hex)

  get_data,thscs_mode_hed,time_thscs_mode_hed,val_thscs_mode_hed

  val_thscs_apid = $
             reform(uint((32b*val_thscs_mode_hed(*,0)/32b))*uint(256) $
           + uint(val_thscs_mode_hed(*,1)))
  val_thscs_sfreq = 2.^(reform( 2b*val_thscs_mode_hed( *, 14)/32b)+1)
  dec2hex,val_thscs_apid(0,0),apid_str

  END

; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX