;+
; PROJECT:
;	HESSI
; NAME:
;	HSI_ANNSEC_PROFILE_BAVER_SETUP
;
; PURPOSE:
;	Adds needed vectors to MAP_PTR to support fast compute of flat image profiles.
;
; CATEGORY:
;	HESSI, UTIL
;
;
; CALLING SEQUENCE:
;
;	hsi_annsec_profile_aver_setup(modpat_obj)
;
; CALLS:
;	none
;
; INPUTS:
;       Modpat_obj - Object containing the hsi_modul_pattern object
;
; OPTIONAL INPUTS:
;	
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	THIS_DET_INDEX - usual meaning
;	THIS_HARMONIC  - usual meaning
;	MAP_PTR
;	
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	HSI_ANNSEC_PROFILE is called with a flat field, photon/sec/pixel.  The vectors
;	out_cos and out_sin are placed into the pointers in the mpat structures.  These
;	vectors are the result of the multiplication of the image by the cosine and sine
;	components of the annular sector maps. 
;
; MODIFICATION HISTORY:
;	Version 1, richard.schwartz@gsfc.nasa.gov, 25-apr-2000.
;
;-
pro hsi_annsec_profile_baver_setup, cbe_obj, mpat_ptr=mpat_ptr

if size(/tname,map_ptr) eq 'POINTER' then begin
	selected = where( ptr_valid(mpat_ptr), ndet)
	total_det = (size(mpat_ptr))[1]
	mpat = mpat_ptr[selected]
	endif

if not exist(mpat) then begin
	mpat = cbe_obj->getdata(class='hsi_modul_pattern')
	det_index_mask = cbe_obj->get(/det_index_mask)
	total_det = (size(det_index_mask))[1]
	selected = where( det_index_mask, ndet)
	mpat = mpat[selected]
	endif

rmap_dim = (*mpat[0]).rmap_dim
for i=0,ndet-1 do begin
	baver = fltarr( rmap_dim[0], rmap_dim[1])+1.0
	profile_aver = hsi_annsec_profile( baver, cbe_obj,$
	this_det_index = selected[i] mod total_det,$
	this_harmonic=selected[i] / total_det, $
	out_cos=cos_out, $
	out_sin=sin_out)
	ptr_free, (*mpat[i]).cmap_aver_ptr
	ptr_free, (*mpat[i]).smap_aver_ptr
	(*mpat[i]).cmap_aver_ptr = ptr_new(cos_out)
	(*mpat[i]).smap_aver_ptr = ptr_new(sin_out)
	endfor
end