
FUNCTION eis_join_windata, wd1, wd2

;+
; NAME
;
;     EIS_JOIN_WINDATA
;
; PROJECT
;
;     Hinode/EIS
;
; EXPLANATION
;
;     This routine takes two windata structures produced by
;     eis_get_windata from a single FITS file, and combines them into
;     a single structure. The arrays are concatenated in the
;     wavelength dimension.
;
;     E.g., suppose you had two wavelength windows, one centered on
;     195 angstroms with 32 wavelength pixels, and one centered on 194
;     angstroms again with 32 wavelength pixels. In the X-direction
;     there are 100 pixels, and in the Y-direction 200 pixels. The new
;     intensity array will be 64x100x200, while the new wavelength
;     array will be 64 elements.
;
;     This is useful if you want to do multi-Gaussian fits across more
;     than one wavelength window.
;
; INPUTS
;
;     WD1   A structure produced by eis_get_windata.
;
;     WD2   A structure produced by eis_get_windata from the same FITS
;           file as WD1
;
; OUTPUTS
;
;     A structure of the same format as WD1 and WD2 but with the
;     following tags modified:
;
;      .line_id  Contains IDs from both windows.
;      .int      wd1.int concatenated with wd2.int in wavelength
;                direction. 
;      .err      wd1.err concatenated with wd2.err in wavelength
;                direction. 
;      .wvl      wd1.wvl concatenated with wd2.wvl.
;      .iwin     The values from wd1 and wd2 are concatenated.
;      .nl       The values from wd1 and wd2 are summed.
;
;     All other tags are set to the same as wd1.
;      
; CALLS
;
;     None.
;
; EXAMPLES
;
;     IDL> wd184=eis_getwindata(l1name,184.54)
;     IDL> wd185=eis_getwindata(l1name,185.21)
;     IDL> wd=eis_join_windata(wd184,wd185)
;
; HISTORY
;
;     Ver.1, 10-Nov-2008, Peter Young
;     Ver.2, 26-Oct-2009, Peter Young
;      The .line_id and .nl tags have been corrected.
;     Ver.3, 16-Dec-2009, Peter Young
;      Added data_quality tag.
;     Ver.4, 3-May-2011, Peter Young
;      Added XCEN, YCEN, WAVE_CORR_SET, WAVE_CORR, WAVE_CORR_TILT and
;      WAVE_CORR_T to the output structure.
;-

IF wd1.filename NE wd2.filename THEN BEGIN
  print,'%EIS_JOIN_WINDATA: WD1 and WD2 must be from the same FITS file. Returning...'
  return, -1
ENDIF 

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

return,wd

END
