;+ ; Smooth a guide data container with a boxcar smoothing of a certain ; width, in channels. For odd width, this uses the built-in idl ; SMOOTH function. For even widths this uses ; doboxcar1d and the ; reference channel is moved left by 1/2 channel width. ; ;

Replaces the contents of the data being smoothed with the smoothed ; data. This can not use dcboxcar because system variables ; (e.g. !g.s[0]) are passed by value and hence dcboxcar can not ; overwrite the data container in that case. ; ;

The continuum side needs more work, especially for the decimate ; case and the even boxcar case. ; ; @param width {in}{required}{type=integer} Width of boxcar in ; channels. ; ; @keyword index {in}{optional}{type=integer}{default=0} guide data container to ; use. ; ; @keyword decimate {in}{optiopnal}{type=boolean} If set, the data ; container is reduced - taking every width channels starting at ; channel 0. ; ; @uses doboxcar1d ; @uses dcextract ; ; @version $Id: boxcar.pro,v 1.3 2005/06/02 17:09:44 bgarwood Exp $ ;- pro boxcar, width, index=index, decimate=decimate compile_opt idl2 if n_elements(width) eq 0 then begin message,'Usage: boxcar, width[, index=index, decimate=decimate]',/info return end if n_elements(index) eq 0 then index=0 if !g.line then begin if index lt 0 or index gt n_elements(!g.s) then begin message,string(n_elements(!g.s),format='("Index must be between 0 and ",i2)'),/info return endif nch=data_valid(!g.s[index]) if nch le 0 then begin message, 'No valid data found to smooth.',/info return endif if (width le 0 or width gt nch) then begin message,string(nch,format='("Width must be between 1 and ",i)'),/info return endif *!g.s[index].data_ptr = doboxcar1d(*!g.s[index].data_ptr,width,/nan,/edge_truncate) if width mod 2 eq 0 then begin !g.s[index].reference_channel -= 0.5 endif if keyword_set(decimate) then begin newdc = dcextract(!g.s[index],0,(nch-1),width) set_data_container,newdc,index=index,/noshow data_free, newdc endif endif else begin if index lt 0 or index gt n_elements(!g.c) then begin message,string(n_elements(!g.c),format='("Index must be between 0 and ", i2)'),/info return endif nch=data_valid(!g.c[index]) if nch le 0 then begin message, 'No valid data found to smooth.',/info return endif if (width le 0 or width gt nch) then begin message,string(nch,format='("Width must be between 1 and ",i)'),/info return endif *!g.c[index].data_ptr = doboxcar1d(*!g.c[index].data_ptr,width,/nan,/edge_truncate) if width mod 2 ne 0 then begin message,'Warning: boxcar with an even width for continuum data skews the result towards early times',/info endif if keyword_set(decimate) then begin newdc = dcextract(!g.c[index],0,(nch-1),width) set_data_container,newdc,index=index,/noshow data_free, newdc endif endelse if not !g.frozen and index eq 0 then show end