
;+ ***********************************************************************
; NAME:
;	NRH_DISP_GRIMAGE
;
; PURPOSE:
;	Cette procedure affiche une image dans une fenetre a une position
; donnee, colonnes lignes
;
; CATEGORY:
;	VISUALISATION NRH
;
; CALLING SEQUENCE:
;	NRH_DISP_GRIMAGE, Data, Str_im, str
;
; INPUTS:
;	DATA	Tableau contenant l'image
;	STR_IM	Structure resultant de la lecture de l'image
;	STR	Structure definie dans GR_IMAGES.PRO
;
; OUTPUTS:
;	Au retour STR.CRLI et STR.CRCO sont modifie pour pointe sur la 
; prochaine zone d'image
;
; PROCEDURE:
;	You can describe the foobar superfloatation method being used here.
;	You might not need this section for your routine.
;
; EXAMPLE:
;	NRH_DISP_GRIMAGE, DATA, Str_im, Str_grim
;		Visualise a la position suivante l'image correspondant 
; au parametre V	
;
; MODIFICATION HISTORY:
;	Ecrit par: J Bonmartin le 07/11/97 (bonmartin@obspm.fr)
;		le 09/11/98 deplace l'inscription de la date (JB)
;       Modif A. Bouteille 05/11/2007  Cercle optique manquant
;        pour les selections de region : TVcircle_clip remplace
;        TVcircle et gere les xrange et yrange)
;       06/11/2008  Gestion des images 2D 3D(true color)  
;-*******************************************************************

PRO NRH_DISP_GRIMAGE, Data, Str_im, Str_lim, Str

sz= size(data)
Xcen = Str_im.Crpixx
Ycen = Str_im.Crpixy
Ray  = Str_im.Ray
Freq = Str_im.freq
date = Str_im.Date
shr =  Str_im.Time

wset, str.crwin
	interpx= FLOAT(str.dim) /FLOAT( str_lim.xf-str_lim.xd)
	interpy= FLOAT(str.dim) /FLOAT( str_lim.yf-str_lim.yd)
		rap = interpx
		if interpx gt interpy then rap = interpy
	nbpx = FIX((str_lim.xf-str_lim.xd+1)*rap)
	nbpy = FIX((str_lim.yf-str_lim.yd+1)*rap)

	if sz(0) eq 2 then IMAGE= Congrid(Data(str_lim.xd:str_lim.xf,$
			str_lim.yd:str_lim.yf),nbpx, nbpy,/CUBIC)
        if sz(0) eq 3 then BEGIN
            data_extr = Data(*,str_lim.xd:str_lim.xf,str_lim.yd:str_lim.yf)
            image     = Congrid(data_extr,3,nbpx, nbpy,/CUBIC)
        ENDIF
	POSITION = str.crli * str.co + str.crco
        low_left_x = str.crco * str.dim
        low_left_y = (str.li - str.crli -1) * str.dim

       if sz(0) eq 2 then TVSCL, Image,str.crco * str.dim,(str.li - str.crli -1) * str.dim else $
       TVSCL, Image,str.crco * str.dim,(str.li - str.crli -1) * str.dim, true = 1
       Xc = (str.crco * str.dim) +((Xcen-str_lim.Xd) *rap)
       Yc = (str.li - str.crli -1) * str.dim +((Ycen-Str_lim.Yd)*rap)

;		Trace du Cercle optique
	XLF = IND_RS(Str_lim.Xd,Xcen,Ray)
	XLS = IND_RS(Str_lim.Xf,Xcen,Ray)
	YLF = IND_RS(Str_lim.Yd,Ycen,Ray)
	YLS = IND_RS(Str_lim.Yf,Ycen,Ray)
        xrange = [low_left_x,low_left_x + nbpx ]
        yrange = [low_left_y,low_left_y + nbpy ]
        Tvcircle_clip,Ray*rap, Xc, Yc, XRANGE = XRANGE, YRANGE = YRANGE

	XT=(str.crco * str.dim) + (Str.dim/2)
	YT=((str.li - str.crli -1)*Str.dim)

       XYOUTS,Xt,Yt+Str.dim-10, $
             STRMID(Str_im.Physpar,6,1)+'-'+STRMID(freq,0,5)+'MHz', $
              Alignment=0.5,charsize=0.5,/device

      XYOUTS,Xt,Yt+2, $
              date+' - '+shr, $
              Alignment=0.5,charsize=0.5,/device

       Position = Position + 1
       str.Crco = Position MOD str.co
       str.crli = Position / str.co

 end
