function ass_or, data, index, subs, only_full=only_full
;
;+
;NAME:
;	ass_or
;PURPOSE:
;	Assemble multiple exposure observing regions into single images
;CALLING SEQUENCE:
;	data = ass_or(data, index, subs)
;INPUT:
;	index	- the index structure
;	data	- the 3-D data array
;OPTIONAL KEYWORD INPUT:
;	only_full- If set, only return the observing images for which
;		   all of the "pfi strips" are available.
;OUTPUT:
;	returns the assembled 3-D array
;OPTIONAL OUTPUT:
;	subs	- The subscripts of the first image used for the
;		  assembly
;RESTRICTIONS:
;	If there is an image in "data" that has already been assembled
;	into an observing region image, and then saved to a file
;	(makes .PFI_FFI b0:b1 values equal to 2) then it just returns
;	the input.  This means that you cannot mix assembled OR images
;	with PFI strips which still require assembly on the input
;HISTORY:
;	Written Fall '92 by M.Morrison
;	20-Oct-92 (MDM) - Modified to simply return the input if it
;			  it is already assembled observing regions.
;			- Added document header
;	30-May-93 (MDM) - Added code to guard against garbage telemetry
;-
;
;
if (max(gt_pfi_ffi(index)) eq 2) then begin
    subs = indgen(n_elements(index))
    return, data		;Data has already been assembled
end
;
ser_num = index.sxt.serial_num
if (min(ser_num) eq max(ser_num)) then h = fltarr(1)+1 $	;case where there is only one image - histogram bombs out
				else h = histogram(index.sxt.serial_num-min(index.sxt.serial_num))
snum_arr = where(h ne 0) + min(index.sxt.serial_num)
n = n_elements(snum_arr)
;
siz = size(data)
nz = siz(3)
;
nx = max(index.sxt.shape_cmd(0))
ny = max(index.sxt.shape_cmd(1))
;
qdebug = 0
if (qdebug) then begin
    print, '# separate images', nz
    print, '# diff serial#   ', n
end
;
data_out = bytarr(nx, ny, n)
subs = intarr(n)
iout = 0
for i=0,n-1 do begin
    snum = snum_arr(i) 
    ss = where(index.sxt.serial_num eq snum)
    ;
    qok = 1
    if (keyword_set(only_full)) then begin
	if (n_elements(ss) ne index(ss(0)).sxt.shape_cmd(1)/64) then qok = 0
    end
    ;
    if (qok) then begin
	for j=0,n_elements(ss)-1 do begin
	    ix = 0
	    iy = (index(ss(j)).sxt.pfi_ffi/16 -1)*64
	    iy = iy < (ny-64)	;MDM 30-May-93 Guard against garbage telemetry
	    data_out(ix,iy,iout) = data(*,*,ss(j))
	    if (qdebug) then print, i,j,ix,iy,ss(j)
	end
        subs(iout) = ss(0)
        iout = iout + 1
    end
end
;
if (iout eq 0) then begin
    print, 'No data selected', string(7b)
    return, 0
end
if (iout ne n) then begin
    data_out = data_out(*,*,0:iout-1)
    subs = subs(0:iout-1)
end
return, data_out
end
