
FUNCTION eis_update_cen_error, fitdata, tilterror, fiterror, $
                               absvel=absvel, abserr=abserr

;+
; NAME
;
;     EIS_UPDATE_CEN_ERROR
;
; PROJECT
;
;     Hinode/EIS
;
; INPUTS
;
;     FITDATA  An EIS line fit structure in the format produced by
;              eis_auto_fit.pro. 
;
;     TILTERROR  A 2D array produced by eis_tilt_error.pro giving the
;                uncertainty on the EIS slit tilt.
;
;     FITERROR A single number giving the uncertainty in the
;              determination of the reference wavelength - see
;              eis_update_fitdata.pro.
;
; OPTIONAL INPUTS
;
;     ABSVEL   This is a velocity shift that is applied to all the
;              centroid measurements. For example, suppose you used O
;              VI 184.1 as your reference line in the quiet Sun. The
;              EIS software assumes that the quiet Sun is at rest,
;              however studies from SUMER show that transition region
;              lines are redshifted in the quiet Sun (e.g., Peter &
;              Judge, ApJ, 1999). O VI is found to be redshifted by 5
;              km/s, thus for this example ABSVEL=5 should be input
;              and so wavelengths in FITDATA will be redshifted by 5
;              km/s. Redshifts should be specified as positive
;              velocities, and blueshifts as negative velocities.
;
;     ABSERR   This input is used to specify an error on ABSVEL. Thus
;              if the O VI quiet Sun absolute velocity (from SUMER) is
;              +5 km/s +/- 2 km/s, then the user should set
;              ABSERR=2. The units are km/s.
;
; OUTPUTS
;
;     A fit structure identical to FITDATA is returned, except that
;     the following tags are modified:
;
;     .aa    The arrays corresponding to the line centroids are
;            updated (although only if ABSVEL was specified).
;     .sigmaa  The arrays corresponding to the centroid errors are
;              updated to include the tilt error and the orbit
;              variation fit error which are added to original fitting
;              error in quadrature. The error on the absolute
;              reference velocity (ABSERR) is also included if it has
;              been specified.
;      .refwvl  If ABSVEL has been specified, then the reference
;               wavelengths are shifted by ABSVEL.
;
; CALLS
;
;     EIS_GET_FITDATA
;
; HISTORY
;
;     Ver.1, 14-Apr-2010, Peter Young
;-

outdata=fitdata

ng=fitdata.ngauss

IF n_elements(absvel) EQ 0 THEN absvel=0.
IF n_elements(abserr) EQ 0 THEN abserr=0.

FOR i=0,ng-1 DO BEGIN
  cen=eis_get_fitdata(fitdata,/cen,line=i,err=cenerr)
 ;
  abscenerr=v2lamb(abserr,fitdata.refwvl[i])
  newerr=sqrt(cenerr^2 + tilterror^2 + fiterror^2 + abscenerr^2)
 ;
 ; Shift the centroids
 ;
  IF absvel NE 0. THEN newcen=cen + v2lamb(absvel,cen)
 ;
 ; Update the centroid and centroid error in the fit structure
 ;
  IF absvel NE 0. THEN outdata.aa[3*i+1,*,*]=newcen
  outdata.sigmaa[3*i+1,*,*]=newerr
 ;
 ; Update the reference wavelengths in the fit structure
 ;
  refwvl=outdata.refwvl[i]
  IF absvel NE 0. THEN outdata.refwvl[i]=refwvl+v2lamb(absvel,refwvl)
ENDFOR 

return,outdata

END
