
;+ ***********************************************************************
; NAME:
;	PLOTPOS2D
;
; PURPOSE:
; 	Plot the heliographic positions contained in a 2D "position"
;	file derived from 1D NRH scans
;
; CATEGORY:
;	NRH1 trace
;
; CALLING SEQUENCE:
;	PLOTPOS2D,  tabpos, posinfo, pastempo, frequence, chdate
;
; INPUTS:
;	tabpos		Array read by LECP1D containing source parameters: 
;			tabpos(numero, type, indice temporel)
;	posinfo		2D array giving for each source: 
;				(i) start time [ms] (posinfo(0, numero))
;				(ii) number of points (posinfo(1, numero))
;	pastempo 	Integration time [ms]
;	frequence	Frequency [MHz]
;	chdate		Date (string)
;
; KEYWORD PARAMETERS:
;		HEURES		Start, end time of plot
;		NUMPOS		Number of source to be plotted 
;				(default: all; first source: numero=1),
;				set to -1 if the requested source is not in
;				the file
;		SHADE		Plot line upon stripe in background colour
;		DATE		Write date in the lower left corner of the plot
;		SYMBOL		Plots symbols 
; 		FIGURE		Type of figure used for the symbols
;		FILL		Use filled figures as symbols
;		SYMSIZE		Size of the symbol
;
; OUTPUTS:
;	None
;
; COMMON BLOCKS:
;	None
;
; MODIFICATION HISTORY:
;	Adapte de XHELIO (bonmartin@obspm.fr)
;	20/5/99: Introduction of keywords for plotting symbols 
;			(Ludwig.klein@obspm.fr)
;-*******************************************************************
;
pro plotpos2d, tabpos, posinfo, pastempo, frequence, chdate, heures=heures, $
	numpos=numpos, SHADE=shade, DATE=date,  $
	SYMBOL=symbol, FIGURE=figure, FILL=fill, SYMSIZE=symsize

b=size(tabpos)
numpar = b(2)	; nbre de parametres de position dans tabpos (1D:5, 2D: 6)
numd = 0 & numf = b(1)-1	; Defaut: afficher toutes les positions
IF KEYWORD_SET(numpos) THEN BEGIN
	nump = numpos -1	;	compteur de positions demarrant a 0
	IF nump GE b(1) THEN BEGIN
		nump = -1
		RETURN
	ENDIF 
	numd = nump & numf = nump
ENDIF

IF KEYWORD_SET(SYMBOL) THEN BEGIN
	IF NOT KEYWORD_SET(symsize) THEN symsize=1.
	IF NOT KEYWORD_SET(figure)  THEN figure='auto'
	IF STRLOWCASE(figure) EQ 'auto' THEN BEGIN
		aux = ROUND(frequence)/100
		IF frequence GT 420. THEN aux = 5
		CASE 1 OF
        	aux EQ 1: symbtrace, xcoord, ycoord, symsize, FIGURE='circle'
		aux EQ 2: symbtrace, xcoord, ycoord, symsize, FIGURE='triangle'
		aux EQ 3: symbtrace, xcoord, ycoord, symsize, FIGURE='square'
		aux EQ 4: symbtrace, xcoord, ycoord, symsize, FIGURE='diamond'
		aux EQ 5: symbtrace, xcoord, ycoord, symsize, FIGURE='pentagon'
		ENDCASE
	ENDIF ELSE BEGIN
		symbtrace, xcoord, ycoord, symsize, FIGURE=figure
	ENDELSE
	USERSYM, xcoord, ycoord, FILL=fill
	symb=8
ENDIF
;-----------------------------------------------------------------------------

FOR numero = numd, numf DO BEGIN
;     Construction du tableau de temps:
	temp = FINDGEN(posinfo(1, numero)) * pastempo + posinfo(0, numero)
;     Extraction de la partie de tabpos concernant la position:
	tab = reform(tabpos(numero, 0:numpar-1, 0:posinfo(1, numero)-1)) 
;     Selection de l'intervalle de temps a tracer:
	c = WHERE(temp GE heures(0) AND temp LE heures(1))
;     Affichage:
	IF N_ELEMENTS(c) GT 1 THEN  BEGIN
		xcoor = REFORM(tab(0,c)) & ycoor = REFORM(tab(1,c))
		IF KEYWORD_SET(SHADE) THEN $	; Trace d'un halo
			OPLOT, tab(0,c), tab(1,c), THICK=5, $
				col = !P.BACKGROUND

		IF KEYWORD_SET(SYMBOL) THEN $
			OPLOT, tab(0,c), tab(1,c), PSYM = symb $
		ELSE $
			OPLOT, tab(0,c), tab(1,c)
	ENDIF
ENDFOR
;-----------------------------------------------------------------------------
; Write date in the lower left coroner of the plot frame
IF (KEYWORD_SET(DATE)) THEN BEGIN
	annot = CONVERT_COORD(!x.crange(0) , !y.crange(0), /DATA, /TO_DEVICE )
	XYOUTS, annot(0)+!d.y_ch_size, annot(1)+!d.y_ch_size, chdate, $
		 /DEVICE, font=0
ENDIF
;-----------------------------------------------------------------------------
; If position is plotted as a symbol, write frequency below the plot frame
IF KEYWORD_SET(SYMBOL) THEN BEGIN
	x = 0.5*( !x.crange(0) + !x.crange(1) )
	annot = CONVERT_COORD( !x.crange(0), !y.crange(0), /DATA, /TO_DEVICE )
	bnnot = CONVERT_COORD( !x.crange(1), !y.crange(0), /DATA, /TO_DEVICE )
	annot(0) = annot(0) + FLOAT(symb-4)/4.*(bnnot(0)-annot(0))
	annot(1) = annot(1) - 1.1* !d.y_ch_size
	datann = CONVERT_COORD([annot(0), annot(1)-!d.y_ch_size], /DEVICE, $
		/TO_DATA)
	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

RETURN
END
