pro rd_rad, infil, out
;
;
;
out = {rd_rad, beta: 0.0, electrons: 0.0, protons: fltarr(3)}
;
openr, lun, infil, /get_lun
;
lin=' '
readf, lun, lin
readf, lun, lin
out.beta = float( strmid(lin, 25, 5) )
;
tot = fltarr(15)
for i=1,10 do readf, lun, lin	;skip header
for i=0,n_elements(tot)-1 do begin
    readf, lun, lin
    tot(i) = float( strmid(lin,  67, 8))
end
out.protons(0) = total( tot(0:3) )
out.protons(1) = total( tot(4:8) )
out.protons(2) = total( tot(9:14) )
;
;
tot = fltarr(19)
for i=1,10 do readf, lun, lin   ;skip header
for i=0,n_elements(tot)-1 do begin
    readf, lun, lin
    tot(i) = float( strmid(lin,  67, 8))
end
out.electrons = total(tot)
;
free_lun, lun
end
;
dir = '/2p/morrison/soft/solara_db/data/'
list = [0, 30, 60, 90, 270, 300, 330]
for i=0,n_elements(list)-1 do begin
    rd_rad, dir+'rad_' + string(list(i), format='(i3.3)') + '.txt', out0
    if (i eq 0) then out = replicate(out0, n_elements(list))
    out(i) = out0
end
;
openw, lun, 'rad_sum.txt', /get_lun
list2 = [0, 30, 60, 90, 60, 30, 0, 330, 300, 270, 300, 330, 0]
for i=0,n_elements(list2)-1 do begin
    ss = where(out.beta eq list2(i))
    out0 = out(ss(0))
    print, i*30, out0.electrons, out0.protons
    printf, lun, i*30, out0.electrons, out0.protons
end
free_lun, lun
;
mat = rdfile('rad_sum.txt', 5)
plot, mat(0,*), mat(1,*)
end
