
;+ ***********************************************************************
; NAME:
;	PLOT_HG_MAN
;
; PURPOSE:
; Compute and plot the heliographic positions corresponding to the NRH
; channels canew, cansn.	
;
; CATEGORY:
;	NRH1 trace
;
; CALLING SEQUENCE:
;	PLOT_HG_MAN, canew, cansn, fwhmew, fwhmsn, number, idate, $
;			frequence, heurms
;
; INPUTS:
;		canew		EW channel
;		cansn		SN channel
;		fwhmew		EW width of the source
;		fwhmsn		SN width
;		number		Running number of plotted positions
;		idate		Array (day, month, year - 1900)
;		frequence	Frequency [MHz]
;		heurms		Time [ms afterr 0 UT]
;	
; KEYWORD PARAMETERS:

;		CORSTAT		Compute correction for static ionosphere
;		CORPOIT		Compute correction using Poitiers dens. meas.
;		SHADE		Embed plotted position within shaded region
;		PSYM		Number of symbol used for plotting (cf. IDL)
;		LABEL		Label plotted positions by a running number,
;				time and frequency
;		DATE		Write date in the lower left corner of the plot
;		FREQUENCY	Write frequency and symbol at bottom of plot
; 		FIGURE
;		FILL=fill
;		SYMSIZE
;		LINESTYLE
;		MESSAGE		Contains computed heliographic centr. position
;
; OUTPUTS:
;	Non
;
; COMMON BLOCKS:
;	Non
;
; MODIFICATION HISTORY:
;	Adapte de XHELIO (bonmartin@obspm.fr)

;	31/3/99	ajout du Keyword DATE pur ecrire (ou non) la date
;	1/9/00  ajout  du Keyword MESSAGE
;		(Ludwig.klein@obspm.fr)

;-*******************************************************************

PRO PLOT_HG_MAN, canew, cansn, fwhmew, fwhmsn, number, idate, frequence, $
	heurms, CORSTAT=icor, CORPOIT=icpoit, SHADE=shade, PSYM=psym, $
	LABEL=label, DATE=date, FREQUENCY=frequency, FIGURE=figure, $
	FILL=fill, SYMSIZE=taille, $
	LINESTYLE=linestyle, MESSAGE=message

ancfont = !p.font
!p.font = 0
IF NOT KEYWORD_SET(PSYM) THEN PSYM = 4	; default symbol: diamond
jinter=0L
htab=lonarr(2) & htab(0)=heurms/3600000
		htab(1) = Heurms/60000 - Htab[0]*60
nb = 1L
xheliogr = 0. & yheliogr=0.

colind=!d.n_colors - !P.background

 aux = ROUND(frequence)/100
 IF frequence GT 420. THEN aux = 5

IF STRLOWCASE(figure) EQ 'auto' THEN BEGIN
	CASE 1 OF
        aux EQ 1:       symbtrace, xcoord, ycoord, taille, FIGURE='circle'
        aux EQ 2:       symbtrace, xcoord, ycoord, taille, FIGURE='triangle'
        aux EQ 3:       symbtrace, xcoord, ycoord, taille, FIGURE='square'
        aux EQ 4:       symbtrace, xcoord, ycoord, taille, FIGURE='diamond'
        aux EQ 5:       symbtrace, xcoord, ycoord, taille, FIGURE='pentagon'
;	ELSE:		symbtrace, xcoord, ycoord, taille, FIGURE='circle'
	ENDCASE
ENDIF ELSE BEGIN
	symbtrace, xcoord, ycoord, taille, FIGURE=figure
ENDELSE
USERSYM, xcoord, ycoord, FILL=fill
symb = 8
text = ' '

;    Plot a single point
IF fwhmew EQ 0. AND fwhmsn EQ 0. THEN BEGIN
	HMER = INTARR(3)
	DEC = INTARR(3)
	INIT_MALAX,Idate, Hmer, Dec, 'SOLEIL'
	CALCPOS, Frequence, Htab[0], Htab[1], Canew, Cansn, Xheliogr, Yheliogr 
	message=STRING(xheliogr, yheliogr, $
		FORMAT='("Centroid position [Rs]: ", 2(F6.3,1X))')
	OPLOT, [xheliogr], [yheliogr], PSYM=symb, COLOR = colind
	IF STRUPCASE(!D.NAME) eq 'PS' AND KEYWORD_SET(SHADE) THEN $
		OPLOT, [xheliogr], [yheliogr], PSYM=symb, $
			COLOR = !P.background
	x = 0.5*( !x.crange(0) + !x.crange(1) )
	annot = CONVERT_COORD( x, !y.crange(0), /DATA, /TO_DEVICE )
	annot(0) = annot(0) + 8*(aux-3)*!d.x_ch_size
	annot(1) = annot(1) - 1.1* !d.y_ch_size
	datann = CONVERT_COORD([annot(0), annot(1)-!d.y_ch_size], /DEVICE, $
		/TO_DATA)
	IF KEYWORD_SET(FREQUENCY) THEN BEGIN
		XYOUTS, annot(0)+.1*!d.x_ch_size, annot(1), $
		STRCOMPRESS( STRING(ROUND(frequence)) + ' MHz'), /DEVICE, $
		charsize=0.8, alignment=0.5
		OPLOT, [datann(0)], [datann(1)], PSYM=symb, /NOCLIP
	ENDIF
;    Plot a cross at the centroid position with arms giving source diameters
;    in the two array directions

ENDIF ELSE BEGIN
	x = 0. & y = 0.
	xheliogr = FLTARR(4) & yheliogr = xheliogr
	HMER = INTARR(3)
	DEC = INTARR(3)
	INIT_MALAX,Idate, Hmer, Dec, 'SOLEIL'
	CALCPOS, Frequence, Htab[0], Htab[1], Canew, Cansn, xh, yh 
	message=STRING(xh, yh, $
		FORMAT='("Centroid position [Rs]: ", 2(F6.3,1X))')
	FOR i = 0, 1 DO BEGIN
		aux = canew + (FLOAT(i)-.5)*fwhmew
		CALCPOS, Frequence, Htab[0], Htab[1], Aux, Cansn, X, Y
		xheliogr(i) = x & yheliogr(i) = y
	ENDFOR

	FOR i = 2, 3 DO BEGIN
		aux = cansn + (FLOAT(i)-2.5)*fwhmsn
		CALCPOS, Frequence, Htab[0], Htab[1], Canew, Aux, X, Y
		xheliogr(i) = x & yheliogr(i) = y
	ENDFOR
	IF fwhmsn EQ 0. THEN text = 'SN ' + STRING(FORMAT='(F5.1)', cansn)+ ';'
	IF fwhmew EQ 0. THEN text = 'EW ' + STRING(FORMAT='(F6.1)', canew)+ ';'
	IF STRUPCASE(!d.name) EQ 'PS' THEN eptrait = 3. ELSE eptrait = 1.
	IF KEYWORD_SET(SHADE) THEN BEGIN
		FOR i = 0, 2, 2 DO OPLOT, xheliogr(i:i+1), yheliogr(i:i+1), $
			THICK=eptrait+4., col = !P.background
	ENDIF
	FOR i = 0, 2, 2 DO OPLOT, xheliogr(i:i+1), yheliogr(i:i+1), $
		COLOR = colind, LINESTYLE=linestyle, THICK=eptrait
ENDELSE


IF KEYWORD_SET(label) THEN BEGIN
;	Inscription du numero de source sous la position trace
	annot = CONVERT_COORD(xheliogr(0), yheliogr(0), /DATA, /TO_DEVICE)
	XYOUTS, annot(0), annot(1)-!d.y_ch_size, STRCOMPRESS(STRING(number)), $
		/DEVICE, alignment=0.5, charsize=0.5
;	Inscription des heures, frequences au bord du cadre/dans la marge
	text = STRING(number) + ': ' + msh(heurms) + ' (' + $
		text +  $
		STRCOMPRESS( STRING( ROUND(frequence) )) + ' MHz)'
	annot = CONVERT_COORD(!x.crange(1), !y.crange(1), /DATA, /TO_DEVICE)
	CASE label OF 
		1:	BEGIN	;	left, inside the frame
				annot = CONVERT_COORD(!x.crange(0), $
					!y.crange(1), /DATA, /TO_DEVICE)
				x = annot(0)+!d.x_ch_size 
				align = 0.
			END
		2:	BEGIN	;	right, inside the frame
				x = annot(0)-!d.x_ch_size 
				align = 1.
			END
		3:	BEGIN	;	right, outside the frame
				x = annot(0)+!d.x_ch_size 
				align = 0.
			END
	ENDCASE
	y = annot(1)- (number+1.5)*!d.y_ch_size
	XYOUTS, x, y, STRCOMPRESS(text), /DEVICE, charsize=0.8, alignment=align
ENDIF
IF (KEYWORD_SET(DATE) AND number EQ 0) THEN BEGIN
	annot = CONVERT_COORD(!x.crange(0) , !y.crange(0), /DATA, /TO_DEVICE )
	i2cdate, idate, chdate
	XYOUTS, annot(0)+!d.y_ch_size, annot(1)+!d.y_ch_size, chdate, $
		 /DEVICE
ENDIF

!p.font = ancfont	; ajout KLK 20/10/97


END
