
;+ ***********************************************************************
; NAME:
;	NRH_HSI_IMAGE
;
; PURPOSE:
;	This procedure creates a serie of simulated HESSI images and writes a
;	FITS file for each image 
;	The images are with two sources, and a motion on one source
;
; CATEGORY:
;	NRH_HESSI
;
; CALLING SEQUENCE:
;	NRH_HSI_IMAGE
;
; INPUTS:
;	The user is called for the number of images to create
;
; KEYWORD PARAMETERS:
;	CLEAN	Simulation by CLEAN Method instead of BACK PROJECTION
;	PLOT	to plot each image
;	REPERT	the directory where to write the files
;
; OUTPUTS:
;	FITS files with one image
;	The name of the files is
;		hessi_image_YYYYMMDD_HHMMSS_is.fts
;			YYYYMMDD, HHMMSS internal time and date of the computer
;
; COMMON BLOCKS:
;	No
;
; PROCEDURE:
;	This procedure use the simulation procedures of HESSI
;
; EXAMPLE:
;	Please provide a simple example here
;
; MODIFICATION HISTORY:
;	Ecrit par:
;-*******************************************************************

PRO NRH_HSI_IMAGE ,Nbi,CLEAN= Clean, PLOT=Plot, REPERT= Repert

IF NOT KEYWORD_SET(REPERT) THEN Repert=''
IF N_PARAMS(NRH_HSI_IMAGE) EQ 0 THEN $
		READ,'Number of IMAGES: ', NBI

O = HSI_IMAGE()
model=replicate({gaussian_source_str},2)
model.amplitude=[4.0,4.0]
model.xysigma=[[6.,6.],[7.,7.]]
	o->set,sim_time_range=[0,4]
	o->set,sim_energy_band=[13.,24.]
	o->set,sim_plot=1.e3

FOR I= 0 , Nbi-1 DO BEGIN
	xy=[[51,-422],[167-(I*2),-351-(I*2)]]
	xyoffset=avg(xy,1)
	xypos =xy-xyoffset#(fltarr(1,2)+1.)
	model.xypos=xypos
	o->set,sim_model=model
	o->set,sim_xyoffset=xyoffset
	o->set,xyoffset=xyoffset

	IF KEYWORD_SET(CLEAN) THEN $
			o->set,image_alg='clean'
	IF KEYWORD_SET(PLOT) THEN o->plot
	Im =O->GETDATA()

	NRH_HSITIME,Date,Heure
		print,'Time:', heure

	FILE= 'hsi_image_'+date+'_'+heure+'_is.fts'
		O->FITSWRITE,FITSFILE= Repert+File

ENDFOR

END