pro mk_limb_pixmap, item, outfil=outfil0, dp=dp, mk_cfil=mk_cfil, demo=demo
;+
;NAME:
;	mk_limb_pixmap
;PURPOSE:
;	To unwrap the limb figure annulus into a rectangle
;SAMPLE CALLING SEQUENCE:
;	mk_limb_pixmap, 'cf50'
;HISTORY:
;	Written 1995 by M.Morrison
;	 2-Apr-96 (MDM) - Put on-line
;V1.1	17-May-96 (MDM) - Added /mk_cfil option to make the format file
;			- Added /demo for certain portion of the code
;-
;
;infil = '/mdisw/dbase/ops/lists/pixmap_limb_afb0.fits'
;
nxout = 3000
nyout = 40
ann_thick = 15
;
infil = '/mdisw/dbase/ops/lists/pixmap_limb_' + item + '.fits'
outfil = '/mdisw/dbase/ops/lists/pixmap' + strtrim(nxout,2) + 'x' + strtrim(nyout,2) + 'rec_limb_' + item + '.fits'
if (n_elements(outfil0) ne 0) then outfil = outfil0
;
list = rfits(infil)
xmat = list(*,1) mod 1024
ymat = list(*,1) / 1024
;
print, infil, ' has ', max(list(*,0))+1, ' data points'
;
xorad = (max(xmat) - min(xmat))/2.	;outter radii
yorad = (max(ymat) - min(ymat))/2.
orad = (xorad + yorad)/2.
xc = max(xmat) - xorad
yc = max(ymat) - yorad
;
xout = dindgen(nxout, nyout) mod nxout
yout = lindgen(nxout, nyout) / nxout
;
ang = xout/(nxout-1)*2*!pi
rad = (orad +0.5*ann_thick - yout/(nyout-1D) * ann_thick)
xpixout = fix( cos(ang) * rad +xc +0.5)
ypixout = fix( sin(ang) * rad +yc +0.5)
;
img3 = bytarr(1024,1024)
img3(xpixout, ypixout) = 255
tvscl, rebin(img3, 512, 512, /sample)
;
img = lonarr(1024,1024)-1
img(list(*,1)) = list(*,0)
out_a = img(xpixout + ypixout*1024L)	;data product pixel numbers
out_b = lindgen(nxout,nyout)		;subscript in (nxout,nyout) array
;
ss = where(out_a ne -1, nss)
out = lonarr(nss, 2)
out(*,0) = out_a(ss)
out(*,1) = out_b(ss)
;
if (keyword_set(demo)) then begin
    if (n_elements(dp) eq 0) then begin
        img = rfits('/mdisw/data/samples/940422_I_raw.fits')
        ;img(0,0) = congrid(img(20:1005, 20:1005), 1024, 1024)	;change the radius
        ;img(0,0) = congrid(img(25:1000, 25:1000), 1024, 1024)	;change the radius
        img(0,0) = congrid(img(26:998, 30:1003), 1024, 1024)	;change the radius
        dp = img(list(*,1))
    end
    ;
    pm_file = '/mdisw/dbase/ops/lists/pixmap512_limb_' + item + '.fits'
    pm = rfits(pm_file)
    aa = intarr(512,512)+600
    aa( pm(*,1) ) = dp( pm(*,0) )
    tvscl, aa
    ;
    bb = intarr(nxout, nyout)
    bb( out(*,1) ) = dp( out(*,0) )
    tvscl, congrid(bb, 512, 75)
end
;
head = [mk_fits_head(out), 'END                                                                             ']
sxaddpar, head, 'INFILE', infil
sxaddpar, head, 'CREATED', !stime
sxaddpar, head, 'PROGRAM', 'MK_LIMB_PIXMAP'
sxaddpar, head, 'PROG_VER', 'Ver 1.1'
wrt_fits, outfil, head, out
;
if (keyword_set(mk_cfil)) then begin
    mat = rd_tfile('/mdisw/dbase/ops/dpc_format/gen_ef20.cfil')
    mat = str_replace(mat, 'ef20', item)
    mat = str_replace(mat, '25-Apr-96', gt_day(!stime, /str))
    prstr, mat, file='/mdisw/dbase/ops/dpc_format/gen_' + item + '.cfil'
end

end