pro wrt_ld_cmd, lun, segment, offset, buf
;
; Creates a control file to load data contained in "buf".
;     Parameters:
;        lun     - logical unit on which the output file is open
;        segment - DEP Load Address Segment
;        offset  - DEP Load Address Offset
;        buf     - An array containing data to be loaded
;

bufinf = size (buf)
len = bufinf(bufinf(0)+2)
op_buf = buf
op_len = len 
if ((op_len mod 4) ne 0) then begin
    op_len = ((len / 4) + 1) * 4
    filbuf = intarr(op_len - len)
    op_buf = [buf(*), filbuf]
endif
print, len, op_len
;stop

n = 1l
while (n le op_len) do begin
    if ((n mod 24) eq 1) then begin
        printf, lun, segment, offset, format = $
            '(/"tcb mbdpml ", 2("0x",z4.4, 1x), "\")
    endif 
    printf, lun, op_buf(n-1), format = '($, "0x", z4.4, " ")'
    if ((n mod 8) eq 0) and (n lt op_len) and ((n mod 24) ne 0) then $
        printf, lun, '\'
    offset = offset + 2 
    n = n + 1
endwhile
printf, lun, ' '

return
end
;............................................
pro mk_list_load, table_start, outfil, list, infil=infil
;+
;NAME:
;	mk_list_load
;PURPOSE:
;	TO take a 1-D vector list and a start address and to
;	modify the contents so that it is consistent and then
;	make the .src load file (telecommands)
;SAMPLE CALLING SEQUENCE:
;	mk_list_load, table_start, outfil, list
;	mk_list_load, '8800'x, 'loi3.src', infil='/mdisw/dbase/ops/lists/loi3.fits'
;RESTRICTIONS:
;	There are several portions of the IP table load command which
;	are hard-wired and they need to be paramters or need to be
;	found in a different file.  (all of the LRDXFR parameters)
;HISTORY:
;	Written 24-Jul-95 by M.Morrison
;	25-Jul-95 (MDM) - Cleaned it up a bit.
;-
;
if (n_elements(infil) ne 0) then list = rfits(infil, h=h)
list = unsign(list, 16)
;
set_list_addr, table_start, list
;
;----------- make the .src load file
;
segment = '2000'x
offset = 0l
;
offset2 	= 0L	;offset for final location?
list_type 	= 9
version		= 0
i_code		= list(0)
list_length	= n_elements(list)
list_load	= n_elements(list)
unknown1	= [224, 0]
unknown2	= [0, '1800'x]
unknown3	= [0, 0, '2000'x, '5000'x, 0]
;
fmt = '(11x, '
fmt = fmt + '2("0x", z4.4, 1x), '
fmt = fmt + '" 4  4 ", '
fmt = fmt + '2("0x", z4.4, 1x), '
fmt = fmt + '" 64  0x000F")'

openw, lun, outfil, /get_lun
printf, lun, '# File: ' + outfil
printf, lun, '# Created: ' + !stime
printf, lun, '#'
printf, lun, 'program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"'

segment0 = segment
offset0  = offset		;save because it is changed within the routine
wrt_ld_cmd, lun, segment0, offset0, list

fmt1 = '(a, (" 0x",z4.4), i7, (" 0x",z4.4), ' + $
	'i7, i7, (" 0x",z4.4), " \")'
fmt2 = '(11x, (" 0x",z4.4), i7, i7, 2i7, " \")'
fmt3 = '(11x, i7, (" 0x",z4.4), 2i7, (" 0x",z4.4), (" 0x",z4.4), i7)'
printf, lun, '#'
printf, lun, 'tcb mbiptbl', list_type, offset2, table_start, $
			version, offset, segment, format=fmt1
printf, lun, i_code, list_length, list_load, unknown1, format=fmt2
printf, lun, unknown2, unknown3, format=fmt3

free_lun, lun
end

