pro rd_hxi_data, lun, ibyt, idset, nout, index, data, roadmap, sel_dsets
;+
;NAME:
;	RD_HXI_DATA
;PURPOSE:
;	Perform the actual data read for HXI files (called from RD_XDA)
;INPUT:
;	lun	- the logical unit number where the file is open
;	ibyt	- the starting byte value to read from
;	idset	- the dataset number for the output matrix
;	nout	- the total number of datasets to be extracted
;	index	- the index structure for all output datasets
;	roadmap	- the roadmap
;	sel_dsets- the indicies of the datasets selected for extraction
;INPUT/OUTPUT:
;	data	- the data
;HISTORY:
;	written 27-Jul-92 by Mons Morrison
;-
;
common rd_hxi_data_blk, ref_dtyp
;
dtyp = index(idset).gen.data_word_type mod 16
;
if (idset eq 0) then begin
    ncol_max = 64		;max(roadmap(sel_dsets).shape_cmd(0))
    nlin_max = 64		;max(roadmap(sel_dsets).shape_cmd(1))

    case dtyp of
	1: data = bytarr(ncol_max, nlin_max, nout)
	2: data = intarr(ncol_max, nlin_max, nout)
	4: data = fltarr(ncol_max, nlin_max, nout)
    endcase
    ref_dtyp = dtyp
end
if (index(idset).gen.ndatabyte eq 0) then return

ncol = index(idset).hxi.shape_sav(0)
nlin = index(idset).hxi.shape_sav(1)
case dtyp of
    1: data0 = bytarr(ncol,nlin)
    2: data0 = intarr(ncol,nlin)
    4: data0 = fltarr(ncol,nlin)
endcase

rdwrt, 'R', lun, ibyt, 0, data0, 1
;
if (dtyp gt ref_dtyp) then case dtyp of	;new data type which requires more space
    2: data = fix(data)	;convert to integer*2
    4: data = float(data)	;convert to real*4
endcase
;
data(0,0,idset) = data0
;
end
