pro ROIUpdateRoiDL,indx,ptr=ptr,doselect=doselect

; Tasks here:
; 1) Update the ROI dropdown list (ROI DL) contents
; 2) Update the (*ptr).RoiDL array to agree with contents of ROI DL
; 3) Select a particular element of the ROI DL using widget_control
; 4) Set (*ptr).RoiDLsel equal to the index num of ROI DL selection
; 5) Set (*ptr).rind to the 'r' structure array index corresponding
;	 to the ROI pointed to by ROI DL selection

; indx is DL index (not ROI number) of desired ROI DL selection--
; remember 0='None'. This indx is not the same as 'rind' (the index of
; the r structure corresponding to the DL selection)

; Determine the appropriate contents of the ROI droplist, by
; discovering the set of used ROIs in r array

	used = (*ptr).r.used
	usedRind = where(used eq 1,cntUsed)

	if cntUsed gt 0 then begin
		; At least one ROI has used=1
		DL = string(format='(I3.3)',(*ptr).r[usedRind].rnum)
		; DL is subset of .RoiDL array (tag of rinfo)
		; (.RoiDL has .nrmax+1 values, including NULLs)
		; Replace existing values of .RoiDL array (subset only)
		; with the values of DL.  Start at 1, since 0='None'
		(*ptr).RoiDL[*] = ""	; Reinitialize the .RoiDL array
		(*ptr).RoiDL[1:cntUsed] = DL	; For storage in rinfo
		DL = ['None',DL]				; For Dropdown list
		(*ptr).RoiDL[0]='None'

	endif else begin
		DL = replicate("",(*ptr).nrmax+1)
		(*ptr).RoiDL[0] = 'None'	; For storage in rinfo
		DL = ['None'] 				; For Dropdown list
	endelse

; Set ROI droplist contents to DL

	id = widget_info((*ptr).roiID,find_by_uname='ROIDropList')
	widget_control,id,set_value = DL
	widget_control,id,scr_xsize=2,units=2

	; If doselect is set, then set the DL's selection to indx

	select = doselect
	if select then begin
		widget_control,id,set_droplist_select=indx

		; Determine the r index corresponding to selected (DL) ROI.
		; selRnum is selected rnum (not ROI DL element).
		; cntUsed is the count of existing ROIs.

		if indx gt 0 then begin
			selRnum = fix(DL[indx])
			rind = selRnum -1
		endif else begin
			; indx eq 0 means 'None' is selected
			; indx will be 0 when first running this proc.
			selRnum = -1	; No ROIs exist
			rind = -1
		endelse
		(*ptr).RoiDLsel = indx
		(*ptr).rind = rind
	endif ; select

end