;+
; PROJECT:
;	HESSI
; NAME:
;	HSI_ANNSEC_COORD
;
; PURPOSE:
;	This procedure computes the coordinates of the annular sector map in Cartesian
;	coordinates.
; CATEGORY:
;	HESSI, IMAGE, UTIL, ANNSEC
;
; CALLING SEQUENCE:
;	Hsi_annsec_coord, hsi_img_obj, x, y, map_ptr=map_ptr
;
; CALLS:
;	HESSI OBJECTS, HSI_ANNSEC_BPROJ_WEIGHT, DATATYPE
;
; INPUTS:
;	Hsi_img_obj - object containing calibrated eventlist object.  Should also contain modpat control object.
;	;
;
; OPTIONAL KEYWORD INPUTS:
;	modpat_ptr - Pointer array which stores the universal modulation pattern map structure.
;		Used in for testing only.  Normally, the object carries the modulation pattern structure.
;
; OUTPUTS:
;	x - x coordinate in arcsec from Sun Center of annular sector map, dimensioned same as image.
;	y - y coordinate in arcsec from Sun Center of annular sector map, dimensioned same as image.
;	rmap - radial coordinate of annular sector map. Not necessarily from sun center, arcsec.
;	thetamap - azimuthal coordinate of annular sector map.  In radians.
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	Uses trigrid interpolation between the two systems.
;
; MODIFICATION HISTORY:
;	Version 1, richard.schwartz@gsfc.nasa.gov, 17-may-2000
;
;-

pro hsi_annsec_coord, hsi_img_obj, x, y, rmap, thetamap, modpat_ptr=modpat_ptr



if size(modpat_ptr,/tname) ne 'POINTER' then $
	modpat_ptr = hsi_img_obj-> getdata(class_name='hsi_modul_pattern')
this_modpat_ptr = modpat_ptr
if size(/tname,this_modpat_ptr) eq 'POINTER' then begin
	valid = where(ptr_valid( this_modpat_ptr))
	this_modpat_ptr = this_modpat_ptr[valid]
	endif

if  size(/tname, hsi_img_obj) eq 'OBJREF' then  begin
	valid= where(hsi_img_obj->get(/det_index_mask))
	this_modpat_ptr = this_modpat_ptr[valid[0]]
	endif



modpat = *this_modpat_ptr[0]


image_dim = modpat.image_dim
rmap_dim  = modpat.rmap_dim
xyoffset  = modpat.xyoffset
xaxis_fov = modpat.xaxis_fov
r0_offset = modpat.r0_offset

rmap    = *modpat.annsec_center_ptr

theta0  = atan(xyoffset[1], xyoffset[0])
thetamap= (findgen(rmap_dim[1])- (rmap_dim[1]-1)/2.0)*modpat.dphi + theta0

x = rmap # cos( thetamap )
y = rmap # sin( thetamap )

if xaxis_fov then begin
	thetamap = thetamap - theta0
	x = rmap # cos( thetamap ) + xyoffset[0] - r0_offset
	y = rmap # sin( thetamap ) + xyoffset[1]
	endif

end




