function read_hetg_xspec, file nlines = file_lines(file) ;print, nlines data_parse = strarr(nlines) get_lun, lun openr, lun, file readf, lun, data_parse close, lun free_lun, lun ;print, transpose(data_parse) search = strpos(data_parse, '!') n = where(search ge 0, ncount) if ncount lt 0 then begin print, 'problem with file header...' return, -1 endif print, 'first line of data at', n[0]+2 data_parse = data_parse[n[0]+1:nlines-1] nlines -= (n[0]+1) ; how many columns in data search = strsplit(data_parse[0], count=ncol) print, data_parse[0] print, 'there are ', ncol, ' column' struct = {wave:0D, bin:0D, flux:0D, err_I:0D} if ncol gt 4 then begin name = 'model'+string(indgen(ncol-4)+1, format="(I0)") help, name help, replicate(0D, ncol-4) for i=1, (ncol-4) do struct = create_struct( struct, 'model'+string(i, format="(I0)"), 0D ) endif search = strpos(data_parse, 'NO') n = where(search ge 0, ncount) nspec = ncount+1 print, 'there are ', nspec, ' spectra' if nspec eq 1 then spec_pos = [-1, nlines] else spec_pos = [-1, n, nlines] print, spec_pos for i=0, nspec-1 do begin nwave = spec_pos[i+1]-1 - spec_pos[i] print, i, ' : ', nwave spec_data = replicate(struct, nwave) reads, data_parse[ spec_pos[i]+1 : spec_pos[i+1]-1 ], spec_data ;spec_data = reverse(spec_data) ; note the wave scale is reversed if i eq 0 then data = create_struct('spec1', spec_data) else data = create_struct(data, 'spec'+string(i+1, format="(I0)"), spec_data) ; for j= spec_pos[i]+1, spec_pos[i+1]-1 do begin endfor return, data end ; col 1 = wavelength ; col 2 = bin half-width ; col 3 = data ; col 4 = uncertainty ; col 5 = model