;+
;  Modification History
;    09-Apr-2004  DG
;      Added code to make it work with observing sequences that run to more
;      than one record.  This change required the arguments to the function
;      to change.  Now OREC is the original record number of the obseq record.
;      A is the associated variable corresponding to the file.  Note that
;      OREC may be changed, and on return is OREC + n_obseq - 1, where n_obseq
;      is the number of records in the observing sequence.  If only 1 record,
;      OREC is returned unchanged.
;-
function srsp_get_obseq,orec,a

   data = getdata(orec,a)
   data = data[0:255]

   ; Create OBSEQ structure
   obseq = {obseq,   id: 0, $
                   nrpt: 0L, $
                     nx: 0, $
                   ppac: ptr_new(0), $
                  pndon: ptr_new(0), $
                 pcalon: ptr_new(0), $
                     pf: ptr_new(0)}

   ptr_free,obseq.pf,obseq.ppac,obseq.pndon,obseq.pcalon
   obseq.id = data[6]             ; ID number of sequence
   obseq.nrpt = uint(data[7])     ; Number of times that sequence repeats
   obseq.nx = data[8]             ; Number of entries in sequence
   ndat = 247

   while (obseq.nx gt ndat) do begin
      print,orec
      orec = orec + 1
      ; Observing sequence extends over multiple records, so read some more
      dat2 = getdata(orec,a)
      dat2 = dat2[0:255]
      data = [data,dat2[6:*]]
      ndat = ndat+250
   endwhile
   print,orec
   vals = reverse(uint(data[9:8+obseq.nx]))   ; "raw" values in sequence (stored in
                                  ; reverse order, so unreverse it).

   obseq.ppac = ptr_new((vals and 'f000'x)/'1000'x)  ; POZ and ACQ code
   obseq.pndon = ptr_new((vals and '800'x)/'800'x)   ; Set if ND is on
   obseq.pcalon = ptr_new((vals and '400'x)/'400'x)  ; Set if FREQ CAL oscillator is on

   ; Create a FREQS array to decode frequency index into frequencies.
   ; Invalid frequencies will return code itself.
   freqs = indgen(700)
   freqs[1:301] = indgen(301)*20 + 2000
   freqs[302:502] = indgen(201)*50 + 8000
   freqs[650:699] = indgen(50)*20 + 1000
   ; Use lowest 10 bits of VALS as frequency code
   f = freqs[vals and '3ff'x]
   obseq.pf = ptr_new(f)

return,obseq
end