
FUNCTION eis_combine_sitstare_windata, wd1, wd2

;+
; NAME:
;     EIS_COMBINE_SITSTARE_WINDATA()
;
; PURPOSE:
;     Takes two data structures created by eis_getwindata and combines them
;     into one structure. The data are assumed to be from a sit-and-stare
;     observation.
;
; CATEGORY:
;     Hinode/EIS; windata.
;
; CALLING SEQUENCE:
;     Result = EIS_COMBINE_SITSTARE_WINDATA( Wd1, Wd2 )
;
; INPUTS:
;     Wd1:  The windata structure for the first file.
;     Wd2:  The windata structure for the second file.
;
; OUTPUTS:
;     A structure with the same tags as the input WD1 and WD2 structures,
;     with increased array sizes.
;
; EXAMPLE:
;     IDL> wd=eis_combine_sitstare_windata(wd1,wd2)
;
; MODIFICATION HISTORY:
;     Ver.1, Peter Young, 21-Feb-2008
;     Ver.2, Peter Young, 14-Apr-2011
;       Added wave_corr related tags
;     Ver.3, Peter Young, 13-Nov-2012
;       Added xcen and ycen to output structure (these are simply set
;       to values of WD1.
;     Ver.4, Peter Young, 08-May-2023
;       Added data_quality to output structure; updated header.
;-


; some sanity checks
;
IF wd1.line_id NE wd2.line_id THEN BEGIN
  print,'%EIS_COMBINE_SITSTARE_WINDATA: mis-match between line IDs!'
  print,wd1.line_id, wd2.line_id
ENDIF

yws1=wd1.hdr.yws
yws2=wd2.hdr.yws

IF yws1 NE yws2 THEN BEGIN
  print,'%EIS_COMBINE_SITSTARE_WINDATA: Warning! YWS values are different for the two structures.'
  print,'     YWS1: '+trim(yws1)
  print,'     YWS2: '+trim(yws2)
ENDIF 

;
; for the .time tag need to work this out for each exposure based on time of
; first exposure.
;
t0=anytim(wd1.time_ccsds[0])
t1=anytim(wd2.time_ccsds[0])
tdiff=t1-t0

wd= { filename: [wd1.filename, wd2.filename] , $
      line_id: wd1.line_id , $
      int: [[wd1.int],[wd2.int]], $
      err: [[wd1.err],[wd2.err]], $
      wvl: wd1.wvl, $
      time: [wd1.time,wd2.time+tdiff], $
      time_ccsds: [wd1.time_ccsds,wd2.time_ccsds], $
      data_quality: [wd1.data_quality, wd2.data_quality], $
      exposure_time: [wd1.exposure_time,wd2.exposure_time], $
      solar_x: [wd1.solar_x,wd2.solar_x], $
      solar_y: wd1.solar_y, $
      nl: wd1.nl, $
      nx: wd1.nx+wd2.nx, $
      ny: wd1.ny, $
      xcen: wd1.xcen, $
      ycen: wd1.ycen, $
      scale: wd1.scale, $
      units: wd1.units, $
      missing: wd1.missing, $
      iwin: wd1.iwin, $
      hdr: wd1.hdr, $
      time_stamp: systime(), $
      wave_corr_set: wd1.wave_corr_set, $
      wave_corr: [wd1.wave_corr,wd2.wave_corr], $
      wave_corr_tilt: wd1.wave_corr_tilt, $
      wave_corr_t: [wd1.wave_corr_t, wd2.wave_corr_t]}

wd1=0
wd2=0

return,wd

END
