FUNCTION eis_read_file_dr_events , fileName

; eg: fileName = $HOME/cmdpln/20070614/auxiliary/dr_200706140100.txt
; And just to amke sure....
IF (FILE_TEST(fileName) NE 1) THEN RETURN , 0

; Read file
orig_lines      = rd_ascii(fileName , lun = lun)
FREE_LUN , lun

;*********************************************************
;/* DR VOLUME ALLOCATION */                                  Remove
;/*    SOT            EIS          XRT        */             Remove
;/*  (Mbit)         (Mbit)       (Mbit)       */             Remove
;/*----------------------------------------------*/          Remove
;      2800.00      600.000      600.000                     Line 0
;/*----------------------------------------------*/          Remove
;                                                            Remove
;                                                            Remove
;/* DATA SIZE DOWNLINKED AT CONTACT PASSES */                Remove
;/*STA   DATE     TIME    DUR    SOT    EIS     XRT  */      Remove
;/*               (UT)   (sec) (Mbit) (Mbit)  (Mbit) */      Remove
;/*--------------------------------------------------*/      Remove
;SVA   20061030  111220   199    480    102    102           Line 1
;SVA   20061030  124930   199    480    102    102           Line 2
;  ................................................          ...
;  ................................................          ...
;  ................................................          ...
;SVA   20061101  073430   205    494    105    105           Line n - 2
;SVA   20061101  091220   201    483    103    103           Line n - 1
;(1-day total)                  9849   2110   2110           Line n
;/*--------------------------------------------------*/
;*********************************************************

;
; 1. Remove blank lines
no_blanks_lines = remove_blank_lines(orig_lines)
; 2. Remove commented lines (comment = "/*"). So left with...
line_array      = eis_remove_lines(no_blanks_lines , '/*')
; So we're left with...
;
;*********************************************************
;      2800.00      600.000      600.000                     Line 0
;SVA   20061030  111220   199    480    102    102           Line 1
;SVA   20061030  124930   199    480    102    102           Line 2
;  ................................................          ...
;  ................................................          ...
;  ................................................          ...
;SVA   20061101  073430   205    494    105    105           Line n - 2
;SVA   20061101  091220   201    483    103    103           Line n - 1
;(1-day total)                  9849   2110   2110           Line n
;*********************************************************

;
; Get volume allocations - on the first line
;
split   = STRSPLIT(line_array[0] , /EXTRACT)
sot_vol = LONG(split[0])
eis_vol = LONG(split[1])
xrt_vol = LONG(split[2])

;
; Get indicies of the lines
; "(1-day total)                 62023  13291  13291"
; and
; "(1-day average)               0.341  0.073  0.073"
; Use these as markers
;

stop



stregex_total = STREGEX(line_array,'(1-day total)'   , /FOLD_CASE)  ; = Line n
stregex_t_ave = STREGEX(line_array,'(1-day average)' , /FOLD_CASE)  ; discontinued

v2_line = "DATA SIZE DOWNLINKED AT CONTACT PASSES"
stregex_v2    = STREGEX(line_array ,v2_line , /FOLD_CASE)
;
; Ensure we have the goods
;
end_of_contacts = WHERE(stregex_total EQ 1 , count)
IF (count NE 1)   THEN RETURN , 0



;
; Contact lines
;
contact_lines = line_array[1:end_of_contacts[0]-1]
nContacts     = N_ELEMENTS(contact_lines)
contact_str   = {res_name   : ''      ,      $
                 start_time : 0.D     ,      $
                 stop_time  : 0.D     ,      $
                 sot_size   : 0L      ,      $
                 eis_size   : 0L      ,      $
                 xrt_size   : 0L             $
                }

contact   = REPLICATE(contact_str,nContacts)
FOR i = 0 , nContacts -1  DO BEGIN

    split = STRSPLIT(contact_lines[i] , /EXTRACT)
    ; Get resource name - either U or S
    contact[i].res_name   = STRMID(split[0],0,1)
    ; Get start_time
    datetime = eis_fix_time(split[1],split[2])
    contact[i].start_time = utc2tai(datetime)
    ; Get stop_time
    datetime_utc = anytim2utc(datetime)
    datetime_utc.time = datetime_utc.time + (split[3] * 1000.)
    contact[i].stop_time = utc2tai(datetime_utc)

    ; Get  SOT, EIS and XRT
    contact[i].sot_size = split[4]
    contact[i].eis_size = split[5]
    contact[i].xrt_size = split[6]

ENDFOR

; OK, tie the whole lot up into 1 structure
dr_struct = {sot_vol:sot_vol,eis_vol:eis_vol,xrt_vol:xrt_vol , $
             contact:contact}

;;
;; T_AVERAGED
;;
;; This has apparently been discontinued
;;
;end_of_t_aved   = WHERE(stregex_t_ave EQ 1 , count)
;
;IF (count NE 1)   THEN BEGIN
;
;    RETURN , dr_struct
;
;ENDIF ELSE BEGIN
;    t_ave_lines = line_array[end_of_contacts[0]+1:end_of_t_aved-1]
;    t_ave_str   = { start_time : 0.D     ,      $
;                    stop_time  : 0.D     ,      $
;                    sot_rate   : 0.      ,      $
;                   eis_rate   : 0.      ,      $
;                   xrt_rate   : 0.             $
;                  }
;    t_ave = REPLICATE(t_ave_str , 5)
;    FOR i = 0 , 5 -1  DO BEGIN
;
;        split = STRSPLIT(t_ave_lines[i] , /EXTRACT)
;
;        t_ave[i].start_time = anytim2tai(eis_fix_time(split[0],split[1]))
;        t_ave[i].stop_time  = anytim2tai(eis_fix_time(split[2],split[3]))
;        t_ave[i].sot_rate   = split[4]
;        t_ave[i].eis_rate   = split[5]
;        t_ave[i].xrt_rate   = split[6]
;
;    ENDFOR
;
;    ; OK, tie the whole lot up into 1 structure
;    stop
;    dr_struct = {sot_vol:sot_vol,eis_vol:eis_vol,xrt_vol:xrt_vol , $
;                 contact:contact,t_ave:t_ave}

RETURN , dr_struct


END
