PRO NRH_IMAGEREF, Data, Xcen, Ycen, rayon, str_lim, $
		CADRE=cadre, ANNOTATION=annotation, LIMB=limb,  $
		SCALE=scale, LABEL=Label, AXIS=Axis, CHARSIZE=Charsize

;+ ***********************************************************************
; NAME:
;	NRH_IMAGEREF
;
; PURPOSE:
;	Cette procedure visualise une image dans une fenetre pouvant servir
;	de reference a la superposition de contours ou de points 
;
; CATEGORY:
;	Visualisation
;
; CALLING SEQUENCE:
;	NRH_IMAGEREF, Data, Xcen, Ycen, rayon, str_lim
;
; INPUTS:
;	DATA	Image a 2 dimensions
;	XCEN	Coordonnee X du centre de l'image, en pixels
;	YCEN	Coordonnee Y
;	RAY	Dimension du rayon solaire en pixels
;	STR_LIM	Limites du trace, structure NRH_STR_LIM
;
; KEYWORD PARAMETERS:
;	CADRE	trace du cadre si presen
;	ANNOTATION	Annotation du cadre si present
;	LIMB	Trace du limbe si present
;	SCALE	TVSCL si tresent sinon TV
;	LABEL	Label associe a l'image
;	AXIS	Label des axes X, Y si present
;	CHARSIZE Dimension des caracteres (0.8 par defaut)
;
; OUTPUTS:
;
; COMMON BLOCKS:
;	Non
;
; PROCEDURE:
;	Cette procedure utilse NRH_PLOT_REF pour fixer les coordonnees
;	correspondant a l'image afin de pouvoir faire correspondre les
;	pixels et les coordonnees d'un point
;	If the device is set to 'PS' (interactively) plots are send to 
;	postcript file
;
; EXAMPLE:
;	
;
; MODIFICATION HISTORY:
;	Ecrit par: J Bonmartin (obspm.fr) le 07/09/98
;			d'apres les programmes de L Klein
;	le 08/01/99 Rajout des Keywords AXIS, CHARSIZE
;	le 22/11/99 modif du calcul de Npix
;	le 25/04/01 Test de sortie Postscript par !D.name(jb)
;       le 06/11/2008 Gestion des images 3D (true colors)
;-*******************************************************************


	IF NOT KEYWORD_SET(LABEL) THEN LABEL=''
	IF NOT KEYWORD_SET(CHARSIZE) THEN Charsize = 0.8

IF !D.name EQ 'X' THEN WINDOW,/FREE	
	FRAME= fltarr(4)
		Frame(0)= Ind_rs(str_lim.xd, Xcen, Rayon)
		Frame(1)= Ind_rs(str_lim.yd, Ycen, Rayon)
		Frame(2)= Ind_rs(str_lim.xf, Xcen, Rayon)
		Frame(3)= Ind_rs(str_lim.Yf, Ycen, Rayon)	
	NRH_PLOT_REF, Frame, /NOERASE	;pour fixer les coordonnees

	CENTRE=[Xcen, Ycen]

	isz = SIZE(data)
	if isz(0) eq 2 then isz = [ 0, 0, isz(1:2)]
	if isz(0) eq 3 then isz = [ 0, 0, isz(2:3)]


	NPIX= INTARR(4)
	Npix[0] = Str_lim.Xd & Npix[1]= Str_lim.Yd
	Npix[2] = Str_lim.Xf & Npix[3]= Str_lim.Yf

	FOR i=2,3 DO IF npix(i) GE isz(i) THEN npix(i)=isz(i)-1
	FOR i=0,1 DO IF npix(i) LT 0 THEN npix(i) = 0

; Bords inferieur gauche et superieur droit du trace
	bordinf =FLOAT( npix(0:1)-centre ) / rayon
	bordsup =FLOAT( npix(2:3)-centre ) / rayon
	bordinf_d = CONVERT_COORD(bordinf, /DATA, /TO_DEVICE)
	bordsup_d = CONVERT_COORD(bordsup, /DATA, /TO_DEVICE)
	sx = bordsup_d - bordinf_d

; le tableau data a 2 ou 3 dimensions.
IF size(data,/n_dim) eq 2 THEN BEGIN
; Trace sur ecran X:
    IF !D.name EQ 'X' THEN BEGIN	
	IF npix(0) LT npix(2) AND npix(1) LT npix(3) THEN BEGIN
		IF KEYWORD_SET(scale) THEN $
			TVSCL,congrid(Data(npix(0):npix(2),$
				npix(1):npix(3)),sx(0), sx(1), /CUBIC), $
				bordinf_d(0), bordinf_d(1) $
		ELSE $
			TV,congrid(Data(npix(0):npix(2),npix(1):npix(3)),$
				sx(0), sx(1), /CUBIC), $
				bordinf_d(0), bordinf_d(1)
	ENDIF
	NRH_PLOT_REF, frame, CADRE=cadre, LIMB=limb, ANNOTATION=annotation, $
		/NOERASE, AXIS = Axis, CHARSIZE = charsize
	XYOUTS,300,35, Label,/Device, ALIGNMENT=0.5, CHARSIZE=Charsize
    ENDIF

; Trace POSTSCRIPT
    IF !D.name EQ 'PS' THEN BEGIN
		NRH_PLOT_REF, frame, NOERASE=noerase
		IF KEYWORD_SET(scale) THEN $
			TVSCL, Data(npix(0):npix(2),npix(1):npix(3)),$
				bordinf(0), bordinf(1), $
				xsize = bordsup(0)-bordinf(0),$
				ysize = bordsup(1)-bordinf(1),$
				/DATA $
		ELSE $
			TV, Data(npix(0):npix(2),npix(1):npix(3)),$
				bordinf(0), bordinf(1), $
				xsize = bordsup(0)-bordinf(0),$
				ysize = bordsup(1)-bordinf(1), /DATA
		NRH_PLOT_REF, frame, CADRE=cadre, LIMB=limb, $
			ANNOTATION=annotation, /NOERASE, AXIS = Axis
		XYOUTS,100,15, LABEL,/Device,/Alignment, CHARSIZE=Charsize
            ENDIF
        ENDIF
IF size(data,/n_dim) eq 3 THEN BEGIN
; Trace sur ecran X:
    IF !D.name EQ 'X' THEN BEGIN	
	IF npix(0) LT npix(2) AND npix(1) LT npix(3) THEN BEGIN
                data_extr = Data(*,npix(0):npix(2),npix(1):npix(3))
                data_win  = congrid(data_extr, 3, sx(0), sx(1), /CUBIC)
		IF KEYWORD_SET(scale) THEN BEGIN
			TVSCL, data_win,$
			       bordinf_d(0), bordinf_d(1),true = 1 
                END ELSE BEGIN
			TV,data_win, $
				bordinf_d(0), bordinf_d(1),true = 1
                ENDELSE
	ENDIF
	NRH_PLOT_REF, frame, CADRE=cadre, LIMB=limb, ANNOTATION=annotation, $
		/NOERASE, AXIS = Axis, CHARSIZE = charsize
	XYOUTS,300,35, Label,/Device, ALIGNMENT=0.5, CHARSIZE=Charsize
    ENDIF

; Trace POSTSCRIPT
    IF !D.name EQ 'PS' THEN BEGIN
		NRH_PLOT_REF, frame, NOERASE=noerase
		IF KEYWORD_SET(scale) THEN $
			TVSCL, Data(*,npix(0):npix(2),npix(1):npix(3)),$
				bordinf(0), bordinf(1), $
				xsize = bordsup(0)-bordinf(0),$
				ysize = bordsup(1)-bordinf(1),$
				/DATA , true=1 $
		ELSE $
			TV, Data(*,npix(0):npix(2),npix(1):npix(3)),$
				bordinf(0), bordinf(1), $
				xsize = bordsup(0)-bordinf(0),$
				ysize = bordsup(1)-bordinf(1),true=1, /DATA
		NRH_PLOT_REF, frame, CADRE=cadre, LIMB=limb, $
			ANNOTATION=annotation, /NOERASE, AXIS = Axis
		XYOUTS,100,15, LABEL,/Device,/Alignment, CHARSIZE=Charsize
            ENDIF
        ENDIF


END







