;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           eis_read_file_op_events
;
; PURPOSE
;           Function to return op_period events
;;
; CATEGORY
;           EIS timeline planning
;
; WRITTEN
;           John A Rainne RAL
;
; VERSION
;          v0.1 JAR 20-Jun-2007
;               There are 2 instances of the "OPPLN_PROHIBIT" field. However,
;               we only want the first!
;          v0.2 JAR 18-Jun-2009
;               1. Use first 'OPPLN_PERMIT' if more than 1 found
;               2. Use 'oppln_permit' as OP Period stop_time (instead of
;                  'op_end')
;
;-
;______________________________________________________________________________
FUNCTION eis_read_file_op_events , fileName


IF (FILE_TEST(fileName) NE 1) THEN stop


lines    = rd_ascii(fileName , lun = lun)
FREE_LUN , lun

; Remove blank lines
lines          = remove_blank_lines(lines)
oppln_prohibit = 0.D
oppln_permit   = 0.D

; Get indicies of lines beginning with "#"
FOR i = 0, N_ELEMENTS(lines) - 1 DO BEGIN

    split = STRSPLIT(lines[i],/EXTRACT)
    tai   = eis_stev2tai(split[2])

    CASE split[0] OF
        'OP_START'       : op_start       = tai
        'OP_END'         : op_end         = tai
        'OPPLN_PROHIBIT' : IF (oppln_prohibit EQ 0) THEN oppln_prohibit = tai
        ;'OPPLN_PERMIT'   : oppln_permit   = tai
        'OPPLN_PERMIT'   : IF (oppln_permit   EQ 0) THEN oppln_permit   = tai
        ELSE        : stop
    ENDCASE

ENDFOR

;op       = {name:'op'       , start_time : op_start       , stop_time : op_end}
op       = {name:'op'       , start_time : op_start       , stop_time : oppln_permit}
prohibit = {name:'prohibit' , start_time : oppln_prohibit , stop_time : oppln_permit}

RETURN , [op,prohibit]


END
