Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/contour_marks.pro'
pro contour_marks, posxy, identify, id2, IMAGE_SPEC=image_spec, ROTATE=rotate, $
			SHOW_SOURCES=show_sources, SHOW_LABELS=show_labels, $
		RELX=relx, RELY=rely, RELATIVE_ARCS=relarcs, HC_MODE=HC_mode
;+
; NAME:
;	contour_marks
; PURPOSE:
;	Draw the Marks (of sources) and Labels on contour-display of mosaic,
;	as set interactively by pro contour_markset.
; CALLING EXAMPLE:
;	contour_marks, posxy, identify, id2, IMAGE_SPEC=mosaic_spec
; INPUTS:
;	posxy
;	identify
;	id2 =
; KEYWORDS:
;	IMAGE_SPEC =
;	ROTATE=
;	SHOW_SOURCES=
;	SHOW_LABELS=
;	HC_MODE=
; RESULTS:
;	Source marks and Labels are draw on window display or hardcopy file.
; EXTERNAL CALLS:
;	function draw_marks
;	pro rotate_coordin
; COMMON BLOCKS:
;	common contour_marks, sources, Labels
;	common HC_color, grey_map, color_trans
; PROCEDURE:
;	Setup coordinates, display image, draw axes, draw contours, ....
; MODIFICATION HISTORY:
;	written, Frank Varosi NASA/GSFC 1990.
;	F.V. 1991, merged code for PostScript & windows into function draw_mark.
;-
  common contour_marks, sources, Labels
  common HC_color, grey_map, color_trans

	if N_elements( HC_mode ) NE 1 then HC_mode=""
	xsiz = posxy(2)-posxy(0)
	ysiz = posxy(3)-posxy(1)
	zfac = [1,1]
	zoff = [0,0]

	if N_struct( image_spec ) EQ 1 then begin

		identify = image_spec.name
		show_sources = image_spec.options.show_marks
		show_labels = image_spec.options.show_Labels
		sim = float( image_spec.size_image )
		rotate = image_spec.rotation * image_spec.rot_applied

		if (image_spec.zoom_enable) then begin
			zoomxy = image_spec.zoom
			zfac = sim(1:2) / (zoomxy(2:3)-zoomxy(0:1)+1)
			zoff = zoomxy(0:1) / sim(1:2)
		  endif

	  endif else if vartype( identify ) NE "STRING" then return

	identim = identify
	if strpos( identim,"MosMath" ) GE 0 then identim = strmid( identim,0,7 )

if !DEBUG then stop

if (N_struct( sources ) GT 0) AND keyword_set( show_sources ) then begin

	ww = where( (([sources.size] GT 0) OR ([sources.size_arcsec] GT 0)) $
				AND ([sources.identify] EQ identim), Nsource )

	if (VarType( id2 ) EQ "STRING") AND (Nsource GT 0) then begin
		w = where( [sources(ww).id2] EQ id2, Nsource )
		if (Nsource GT 0) then  ww = ww(w)
	   endif

	if (Nsource GT 0) then begin

		if keyword_set( relarcs ) then begin
		  endif else begin
			rotate_coordin, sources(ww).nposx, sources(ww).nposy, $
					pos_x, pos_y, ROT=rotate, /NORM, $
					ZOOM_FAC=zfac, ZOOM_OFF=zoff
		   endelse

		pos_x = [pos_x]
		pos_y = [pos_y]

		w = where( (pos_x GE 0) AND (pos_x LE 1) AND $
			   (pos_y GE 0) AND (pos_y LE 1), Nsource )

		if (Nsource GT 0) then begin
			ww = ww(w)
			sourcew = sources(ww)
			x = [ xsiz * pos_x(w) + posxy(0) ] * !D.x_vsize
			y = [ ysiz * pos_y(w) + posxy(1) ] * !D.y_vsize
			msize = [sourcew.size] * ((!D.x_vsize + !D.y_vsize)/2)
			wa = where( [sourcew.size_arcsec] GT 0, Nsa )
			if (Nsa GT 0) AND $
			   (N_struct( image_spec ) EQ 1) then begin
				apix=(image_spec.RA_pix + image_spec.DEC_pix)/2
				msp = sourcew(wa).size_arcsec/apix
				r = (rotate MOD 2)
				spix = zfac(r)/sim(r+1)
				msize(wa) = !D.x_vsize * xsiz * msp * spix
			   endif
			colors = [sourcew.color]
			colorb = [sourcew.colorb]
			sthick = [sourcew.thickness]
			symbols = [sourcew.symbol]

			if (!D.name EQ "PS") AND (HC_mode NE "color") then begin
				colors = grey_map( colors )
				colorb = grey_map( colorb )
			   endif
		   endif
	   endif

	for i=0,Nsource-1 do  stat = draw_mark( x(i), y(i), msize(i), $
						SYMBOL=symbols(i), $
						THICK=sthick(i), $
						FORE=colors(i), $
						BACK=colorb(i), /NOSAVE )
   endif

if (N_struct( Labels ) GT 0) AND keyword_set( show_Labels ) then begin

	ww = where( ([Labels.size] GT 0) AND $
		    ([Labels.identify] EQ identim), NLabel )

	if (NLabel GT 0) then begin

		rotate_coordin, Labels(ww).nposx, Labels(ww).nposy, $
				pos_x, pos_y, ROT=rotate, /NORM, $
				ZOOM_FAC=zfac, ZOOM_OFF=zoff

		x = [ xsiz * pos_x + posxy(0) ]
		y = [ ysiz * pos_y + posxy(1) ]

		w = where( (x GE 0) AND (x LE 1) AND $
			   (y GE 0) AND (y LE 1), NLabel )

		if (NLabel GT 0) then begin
			x = x(w)
			y = y(w)
			ww = ww(w)
			colors = [Labels(ww).color]
			if (!D.name EQ "PS") AND (HC_mode NE "color") then $
						colors = grey_map( colors )
		   endif
	   endif

	for i=0,NLabel-1 do begin
		Label = Labels(ww(i))
		xyouts,/NORM,x(i),y(i),Label.text,SIZ=Label.size,COL=colors(i)
	   endfor
   endif

return
end