pro reg_check, infil, outfil, hc=hc
;+
;NAME:
;	reg_check
;PURPOSE:
;	To take an .ips file as input and to find all of the register
;	usage and to look for conflicts.  Conflicts are flagged with
;	a >>
;SAMPLE CALLING SEQUENCE:
;	reg_check
;	reg_check, infil, outfil
;	reg_check, '/mdisw/cfl/dev/ip/mkdps.ips', 'dd.out'
;OPTIONAL INPUT:
;	infil	- The .ips input file.  Default is:
;		  '/mdisw/cfl/dev/ip/mkdps.ips'
;	outfil	- If present, save the results to the output file.
;OPTIONAL KEYWORD OUTPUT:
;	hc	- If set, send the results to the printer.
;HISTORY:
;	Written 1-Aug-95 by M.Morrison
;	 1-Aug-95 (MDM) - Added information on what instructions was used
;			  with the register
;-
;
if (n_elements(infil) eq 0) then infil = '/mdisw/cfl/dev/ip/mkdps.ips
;spawn, ['grep', 'SETREGS', infil], r, /noshell
mat = rd_tfile(infil, nocomment=';')
remtab, mat, mat
mat = mat + ' '
;
;;out = strarr(8192)
;;ss = wc_where(mat, '*SETREG *')
;;r = mat(ss)
;;r = strcompress(strtrim(r, 2))
;;v = fix(strmid(r, 8, 4))
;;for i=0,n_elements(v)-1 do out(v(i)) = out(v(i)) + 'O'


ss = wc_where(mat, '*SETREG*')
r = mat(ss)
r = strcompress(strtrim(r, 2))
n = n_elements(r)
v = intarr(n)
for i=0,n-1 do begin & arr = str2arr(r(i), delim=' ') & v(i) = fix(strmid(arr(1),1,5)) & end
ss = sort(v)
r = r(ss)
v = v(ss)
;
narr = intarr(n)
for i=0,n-1 do begin & arr = str2arr(r(i), delim=' ') & narr(i) = fix(arr(2)) & end
ss = wc_where(r, '*SETREG *')
narr(ss) = 1	;SETREG instead of SETREGS
v2 = v+narr
diff = v2-v(1:*)
ss = where(diff gt 0)
extra = strarr(n)+'   '
if (ss(0) ne -1) then extra(ss) = '>> '
r = str_replace(r, 'SETREG ', 'SETREG  ')
out = extra + r
;
extra2 = strarr(n)
for i=0,n-1 do begin
    ss2 = wc_where(mat, '*R' + strtrim(v(i),2) +' *', nss2)
    if (nss2 ne 0) then begin
	;;print, mat(ss2)
	r2 = strcompress(strtrim(mat(ss2), 2))
	ss3 = where(strpos(r2, 'SETREG') eq -1, nss3)
	for j=0,nss3-1 do extra2(i) = extra2(i) + ' ' + (str2arr(r2(ss3(j)), delim=' '))(0)
    end
end
out = strmid(out+'                                                                  ', 0, 70) + extra2
;
out = ['REG_CHECK  Ver 2.0  Program Run: ' + !stime, ' ', 'Infil: ' + infil, ' ', out]
prstr, out, /nomore
if (keyword_set(outfil)) then prstr, out, file=outfil
if (keyword_set(hc)) then prstr, out, /hc
end