;+ ; Add some data into an accum_struct. Not intended for use by general ; users. ; ;

The data is : sum(wt*data) ;

The times are summed: sum(teff), sum(tint) ;

The wt is summed: sum(wt) ;

The tsys_sq is : sqrt(sum(wt*Tsys^2)) ; ;

f_delt is used as a check to see if the channel spacing matches ; the ongoing average. If not supplied, the check is not done. ; ;

If a weight (wt) is not supplied, it will be teff/Tsys^2 ; If teff is not supplied, tint will be used in its place. ; ; @param accumbuf {in}{required}{type=accum_struct structure} The ; structure to hold the results of this accumlation. Care must be ; taken if this is !g.accumbuf. Simply passing it in will not work ; because global values are passed by value not reference. See ; the code in accum.pro for an example of how to use this in that case. ; ; @param data {in}{required}{type=float array} The data to add to the ; accumulation structure. It must have the same number of elements as ; the ongoing accumulation (if this is not the first one added in). ; ; @param tint {in}{required}{type=float} Integration time. ; ; @param tsys {in}{required}{type=float} System temperature. ; ; @param teff {in}{optional}{type=float} Effective integration time. ; ; @param f_delt {in}{optional}{type=float} Channel spacing. ; ; @keyword wt {in}{optional}{type=float} Weight to give this data. ; ; @private_file ; ; @version $Id: accumulate.pro,v 1.2 2005/05/29 22:44:28 bgarwood Exp $ ;- PRO accumulate, accumbuf, data, tint, tsys, teff, f_delt, wt=wt compile_opt idl2 if n_params() lt 4 then begin message,'Usage: accumulate, accumbuf, data, tint, tsys [,teff, f_delt, wt=wt4]',/info return endif ; argument check if (tag_names(accumbuf,/structure_name) ne 'ACCUM_STRUCT') then begin message, 'accumbuf is not the right type of structure' return endif ; substitute defaults where necessary if (n_elements(teff) eq 0) then teff = tint ; watch for teff=0.0, leads to zero weight if teff le 0.0 then begin message,'negative or zero EXPOSURE, using 1s',/info teff = 1.0 endif ; early version of sdfits didn't have a DURATION, so it will be 0.0 if tint lt teff then tint = teff tsys_sq = tsys^2 if (n_elements(wt) eq 0) then begin wt = teff / tsys_sq endif wtData = wt*data wtTsys_sq = wt*tsys_sq if (accumbuf.n eq 0) then begin ; first one in, free data ptr as necessar if ptr_valid(accumbuf.data_ptr) then ptr_free,accumbuf.data_ptr accumbuf.data_ptr = ptr_new(wtData) accumbuf.wt = wt accumbuf.teff = teff accumbuf.tint = tint accumbuf.tsys_sq = wtTsys_sq if (n_elements(f_delt) ne 0) then begin accumbuf.f_delt = f_delt endif accumbuf.n = 1 endif else begin ; require that the number of elements be the same if (n_elements(data) ne n_elements(*accumbuf.data_ptr)) then begin message, 'Number of elements in data differs from accum buf - nothing added to accumbuf',/info return endif ; warn if f_delt set and not equal to accum buf's value if (n_elements(f_delt) ne 0 and f_delt ne accumbuf.f_delt) then begin message, 'Warn: the resolution is different from that in accumbuf',/info endif *accumbuf.data_ptr += wtData accumbuf.wt += wt accumbuf.teff += teff accumbuf.tint += tint accumbuf.tsys_sq += wtTsys_sq accumbuf.n += 1 endelse END