; Minimum code to read and calibrate a cycle of data
; Start with filename, and the record number of the header record of the scan of interest
pro min_code,filename,hrec

   ; Open file
   lun = openarc(filename,a,nrec)

   ; Set up structures for a new scan, starting at HREC (REC points to start of data)
   rec = newscan(a,nrec,hrec,header,obseq,cfg,traj,refcal,gparm,geometry,pRecent,pOld,cyc_str) - 1

   ; Explicitly copy "CYCLE structure" arrays
   bigdata = temporary(*cyc_str.pbigdata)
   pol = temporary(*cyc_str.ppol)

   ; Put a loop here, to loop over cycles.
      ; Get a cycle of data
      cycle = get_cycle(a,data,rec,header,obseq,cfg,tcycle)

      bigdata(0) = cycle            ; Convert CYCLE to channelized floating array
      flagool,bigdata,header,obseq      ; Apply flags for notrack, OOL
      ; Correct for complex gain and attenuation
      smldata = gaincor(bigdata,pol,header,cfg,obseq,tcycle,gparm,geometry,uv)
   ; End loop

   ; Free memory associated with structures
   freescan,obseq,traj,refcal,gparm,geometry,pRecent,pOld,cyc_str
   free_lun,lun

return
end
