;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           DB_READ_STUDYRASTER_ENTRY
;
; PURPOSE
;           This function reads the STUDY2 database and returns a
;           study_raster structure
;
; NOTES
;
; CATEGORY
;           EIS Database
;
; WRITTEN
;           John A Rainne RAL
;
; VERSION
;           v0.1 JAR 2-Apr-2007
;               Removed STO P from function
;           v0.2 JAR 3-Apr-2007
;               Included additional raster tags
;           v0.3 JAR 13-Apr-2007
;               Calculate raster width - using "eis_get_total_raster_width"
;
;------------------------------------------------------------------------------;
FUNCTION db_read_studyraster_entry , id , index

status     = eis_open_db(/STDRA)
constraint = STRJOIN(['SY_ID='     , STRCOMPRESS(id    , /REMOVE)     ,     $
                      ',RA_INDEX=' , STRCOMPRESS(index , /REMOVE)]    ,     $
                       /SINGLE)
entry      = dbfind(constraint , /SILENT , count = count)
entry      = entry[0]


ra                = {eis_study_raster}
ra.ra_index       = dbval(entry , 'RA_INDEX')
ra.ra_id          = dbval(entry , 'RA_ID')
ra.ra_nwindows    = dbval(entry , 'RA_NWINDOWS')
ra.ra_repeats     = dbval(entry , 'RA_REPEATS')
ra.ra_compression = dbval(entry , 'RA_COMPRESSION')
ra.ra_duration    = dbval(entry , 'RA_DURATION')
ra.ra_volume      = dbval(entry , 'RA_VOLUME')
ra.asrc_enabled   = dbval(entry , 'ASRC_ENABLED')
ra.asrc_direction = dbval(entry , 'ASRC_DIRECTION')
ra.asrc_skip      = dbval(entry , 'ASRC_SKIP')
ra.asrc_nSteps    = dbval(entry , 'ASRC_NSTEPS')


aec = {eis_aec_props}
aec.aec_flag = dbval(entry, 'RA_AEC_FLG')
e = dbval(entry, 'RA_AEC_PROPS')
    aec.upper_threshold = e[0]
    aec.lower_threshold = e[1]
    aec.upper_count_limit = e[2]
    aec.lower_count_limit = e[3]
    aec.exposure_id = e[4]
    aec.max_run_time = e[5]
ra.aec_props = aec

flare = {eis_flare_props}
flare.flare_flag = dbval(entry, 'RA_EIS_FLR_FLG')
e = dbval(entry, 'RA_EIS_FLR_PROPS')
    flare.x_centre = e[0]
    flare.y_centre = e[1]
    flare.x_pixel_threshold = e[2]
    flare.y_pixel_threshold = e[3]
    flare.x_min_limit = e[4]
    flare.y_min_limit = e[5]
ra.eis_flare_props = flare

event = {eis_event_props}
event.event_flag = dbval(entry, 'RA_EIS_EVT_FLG')
e = dbval(entry, 'RA_EIS_EVT_PROPS')
    event.x_pixel_threshold = e[0]
    event.y_pixel_threshold = e[1]
    event.x_min_limit = e[2]
    event.y_min_limit = e[3]
ra.eis_event_props = event

xrt = {xrt_flare_props}
e = dbval(entry, 'RA_XRT_PROPS')
    xrt.xrt_flag = e
ra.xrt_flare_props = xrt

dbclose


; Get further info from raster database
eis_raster          = db_read_raster_entry(ra.ra_id)
ra.ra_acronym       = eis_raster.acronym
ra.ra_title         = eis_raster.title
ra.ll_id            = eis_raster.ll_id
;
; JAR 3-Apr-2007
; Added these extra tags
ra.windHeight       = eis_raster.windHeight
ra.scan_fm_nsteps   = eis_raster.scan_fm_nsteps   
ra.scan_fm_stepSize = eis_raster.scan_fm_stepSize
ra.slitindex        = eis_raster.slitindex
ra.rastertype       = eis_raster.rastertype
ra.ra_width         = eis_get_total_raster_width(eis_raster)


RETURN , ra


END
