;+
; NAME:
;	smei_star_showsmooth
; PURPOSE:
;	Internal use only (by smei_star_show)
; CATEGORY:
;	camera/idl/star
; CALLING SEQUENCE:
	FUNCTION smei_star_showsmooth, time, fnc, $
		dtsmooth	= dtsmooth	, $
		tsmooth 	= tsmooth	, $
		sigma		= sigma
; INPUTS:
;	time
;	fnc
; OPTIONAL INPUT PARAMETERS:
;	dtsmooth=dtsmooth
; OUTPUTS:
;	Result
; OPTIONAL OUTPUT PARAMETERS:
;	sigma=sigma
; INCLUDE:
	@compile_opt.pro		; On error, return to caller
; CALLS:
;	IsTime, IsType, TimeSet, TimeUnit, TimeGet, BadValue
; PROCEDURE:
; MODIFICATION HISTORY:
;	OCT-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
;-

new_fnc = fnc

CASE 0 OF

IsTime(dtsmooth):

IsType(fnc,/generic_float):

ELSE: BEGIN

	msec = TimeUnit(/msec)
	dts  = TimeGet(dtsmooth,/diff,/full,msec,/scalar)/2

	has_sigma = arg_present(sigma)
	IF has_sigma THEN	$
		sigma = make_array(type=IsType(fnc),dim=size(fnc,/dim),value=BadValue(fnc))

	ntt = n_elements(time)
	tt = TimeSet(time)
	CASE IsTime(tsmooth) OF
	0: itt = lindgen(ntt)
	1: itt = where(TimeOp(tt,tsmooth[0],msec) GE 0 AND TimeOp(tt,tsmooth[1],msec) LE 0,ntt)
	ENDCASE

	FOR i=0,ntt-1 DO BEGIN
		dtt = TimeOp(/subtract,tt,tt[itt[i]],msec)
		good = where( abs(dtt) LE dts, ngood )
		IF ngood GT 1 THEN BEGIN
			new_fnc[itt[i]] = mean(fnc[good],/nan)
			IF has_sigma THEN		$
				IF ngood GT 2 THEN	$
					sigma[itt[i]] = stddev(fnc[good],/nan)
		ENDIF
	ENDFOR

END

ENDCASE

RETURN, new_fnc  &  END
