PRO RH_PERIODISE,  n_period,  npi,  image,  image_larg

;+ ***********************************************************************
; NAME:
;	RH_PERIODISE
; PURPOSE:
;	Cette procedure calcule l'image periodis'ee sur  n_period  periodes.
;	  On prevoit que  n_period  puisse etre 1.5, 2 ou 4, a l'exclusion 
;	  d'aures valeurs.
; CATEGORY:
;	
; CALLING SEQUENCE:
;    RH_PERIODISE, $
;      INPUTS:
;	PERIOD	nombre de periodes a reproduire.
;	NPI	dimension en x et en y de l'image (en pratique toujours l'image
;		  interferometrique.
;	IMAGE	image a periodiser.
;      OUTPUTS:
;	IMAGE_LARG  : image elargie
; KEYWORD PARAMETERS:
; EXAMPLE:
;
; MODIFICATION HISTORY:
; 01 jul 17	clarification des commentaires, adoption de la notation npi
;		  puisque PERIODISE n'est utilise que pour l'image interfero-
;		  metrique.
;-**************************************************************************
    npt = n_period*npi
    if((n_period ne 1.5) and (n_period ne 2) and (n_period ne 3)) then begin
	print, 'RH_PERIODISE : valeur de periodisation non prevue'
	stop
    endif

    if (n_period le 2) then begin
	    ; l'image est coupee en 4 (numero 1 coin inf gauche, 4 sup droit)
	np2 = npi/2
	im_1 = fltarr(np2, np2)  & im_2 = im_1  & im_3 = im_1  & im_4 = im_1
	im_1(0, 0) = image(0   : np2 - 1,    0   : np2 - 1)
	im_2(0, 0) = image(np2 : npi - 1,    0   : np2 - 1)
	im_3(0, 0) = image(0   : np2 - 1,    np2 : npi - 1)
	im_4(0, 0) = image(np2 : npi - 1,    np2 : npi - 1)
	image_larg = fltarr(npi*2, npi*2)

	image_larg(0    , 0) = im_4
	image_larg(  np2, 0) = im_3
	image_larg(2*np2, 0) = im_4
	image_larg(3*np2, 0) = im_3

	image_larg(0    , np2) = im_2
	image_larg(  np2, np2) = im_1
	image_larg(2*np2, np2) = im_2
	image_larg(3*np2, np2) = im_1

	toto = image_larg(* , 0:npi-1)		; la moitie inferieure.
	image_larg(0, npi) = toto		; image sur champ double
	if ((n_period gt 1.4) and (n_period lt 1.6)) then  begin
	    image_larg = image_larg(np2/2 : 2*npi-1 - np2/2, $
				    np2/2 : 2*npi-1 - np2/2)
	endif
	icon = 0
	if (icon eq 1) then begin
	    im_512   = congrid(image     , 512, 512, cubic=-0.732)
	    im_l_512 = congrid(image_larg, 512, 512, cubic=-0.732)
	    window, 0
	    tvscl, im_512
	    window, 1
	    tvscl, im_l_512
	    stop
	endif
    endif

    if (n_period ge 3) then begin
	image_int = fltarr(npi,  n_period * npi)
	for i=0, n_period-1  do begin
            image_int(*,   i * npi : (i + 1) * npi - 1) = image
	endfor
	image_larg = fltarr(npt, npt)
;	for i=0, n_period - 2   do image_larg = [image_larg, image_int]
	for i=0, n_period - 1   do begin
            image_larg(i * npi : (i + 1) * npi - 1,   *) = image_int
	endfor
    endif

    return
    end			; fin de RH_PERIODISE.
