pro ROI_UpdatePixCoord,pinfo,ptr=pr

; Update the pixel coordinates of any ROI's that have the
; rotate flag set and store them in the ROI info structure

fmt = '(I3,I3,I4,I4)'
nsew = fltarr(2)
Hdr = (*pinfo).ftsHdr
i = 1 	; Point Id counter
; Check that there is at least one ROI defined (.nr gt 0)
	if (*pr).nr gt 0 then begin
		spawn,'copy /Y ROIBounds.txt ROIBounds.bak',/HIDE
		openw,lun1,'ROIBounds.txt',/get_lun
		for j = 0,(*pr).nr-1 do begin
			r = (*pr).r[j]		; Simplifies syntax
			; Get ID of region 'j'
			;roiID = (*pr).id[j]
			roiID = r.rnum

			; Get delta time (seconds)
			dsec = 0
			if r.rot gt 0 then begin
				; Get date/time of current image
				dobs = Hdr[where(strmatch(Hdr,'DATE_OBS*') eq 1)]
				dobs = strmid(dobs[0],11,23) 	; date in CDF epoch3 format(nearly)
				imgep = cdf_parse_epoch3(dobs)
				origep = cdf_parse_epoch3(r.date)
				dsec = long((imgep - origep)/1000.)
			endif
			ip = r.pts
			for k = 0,ip-1 do begin
				; Do each point for the ROI
				; Get pixel coords from arc second coords
				xa = r.xa[k]
				ya = r.ya[k]
				nsew = sxi_arcs2pix(xa,ya,pinfo, $
					deltasecs = dsec)
				nsew = round(nsew)
				r.x[k] = nsew[0]
				r.y[k] = nsew[1]

				str = string(format=fmt,i,roiID,nsew[0],nsew[1])
				printf,lun1,str
				i = i+1	;Increment point Id
			endfor
			v = where(r.x ne 0,cnt)
			r.tx = fix(mean(r.x[v]))
			r.ty = fix(mean(r.y[v]))
			(*pr).r[j] = r

		endfor
	endif
end