pro avepointmap, startscan, npoints, nref, ntimes, smooth, name
;; for GBTIDL
;; Accumulate scans for both polarizations for each position in a
;; npoints=NxN map with an off every nref point and going ntimes.
;; Assumes the first scan is a reference position.
;; Will average polarization then boxcar smooth (with decimate)
;; by smooth, fit and subtract baseline.
;; Example of use for 3x3 map with ref every 3 points that was
;; run twice, and boxcar smooth by 20 channels, starting in record
;; number 22,
;; avepointmap,22,9,3,2,20
;; This could be execute in a sb with the following command:
;; PointMapWithReference (source, hlen, vlen, hdel, vdel, refoff, 3, 300)
;; Assumes nfit, nregions or setregion have been run and all relevant
;; data flagged.
k=0
jj=0
for j=1,npoints do begin
for i=0,ntimes-1 do begin
if((j mod nref eq 0) and (i eq 0)) then k=k+nref+1
SIGscan=startscan + j + jj+ i*(npoints+nref)
REFscan=startscan + k + i*(npoints+nref)
if((i eq ntimes-1) and (j eq npoints)) then REFscan=REFscan-nref-1
print, "cycle=",i+1," point=",j," [SIGscan,REFscan]=",SIGscan,REFscan
getsigref,SIGscan,REFscan,plnum=0
accum
getsigref,SIGscan,REFscan,plnum=1
accum
if((j mod nref eq 0) and (i eq (ntimes-1))) then jj=jj+1
endfor
print,"avg what has been accumulated"
ave
;keep
boxcar,smooth,/decimate
chan
baseline
velo
print,name+'pos'+strtrim(j,2)+'.sp'
write_ps,name+'pos'+strtrim(j,2)+'.ps'
write_ascii,name+'pos'+strtrim(j,2)+'.sp'
endfor
end