;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           EIS_READ_FILE_STATION_EVENTS
;
; PURPOSE
;           This function reads a station events provided by the CO. It
;           lists all the contacts with various ground stations.
;
; OUTPUTS
;           An array of pass structures - 1 for each entry in the list
;
; CATEGORY
;           EIS timeline planning
;
; WRITTEN
;           John A Rainne RAL 7-Nov-2006
;
; VERSION
;           v0.1 JAR 7-Feb-2007
;               Added a CATCH statement - just in case the file
;               cannot be read, for whatever reason.
;
;------------------------------------------------------------------------------;
FUNCTION eis_read_file_station_events , fileName

;fileName = '/home/sstdljar/jar24/cmdpln/20061113/stev_200611138000.evt'
;
; Catch an ERROR
;
CATCH , error_status
IF Error_status NE 0 THEN BEGIN

    mText = ["Couldn't read file: " , "" , fileName]
    crap  = DIALOG_MESSAGE(mText , /ERROR)
    RETURN , 0

ENDIF

lines    = rd_ascii(fileName , lun = lun)
; Append a final blank line - just as an insurance policy
lines    = [lines , '']
nLines   = N_ELEMENTS(lines)
FREE_LUN , lun

blanks = WHERE(STRLEN(STRTRIM(lines,2)) EQ 0)
stev   = 0
FOR i  = 0 , N_ELEMENTS(blanks)-2 DO BEGIN

    IF (blanks[i+1] - blanks[i] GT 2) THEN BEGIN


        block = remove_blank_lines(lines[blanks[i]:blanks[i+1]])

        pass  = {name:'',start_time:0.D,stop_time:0.D}
        ; Get Station Name
        split = STRSPLIT(block[0] , /EXTRACT)

        pass.name = split[1]
        ;print,split[1]
        ; Get start_time
        trunc = STRMID(block[1],STRPOS(block[1],'/')-4 , 19)
        ;print,trunc
        pass.start_time = eis_stev2tai(trunc)
        ; Get stop_time
        date  = block[N_ELEMENTS(block) - 1]
        trunc = STRMID(date,STRPOS(date,'/')-4 , 19)
        ;print,trunc
        pass.stop_time = eis_stev2tai(trunc)

        CASE N_TAGS(stev) OF
            0    : stev = pass
            ELSE : stev = [stev , pass]
        ENDCASE

    ENDIF

ENDFOR

RETURN , stev

END
