pro fort2hxi, infil, index, data, qdebug=qdebug
;
;
rd_hxtimg, data, header, info, infil
;
hda_file = header.file
if (not file_exist(hda_file)) then begin            ;check default directory first
     hda_file = file_list( data_paths(), header.file )      ;check on-line directories second
     hda_file = hda_file(0)
     while (hda_file eq '') do begin                ;make the user type in the directory
    tbeep, 3
    print, 'FORT2HXI: Cannot find file: ', header.file
    input, 'Please enter the directory where the file exists: ', dir, ' '
    ff = file_list(dir, header.file)
    hda_file = ff(0)
    end
end

siz = size(data)
nx = siz(1)
ny = siz(2)
;
n = n_elements(info)
st_dsets = info.range(0,0)
;
rd_xda, hda_file, st_dsets, index0, dummy, roadmap, /nodata
;
hxt_struct,hxi_index=hxi_index
index = str_merge(index0, hxi_index)
;
;-------------------- Values that are the same for every image
;
;QS structures ?? - gain array, ...     ;??
;
index.hxi.grause    = 0         ;??
index.hxi.x0        = header.x0
index.hxi.y0        = header.y0

index.hxi.alpha     = header.alpha
index.hxi.iway      = header.iway
index.hxi.syserr_tech   = 0         ;??
index.hxi.he_mod_adj    = 0         ;??
index.hxi.syserr    = header.syserr
index.hxi.gamma0    = header.gamma
index.hxi.laminc    = header.laminc
index.hxi.chilim    = header.chilim
index.hxi.area      = header.area
;
index.hxi.resolution    = 1.97*1000 ;??
;
index.hxi.shape_sav(0)  = nx
index.hxi.shape_sav(1)  = ny
;
;-------------------- Values that are different for each image
;
for i=0,n-1 do begin
    index(i).hxi.cnts_p_cm2 = info(i).btot      ;??

    fort2hxi_tim, hda_file, info(i).range(*,0), time, day, actim, interval      ;?? why 4x4 range array?
    index(i).gen.time       = time
    index(i).gen.day        = day
    index(i).hxi.actim      = actim
    index(i).hxi.interval   = interval

    fort2hxi_tim, hda_file, header.bgd.range(*,0), time, day, actim, interval
    index(i).hxi.bkg_time   = time
    index(i).hxi.bkg_day    = day
    index(i).hxi.bkg_actim  = actim
    index(i).hxi.bkg_interval   = interval

    if (keyword_set(qdebug)) then begin
    print, 'Data...'
    prstr, info.time
    print, '  ACTIM:    ', fmt_tim(index(i), /msec), ' to ', fmt_tim(anytim2ints(index(i), off=index(i).hxi.actim/10.), /msec)
    print, '  INTERVAL: ', fmt_tim(index(i), /msec), ' to ', fmt_tim(anytim2ints(index(i), off=index(i).hxi.interval/10.), /msec)
    btime = anytim2ints([index(i).hxi.bkg_time, index(i).hxi.bkg_day])
    print, 'Background...'
    prstr, header.bgd.time
    print, '  ACTIM:    ', fmt_tim(btime, /msec), ' to ', fmt_tim(anytim2ints(btime, off=index(i).hxi.bkg_actim/10.), /msec)
    end

    index(i).hxi.chan       = header.ch ;???

    index(i).hxi.lambda     = info(i).lambda
    index(i).hxi.iteration  = info(i).iter
    index(i).hxi.chi2       = info(i).chi2
    index(i).hxi.delta      = info(i).delta
    getmax, data(*,*,i), maxb, xmx, ymx     ;mctiernan's program
    index(i).hxi.max_bright = maxb
    index(i).hxi.x_max      = xmx
    index(i).hxi.y_max      = ymx
end

;data = rotate(data, 7)                 ;flip image N/S (not E/W) ????? - removed 16-Dec-93
end