pro proc_vldc, filename, nerr_arr, label
;
;	/md60/log/sci160k/950106_014603
;
nerr_arr = intarr(3)
label    = strarr(3)
;
;arr = str2arr(img_list)
;p = (where(strpos(arr, '-') ne -1))(0)
;if (p ne -1) then begin
    ;arr0 = arr
    ;temp = fix(str2arr(arr0(p), delim='-'))
    ;arr = indgen( temp(1)-temp(0)+1 ) + temp(0)
    ;if (p gt 0) then arr = [fix(arr0(0:p-1)), arr]
    ;if (p lt n_elements(arr0)-1) then arr = [arr, fix(arr0(p+1:*))]
;end else begin
    ;arr = fix(arr)
;end

arr = indgen(10)

read_mdi, filename, arr(0), sqrt_tbl, hdr
read_mdi, filename, arr(1), recip_tbl, hdr
read_mdi, filename, arr(2), vel_tbl, hdr
read_mdi, filename, arr(3), sa_img, hdr
read_mdi, filename, arr(4), sc_img, hdr
read_mdi, filename, arr(5), sd_img, hdr
read_mdi, filename, arr(6), si_img, hdr
read_mdi, filename, arr(7), vel_img, hdr
read_mdi, filename, arr(8), ld_img, hdr
read_mdi, filename, arr(9), ic_img, hdr

; Calculate Velocity

sa = ishft (sa_img, 2)
sc = ishft (sc_img, 2)
ssum = sa_img + sc_img

temp = where (ssum lt 0)
temp_inf = size (temp)

;if (ssum gt 0) then denom = sa
denom = reform (sa, 1048576l)
if (temp_inf(0) ne 0) then begin
    lin_sc = reform(sc, 1048576l)
    denom(temp) = lin_sc(temp)
endif

recip = recip_tbl (denom)
prod32 = long(recip) * long(ssum)
alpha = ishft ((prod32 and '7fff000'x), -12)
calc_v = vel_tbl (alpha)
dummy = where(abs(calc_v - vel_img) gt 1, nerr)
print, ' ' 
print, '-----------------------------------'
print, nerr, format = '(i6, " Errors in Velocity Image")'
nerr_arr(0) = nerr
label(0) = 'VLDC: Vel'

; Calculate Line Depth

sum_of_sq = long(sa_img)*long(sa_img) + long(sc_img)*long(sc_img)
ssq = ishft (ishft (sum_of_sq, 4), -16)
calc_ld = sqrt_tbl (ssq)
dummy = where(abs(calc_ld - ld_img) gt 1, nerr)
print, nerr, format = '(i6, " Errors in Line Depth Image")'
nerr_arr(1) = nerr
label(1) = 'VLDC: LD'

; Calculate Continuum

lsd_img = (sd_img) and '0000ffff'x
lsi_img = (si_img) and '0000ffff'x
lld_img = (ld_img) and '0000ffff'x
calc_ic =  (((((lsi_img*2)+lld_img)/2)+(lsd_img/4))/2)-200
;calc_ic = (((((long(si_img)*2)+long(ld_img))/2)+(long(sd_img)/4))/2)-200
dummy = where(abs(calc_ic - ic_img) gt 1, nerr)
print, nerr, format = '(i6, " Errors in Continuum Image")'
nerr_arr(2) = nerr
label(2) = 'VLDC: Con'

print, '-----------------------------------'
end
