; $Id: eis_moment__gauss.pro 405 2010-07-04 11:21:38Z viggoh $
;+
; NAME:
;       EIS_MOMENT__DEFINE
;
; PURPOSE:
;       EIS_MOMENT__DEFINE defines the class EIS_MOMENT. Objects of this
;       class contains intensity, velocity and line width data 
;       (0th, 1st and 2nd order intensity moments)
;       from the EIS instrument on SOLAR-B. The
;       EIS_MOMENT class inherits the superclass HW_DATA
;
; CATEGORY:
;       Hansteen/Wikstol Data analysis SW
;
; CALLING SEQUENCE:
;       The EIS_MOMENT__DEFINE procedure is not called directly. An
;       object of class EIS_INT_DATA is created with the following
;       statement: 
;                   eis_int_data = obj_new('eis_int_data', eis_data )
;
; INPUTS:
;       eis_data: Object of class EIS_DATA, containing the EIS data
;       from which the intensity data will be calculated and stored in
;       the instance data of the EIS_INT_DATA object.
;
; KEYWORD PARAMETERS:
;
;
; OUTPUTS:
;       Objects of type EIS_MOMENT 
;
; CALLS:
;
;
; COMMON BLOCKS:
;       
;
; PROCEDURE:
;       The procedure opens an object of class EIS_MOMENT. The
;       INIT-method of this object is called automatically. In the
;       INIT method, the method called CONSTRUCT is called. This
;       method uses the information from the EIS_DATA
;       object to perform moment calculations 
;       order to calculate intensity for all line window profiles. 
;       The moments are stored in the instance data called 'w' 
;       of EIS_MOMENT.
;  
; 
; RESTRICTIONS:
;
;
; MODIFICATION HISTORY:
;       09-Feb-2004: Oivind Wikstol, version 1.0
;       30-Apr-2009: A. Gardini      Fixed 1 pixel shift error.
;-
pro eis_moment::gauss, data, iwin
; read line window data
  data-> getwin, iwin, wd, pos

; get wavelength scale
  lstr = data-> getlambda()
    if pos[0] gt 2147 then begin
    lambda = lstr.scale_a 
    pos[0] = pos[0]-2148
  endif else lambda = lstr.scale_b
  lambda = lambda[pos[0]:pos[0]+pos[1]-1]
  sz = size(lambda)
; right now, use pixels as xscale
  lambda = indgen(sz[1]) + pos[0]
; create average spectrum
  mspec = mean_spec(wd)  
; Perform gaussfit on average spectrum to get typical parameters
  xcfit, lambda, mspec, fitstr

; define weights for gauss-fit as inverse of number of counts:
  wts = 1./(wd > 1)

; run gaussfit on wd:
  missing = -100.   ; missing points value
  cfit_block, lambda, wd, wts, fitstr, missing, result, residual, /double

; finally, put result into place in the instances of the eis_moment object:
  (*self.w[iwin])[*, *, 0] = result[0, *, *]  ; intensity
  (*self.w[iwin])[*, *, 1] = result[1, *, *]  ; velocity
  (*self.w[iwin])[*, *, 2] = result[2, *, *]  ; width
return
end
