pro mk_ff_patch, list, base_addr, addr, outfil, append=append, comment=comment, table=table, gen_data=gen_data
;+
;NAME:
;	mk_ff_patch
;PURPOSE:
;	To build the control file to patch the flat field data
;HISTORY:
;	Written May-96 by M.Morrison
;	27-Jun-96 (MDM) - Added new list of pixels
;			- Changed some of the comments for each pixel
;	11-Jul-96 (MDM) - Modification to allow VEL table #2 patches
;			- Modification to format negative words properly
;       15-Aug-96 (MDM) - Created the patch #2 for velocity
;	16-Sep-96 (MDM) - Patch for FF for Sep-96
;	24-Sep-96 (MDM) - Patch for FF for second Sep-96 fix
;	25-Sep-96 (MDM) - Corrected "mbiptbl" command generation for
;			  the case between LIST and TABLE loads
;			  (Tables = velocity, lists = flat field)
;			- Patch for FF for third (last?) Sep-96 fix
;	30-Sep-96 (MDM) - Another Sep-96 4 pixel patch (944592)
;	14-Oct-96 (MDM) - Added capability to do VWBIN patch
;	21-Oct-96 (MDM) - Added velocity patch entry for 19-Oct blip
;	28-Oct-96 (MDM) - FF patch
;	 5-Nov-96 (MDM) - Added capability to do sqrt#1 patch
;			- Removed the directory name from the output file
;	12-Nov-96 (MDM) - Added Nov-96 VWBIN patch (pixel 31314)
;	13-Nov-96 (MDM) - Added FF patch for page 10
;	13-Nov-96 (MDM) - Changed wait from 60 to 90 seconds because
;			  the 60 sec wait causes FE0x and FBAD errors!
;			  (this was true months ago too)
;	15-Nov-96 (MDM) - Added patch to page 10 when in proper location
;	19-Nov-96 (MDM) - More patches to page 10
;	25-Nov-96 (MDM) - Patches to page 12 (4 pixels)
;	25-Nov-96 (MDM) - Added capability to do SQRT#4 patch
;	27-Nov-96 (MDM) - Few patches to page 12
;	 2-Dec-96 (MDM) - Single pixel patch in page 12
;        2-Jan-97 (CNF) - Single pixel patch in page 12
;	 6-Jan-97 (MDM) - Added IRBIN 7005 and 7007
;			- Added SET_LIST_ADDR call for VWBIN (put
;			  it in for IRBIN too)
;	 9-Jan-97 (MDM) - Added sqrt#2, sqrt#3, sqrt#4, and recip#1
;			- Renumbered the option menu
;	15-Jan-97 (MDM) - Added crop
;	27-Jan-97 (CNF) - Patch single point of vwbin
;	 2-Jan-97 (CNF) - Patch single pixel in ff
; 	20-Feb-97 (CNF) - Patch 3 pixels in ff
;	17-Mar-97 (CNF) - Single pixel patch to sqrt4 table
;	23-Mar-97 (CNF) - Patch 3 pixels in ff
;   	28-Mar-97 (CNF) - Patch 2 pixels in ff
;	 2-Apr-97 (CNF) - Patch 1 pixel in ff
;        7-Apr-97 (CNF) - Patch 1 pixel in ff 
;	16-Apr-97 (MDM) - Patch 1 pixel in ff
;	21-Apr-97 (MDM) - Patch SQRT2 and RECIP1
;       29-Apr-97 (CNF) - Patch 7 pixels in ff
;	28-May-97 (CNF) - Patch 1 pixel in ff
;       30-May-97 (CNF) - Patch 1 pixel if ff
;	 4-Jun-97 (CNF) - Patch 1 pixel in ff
;	 9-Jun-97 (MDM) - Patch 1 pixel if Vel2
;	15-Jul-97 (MDM) - Many pixel patch for new Flat field
;			- Changed flat field to flat_005.fits
;	17-Jul-97 (CNF) - Patch 1 pixel in sqrt2 table
;	23-Jul-97 (EBZ) - Patch 1 pixel in ff
;  	13-Aug-97 (CNF) - Patch 2 points in recip1
;       13-Aug-97 (CNF) - Patch 1 point in sqrt2 table
;	16-Sep-97 (CNF) - Patch 1 pixel in ff
;	30-Sep-97 (MDM) - Added RWBIN patch
;			- Patched RWBIN pixel 8489
;	06-Oct-97 (EBZ) - Patch 1 pixel in ff
;       20-Oct-97 (EBZ) - Patch 1 pixel in sqrt4 table
;	13-Nov-97 (CNF) - Patch 1 pixel in ff	
;       24-Nov-97 (EBZ) - Patch 1 pixel in vwbin table
;	25-Nov-97 (EBZ) - Patch 1 pixel in ff
;	01-Dec-97 (EBZ) - Patch 1 pixel in ff
;	08-Dec-97 (EBZ) - Patch 1 pixel in vwbin table
;       22-Dec-97 (EBZ) - Patch 4 pixels in ff
;        7-Jan-98 (CNF) - Patch 5 pixels in rwbin
;        2-Feb-98 (CNF) - Patch 1 pixel in recip1
;	24-Feb-98 (EBZ) - Patch 1 pixel in vwbin table
;	 2-Mar-98 (EBZ) - Patch 1 pixel in ff
;	18-Mar-98 (EBZ) - Patch 1 pixel in ff
;	20-Apr-98 (EBZ) - Patch 1 pixel in ff
;       23-Apr-98 (EBZ) - Patch 1 pixel in ff
;	12-May-98 (EBZ) - Patch 2 pixels in ff
;	27-May-98 (EBZ) - Patch 1 pixel in sqrt2 table
;	20-Oct-98 (CNF) - Patch 20 pixels in vwbin
;	23-Oct-98 (EBZ) - Patch 1 pixel in vwbin table
;	26-Oct-98 (EBZ) - Patch the same bad pix in vwbin table
;	 3-Nov-98 (EBZ) - Patch 1 pixel in ff
;	12-Nov-98 (EBZ) - Patch 1 pixel in ff
;	 3-Feb-99 (EBZ) - Patch 1 pixel in sqrt3 table
;	 3-Feb-99 (EBZ) - Patch 4 pixels in ff
;	10-Mar-99 (EBZ) - Patch 1 pixel in ff
;	19-Apr-99 (CNF) - Patch 4 pixels in ff
;	23-Apr-99 (EBZ) - Patch 7 pixels in ff
;	26-Apr-99 (EBZ) - Patch 1 pixel in ff
;        4-Jun-99 (SEG) - Patch 1 pixel in sqrt4 table
;	29-Jun-99 (SEG) - Patch 1 pixel in ff
;        7-Jul-99 (SEG) - Patch 1 pixel in irbin table
;       26-Jul-99 (SEG) - Patch 1 pixel in velocity2 table
;       03-Aug-99 (SEG) - Patch 1 pixel in vwbin table
;       23-Aug-99 (SEG) - Patch 1 pixel in velocity2 table
;	26-Aug-99 (SEG) - Patch 1 pixel in ff
;	20-Sep-99 (SEG) - Patch 2 pixels in ff
;   	21-Sep-99 (SEG) - Patch 2 pixels in ff
;	24-Sep-99 (SEG) - Patch 7 pixels in ff
;	27-Sep-99 (EBZ) - Patch 18 pixels in ff
;	27-Sep-99 (EBZ) - Changed table number to be 0 instead of a strange
;			  number that was accidentally there
;	13-Oct-99 (SEG) - Patch 1 bad pixel in ff
;	26-Oct-99 (EBZ) - Patch 1 pixel in ff
;	28-Oct-99 (EBZ) - Patch 1 pixel in velocity2 table
;	15-Nov-99 (SEG) - Patch 1 pixel in the ff
;	31-Dec-99 (SEG) - Patch 1 pxiel in the ff
;	12-Apr-00 (EBZ) - Patch 1 pixel in ff
;	24-Apr-00 (SEG) - Patch 1 pixel in ff
;	 8-May-00 (EBZ) - Patch 2 pixels in vwbin table
;	 9-Jun-00 (EBZ) - Patch 1 pixel in ff
;	11-Jul-00 (SEG)	- Patch 2 pixel in ff
;	17-Jul-00 (SEG) - Patch 1 pixel in vel2 table
;		  (SEG) - Patch 1 pixel in vwbin table
;	10-Aug-00 (SEG) - Patch 1 pixel in ff
;	05-Oct-00 (SEG) - Patch 1 pixel in ff
;	12-Oct-00 (SEG) - Patch 1 pixel in ff
;	 9-Nov-00 (SEG) - Patch 2 pixels in ff
;	 5-Dec-00 (SEG) - Patch 1 pixel in ff
;	18-Apr-01 (SEG) - Patch 1 pixel in ff
;	25-May-01 (SEG) - Patch 2 pixel in ff
;	04-Jun-01 (SEG) - Patch 1 pixel in ff
;	11-Jun-01 (SEG)	- Patch 1 pixel in recip1 
;	28-Aug-01 (JLRS) - Patch 1 pixel in recip1
;	19-Sep-01 (SEG)	- Patch 1 pixel in ff
;	15-Oct-01 (SEG) - Patch 1 pixel in ff
;	05-Nov-01 (SEG) - Patch 1 pixel in ff
;	08-Nov-01 (SEG) - Patch 5 bad pixels in ff
;	17-Dec-01 (SEG) - Patch 1 bad pixel in ff
;	04-Jan-02 (SEG) - Patch 2 bad pixel in ff
;	13-Feb-02 (SEG) - Patch 14 bad pixels in ff
;	14-Feb-02 (SEG) - Patch 2 bad pixels in vwbin table
;	10-Apr-02 (SEG) - Patch 1 bad pixel in ff
;	30-Apr-02 (SEG) - Patch 1 bad pixel in ff
;	14-May-02 (SEG) - Patch 1 bad pixel in ff
;	17-May-02 (SEG) - Patch 1 bad pixel in ff
;	05-Jun-02 (SEG) - Patch 1 bad pixel in ff
;	13-Jun-02 (SEG) - Patch 1 bad pixel in ff
;	25-Jun-02 (SEG) - Patch 2 bad pixels in lookup_recip1 table
;	08-Jul-02 (SEG) - Patch 2 bad pixels in the ff
;	14-Oct-02 (SEG) - Patch 6 bad pixels in the ff
;	07-Nov-02 (JLRS) - Patch 1 bad pixel in the ff
;	27-Nov-02 (SEG) - Patch 1 bad pixel in the ff
;	13-Dec-02 (SEG) - Patch 1 bad pixel in the ff
;	26-Dec-02 (SEG) - Patch 1 bad pixel in the ff
;	17-Mar-03 (SEG) - Patch 1 bad pixel in the ff
;	16-Apr-03 (JLRS) - patch 1 bad pixel in the ff
;	25-Apr-03 (SEG) - Patch 1 bad pixel in vwbin table
;	12-May-03 (SEG) - Patch 1 bad pixel in the ff
;	18-Aug-03 (SEG) - Patch 1 bad pixel in the ff
;	12-Sep-03 (SEG) - Patch 1 bad pixel in the lookup_recip1 table
;	01-Oct-03 (SEG) - Patch 1 bad pixel in the ff
;	10-Oct-03 (SEG) - Patch 1 bad pixel in the ff
;	03-Dec-03 (SEG) - Patch 2 bad pixels in the ff
;	01-Mar-04 (SEG) - Patch 1 bad pixel in the ff
;	17-May-04 (SEG) - Patch 1 bad pixel in lookup_velocity2 table
;	21-May-04 (SEG) - Patch 1 bad pixel in the ff
;	21-Jul-04 (SEG) - Patch 1 bad pixel in the ff
;	26-Jul-04 (ZAF) - Patch 1 bad pixel in the ff
;	02-Aug-04 (SEG) - Patch 1 bad pixel in the ff
;	16-Aug-04 (SEG) - Patch 1 bad pixel in the ff
;       14-Sep-04 (SEG) - Patch 1 bad pixel in the ff
;       25-Oct-04 (SEG) - Patch 1 bad pixel in the ff 
;	10-Nov-04 (SEG) - Patch 1 bad pixel in the lookup_sqrt4 table
;       29-Nov-04 (SEG) - Patch 2 bad pix in the ff
;	31-Jan-05 (SEG) - Patch 1 bad pixel in the ff
;	20-Feb-05 (SEG) - Patch 1 bad pixel in the rwbin_5005 table
;	22-Feb-05 (SEG) - Patch 1 bad pixel in the ff
;	10-Mar-05 (SEG) - Patch 1 bad pixel in the ff
;	26-May-05 (SEG) - Patch 2 bad pixels in the ff
;	27-Jun-05 (SEG) - Patch 1 bad pixel in the lookup_sqrt4 table
;	30-Jun-05 (SEG) - Patch 1 bad pixel in the rwbin_5005 table
;	01-Jul-05 (SEG) - Patch 1 bad pixel in the ff
;	13-Jul-05 (SEG) - Patch 1 bad pixel in the ff
;	18-Jul-05 (SEG) - Patch 1 bad pixel in the ff
;	26-Aug-05 (SEG) - Patch 1 bad pixel in the ff
;	01-Sep-05 (SEG) - Patch 1 bad pixel in the ff
;       06-Sep-05 (SEG) - Patch 1 bad pixel in the vwbin_6007 table
;       31-Oct-05 (SEG) - Patch 1 bad pixel in the ff
;	09-Dec-05 (SEG) - Patch 6 bad pixels in the ff
;	01-Jan-06 (SEG) - Patch 1 bad pixels in the ff
;	09-Jan-06 (SEG) - Patch 1 bad pixel in the ff
;	12-Jan-06 (SEG) - Patch 1 bad pixel in the ff
;       17-Jan-06 (SEG) - Patch 1 bad pixel in the vwbin_6007 table
;       07-Feb-06 (JLRS) - Patch 1 bad pixel in the ff
;	14-Feb-06 (ZAF) - Patch 1 bad pixel in the vwbin_6007 table
;	22-Feb-06 (SEG) - Patch 2 bad pixels in the ff
;	13-Mar-06 (SEG) - Patch 1 bad pixel in the ff
;	24-Apr-06 (SEG) - Patch 1 bad pixel in the lookup_velocity2 table 
;	26-Apr-06 (SEG) - Patch 1 bad pixel in the irbin_7005 table
;	16-May-06 (HHT) - Patch 1 bad pixel in the ff
;	22-May-06 (SEG) - Patch 1 bad pixel in the vwbin_6007 table
;	19-Jun-06 (SEG) - Patch 2 bad pixels in the ff
;       31-Jul-06 (SEG) - Patch 1 bad pixel in the ff
;	24-Aug-06 (SEG) - Patch 1 bad pixel in the ff
;	25-Sep-06 (SEG) - Patch 1 bad pixel in the ff
;	30-Oct-06 (SEG) - Patch 1 bad pixel in the ff
;	08-Nov-06 (SEG) - Patch 1 bad pixel in the ff
;	17-Nov-06 (SEG) - Patch 2 bad pixels in the rwbin table
;	13-Dec-06 (SEG) - Patch 3 bad pixels in the ff
;
break_file, outfil, dsk_log, dir000, filnam
if (n_elements(descr) eq 0) then descr = 'Load something to address ' + string(addr, format='(z8.8)')

if (keyword_set(append)) then begin
    openu, lun, outfil, /get_lun, /append
    printf, lun, ' '
    printf, lun, '##--------------------------------------------------------------
    printf, lun, ' ' 
end else begin
    ssw_file_delete, outfil
    openw, lun, outfil, /get_lun
    printf, lun, '# File: ' + outfil
    printf, lun, '# Created: ' + !stime
    for i=0,n_elements(comment)-1 do printf, lun, '# ' + comment(i)
    printf, lun, '#'
    printf, lun, 'program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"'
    printf, lun, 'source "' + outfil + '"'
    printf, lun, 'descr "' + filnam + ' - ' + descr + '"'
end

n = n_elements(list)

fmt0 = '(" 0x", z4.4, 1x)'
fmt = '(' + strtrim(n,2) + fmt0 + ')'
source = ' 0x8000 0x8810 '
slist = zformat(list, 4, /mdi_leading, /string)
;idest = '50000000'x + addr
;idest = '60000000'x + addr
idest = base_addr + addr
;;dest = string( (idest mod '10000'x), (idest/'10000'x), format='(2'+fmt0+')')
;dest = zformat( [(idest mod '10000'x), (idest/'10000'x)], /mdi_leading, /string)
dest = zformat( [idest and 'ffff'x, ishft(idest, -16)], /mdi_leading, /string)
fmt99 = '(a, i8, "  X:", i4, "  Y", i4, a)'

type = ' 10 '						;flat field (or) list
if (keyword_set(table)) then type = ' 8 '		;velocity table
if (keyword_set(gen_data)) then type = ' 11 '		;flat field in page 10 (simple data)

printf, lun, ' '
printf, lun, '# *********** Fixing Pixel: ', addr, addr mod 1024, addr/1024, '****************', format=fmt99
printf, lun, 'tcb mbdpml 0x2000 0x0000 \
printf, lun, '      ' + slist
printf, lun, '
printf, lun, 'tcb mbdpml 0 0x547a 0xa390	## patch to remove increment
printf, lun, 'tcb mbiptbl ' + type + dest + '  0   0 0x2000 ' + strtrim(n,2)
printf, lun, 'wait time 90			## allow IP interrupt
printf, lun, 'tcb mbdpml 0 0x547a 0xa340	## patch back to original


free_lun, lun
end
;--------------------------------------------------------------------
;
;
if (n_elements(code) eq 0) then code = 0
last_code = code
print, 'Enter 0 for flat field (page 12)'
print, '      4 for flat field (backup copy in page 10)
print, '      5 for flat field (loading copy in page 10)
print, '     11 for sqrt table #1
print, '     12 for sqrt table #2
print, '     13 for sqrt table #3
print, '     14 for sqrt table #4
print, '     21 for recip table #1
print, '     30 for crop (0f00)
print, '     31 for crop (0fc0
print, '     50 for RWBIN
print, '     60 for VWBIN
print, '     75 for IRBIN-7005
print, '     77 for IRBIN-7007
print, '     82 for vel table #2
;
input, 'Enter option', code, code
;
gen_data = 0
;;qread = (n_elements(img0) eq 0) or (last_code ne code)
qread = 1	;MDM 15-Jul-97 (above code was not quite right)
case code of
	0: begin
	    ;;if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_003.fits')
	    if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_005.fits')
	    ss = circle_mask(img0, 512, 512, 'GT', 520)
	    img0(ss)=1.0
	    img0=round(img0*16384L) >0 <32767
	    base_addr = '60000000'x
	    outfil = 'mk_ff_patch.src'
	    ;pix = [388224, 566068, 589604]
	    ;pix = [145235, 146771, 147027, 267354, 321626, 388224, 566068, 589604, 814216, 887944]
	    ;pix = [130620, 489756]
	    ;pix = [551379, 882972, 917052]
	    ;pix = [        882972, 917052, 944599]
	    ;pix = 944592
	    ;pix = 213482
	    ;pix = [528981, 541868, 668185, 676997]
	    ;pix = [417795, 417799, 541868, 541875, 668185]
	    ;pix = [614005]
	    ;pix = 190144	
	    ;pix = 868642	
            ;pix = [818562, 843138, 900482]
	    ;pix = [684605, 717373, 741949]
	    ;pix = [821862, 126287]
	    ;pix = 620425
 	    ;pix = 1026440	
 	    ;pix = 724486
	    ;pix = [787045, 811877, 828005, 840101, 860773, 872869, 893541]	
	    ;pix = 335458 
            ;pix = 770130
            ;pix = [83624, 174422, 247526, 267592, 292031, $
	    ;		indgen(36)*8 + 543648, $
	    ;		557056, 589824, 834285, 946384]
 	    ;pix = 317054
	    ;pix = 468725
	    ;pix = 475627 
	    ;pix = 590266
	    ;pix = 244161
	    ;pix = 773236
	    ;pix = 650979
	    ;pix = 20901
	    ;pix = 759400
 	    ;pix = 156000
	    ;pix = [295864, 664657] 
	    ;pix = 515777
	    ;pix = 259530
            ;pix = [242064, 492593, 503644, 504226]
	    ;pix = 641032
	    ;pix = [64886,  89718, 97910, 596732]
            ;pix = [157450, 165642, 173834, 190346, 20660, 239370, 740514]
	    ;pix = [206602]
    	    ;pix = [598779] 
 	    ;pix = 239163
	    ;pix = [666780, 698268]
            ;pix = [695943, 695947]
	    ;pix = [695943, 695947, 686619, 686637, 686643, 686648, 686654]
	    ;pix = [569974, 569978, 569995, 649339, 649341, 649393, 649427, 649432, 649469, 649474, 649477, 649487, 686619, 686637, 686643, 686648, 686654, 695943, 695947]
	    ;pix = 883062
	    ;pix = 997965
	    ;pix = 960130
	    ;pix =  137837
	    ;pix = 766325
	    ;pix = 573523
	    ;pix = 307604
	    ;pix = [536460, 758159]
	    ;pix = 190123
	    ;pix = 383505
	    ;pix = 448967
	    ;pix = [247533, 262619]
	    ;pix = 160293
	    ;pix = 35483
	    ;pix = [393890, 394146]
	    ;pix = 325226
	    ;pix = 587708
	    ;pix = 935345
	    ;pix = 180537
	    ;pix = [821923, 331468, 714196, 772397, 797347]
	    ;pix = 503731
	    ;pix = [527813, 560581]
	    ;pix = [65003, 201886, 240113, 243065, 243321,269491, 377485, 385344, 599862, 629034, 663164, 696797, 753786, 798376]
	    ;pix = 753388
	    ;pix = 177728
	    ;pix = 597746
	    ;pix = 479764
	    ;pix = 581052
	    ;pix = 891402
	    ;pix = [1018341, 1026533]
	    ;pix = [378323, 951544, 951545, 951546, 951547, 951549]
	    ;pix = [113075]
	    ;pix = 884057
	    ;pix = 377681
	    ;pix = 685285
	    ;pix = 973209
 	    ;pix = 695500
	    ;pix = 555372
	    ;pix = 673519
	    ;pix = 681945
	    ;pix = 882220
	    ;pix = [670927, 671183]
	    ;pix = 379234
	    ;pix = 646054
	    ;pix = 835169
	    ;pix = 326081
	    ;pix = 692461
	    ;pix = 829157
	    ;pix = 178411
	    ;pix = 728449 
	    ;pix = [44730, 751364]
	    ;pix = 475470
	    ;pix = 705171
	    ;pix = 1013361
	    ;pix = [283123,1029492]
	    ;pix = 163484
	    ;pix = 285258
	    ;pix = 343502
	    ;pix = 480698
	    ;pix = 853700
	    ;pix = 578798
	    ;pix = [283952, 292400, 359472, 361136, 369328, 384304]
	    ;pix = [297363, 845615]
	    ;pix = 251234
	    ;pix = 861884
	    ;pix =  186601
	    ;pix = [746378, 770954]
	    ;pix = 964323
            ;pix = 591533
	    ;pix = [460503,468695]
	    ;pix = 475623
	    ;pix = 845623
	    ;pix = 468419
	    ;pix = 223912
	    ;pix = 143012
	    pix = [573953, 733095, 948443]
;
	    table = 0
	  end
	4: begin
	    ;;if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_003.fits')
	    if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_005.fits')
	    ss = circle_mask(img0, 512, 512, 'GT', 520)
	    img0(ss)=1.0
	    img0=round(img0*16384L) >0 <32767
	    base_addr = '50000000'x + '80000'x - '30000'x
	    outfil = 'mk_ff10_patch.src'
	     pix = [206275,209130,214632,243935,247126,265831,268878,268887,273322,277269, $
			291431,292515,304668,319773,323100,323356,329108,340110,360854,362699, $
			369400,369602,388343,394778,399679,402157,419807,423843,430993,437118, $
			438244,443543,443693,444797,490676,502238,502617,503229,503595,510340, $
			510453,542055,546372,557494,566068,567545,572295,575698,581375,583772, $
			584153,595167,601458,604685,609459,620970,623087,629878,636241,644989, $
			652259,652581,661112,662098,667130,695164,696720,737190,739579,749800, $
			777425,802635,808559,834923,840603]
	     table = 0
	     gen_data = 1
	  end
	5: begin
	    ;;if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_003.fits')
	    if (qread) then img0=rfits('/mdisw/dbase/cal/files/flat_005.fits')
	    ss = circle_mask(img0, 512, 512, 'GT', 520)
	    img0(ss)=1.0
	    img0=round(img0*16384L) >0 <32767
	    base_addr = '50000000'x 
	    outfil = 'mk_ff10_patch.src'
	     ;pix = [201335,237386,259401,306469,322065,335367,393106]
	     pix = [16815,239852,298427,352320,509425,616734,616990,636023,759937,851231, $
			indgen(12)*8+859640]
	     table = 0
	     gen_data = 1
	  end
	11: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_sqrt1.fits')
	    base_addr = '80090000'x
	    outfil = 'mk_sqrt1_patch.src'
            pix = [4486]
	    table = 1
	   end
	12: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_sqrt2.fits')
	    base_addr = '80080000'x
	    outfil = 'mk_sqrt2_patch.src'
            ;pix = 6659
            ;pix = 5074
	    ;pix = 25620
	    ;pix = 17726
	    ;pix = 18487
	     pix = 18619
	    table = 1
	   end
	13: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_sqrt3.fits')
	    base_addr = '80070000'x
	    outfil = 'mk_sqrt3_patch.src'
            ;pix = 0
	     pix = 9841
	    table = 1
	   end
	14: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_sqrt4.fits')
	    base_addr = '80060000'x
	    outfil = 'mk_sqrt4_patch.src'
            ;pix = [5891]
            ;pix = [7469]
	    ;pix=[1610]
	    ;pix=[11482]
	    ;pix = [5935]
	    pix = [4815]
	    table = 1
	   end
	21: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_recip1.fits')
	    base_addr = '80098000'x
	    outfil = 'mk_recip1_patch.src'
            ;pix = 18947
            ;pix = 18898
	    ;pix = [1854, 9790]
	    ;pix = 22717
	    ;pix = 30899
	    ;pix = [23871, 32063]
	    pix = 18031
	    table = 1
	   end
	30: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_crop_0f00.fits')
	    base_addr = '70050000'x
	    img0 = unsign(img0, 16)
	    set_list_addr, '50000'x, img0	
	    outfil = 'mk_crop0f00_patch.src'
            pix = 0
	    table = 0
	   end
	31: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_crop_0fc0.fits')
	    base_addr = '70000000'x
	    img0 = unsign(img0, 16)
	    outfil = 'mk_crop0fc0_patch.src'
            pix = 0
	    table = 0
	   end
	50: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_rwbin_5005.fits')
	    base_addr = '70011000'x
	    img0 = unsign(img0, 16)
	    set_list_addr, '11000'x, img0	
	    outfil = 'mk_rwbin_patch.src'
	    ;pix = [8489]
	    ;pix = 7802
	    ;pix = [8677]
	    pix = [6801, 13713]
	    table = 0
	   end
	60: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_vwbin_6007.fits')
	    base_addr = '70040000'x
	    img0 = unsign(img0, 16)
	    set_list_addr, '40000'x, img0	
	    outfil = 'mk_vwbin_patch.src'
            ;pix = [37058]
            ;pix = [31314]
	    ;pix = [23430]
	    ;pix = [27201]
	    ;pix = [38165]
	    ;pix = [3922]
	    ;pix = [401, 402, 403, 404, 405, 406, 408, 409, 411, 412, $
	    ;       413, 414, 415, 416, 417, 418, 419, 533, 534, 535]
	    ;pix = [400]
	    ;pix = 26257
	    ;pix=[5386,51722]
	    ;pix = 43340
	    ;pix = [400, 403]
	    ;pix = 19938
	    ;pix = 6582
	    ;pix = 49672
	    ;pix = 13711
	    pix = 20012
	    table = 0
	   end
	75: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_irbin_7005.fits')
	    base_addr = '70034000'x
	    img0 = unsign(img0, 16)
	    set_list_addr, '34000'x, img0	
	    outfil = 'mk_irbin_patch.src'
            ;pix = 8793
	    pix = 14416
	    table = 0
	   end
	77: begin
	    img0=rfits('/mdisw/dbase/ops/lists/list_irbin_7007.fits')
	    base_addr = '70030000'x
	    img0 = unsign(img0, 16)
	    set_list_addr, '30000'x, img0	
	    outfil = 'mk_irbin_patch.src'
            ;pix = 0
	    ;pix =  2433
	    pix = 7839
	    table = 0
	   end
	82: begin
	    img0=rfits('/mdisw/dbase/ops/lists/lookup_velocity2.fits')
	    base_addr = '80028000'x
	    outfil = 'mk_vel2_patch.src'
	    ;pix = [13845,31596]
            ;pix = [13970]
            ;pix = [4300]
            ;pix = [17264]
            ;pix = 17845
	    ;pix= 8601
	    ;pix = 4361
	    ;pix = 23992
	    ;pix = 4751
	    pix = 10653
	    table = 1
	   end

endcase
;
npix = intarr(n_elements(pix))+1 > 8
for i=0,n_elements(pix)-1 do begin
    staddr = pix(i)
    staddr = staddr - (staddr mod 4)		;make sure it's on 4 word boundary
    mk_ff_patch, img0(staddr:staddr+npix(i)-1), base_addr, staddr, outfil, $
	append=(i ne 0), table=table, gen_data=gen_data
end
;
print, 'Writing ' + outfil
end






















