;+
pro chkalign, rimg, ximg, yimg, nerr, label
;
; Checks XALIGN and YALIGN instruction results.
;
;      /md60/log/sci160k/950114_004628
;
;;read_mdi, fn, 0, rimg, hdr
;;read_mdi, fn, 1, ximg, hdr
;;read_mdi, fn, 2, yimg, hdr

label = 'ALIGN: ' + ['X', 'Y']
nerr = [999, 999]
if (n_elements(rimg) lt 512*512L) then return
if (n_elements(ximg) lt 512*512L) then return
if (n_elements(yimg) lt 512*512L) then return

lrimg = long(rimg) and '0000ffff'x
lximg = long(ximg) and '0000ffff'x
lyimg = long(yimg) and '0000ffff'x

lrimg = reform(lrimg(0:'3FFFF'x),512,512)
lximg = reform(lximg(0:'3FFFF'x),512,512)
lyimg = reform(lyimg(0:'3FFFF'x),512,512)

x_opbuf = lonarr(512,512)
y_opbuf = lonarr(512,512)

;*************
df_x = 4096
df_y = 3072
;*************

for j = 0, 510 do $
    x_opbuf(j,*) = ((lrimg(j,*) * (16384-df_x)) + $
                    (lrimg(j+1,*) * df_x)) / 16384

dif_x_inf = size (where (x_opbuf(0:510,*) ne lximg(0:510,*)))

for j = 0, 510 do $
    y_opbuf(*,j) = ((x_opbuf(*,j) * (16384-df_y)) + $
                    (x_opbuf(*,j+1) * df_y)) / 16384

dif_y_inf = size (where (y_opbuf(0:510,0:510) ne lyimg(0:510,0:510)))


print, ' '
print, '--------------------------'
nerr_x = 0
if (dif_x_inf(0) ne 0) then nerr_x = dif_x_inf(1)
print, nerr_x, ' Errors in XALIGN'

nerr_y = 0
if (dif_y_inf(0) ne 0) then nerr_y = dif_y_inf(1)
print, nerr_y, ' Errors in YALIGN'
print, '--------------------------'

nerr = [nerr_x, nerr_y]
label = 'ALIGN: ' + ['X', 'Y']

end
