;+
; PROJECT
;           SolarB EIS
;
; NAME
;           eis_structure_container__define
;
; PURPOSE
;           Defines an object wrapper for structures
;
;
; CATEGORY
;           Timeline planning (timeline)
;
;
; WRITTEN
;           John A Rainnie RAL October 2005
;
; VERSION
;          v0.1 JAR 13-Jun-2007
;               Included bug fix to allow correct initialisation and saving
;               of studies that are moved.
;          v0.2 JAR 5-Jul-2007
;               Updated "relative_raster_pointing" method.
;          v0.3 JAR 6-Jul-2007
;               Added method "offset_pointing_mechan" to calculate x_point
;               and y_point if supplying mechanical units (MIP and YIP)
;               offsets.
;          v0.4 JAR 12-Jul-2007
;               Now save tracking curve returned from re-point file
;          v0.5 JAR 22-Aug-2007
;               Flag "set" method to be saved.
;          v0.6 JAR 5-Sep-2007
;               Added 4 ASRC tags to "setproperty" method
;          v0.7 JAR 11-Sep-2007
;               Added method to move/copy ENG studies (existing MOVE method
;               works for SCI studies)
;          v0.8 JAR 18-Oct-2007
;               Ensure pointing changes made in image_tool are saved - by
;               setting SAVE flag.
;          v0.9 JAR 18-Mar-2008
;               Added minimum value (of 1.0) to YIP
;          v1.0 JAR 27-Mar-2008
;               Tidied up a couple of STOPs.
;          v1.1 JAR 22-May-2008
;               Added "compression" keyword to "setproperty" method
;          v1.2 JAR 5-Jun-2008
;               Added keyword NUM_DAYS to methods;
;                 + "initialise_raster_pointing"
;                 + "relative_raster_pointing"
;          v1.3 JAR 4-Aug-2008
;               Change HOP_ID and NOAA_NUM to numbers.
;          v1.4 JAR 13-Jul-2009
;               Added new method "set_as_time_tagged" to reset time_tagged
;               tag to 1. This is used when copying a study.
;          v1.5 JAR 13-Aug-2009
;               Added entry_type and recursive tags to getproperty method
;          v1.6 JAR 18-Oct-2013
;               Added method "set_resp_id" to set response study id into
;               tag: sc.xrt_flare_response.response_study_id
;          v1.7 JAR 24-Sep-2014
;               Added method "refresh_raster_pointing" which recalculates
;               the pointing with no changes except for offset mode.
;          v1.8 JAR 04-Dec-2014
;               Added keywords to method "::set_resp_id" to differentiate
;               between triggers
;
;-
;______________________________________________________________________________
; INIT
;______________________________________________________________________________
FUNCTION eis_structure_container::INIT, structure_type

Self.structure_container_pointer = PTR_NEW(structure_type)

RETURN , 1

END
;______________________________________________________________________________
; CLEANUP
;______________________________________________________________________________
PRO eis_structure_container::CLEANUP

PTR_FREE , Self.structure_container_pointer

END
;______________________________________________________________________________
; Set
;______________________________________________________________________________
PRO eis_structure_container::set , structure_container

(*Self.structure_container_pointer) = structure_container
; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Get solarb_science
;______________________________________________________________________________
FUNCTION eis_structure_container::get_solarb_science

RETURN, (*Self.structure_container_pointer).science_component.solarb_science

END
;______________________________________________________________________________
; Get
;______________________________________________________________________________
FUNCTION eis_structure_container::get

RETURN, (*Self.structure_container_pointer)

END
;______________________________________________________________________________
; Read Science & Science2 database
;______________________________________________________________________________
PRO eis_structure_container::get_all_info

tl = (*Self.structure_container_pointer)
tc = tl.time_component

IF (tc.sequence_id EQ 0) THEN stop

exten = ''
IF (tc.respond_to_eis_flare EQ 1) THEN exten = ' (EIS Flare Trigger)'
IF (tc.respond_to_eis_event EQ 1) THEN exten = ' (Bright Point Trigger)'
IF (tc.respond_to_xrt_flare EQ 1) THEN exten = ' (XRT Flare Trigger)'
print,STRJOIN(['Accessing timeline entry seq_id = ',     $
                STRCOMPRESS(tc.sequence_id,/REMOVE)   ,      $
                exten],/SINGLE)

sc = eis_get_science_entry(tc.sequence_id)
(*Self.structure_container_pointer).science_component = sc

; Flag that the science component has been read
(*Self.structure_container_pointer).time_component.read_all = 1

END
;______________________________________________________________________________
; SET OBSTITLE
;______________________________________________________________________________
PRO eis_structure_container::update_obstitle , obstitle

print,"Obsolete call...."
RETURN
(*Self.structure_container_pointer).science_component.obstitle =            $
                             STRTRIM(obstitle,2)
; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; SET OBS_DEC
;______________________________________________________________________________
PRO eis_structure_container::update_obs_dec , obs_dec

print,"Obsolete call...."
RETURN
(*Self.structure_container_pointer).science_component.obs_dec =             $
                             STRTRIM(obs_dec,2)
; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; SET OBS_DEC
;______________________________________________________________________________
PRO eis_structure_container::update_sci_obj , sci_obj

(*Self.structure_container_pointer).science_component.sci_obj =             $
                             STRTRIM(sci_obj)
; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; SET NOAA_NUM
;______________________________________________________________________________
PRO eis_structure_container::update_noaa_num , noaa_num

(*Self.structure_container_pointer).science_component.noaa_num =            $
                             STRTRIM(noaa_num)
; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; SET STUDY_TAG
;______________________________________________________________________________
PRO eis_structure_container::update_study_tag , obstitle = obstitle   ,     $
                                                obs_dec  = obs_dec    ,     $
                                                join_sb  = join_sb    ,     $
                                                jop_id   = jop_id     ,     $
                                                noaa_num = noaa_num   ,     $
                                                sci_obj  = sci_obj    ,     $
                                                obs_id   = obs_id     ,     $
                                          solarb_science = solarb_science
; obstitle
; obs_dec
; join_sb
; hop_id
; noaa_num
; sci_obj

; Unpack structure
sc = (*Self.structure_container_pointer).science_component

IF (N_ELEMENTS(obstitle)  GT 0) THEN sc.obstitle = obstitle
IF (N_ELEMENTS(obs_dec)   GT 0) THEN sc.obs_dec  = obs_dec
IF (N_ELEMENTS(join_sb)   GT 0) THEN sc.join_sb  = join_sb
IF (N_ELEMENTS(jop_id)    GT 0) THEN sc.jop_id   = FIX(jop_id)
IF (N_ELEMENTS(noaa_num)  GT 0) THEN sc.noaa_num = FIX(noaa_num)
IF (N_ELEMENTS(sci_obj)   GT 0) THEN sc.sci_obj  = sci_obj
IF (N_ELEMENTS(obs_id)    GT 0) THEN sc.obs_id   = obs_id
IF (N_ELEMENTS(solarb_science) GT 0) THEN sc.solarb_science = solarb_science

; Update structure
(*Self.structure_container_pointer).science_component = sc

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; set seq_id
;______________________________________________________________________________
PRO eis_structure_container::set_seq_id , seq_id = seq_id

; Update sequence_id
(*Self.structure_container_pointer).time_component.sequence_id    = seq_id
(*Self.structure_container_pointer).science_component.sequence_id = seq_id

END
;______________________________________________________________________________
; set response_study_id
;______________________________________________________________________________
PRO eis_structure_container::set_resp_id , xrtf_resp_id = xrtf_resp_id ,   $
                                           eisf_resp_id = eisf_resp_id
; JAR 04-Dec-2014
; Added keywords "xrtf_resp_id" and "eisf_resp_id" to differentiate
; between triggers
IF (N_ELEMENTS(xrtf_resp_id) NE 0) THEN BEGIN
   (*Self.structure_container_pointer).science_component.xrt_flare_response.response_study_id = xrtf_resp_id
ENDIF
IF (N_ELEMENTS(eisf_resp_id) NE 0) THEN BEGIN
   (*Self.structure_container_pointer).science_component.eis_flare_response.response_study_id = eisf_resp_id
ENDIF

END
;______________________________________________________________________________
; SET_PROPERTY
;______________________________________________________________________________
PRO eis_structure_container::set_index , index

; Update working_raster index
(*Self.structure_container_pointer).science_component.working_raster = index

END
;______________________________________________________________________________
; Set copied study as time_tagged = 1
;______________________________________________________________________________
PRO eis_structure_container::set_as_time_tagged

(*Self.structure_container_pointer).time_component.time_tagged = 1

END
;______________________________________________________________________________
; UNFlag the save tag
;______________________________________________________________________________
PRO eis_structure_container::flag_save

(*Self.structure_container_pointer).time_component.save = 1

END
;______________________________________________________________________________
; UNFlag the save tag
;______________________________________________________________________________
PRO eis_structure_container::unflag_save

(*Self.structure_container_pointer).time_component.save = 0

END
;______________________________________________________________________________
; SET_PROPERTY
;______________________________________________________________________________
PRO eis_structure_container::setproperty                         ,         $
                                x_point        = x_point         ,         $
                                y_point        = y_point         ,         $
                                mip            = mip             ,         $
                                yip            = yip             ,         $
                                ra_repeats     = ra_repeats      ,         $
                                asrc_enabled   = asrc_enabled    ,         $
                                asrc_direction = asrc_direction  ,         $
                                asrc_skip      = asrc_skip       ,         $
                                asrc_nsteps    = asrc_nsteps     ,         $
                                compression    = compression

science = (*Self.structure_container_pointer).science_component
index   = science.working_raster
IF (index LT 0) THEN RETURN
sra     = science.studyRasters[index]

IF (N_ELEMENTS(x_point)        GT 0) THEN sra.x_point        = x_point
IF (N_ELEMENTS(y_point)        GT 0) THEN sra.y_point        = y_point
IF (N_ELEMENTS(mip)            GT 0) THEN sra.mip            = mip
IF (N_ELEMENTS(yip)            GT 0) THEN sra.yip            = yip
IF (N_ELEMENTS(ra_repeats)     GT 0) THEN sra.ra_repeats     = ra_repeats
IF (N_ELEMENTS(asrc_enabled)   GT 0) THEN sra.asrc_enabled   = asrc_enabled
IF (N_ELEMENTS(asrc_direction) GT 0) THEN sra.asrc_direction = asrc_direction
IF (N_ELEMENTS(asrc_skip)      GT 0) THEN sra.asrc_skip      = asrc_skip
IF (N_ELEMENTS(asrc_nsteps)    GT 0) THEN sra.asrc_nsteps    = asrc_nsteps
IF (N_ELEMENTS(compression)    GT 0) THEN sra.ra_compression = compression

; Update studyRaster
(*Self.structure_container_pointer).science_component.studyRasters[index]=sra

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; MOVE engineering entry
;______________________________________________________________________________
PRO eis_structure_container::move_tl_eng_entry , new_start_time

st_dur = (*Self.structure_container_pointer).time_component.end_time -     $
         (*Self.structure_container_pointer).time_component.start_time

(*Self.structure_container_pointer).time_component.start_time = new_start_time
(*Self.structure_container_pointer).time_component.end_time   = new_start_time + $
                                                                st_dur

print,''
print,STRJOIN(['Study moved to ',anytim2utc(new_start_time,/stime)],/SINGLE)
print,''

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; MOVE science entry
;______________________________________________________________________________
PRO eis_structure_container::move_tl_entry , new_start_time

(*Self.structure_container_pointer).time_component.start_time = new_start_time

print,''
print,STRJOIN(['Study moved to ',anytim2utc(new_start_time,/stime)],/SINGLE)
print,''

; Call "update_study_properties" to
Self->update_study_properties

; Re-initialise pointing - but retain relative pointing (ie: keep MIP/YIP)
Self->relative_raster_pointing

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; GET_PROPERTY - Called by application to get copies of class members
;______________________________________________________________________________
PRO eis_structure_container::getproperty , start_time  = start_time  ,      $
                                           end_time    = end_time    ,      $
                                           time_tagged = time_tagged ,      $
                                           seq_id      = seq_id      ,      $
                                           read_all    = read_all    ,      $
                                           save        = save        ,      $
                                           visible     = visible     ,      $
                                           entry_type  = entry_type  ,      $
                                           recursive   = recursive

entry = (*Self.structure_container_pointer)

start_time  = entry.time_component.start_time
end_time    = entry.time_component.end_time
time_tagged = entry.time_component.time_tagged
seq_id      = entry.time_component.sequence_id
read_all    = entry.time_component.read_all
save        = entry.time_component.save
visible     = entry.time_component.visible
entry_type  = entry.time_component.entry_type
recursive   = entry.time_component.recursive

END
;______________________________________________________________________________
; Calculate Study Duration
;______________________________________________________________________________
PRO eis_structure_container::update_study_properties

nRasters = (*Self.structure_container_pointer).science_component.nRasters
; Nothing to do if there are zero rasters
IF (nRasters EQ 0) THEN RETURN

Self->update_raster_properties

tc = (*Self.structure_container_pointer).time_component
sc = (*Self.structure_container_pointer).science_component

; Update duration for science_component
; Sum all sra durations
st_dur = TOTAL(sc.studyRasters[0:sc.nRasters-1].ra_duration)
st_dur = st_dur + LONG64(21.e3)                   ; slit-slot movement
st_dur = st_dur + LONG64(1.5e3 * sc.nRasters)     ; movement to MIP
(*Self.structure_container_pointer).science_component.duration = st_dur
;help,sec2dhms(st_dur/1000.)

; Update volume for science_component
; Sum all sra volumes
st_vol = LONG64(0)
FOR i = 0 , sc.nRasters - 1 DO BEGIN

    ra_vol = eis_compression(sc.studyRasters[i] , target = sc.target)
    st_vol = st_vol + ra_vol

ENDFOR
(*Self.structure_container_pointer).science_component.volume = st_vol

; Now update end_time in time_component
end_time = tc.start_time + (st_dur / 1000.)
(*Self.structure_container_pointer).time_component.end_time = end_time

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Calculate Raster Durations
;______________________________________________________________________________
PRO eis_structure_container::update_raster_properties

tc = (*Self.structure_container_pointer).time_component
sc = (*Self.structure_container_pointer).science_component
; Get study start_time -> st_st
st_st   = tc.start_time

FOR i = 0, sc.nRasters - 1 DO BEGIN

    sra = sc.studyRasters[i]

    ra  = db_read_raster_entry(sra.ra_id)

    ;
    ; DURATION
    ;
    ; Call "eis_raster_duration" function to return duration (ms)
    ;ra_dur = eis_raster_duration( ra , ll)
    ;ra_dur = sra.ra_duration
    ; Update raster duration
    sra.ra_duration = ra.duration * sra.ra_repeats
    ;
    ; VOLUME
    ;
    ; Call "eis_raster_duration" function to return duration (ms)
    ;ra_vol = sra.ra_volume

    ; Update raster duration
    sra.ra_volume   = ra.volume * sra.ra_repeats

    ; Update raster start time
    sra.ra_start_time = st_st
    ; Reset st_st
    st_st = st_st + (sra.ra_duration/1000.)
    ; Update raster stop time
    sra.ra_stop_time = st_st

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Calculate Raster Durations
;______________________________________________________________________________
PRO eis_structure_container::relative_raster_pointing                ,     $
                                      num_days = num_days

IF (N_ELEMENTS(num_days) EQ 0) THEN num_days = 3

; This method is called from the pointing gui.
tc        = (*Self.structure_container_pointer).time_component
science   = (*Self.structure_container_pointer).science_component

FOR i = 0, science.nRasters - 1 DO BEGIN

    sra = science.studyRasters[i]
    ; Get spacecraft pointing info
    pointing = eis_get_raster_pointing(sra.ra_start_time             ,     $
                                       sra.ra_stop_time              ,     $
                                       num_days = num_days)

    ; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
    sot_offset = science.disturbance
    sot_offset = FLOAT(STRSPLIT(sot_offset,',',/EXTRACT))

    ; Update raster pointing
    IF (N_TAGS(pointing) NE 0) THEN BEGIN

        ; Got s/c pointing from re-point file
        ; Already have MIP - which we want to retain
        ; So what we want is sc_x/y (from re-point file) and then calculate
        ; new values of x/y_point
        ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
        ; "eis_get_xy_point"
       ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        xy_point = eis_get_xy_point(pointing.x_point  ,                    $
                                    pointing.y_point  ,                    $
                                    sra.mip           ,                    $
                                    sra.yip           ,                    $
                                    sra.ra_id         ,                    $
                                    science.obs_id    ,                    $
                                    sra.ra_start_time ,                    $
                                    sot_offset  )

        ; Add del_sc_x and del_sc_y to raster pointing
        sra.x_point = xy_point.x_point
        sra.y_point = xy_point.y_point

        ; Save new (EIS-corrected) sc pointing
        sra.sc_x    = pointing.x_point
        sra.sc_y    = pointing.y_point
        sra.cmp     = pointing.tracking

        ; *****************************************************************
        ; JAR 26-Sep-2013: Update response entry pointing
        ; *****************************************************************
        ; If this is an XRTF trigger study, then update response pointing
        ; We know it's an XRTF trigger cos both TL and sra tags are set to 1
        ; 1. tc.respond_to_xrt_flare      = 1
        ; 2. sra.xrt_flare_props.xrt_flag = 1
        ; Let's use the latter since then we know which studyRaster it is
       IF (sra.xrt_flare_props.xrt_flag EQ 1) THEN BEGIN
           ; Get saved response entry
           r = db_read_response_entry(seq_id=tc.sequence_id)

           IF (N_TAGS(r) EQ 0) THEN stop

           ; Update response entry to reflect new solar coords and s/c pointing
           ; These have already been updated for the hunter study.
           ; If "verify fov" is enabled, update response solar and s/c
           ; pointings to those of (already updated) sra
           print,'New pointings'
           print,sra.x_point,sra.y_point
           r.ra1_xcen = sra.x_point
           r.ra1_ycen = sra.y_point
           r.ra1_sc_x = sra.sc_x
           r.ra1_sc_y = sra.sc_y
           ; Now save response study
           db_save_response_entry_update , r

           ;stop
        ENDIF
        ; *****************************************************************


    ENDIF

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Add running offsets to raster pointing
;______________________________________________________________________________
PRO eis_structure_container::offset_pointing_mechan , x_offset , y_offset

science   = (*Self.structure_container_pointer).science_component
; Get pointing of first raster
x_initial = science.studyRasters[0].mip
y_initial = science.studyRasters[0].yip

; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = FLOAT(STRSPLIT(science.disturbance,',',/EXTRACT))

FOR i = 0, science.nRasters - 1 DO BEGIN

    sra = science.studyRasters[i]

    sra.mip = x_initial + (i * x_offset)
    sra.yip = y_initial + (i * y_offset)

    ; Retaining s/c pointing and MIP/YIP, get x_point and y_point
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
    ; "eis_get_xy_point"
    obs_id   = science.obs_id
    aia_time = sra.ra_start_time
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    xy_point = eis_get_xy_point(sra.sc_x                    ,              $
                                sra.sc_y                    ,              $
                                sra.mip                     ,              $
                                sra.yip                     ,              $
                                sra.ra_id                   ,              $
                                obs_id                      ,              $
                                aia_time                    ,              $
                                sot_offset)

    sra.x_point = xy_point.x_point
    sra.y_point = xy_point.y_point

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Add running offsets to raster pointing
;______________________________________________________________________________
PRO eis_structure_container::offset_pointing_coords , x_offset , y_offset

science   = (*Self.structure_container_pointer).science_component
; Get pointing of first raster
x_initial = science.studyRasters[0].x_point
y_initial = science.studyRasters[0].y_point

; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = FLOAT(STRSPLIT(science.disturbance,',',/EXTRACT))

FOR i = 0, science.nRasters - 1 DO BEGIN

    sra = science.studyRasters[i]

    sra.x_point = x_initial + (i * x_offset)
    sra.y_point = y_initial + (i * y_offset)

    ; Get MIP and YIP
    delx = sra.sc_x - sra.x_point
    dely = sra.sc_y - sra.y_point

    ra_id       = sra.ra_id
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
    ; "eis_get_mirror_position"
    obs_id   = science.obs_id
    aia_time = sra.ra_start_time
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    mirror_pos  = eis_get_mirror_position(delx , dely , ra_id   ,  $
                                        obs_id , aia_time , sot_offset)
    sra.mip     = mirror_pos.mip
    ; JAR 18-Mar-2008. Just for insurance
    sra.yip     = mirror_pos.yStart > 1

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Initialise raster pointings - centre on s/c pointings
;______________________________________________________________________________
PRO eis_structure_container::initialise_raster_pointing , $
                                      num_days = num_days

print,'eis_structure_container::initialise_raster_pointing'


IF (N_ELEMENTS(num_days) EQ 0) THEN num_days = 3

; This method is called;
; (a) whenever a new study is added to the timeline
; (b) from the pointing GUI ("Refresh")
; For each study raster, it calls "eis_get_raster_pointing" which goes
; looking for an entry in the appropriate (J-Side supplied) re-point
; file, eg: "/cmdpln/20070112/re-point200601120001.txt"
; It then sets the raster pointing to those sc pointing values,
; effectively centering the raster in the EIS FOV

science = (*Self.structure_container_pointer).science_component

; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = FLOAT(STRSPLIT(science.disturbance,',',/EXTRACT))

FOR i = 0, science.nRasters - 1 DO BEGIN

    sra = science.studyRasters[i]
    ; Get spacecraft pointing info
    pointing = eis_get_raster_pointing(sra.ra_start_time   ,     $
                                       sra.ra_stop_time    ,     $
                                       num_days = num_days )
    ; Update raster pointing
    IF (N_TAGS(pointing) NE 0) THEN BEGIN

        sra.x_point = pointing.x_point
        sra.y_point = pointing.y_point
        sra.sc_x    = pointing.x_point
        sra.sc_y    = pointing.y_point
        sra.cmp     = pointing.tracking

    ENDIF ELSE BEGIN

        ; JAR 24-Se-2014
        ; No need to zero these values.
        ;sra.x_point = 0.D
        ;sra.y_point = 0.D
        ;sra.sc_x    = 0.D
        ;sra.sc_y    = 0.D

    ENDELSE

    delx = sra.sc_x - sra.x_point
    dely = sra.sc_y - sra.y_point

    ; Get MIP and YIP
    ra_id       = sra.ra_id
    ; JAR 31-Mar-2014
    ; Add inputs "obs_id" and "aia_time"
    mirror_pos  = eis_get_mirror_position(delx , dely , ra_id ,    $
                                     science.obs_id , sra.ra_start_time , $
                                     sot_offset)
    sra.mip     = mirror_pos.mip
    ; JAR 18-Mar-2008. Just for insurance
    sra.yip     = mirror_pos.yStart > 1

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

    ;stop

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Initialise raster pointings - centre on s/c pointings
;______________________________________________________________________________
PRO eis_structure_container::refresh_raster_pointing

science = (*Self.structure_container_pointer).science_component

; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = FLOAT(STRSPLIT(science.disturbance,',',/EXTRACT))

FOR i = 0, science.nRasters - 1 DO BEGIN

    sra = science.studyRasters[i]

    ; Get MIP and YIP
    ; JAR 31-Mar-2014
    ; Add inputs "obs_id" and "aia_time"
    delx = sra.sc_x - sra.x_point
    dely = sra.sc_y - sra.y_point
    mirror_pos  = eis_get_mirror_position(delx , dely , sra.ra_id ,    $
                                     science.obs_id , sra.ra_start_time , $
                                     sot_offset)
    sra.mip     = mirror_pos.mip
    ; JAR 18-Mar-2008. Just for insurance
    sra.yip     = mirror_pos.yStart > 1

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Calculate Raster Durations
;______________________________________________________________________________
PRO eis_structure_container::update_raster_pointing , s , point_stc

FOR i = 0, s.science_component.nRasters - 1 DO BEGIN

    sra = s.science_component.studyRasters[i]

    ; Get
    delx = sra.sc_x - point_stc[i].xcen
    dely = sra.sc_y - point_stc[i].ycen

    ; Get MIP and YIP
    ra_id = sra.ra_id
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
    ; "eis_pointing_offset"
    obs_id   = s.science_component.obs_id
    aia_time = sra.ra_start_time
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 27-Aug-2014
    sot_offset = s.science_component.disturbance
    sot_offset = FLOAT(STRSPLIT(sot_offset,',',/EXTRACT))
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    mirror_pos = eis_get_mirror_position(delx , dely , ra_id,   $
                                        obs_id , aia_time ,  $
                                         sot_offset)

    ; Update pointing values
    sra.x_point = point_stc[i].xcen
    sra.y_point = point_stc[i].ycen
    sra.mip     = mirror_pos.mip
    ; JAR 18-Mar-2008. Just for insurance
    sra.yip     = mirror_pos.yStart > 1

    ; Update studyRaster
    (*Self.structure_container_pointer).science_component.studyRasters[i]=sra

ENDFOR

; Flag entry to be saved
Self->flag_save

END
;______________________________________________________________________________
; Definition
;______________________________________________________________________________
PRO eis_structure_container__DEFINE

dummy = {eis_structure_container, structure_container_pointer : PTR_NEW()}

END
