;+
; PROJECT:
;           Solar-B EIS
;
; NAME:
;           EIS_PLOT_STEV
;
; PURPOSE:
;           Plots any of given resource item on the resource row
;
; CATEGORY:
;           Planning, Science
;
; EXPLANATION:
;           This routine plots any of the resource items on the science
;           plan display. Currently, DSN contact times, commanding times
;           (throughput RCR), and delayed commanding times
;           (payload_reserved) should be plotted on the same row; Other
;           station events should be plotted on the other row.
;
; SYNTAX:
;           plot_resource, resource, startdis, row
;
; INPUTS:
;           RESOURCE -  Array of {eis_timeline_graphics_resource} structures
;                       that has at least the following tags:
;               RES_NAME   - Resource type (name of resource item)
;               START_TIME - The beginning times of the resource item, in TAI
;               end_time   - The end times of the resource item, in TAI
;
;           STARTDIS - Start time of the display, in any CDS time format
; KEYWORDS:
;           ROW       - row number in which the item is plotted (default: 0)
;
; RESTRICTIONS:
;           PLOT_FRAME must be called first.
;
; HISTORY:
;           V0 August 2005 - John Rainnie, RAL
;           Based on "/ssw/soho/gen/idl/science/plot_resource.pro"
;           retained backbone of procedure but changed resouse names etc for EIS
;           choice of row and subrow, now depends on resource type
;          v0.1 26 July 2006 John Rainnie
;
;          v0.2 21-Feb-2007, Peter Young
;               Removed stop statement from station_name CASE statement
;          v0.3 24-Jan-2008 JAR
;               Added stations OKN and MSD to list
;          v0.4 JAR 30-Jun-2008
;               Added 'GS_1' and 'GS_' to list
;
;-
;______________________________________________________________________________
PRO eis_plot_stev, stev , startdis , row = row

datastart      = anytim2utc(startdis)
datastart.time = 0
daystart       = utc2tai(datastart) ; start of STARTDIS in TAI

t1 = (stev.start_time - daystart) / 3600.d0
t2 = (stev.stop_time  - daystart) / 3600.d0

;---------------------------------------------------------------------------
;  There are 3 types of EIS station events: PERTH, UCHINOURA contact
;  and SVALBARD contact ground based support.
;---------------------------------------------------------------------------
station_name = STRMID(stev.name,0,3)

CASE station_name OF
    'PRT' : color   = 1     ; Red
    'KTU' : color   = 2     ; Green
    'USC' : color   = 3     ; Blue
    'MSP' : color   = 4     ; Cyan
    'SNT' : color   = 5     ; Yellow
    'KRN' : color   = 6     ; Dark Slate Blue
    'MSD' : color   = 7     ; Navy
    'OKN' : color   = 8     ; Light Yellow
    'SVA' : color   = 9     ; Sky Blue
    'GS_1': color   = 11    ; Light Salmon
    'GS_' : color   = 11    ; Light Salmon
    'TES' : color   = 11    ; Light Salmon
    ':'   : color   = 10    ; Orange
    ''    : color   = 10    ; Orange
   ;
   ; PRY, 21-Feb-2007
   ;  I've added the following to ensure the program does not stop if a new
   ; station name is encountered. A warning message is printed to the IDL
   ; window.
   ;
    ELSE  : BEGIN
      color=10 ; Orange
      print,'% EIS_PLOT_STEV: ** WARNING **'
      print,'Station name '+station_name+' has not previously been used. Please inform'
      print,'John Rainnie (j.a.rainnie@rl.ac.uk) so that it can be added to the'
      print,'eis_mk_plan database.'
      print,''
    END
ENDCASE

;---------------------------------------------------------------------------
;  Match number of sub rows in the resource row
;---------------------------------------------------------------------------
num_rows = 1;3

;---------------------------------------------------------------------------
;  Sub-row width refelcts the fact that there is 5% of space reserved
;  in the bottom and top of the row
;---------------------------------------------------------------------------
sub_row = 0
srow_wid = 0.9/num_rows

y1 = row + 0.05 + (sub_row * srow_wid)
y2 = y1  + srow_wid
x1 = t1 > !x.crange(0)
x2 = t2 < !x.crange(1)
IF (x2 GT x1) THEN POLYFILL , [x1 , x2 , x2 , x1] ,                         $
                              [y1 , y1 , y2 , y2] , color = color
XYOUTS , x2 , y1 , station_name

END
