;
;==========================================================================
;
; FILE: dwell_demo.pro
;
; USAGE: dwell_demo, filename
;        ARGUMENTS    filename   Name of UF disk file
;
; ABSTRACT:  Demonstration program to read two UF fields dwell by dwell
;
; AUTHOR:  I. Jeff Caylor
;          Science Systems and Applications, Inc.
;          5900 Princess Garden Parkway, Suite 300
;          Lanham, MD  20706
;
;     at:  NASA Goddard Space Flight Center
;          Code 912
;          Greenbelt, MD 20771
;          Voice: (301) 286-3767
;          Fax:   (301) 286-1762
;          Email: jeff.caylor@gsfc.nasa.gov
;
; CREATED: 15 August 1995
;
; MODIFIED:
;       8 Jan 2003  GMH
;       Added fieldname keyword.
;
;==========================================================================
;
PRO dwell_demo, filename, FIELDNAME = fieldname
  PRINT, 'Reading file: ', filename
  OPENR, infile, filename, /GET_LUN
;
; ZN = Nadir original dBZ      VN = Nadir corrected Doppler
;
  fieldname = ['ZN','VN']
;
  maxgates = 800
  nfields = N_ELEMENTS(fieldname)
  dwell = FLTARR(nfields, maxgates)
;
  cnt = 0
  WHILE (EOF(infile) NE 1)  DO  BEGIN
    UF_read_dwell, infile, ufbuf, /RDSS
    ;
    ; Extract field data from the UF buffer and trim the array
    ;
    FOR n = 0, nfields - 1 DO BEGIN
      UFnameddata, ufbuf, fieldname(n), data, ngates, ERROR = status
      dwell(n, 0 : ngates - 1) = data(0:ngates-1)
    ENDFOR
    dwell = dwell(*, 0 : ngates - 1)
;
    PRINT, UFstrtime(ufbuf), UFdwell(ufbuf), UFedop_ins_altitude(ufbuf), $
           UFedop_ins_latitude(ufbuf), UFedop_ins_longitude(ufbuf), ngates

;     DO PROCESSING ON THE DWELL HERE

; Print parameter 1 and 2 minima and maxima
    xx = REFORM(dwell(0,*))  & yy = REFORM(dwell(1,*))
    PRINT,MIN(xx,index1), MAX(xx,index2), MIN(yy,index3), MAX(yy,index4)
    PRINT,' index:  ', index1, index2, index3, index4, cnt
    cnt = cnt + 1
    
  ENDWHILE
  CLOSE, infile
  FREE_lun, infile
END
