Viewing contents of file '../idllib/astron/contrib/varosi/vlibm/allpro/deconv_review.pro'
pro DeConv_Review, deconv_result, deconv_infos, obs_image, obs_psf,  $
						SHOW_PSF=show_psf,   $
					DIRECTORY=direct, SAVE_NAME=save_name, $
					LOG10_MIN=Log10, TV_MONITOR=tv_monit,  $
					WAIT_SECONDS=wsec, NO_RESIDUALS=nores
;+
; NAME:
;       DeConv_Review
; PURPOSE:
;	Review previously computed deconvolution results saved by Deconv_Tool.
;	Routine prompts user for file/directory selection.
; CALLING EXAMPLE:
;       deconv_review, deconv_result, deconv_infos, obs_image, obs_psf, /TV
; KEYWORDS:
;       SAVE_NAME = file name (before ".") into which statistics and results
;		were saved. If specified, these files will be restored
;		and reviewed, otherwise directory will be searched and
;		user can select from all files created by DeConv_Tool.
;       DIRECTORY = sub-directory in which to look for files.
;	WAIT_SECONDS = # seconds to wait between reviewing each saved iteration.
;	/NO_RESIDUALS : do not bother computing/displaying residuals etc.
;       /TV_MONITOR : display image results using tv (to bit-mapped display).
;       /SHOW_PSF : display 2D images and 3D surface of PSF, and statistics.
; OUTPUTS:
;       deconv_result = result of deconvolution, final, or whenever paused.
;       deconv_info = structure array containing statistics
;			about deconv results at all saved iterations.
;       obs_image = the original observed image (the data).
;       obs_psf = the point spread function used for deconvolution of data.
; EXTERNAL CALLS:
;	pro find_files
;	function find_dirs
;       pro deconv_analyze
;       pro show_psf
;       pro zoomw
;       pro zoomwp
;       pro color_tables
;       function positivity
;       function get_cursor_win
; COMMON BLOCKS:
;       common deconv_tool, winz	(the window to zoom)
; MODIFICATION HISTORY:
;       Written, Frank Varosi NASA/GSFC 1992.
;-
  common deconv_tool, winz

	if N_elements( wsec ) NE 1 then wsec=1
	if N_elements( save_name ) EQ 1 then goto,REVIEW

	find_files, files_dc, filnams, FILEXT=".0000", DIR=direct
	Nfile = N_elements( filnams )

	directs = find_dirs( NDIR=Ndir, DIR=direct, /LINK, NLINK=NLink )
	Ndir = Ndir + NLink
	Nsel = Nfile + Ndir

	if (Nsel LE 0) then begin
		print," No Files Found"
		return
	   endif

	if (Ndir GT 0) then begin

		dirnams = directs + " --->"

		if (Nfile LE 0) then menu = [ "Select a Folder:", dirnams ]  $
		  else menu = [ "Select a File or Folder:", dirnams, filnams ]

	  endif else menu = [ "Select a File of images:", filnams ]

	if (!D.name EQ "X") OR (!D.name EQ "SUN") then begin

		menu = [menu," ","NOTHING"]
		filsel = wmenu( menu, INIT=1, TITLE=0 ) -1

	  endif else begin

	   endelse

	if (filsel LT 0) OR (filsel GE Nsel) then begin

		print," Nothing selected"
		return

	 endif else if (filsel GE 0) AND (filsel LT Ndir) then begin

		if N_elements( direct ) LE 0 then direct=""

		DeConv_Review, deconv_result, deconv_infos, obs_image, obs_psf,$
				LOG=Log10, SHOW=show_psf, TV=tv_monit, $
				DIR=[ direct , directs(filsel) ], NO_RES=nores
		return

	  endif else save_name = filnams(filsel-Ndir)

REVIEW:
	snw = get_words( save_name, DELIM=["(",")"] )
	if N_elements( snw ) GT 1 then begin
		save_name = snw(0)
		for i=1,N_elements( snw )-1 do $
					save_name = save_name + "*" + snw(i)
	   endif
	files = findfile( dir_path( direct ) + save_name + ".*" )
	nsaved = N_elements( files )
	print," DeConv run:  "+save_name+"  has "+strtrim(nsaved,2)+" files"
	deconv_infos = deconv_struct( nsaved )
	deconv_infos.file = files

;Start the Review:

	deconv_restore, files(0), deconv_infos, IMAGE=obs_image, PSF=obs_psf, $
						COUNT_INDEX=0, STATUS=status
	if keyword_set( tv_monit ) AND $
	   keyword_set( show_psf ) then show_psf, obs_psf, $
					NAME=deconv_infos(0).psf_stats.name
	print," "
	print," press any key to pause..."
	kf = 1

;This is start of the Review Loop:

	for m=1,nsaved-1 do begin

		deconv_restore, files(m), deconv_infos, deconv_result, $
						COUNT_INDEX=kf, STATUS=status

		if (status GT 0) then begin

			DeConv_Analyze, obs_image, obs_psf, deconv_result,  $
				deconv_infos(kf), INIT=(kf LE 1),  $
				FT=psf_ft, NO_RES=nores, LOG=Log10, TV=tv_monit
			kf = kf+1
			zoomwp,winz
			wait,wsec
		   endif

		if strlen( get_kbrd(0) ) GT 0 then begin

		   ASK:	print,string( 7b ) + "       q to quit,"
			if keyword_set( tv_monit ) then begin
				print,"       c for color adjustment,"
				print,"       z to ZOOM,"
			   endif
			print," any other key will continue:"
			key = strlowcase( get_kbrd(1) )

			if (key EQ "c") AND keyword_set( tv_monit ) then begin
				color_tables,INIT=9,IMAGE=get_cursor_win()
				goto,ASK
			 endif else if (key EQ "z") AND $
				keyword_set( tv_monit ) then begin
				winz = get_cursor_win()
				zoomw,winz
				goto,ASK
			  endif else if (key EQ "q") then goto,QUIT

			print," continuing... press any key to pause..."
		   endif

	  endfor	;end of Review Loop.
QUIT:
	kf = kf-1
	if N_elements( deconv_result ) GT 0 then $
			deconv_result = positivity( deconv_result, $
					EPS=deconv_infos(kf).positivity_eps )
	deconv_infos(kf).select_flag = 1
	deconv_infos = deconv_infos(1:kf)
return
end